Google ads integration for all modules:
1. Webseries 2. karaoke 3. audio books 4. GamesActivity 5. GamePlayerActivity 6. KaraokePlayerActivity 5. FMActivity Home2Fragment ad size update
This commit is contained in:
@@ -17,6 +17,10 @@ import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||
import com.google.android.gms.ads.AdListener
|
||||
import com.google.android.gms.ads.AdRequest
|
||||
import com.google.android.gms.ads.AdSize
|
||||
import com.google.android.gms.ads.AdView
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
import com.jwplayer.pub.api.media.playlists.PlaylistItem
|
||||
import com.woka.R
|
||||
@@ -34,6 +38,8 @@ import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityAudioBooksBinding
|
||||
import com.woka.databinding.DialogModuleShowerBinding
|
||||
import com.woka.googleads.AUDIO_BOOKS_BANNER_AD
|
||||
import com.woka.googleads.AUDIO_BOOKS_TRAILER_AD
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.players.models.VideoPlayList
|
||||
import com.woka.players.models.VideoViewData
|
||||
@@ -68,7 +74,7 @@ class AudioBooksActivity : WokaBaseActivity() {
|
||||
|
||||
private lateinit var playerLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
private var adLoaded = false
|
||||
private var customAdLoaded = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -99,6 +105,8 @@ class AudioBooksActivity : WokaBaseActivity() {
|
||||
|
||||
noSignInDialog = NoSignInDialog(this)
|
||||
|
||||
customAdLoaded = false
|
||||
|
||||
initLaunchers()
|
||||
|
||||
initViews()
|
||||
@@ -107,10 +115,10 @@ class AudioBooksActivity : WokaBaseActivity() {
|
||||
|
||||
clickEvents()
|
||||
|
||||
setObservers()
|
||||
|
||||
loadAds()
|
||||
|
||||
setObservers()
|
||||
|
||||
if (!viewModel.audioBookLiveData.isInitialized) {
|
||||
viewModel.loadAudioSongs()
|
||||
}
|
||||
@@ -202,7 +210,7 @@ class AudioBooksActivity : WokaBaseActivity() {
|
||||
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
|
||||
adLoaded = true
|
||||
customAdLoaded = true
|
||||
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
@@ -298,6 +306,10 @@ class AudioBooksActivity : WokaBaseActivity() {
|
||||
newList.size
|
||||
)
|
||||
}
|
||||
|
||||
if (!customAdLoaded){
|
||||
loadGoogleAds()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,9 +342,11 @@ class AudioBooksActivity : WokaBaseActivity() {
|
||||
}
|
||||
|
||||
private fun loadTrailerData(audioBookData: AudioBookData) {
|
||||
if (adLoaded) return
|
||||
|
||||
binding.apply {
|
||||
if (customAdLoaded) {
|
||||
return
|
||||
}
|
||||
|
||||
trailerView.show()
|
||||
adjustTrailerImage()
|
||||
|
||||
@@ -604,4 +618,66 @@ class AudioBooksActivity : WokaBaseActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadGoogleAds(){
|
||||
if (customAdLoaded) return
|
||||
|
||||
// banner ad
|
||||
val adView = AdView(this)
|
||||
|
||||
adView.adListener = object : AdListener(){
|
||||
override fun onAdLoaded() {
|
||||
super.onAdLoaded()
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
binding.adBtn.hide()
|
||||
|
||||
adjustTrailerImage()
|
||||
}
|
||||
}
|
||||
|
||||
adView.setAdSize(
|
||||
AdSize.LARGE_BANNER
|
||||
)
|
||||
adView.adUnitId = AUDIO_BOOKS_BANNER_AD
|
||||
binding.toolbarAdsContainer.addView(adView)
|
||||
adView.loadAd(AdRequest.Builder().build())
|
||||
|
||||
// full ad at masila image
|
||||
binding.trailerImage.post {
|
||||
val adView2 = AdView(this)
|
||||
|
||||
adView2.adListener = object : AdListener(){
|
||||
override fun onAdLoaded() {
|
||||
super.onAdLoaded()
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
binding.adBtn.hide()
|
||||
|
||||
binding.adsContainer.setBackgroundResource(R.color.black)
|
||||
|
||||
adjustTrailerImage()
|
||||
|
||||
customAdLoaded = true
|
||||
}
|
||||
}
|
||||
|
||||
adView2.setAdSize(
|
||||
AdSize(
|
||||
binding.trailerImage.width / resources.displayMetrics.density.toInt(),
|
||||
binding.trailerImage.height / resources.displayMetrics.density.toInt(),
|
||||
)
|
||||
)
|
||||
adView2.adUnitId = AUDIO_BOOKS_TRAILER_AD
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView2)
|
||||
|
||||
adView2.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,18 @@
|
||||
package com.woka.googleads
|
||||
|
||||
const val TEST_INTERSTITIAL_AD = "ca-app-pub-5699008063638916/6300144761"
|
||||
// WEB SERIES
|
||||
const val WEB_SERIES_TRAILER_AD = "ca-app-pub-5699008063638916/6110095586"
|
||||
const val WEB_SERIES_BANNER_AD = "ca-app-pub-5699008063638916/6110095586"
|
||||
|
||||
// KARAOKE
|
||||
const val KARAOKE_TRAILER_AD = "ca-app-pub-5699008063638916/6110095586"
|
||||
const val KARAOKE_BANNER_AD = "ca-app-pub-5699008063638916/6110095586"
|
||||
|
||||
// AUDIO BOOKS
|
||||
const val AUDIO_BOOKS_TRAILER_AD = "ca-app-pub-5699008063638916/6110095586"
|
||||
const val AUDIO_BOOKS_BANNER_AD = "ca-app-pub-5699008063638916/6110095586"
|
||||
|
||||
// GAME
|
||||
const val GAME_TRAILER_AD = "ca-app-pub-5699008063638916/6110095586"
|
||||
const val GAME_BANNER_AD = "ca-app-pub-5699008063638916/6110095586"
|
||||
const val GAME_INTERSTITIAL_AD = "ca-app-pub-5699008063638916/6300144761"
|
||||
@@ -11,13 +11,11 @@ import android.content.IntentFilter
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewGroup.MarginLayoutParams
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.fragment.app.Fragment
|
||||
@@ -45,7 +43,6 @@ import com.woka.streamingurls.StreamingUrlRepository
|
||||
import com.woka.userPreference.UserType
|
||||
import com.woka.userdata.userDataModels.UserDataResponse
|
||||
import com.woka.utils.ProgressView
|
||||
import com.woka.utils.TAG
|
||||
import com.woka.utils.changeLocale
|
||||
import com.woka.utils.hide
|
||||
import com.woka.utils.scaleAnimate
|
||||
@@ -117,13 +114,11 @@ class Home1Fragment : Fragment() {
|
||||
// Calculate aspect ratio
|
||||
val aspectRatio = screenHeight.toFloat() / screenWidth.toFloat()
|
||||
|
||||
Log.d(TAG, "setUpDynamicViewSizes: $aspectRatio")
|
||||
|
||||
when {
|
||||
aspectRatio > 2.1 -> {
|
||||
// screen is taller
|
||||
}
|
||||
aspectRatio > 2 -> {
|
||||
aspectRatio > 1.85 -> {
|
||||
// screen is normal size
|
||||
}
|
||||
else -> {
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import androidx.core.view.updateMargins
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.bumptech.glide.Glide
|
||||
@@ -27,6 +28,7 @@ import com.woka.audiobooks.views.AudioBooksActivity
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.FragmentHome2Binding
|
||||
import com.woka.googleads.GAME_BANNER_AD
|
||||
import com.woka.home.viewmodels.HomeViewModel
|
||||
import com.woka.home.views.FMActivity
|
||||
import com.woka.karaoke.views.KaraokeActivity
|
||||
@@ -84,14 +86,16 @@ class Home2Fragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun loadGoogleAds() {
|
||||
binding.adView.adListener = object : AdListener() {
|
||||
override fun onAdFailedToLoad(p0: LoadAdError) {
|
||||
super.onAdFailedToLoad(p0)
|
||||
Log.d("aditya_ad_testing", "onAdFailedToLoad: $p0")
|
||||
}
|
||||
}
|
||||
|
||||
binding.adView.loadAd(
|
||||
val adView = AdView(requireContext())
|
||||
|
||||
adView.adUnitId = GAME_BANNER_AD
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, AdSize.AUTO_HEIGHT))
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
|
||||
@@ -11,10 +11,14 @@ import androidx.media3.common.MediaItem
|
||||
import androidx.media3.common.PlaybackException
|
||||
import androidx.media3.common.Player
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import com.google.android.gms.ads.AdRequest
|
||||
import com.google.android.gms.ads.AdSize
|
||||
import com.google.android.gms.ads.AdView
|
||||
import com.woka.R
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityFmactivityBinding
|
||||
import com.woka.googleads.GAME_BANNER_AD
|
||||
import com.woka.userdata.UserRepository
|
||||
import com.woka.userdata.userDataModels.VideoViewRequestData
|
||||
import com.woka.utils.TAG
|
||||
@@ -72,6 +76,8 @@ class FMActivity : WokaBaseActivity() {
|
||||
|
||||
setObservers()
|
||||
|
||||
loadGoogleAds()
|
||||
|
||||
playbackStartTime = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
@@ -198,6 +204,22 @@ class FMActivity : WokaBaseActivity() {
|
||||
})
|
||||
}
|
||||
|
||||
private fun loadGoogleAds() {
|
||||
|
||||
val adView = AdView(this)
|
||||
|
||||
adView.adUnitId = GAME_BANNER_AD
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, 60))
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
private fun updateVolumeButtons(){
|
||||
val volume = (Math.round(player.volume * 10) / 10.0).toFloat()
|
||||
Log.d(TAG, "updateVolumeButtons: $volume")
|
||||
|
||||
@@ -188,8 +188,8 @@ class HomeActivity : WokaBaseActivity(),
|
||||
(getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager).unregisterNetworkCallback(networkCallback)
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
RemoteSync.syncClickEvents()
|
||||
RemoteSync.syncAdClickEvents()
|
||||
// RemoteSync.syncClickEvents()
|
||||
// RemoteSync.syncAdClickEvents()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +31,14 @@ import androidx.media3.common.PlaybackException
|
||||
import androidx.media3.common.Player
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import com.google.android.gms.ads.AdRequest
|
||||
import com.google.android.gms.ads.AdSize
|
||||
import com.google.android.gms.ads.AdView
|
||||
import com.woka.R
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityKaraokePlayerrBinding
|
||||
import com.woka.googleads.GAME_BANNER_AD
|
||||
import com.woka.players.models.PlayBackState
|
||||
import com.woka.userdata.UserRepository
|
||||
import com.woka.userdata.userDataModels.VideoViewRequestData
|
||||
@@ -158,6 +162,8 @@ class KaraokePlayerActivity : WokaBaseActivity() {
|
||||
|
||||
loadAudioFromUrl()
|
||||
|
||||
loadGoogleAds()
|
||||
|
||||
onBackPressedDispatcher.addCallback {
|
||||
if (playbackStartTime > 0) {
|
||||
val elapsed = System.currentTimeMillis() - playbackStartTime
|
||||
@@ -459,7 +465,7 @@ class KaraokePlayerActivity : WokaBaseActivity() {
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
val url = URL(karaokePlayerData?.karaokeVideoUrl)
|
||||
val url = URL("https://content.jwplatform.com/videos/699dmCGz-7bKGpMKj.mp4")
|
||||
copyStreamToFile(url.openConnection().getInputStream(), File(karaokeMusicPath))
|
||||
runOnUiThread {
|
||||
binding.recorderView.show()
|
||||
@@ -477,6 +483,22 @@ class KaraokePlayerActivity : WokaBaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadGoogleAds() {
|
||||
|
||||
val adView = AdView(this)
|
||||
|
||||
adView.adUnitId = GAME_BANNER_AD
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, 100))
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
private fun playStopPlayingAudio() {
|
||||
when (recordingState) {
|
||||
RecordingState.NOT_RECORDING -> {
|
||||
|
||||
@@ -18,6 +18,10 @@ import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||
import com.google.android.gms.ads.AdListener
|
||||
import com.google.android.gms.ads.AdRequest
|
||||
import com.google.android.gms.ads.AdSize
|
||||
import com.google.android.gms.ads.AdView
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
import com.woka.R
|
||||
import com.woka.WokaApp.Companion.userPrefs
|
||||
@@ -28,6 +32,8 @@ import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityKaraokeBinding
|
||||
import com.woka.databinding.DialogModuleShowerBinding
|
||||
import com.woka.googleads.KARAOKE_BANNER_AD
|
||||
import com.woka.googleads.KARAOKE_TRAILER_AD
|
||||
import com.woka.karaoke.KaraokeRepository
|
||||
import com.woka.karaoke.adapters.ContinueKaraokeAdapter
|
||||
import com.woka.karaoke.adapters.KaraokeAdapter
|
||||
@@ -68,7 +74,7 @@ class KaraokeActivity : WokaBaseActivity() {
|
||||
|
||||
private lateinit var playerLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
private var adLoaded = false
|
||||
private var customAdLoaded = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -101,6 +107,8 @@ class KaraokeActivity : WokaBaseActivity() {
|
||||
|
||||
noSignInDialog = NoSignInDialog(this)
|
||||
|
||||
customAdLoaded = false
|
||||
|
||||
initLaunchers()
|
||||
|
||||
initViews()
|
||||
@@ -109,10 +117,10 @@ class KaraokeActivity : WokaBaseActivity() {
|
||||
|
||||
clickEvents()
|
||||
|
||||
setObservers()
|
||||
|
||||
loadAds()
|
||||
|
||||
setObservers()
|
||||
|
||||
if (!viewModel.karaokeLiveData.isInitialized) {
|
||||
viewModel.loadKaraokeSongs()
|
||||
}
|
||||
@@ -202,9 +210,11 @@ class KaraokeActivity : WokaBaseActivity() {
|
||||
}
|
||||
|
||||
private fun loadTrailerData(karaokeData: KaraokeData) {
|
||||
if (adLoaded) return
|
||||
|
||||
binding.apply {
|
||||
if (customAdLoaded) {
|
||||
return
|
||||
}
|
||||
|
||||
trailerView.show()
|
||||
adjustTrailerImage()
|
||||
|
||||
@@ -522,6 +532,10 @@ class KaraokeActivity : WokaBaseActivity() {
|
||||
newList.size
|
||||
)
|
||||
}
|
||||
|
||||
if (!customAdLoaded){
|
||||
loadGoogleAds()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -565,7 +579,7 @@ class KaraokeActivity : WokaBaseActivity() {
|
||||
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
|
||||
adLoaded = true
|
||||
customAdLoaded = true
|
||||
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
@@ -599,4 +613,66 @@ class KaraokeActivity : WokaBaseActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadGoogleAds(){
|
||||
if (customAdLoaded) return
|
||||
|
||||
// banner ad
|
||||
val adView = AdView(this)
|
||||
|
||||
adView.adListener = object : AdListener(){
|
||||
override fun onAdLoaded() {
|
||||
super.onAdLoaded()
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
binding.adBtn.hide()
|
||||
|
||||
adjustTrailerImage()
|
||||
}
|
||||
}
|
||||
|
||||
adView.setAdSize(
|
||||
AdSize.LARGE_BANNER
|
||||
)
|
||||
adView.adUnitId = KARAOKE_BANNER_AD
|
||||
binding.toolbarAdsContainer.addView(adView)
|
||||
adView.loadAd(AdRequest.Builder().build())
|
||||
|
||||
// full ad at masila image
|
||||
binding.trailerImage.post {
|
||||
val adView2 = AdView(this)
|
||||
|
||||
adView2.adListener = object : AdListener(){
|
||||
override fun onAdLoaded() {
|
||||
super.onAdLoaded()
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
binding.adBtn.hide()
|
||||
|
||||
binding.adsContainer.setBackgroundResource(R.color.black)
|
||||
|
||||
adjustTrailerImage()
|
||||
|
||||
customAdLoaded = true
|
||||
}
|
||||
}
|
||||
|
||||
adView2.setAdSize(
|
||||
AdSize(
|
||||
binding.trailerImage.width / resources.displayMetrics.density.toInt(),
|
||||
binding.trailerImage.height / resources.displayMetrics.density.toInt(),
|
||||
)
|
||||
)
|
||||
adView2.adUnitId = KARAOKE_TRAILER_AD
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView2)
|
||||
|
||||
adView2.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,8 @@ import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.DialogContinueEpisodeBinding
|
||||
import com.woka.databinding.FragmentWebSeriesBinding
|
||||
import com.woka.googleads.WEB_SERIES_BANNER_AD
|
||||
import com.woka.googleads.WEB_SERIES_TRAILER_AD
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.players.models.VideoPlayList
|
||||
import com.woka.players.models.VideoViewData
|
||||
@@ -49,7 +51,6 @@ import com.woka.utils.hide
|
||||
import com.woka.utils.lightStatusBar
|
||||
import com.woka.utils.setVisibility
|
||||
import com.woka.utils.show
|
||||
import com.woka.utils.toast
|
||||
import com.woka.webseries.adapters.ContinueEpisodeAdapter
|
||||
import com.woka.webseries.adapters.SpinnerAdapter
|
||||
import com.woka.webseries.adapters.WebSeriesShowAdapter
|
||||
@@ -76,6 +77,8 @@ class WebSeriesFragment : Fragment() {
|
||||
|
||||
private lateinit var playerLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
private var isAdLoaded = false
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
@@ -92,6 +95,9 @@ class WebSeriesFragment : Fragment() {
|
||||
it.window.statusBarColor = 0
|
||||
it.window.lightStatusBar(false)
|
||||
}
|
||||
|
||||
isAdLoaded = false
|
||||
loadingMore = false
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@@ -115,7 +121,7 @@ class WebSeriesFragment : Fragment() {
|
||||
|
||||
setObservers()
|
||||
|
||||
loadAds()
|
||||
loadCustomAds()
|
||||
|
||||
if (!viewModel.showCategoryLiveData.isInitialized) {
|
||||
viewModel.loadCategories()
|
||||
@@ -395,7 +401,7 @@ class WebSeriesFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadAds(){
|
||||
private fun loadCustomAds(){
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let { ads ->
|
||||
val theme1ads = ads.filter { it.for_page == ForPage.WEB_SERIES.value}
|
||||
@@ -405,6 +411,8 @@ class WebSeriesFragment : Fragment() {
|
||||
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
|
||||
isAdLoaded = true
|
||||
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerTxt.hide()
|
||||
|
||||
@@ -438,6 +446,30 @@ class WebSeriesFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun loadGoogleAds(){
|
||||
if (isAdLoaded) return
|
||||
|
||||
// banner ad
|
||||
val adView = AdView(requireContext())
|
||||
|
||||
adView.adListener = object : AdListener(){
|
||||
override fun onAdLoaded() {
|
||||
super.onAdLoaded()
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerTxt.hide()
|
||||
binding.adBtn.hide()
|
||||
|
||||
adjustMasilaImage()
|
||||
}
|
||||
}
|
||||
|
||||
adView.setAdSize(
|
||||
AdSize.LARGE_BANNER
|
||||
)
|
||||
adView.adUnitId = WEB_SERIES_BANNER_AD
|
||||
binding.toolbarAdsContainer.addView(adView)
|
||||
adView.loadAd(AdRequest.Builder().build())
|
||||
|
||||
// full ad at masila image
|
||||
binding.masilaImage.post {
|
||||
val adView2 = AdView(requireContext())
|
||||
|
||||
@@ -446,6 +478,9 @@ class WebSeriesFragment : Fragment() {
|
||||
super.onAdLoaded()
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerTxt.hide()
|
||||
binding.adBtn.hide()
|
||||
|
||||
binding.adsContainer.setBackgroundResource(R.color.black)
|
||||
|
||||
adjustMasilaImage()
|
||||
}
|
||||
@@ -457,7 +492,7 @@ class WebSeriesFragment : Fragment() {
|
||||
binding.masilaImage.height / resources.displayMetrics.density.toInt(),
|
||||
)
|
||||
)
|
||||
adView2.adUnitId = "ca-app-pub-5699008063638916/6110095586"
|
||||
adView2.adUnitId = WEB_SERIES_TRAILER_AD
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView2)
|
||||
|
||||
@@ -10,10 +10,14 @@ import android.webkit.WebSettings
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import com.google.android.gms.ads.AdRequest
|
||||
import com.google.android.gms.ads.AdSize
|
||||
import com.google.android.gms.ads.AdView
|
||||
import com.woka.R
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityGamePlayerBinding
|
||||
import com.woka.googleads.GAME_BANNER_AD
|
||||
import com.woka.userdata.UserRepository
|
||||
import com.woka.userdata.userDataModels.VideoViewRequestData
|
||||
import com.woka.utils.DecisionDialog
|
||||
@@ -61,6 +65,8 @@ class GamePlayerActivity : WokaBaseActivity() {
|
||||
initWebView(it.gameUrl)
|
||||
}
|
||||
|
||||
loadGoogleAds()
|
||||
|
||||
binding.webView.setOnTouchListener { _, event ->
|
||||
if (event.action == MotionEvent.ACTION_DOWN){
|
||||
clicksCount++
|
||||
@@ -165,4 +171,20 @@ class GamePlayerActivity : WokaBaseActivity() {
|
||||
}
|
||||
decisionDialog.show()
|
||||
}
|
||||
|
||||
private fun loadGoogleAds() {
|
||||
|
||||
val adView = AdView(this)
|
||||
|
||||
adView.adUnitId = GAME_BANNER_AD
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, 60))
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,10 @@ import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||
import com.google.android.gms.ads.AdListener
|
||||
import com.google.android.gms.ads.AdRequest
|
||||
import com.google.android.gms.ads.AdSize
|
||||
import com.google.android.gms.ads.AdView
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
import com.woka.R
|
||||
import com.woka.WokaApp.Companion.userPrefs
|
||||
@@ -26,8 +30,10 @@ import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityGamesBinding
|
||||
import com.woka.databinding.DialogModuleShowerBinding
|
||||
import com.woka.googleads.GAME_BANNER_AD
|
||||
import com.woka.googleads.InterstitialAds
|
||||
import com.woka.googleads.TEST_INTERSTITIAL_AD
|
||||
import com.woka.googleads.GAME_INTERSTITIAL_AD
|
||||
import com.woka.googleads.GAME_TRAILER_AD
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.userPreference.UserType
|
||||
import com.woka.utils.NoSignInDialog
|
||||
@@ -63,7 +69,7 @@ class GamesActivity : WokaBaseActivity() {
|
||||
|
||||
private lateinit var noSignInDialog: NoSignInDialog
|
||||
|
||||
private var adLoaded = false
|
||||
private var customAdLoaded = false
|
||||
|
||||
private lateinit var interstitialAds: InterstitialAds
|
||||
|
||||
@@ -94,7 +100,9 @@ class GamesActivity : WokaBaseActivity() {
|
||||
noSignInDialog.show()
|
||||
}
|
||||
|
||||
interstitialAds = InterstitialAds(this, TEST_INTERSTITIAL_AD)
|
||||
interstitialAds = InterstitialAds(this, GAME_INTERSTITIAL_AD)
|
||||
|
||||
customAdLoaded = false
|
||||
|
||||
initViews()
|
||||
|
||||
@@ -102,10 +110,10 @@ class GamesActivity : WokaBaseActivity() {
|
||||
|
||||
clickEvents()
|
||||
|
||||
setObservers()
|
||||
|
||||
loadAds()
|
||||
|
||||
setObservers()
|
||||
|
||||
if (!viewModel.gamesLiveData.isInitialized){
|
||||
viewModel.loadGames()
|
||||
}
|
||||
@@ -186,9 +194,11 @@ class GamesActivity : WokaBaseActivity() {
|
||||
}
|
||||
|
||||
private fun loadTrailerData(gameData: GameData) {
|
||||
if (adLoaded) return
|
||||
|
||||
binding.apply {
|
||||
if (customAdLoaded) {
|
||||
return
|
||||
}
|
||||
|
||||
trailerView.show()
|
||||
adjustTrailerImage()
|
||||
|
||||
@@ -448,6 +458,10 @@ class GamesActivity : WokaBaseActivity() {
|
||||
newList.size
|
||||
)
|
||||
}
|
||||
|
||||
if (!customAdLoaded){
|
||||
loadGoogleAds()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -465,7 +479,7 @@ class GamesActivity : WokaBaseActivity() {
|
||||
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
|
||||
adLoaded = true
|
||||
customAdLoaded = true
|
||||
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
@@ -499,4 +513,69 @@ class GamesActivity : WokaBaseActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadGoogleAds(){
|
||||
if (customAdLoaded) return
|
||||
|
||||
// banner ad
|
||||
val adView = AdView(this)
|
||||
|
||||
adView.adListener = object : AdListener(){
|
||||
override fun onAdLoaded() {
|
||||
super.onAdLoaded()
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
binding.adBtn.hide()
|
||||
|
||||
adjustTrailerImage()
|
||||
}
|
||||
}
|
||||
|
||||
adView.setAdSize(
|
||||
AdSize.LARGE_BANNER
|
||||
)
|
||||
adView.adUnitId = GAME_BANNER_AD
|
||||
|
||||
binding.toolbarAdsContainer.removeAllViews()
|
||||
binding.toolbarAdsContainer.addView(adView)
|
||||
|
||||
adView.loadAd(AdRequest.Builder().build())
|
||||
|
||||
// full ad at masila image
|
||||
binding.trailerImage.post {
|
||||
val adView2 = AdView(this)
|
||||
|
||||
adView2.adListener = object : AdListener(){
|
||||
override fun onAdLoaded() {
|
||||
super.onAdLoaded()
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
binding.adBtn.hide()
|
||||
|
||||
binding.adsContainer.setBackgroundResource(R.color.black)
|
||||
|
||||
adjustTrailerImage()
|
||||
|
||||
customAdLoaded = true
|
||||
}
|
||||
}
|
||||
|
||||
adView2.setAdSize(
|
||||
AdSize(
|
||||
binding.trailerImage.width / resources.displayMetrics.density.toInt(),
|
||||
binding.trailerImage.height / resources.displayMetrics.density.toInt(),
|
||||
)
|
||||
)
|
||||
adView2.adUnitId = GAME_TRAILER_AD
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView2)
|
||||
|
||||
adView2.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,6 +153,14 @@
|
||||
android:layout_gravity="top"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ads_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_160sdp"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:translationZ="1dp"/>
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/top_pinned_view"
|
||||
android:layout_width="match_parent"
|
||||
@@ -227,6 +235,23 @@
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
app:cardElevation="0dp"
|
||||
app:cardCornerRadius="3dp"
|
||||
app:cardBackgroundColor="@android:color/transparent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/toolbar_ads_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"/>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="15dp"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/img_fm_bg">
|
||||
|
||||
@@ -43,6 +42,8 @@
|
||||
android:src="@drawable/img_fm_masila"
|
||||
android:contentDescription="@string/image"
|
||||
android:scaleType="fitXY"
|
||||
|
||||
android:layout_marginTop="15dp"
|
||||
/>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
@@ -159,6 +160,15 @@
|
||||
android:layout_marginTop="15dp"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ads_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="15dp"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
@@ -11,7 +11,18 @@
|
||||
<WebView
|
||||
android:id="@+id/web_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
android:layout_height="match_parent"
|
||||
android:layout_above="@id/ads_container"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ads_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:layout_alignParentBottom="true"
|
||||
/>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/back_btn"
|
||||
|
||||
@@ -153,6 +153,14 @@
|
||||
android:layout_gravity="top"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ads_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_160sdp"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:translationZ="1dp"/>
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/top_pinned_view"
|
||||
android:layout_width="match_parent"
|
||||
@@ -227,6 +235,23 @@
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
app:cardElevation="0dp"
|
||||
app:cardCornerRadius="3dp"
|
||||
app:cardBackgroundColor="@android:color/transparent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/toolbar_ads_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"/>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
@@ -143,6 +143,14 @@
|
||||
android:src="@drawable/img_masila_full"
|
||||
app:layout_collapseMode="parallax" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ads_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_160sdp"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:translationZ="1dp"/>
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/top_pinned_view"
|
||||
android:layout_width="match_parent"
|
||||
@@ -216,6 +224,23 @@
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
app:cardElevation="0dp"
|
||||
app:cardCornerRadius="3dp"
|
||||
app:cardBackgroundColor="@android:color/transparent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/toolbar_ads_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"/>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
@@ -14,6 +14,18 @@
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ads_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
|
||||
android:layout_below="@id/constraintLayout"
|
||||
|
||||
android:layout_marginTop="15dp"
|
||||
/>
|
||||
|
||||
<androidx.media3.ui.PlayerView
|
||||
android:id="@+id/player_view"
|
||||
android:layout_width="match_parent"
|
||||
@@ -24,50 +36,50 @@
|
||||
/>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/constraintLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back_btn"
|
||||
style="@style/ExoStyledControls.Button.Center.PlayPause"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:contentDescription="@string/image"
|
||||
android:src="@drawable/ic_close"
|
||||
android:layout_margin="25dp"
|
||||
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:contentDescription="@string/image"
|
||||
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/ic_close"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
||||
style="@style/ExoStyledControls.Button.Center.PlayPause"
|
||||
/>
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
style="@style/ExoStyledControls.Button.Center.PlayPause"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:fontFamily="@font/exo_2_bold"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_14ssp"
|
||||
android:textAlignment="center"
|
||||
|
||||
android:ems="10"
|
||||
android:maxLines="1"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_margin="15dp"
|
||||
android:ellipsize="end"
|
||||
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:ems="10"
|
||||
android:fontFamily="@font/exo_2_bold"
|
||||
android:maxLines="1"
|
||||
|
||||
android:layout_margin="15dp"
|
||||
android:textAlignment="center"
|
||||
|
||||
android:textColor="@color/white"
|
||||
|
||||
android:textSize="@dimen/_14ssp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/back_btn"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
app:layout_constraintTop_toTopOf="@id/back_btn"
|
||||
app:layout_constraintBottom_toBottomOf="@id/back_btn"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
||||
style="@style/ExoStyledControls.Button.Center.PlayPause"
|
||||
|
||||
/>
|
||||
|
||||
|
||||
@@ -531,15 +531,14 @@
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
<com.google.android.gms.ads.AdView
|
||||
xmlns:ads="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/ad_view"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:id="@+id/ads_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="25dp"
|
||||
ads:adSize="320x100"
|
||||
ads:adUnitId="ca-app-pub-5699008063638916/6110095586" />
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/coming_soon_txt"
|
||||
|
||||
@@ -155,6 +155,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_160sdp"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:translationZ="1dp"/>
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
@@ -233,6 +234,23 @@
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
app:cardElevation="0dp"
|
||||
app:cardCornerRadius="3dp"
|
||||
app:cardBackgroundColor="@android:color/transparent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/toolbar_ads_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"/>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
Reference in New Issue
Block a user