Integrated v2 api for get_ad_data.
Data caching and implemented it on screens in all the files.
This commit is contained in:
@@ -4,9 +4,13 @@ import com.woka.advertisements.models.AdsResponse
|
||||
import com.woka.networking.ApiResponse
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface AdsApiService {
|
||||
|
||||
@GET("get_ad_data")
|
||||
suspend fun getAdsData() : Response<ApiResponse<AdsResponse>>
|
||||
@GET("v2/get_ad_data")
|
||||
suspend fun getAdsData(
|
||||
@Query("start") start: Int = 0,
|
||||
@Query("limit") limit: Int = 20
|
||||
) : Response<ApiResponse<AdsResponse>>
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.woka.advertisements
|
||||
|
||||
import com.woka.advertisements.models.AdData
|
||||
import com.woka.advertisements.models.AdResult
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.networking.RetrofitHelper
|
||||
import com.woka.networking.RetrofitHelper.handleApiCall
|
||||
@@ -10,9 +10,9 @@ object AdsRepository {
|
||||
private val apiService = RetrofitHelper.getRetrofit().create(AdsApiService::class.java)
|
||||
|
||||
@Volatile
|
||||
private var adsData: List<AdData>? = null
|
||||
private var adsData: List<AdResult>? = null
|
||||
|
||||
suspend fun getADs(): List<AdData>?{
|
||||
suspend fun getADs(): List<AdResult>?{
|
||||
if (adsData != null){
|
||||
return adsData
|
||||
}
|
||||
|
||||
10
app/src/main/java/com/woka/advertisements/models/AdResult.kt
Normal file
10
app/src/main/java/com/woka/advertisements/models/AdResult.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.woka.advertisements.models
|
||||
|
||||
data class AdResult(
|
||||
val advertisement: Advertisement?,
|
||||
val google_ad: GoogleAd?,
|
||||
val id: Int?,
|
||||
val is_active: String?,
|
||||
val page_name: String?,
|
||||
val slug: String?
|
||||
)
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.woka.advertisements.models
|
||||
|
||||
data class AdsResponse(
|
||||
val result: List<AdData?>?,
|
||||
val result: List<AdResult?>?,
|
||||
val total_records: Int?
|
||||
)
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.woka.advertisements.models
|
||||
|
||||
data class AdData(
|
||||
data class Advertisement(
|
||||
val ad_company: String?,
|
||||
val ad_link: String?,
|
||||
val ad_pages_xid: Int?,
|
||||
val banner_image: String?,
|
||||
val button_image: String?,
|
||||
val for_page: String?,
|
||||
val id: Int?,
|
||||
val is_active: String?,
|
||||
val title: String?
|
||||
)
|
||||
@@ -7,5 +7,10 @@ enum class ForPage(val value: String) {
|
||||
KARAOKE("karaoke"),
|
||||
AUDIO_BOOKS("audio-books"),
|
||||
GAMES("games"),
|
||||
SHOP_SUPER_CATEGORY("shop-super-category");
|
||||
SHOP_SUPER_CATEGORY("shop-super-category"),
|
||||
|
||||
FM("fm"),
|
||||
GAME_INTERSTITIAL("game-interestial"),
|
||||
GAME_PLAYER("game-web-view"),
|
||||
KARAOKE_PLAYER("karaoke-player");
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.woka.advertisements.models
|
||||
|
||||
data class GoogleAd(
|
||||
val ad_pages_xid: Int?,
|
||||
val id: Int?,
|
||||
val is_active: String?
|
||||
)
|
||||
@@ -76,6 +76,7 @@ class AudioBooksActivity : WokaBaseActivity() {
|
||||
private lateinit var playerLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
private var customAdLoaded = false
|
||||
private var shallLoadGoogleAd = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -205,43 +206,45 @@ class AudioBooksActivity : WokaBaseActivity() {
|
||||
private fun loadAds(){
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let { ads ->
|
||||
val theme1ads = ads.filter { it.for_page == ForPage.AUDIO_BOOKS.value}
|
||||
val theme1ads = ads.filter { it.slug == ForPage.AUDIO_BOOKS.value}
|
||||
|
||||
if (theme1ads.isNotEmpty()){
|
||||
val adDetails = theme1ads.first()
|
||||
theme1ads.first().advertisement?.let {adDetails ->
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
customAdLoaded = true
|
||||
|
||||
customAdLoaded = true
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
binding.adButtonView.show()
|
||||
|
||||
binding.adButtonView.show()
|
||||
binding.trailerView.show()
|
||||
adjustTrailerImage()
|
||||
|
||||
binding.trailerView.show()
|
||||
adjustTrailerImage()
|
||||
|
||||
adDetails.banner_image?.let {url ->
|
||||
binding.trailerImage.loadImage(url)
|
||||
}
|
||||
|
||||
adDetails.button_image?.let {url ->
|
||||
binding.adButtonImg.loadImage(url)
|
||||
}
|
||||
|
||||
adDetails.ad_link?.let {url ->
|
||||
binding.adBtn.setOnClickListener {
|
||||
AdClicksHelper.addClick(adDetails.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
adDetails.banner_image?.let {url ->
|
||||
binding.trailerImage.loadImage(url)
|
||||
}
|
||||
|
||||
binding.trailerImage.setOnClickListener {
|
||||
binding.adBtn.performClick()
|
||||
adDetails.button_image?.let {url ->
|
||||
binding.adButtonImg.loadImage(url)
|
||||
}
|
||||
|
||||
adDetails.ad_link?.let {url ->
|
||||
binding.adBtn.setOnClickListener {
|
||||
AdClicksHelper.addClick(adDetails.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
}
|
||||
|
||||
binding.trailerImage.setOnClickListener {
|
||||
binding.adBtn.performClick()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shallLoadGoogleAd = theme1ads.first().google_ad != null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -309,7 +312,7 @@ class AudioBooksActivity : WokaBaseActivity() {
|
||||
)
|
||||
}
|
||||
|
||||
if (!customAdLoaded){
|
||||
if (!customAdLoaded && shallLoadGoogleAd){
|
||||
loadGoogleAds()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,26 +604,26 @@ class Home1Fragment : Fragment() {
|
||||
private fun loadAds(){
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let {ads ->
|
||||
val homeAds = ads.filter { it.for_page == ForPage.THEME_1.value }
|
||||
val homeAds = ads.filter { it.slug == ForPage.THEME_1.value }
|
||||
|
||||
if (homeAds.isNotEmpty()){
|
||||
val adDetails = homeAds.first()
|
||||
homeAds.first().advertisement?.let {adDetails ->
|
||||
adClickHelper.addImpression(adDetails.id)
|
||||
|
||||
adClickHelper.addImpression(adDetails.id)
|
||||
adDetails.banner_image?.let {url ->
|
||||
binding.imgAd.loadImage(url)
|
||||
binding.adView.show()
|
||||
}
|
||||
|
||||
adDetails.banner_image?.let {url ->
|
||||
binding.imgAd.loadImage(url)
|
||||
binding.adView.show()
|
||||
}
|
||||
adDetails.ad_link?.let {url ->
|
||||
binding.adView.setOnClickListener {
|
||||
|
||||
adDetails.ad_link?.let {url ->
|
||||
binding.adView.setOnClickListener {
|
||||
adClickHelper.addClick(adDetails.id)
|
||||
|
||||
adClickHelper.addClick(adDetails.id)
|
||||
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.bumptech.glide.Glide
|
||||
import com.google.android.gms.ads.AdRequest
|
||||
import com.google.android.gms.ads.AdSize
|
||||
@@ -15,6 +16,8 @@ import com.google.android.gms.ads.AdView
|
||||
import com.jwplayer.pub.api.media.playlists.PlaylistItem
|
||||
import com.woka.R
|
||||
import com.woka.WokaApp
|
||||
import com.woka.advertisements.AdsRepository
|
||||
import com.woka.advertisements.models.ForPage
|
||||
import com.woka.audiobooks.views.AudioBooksActivity
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
@@ -38,6 +41,7 @@ import com.woka.utils.hide
|
||||
import com.woka.utils.show
|
||||
import com.woka.webseries.views.WebSeriesActivity
|
||||
import com.woka.wokagames.views.GamesActivity
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class Home2Fragment : Fragment() {
|
||||
|
||||
@@ -77,19 +81,28 @@ class Home2Fragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun loadGoogleAds() {
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let { ads ->
|
||||
val fmAds = ads.filter { it.slug == ForPage.THEME_2.value }
|
||||
|
||||
val adView = AdView(requireContext())
|
||||
if (fmAds.isNotEmpty()){
|
||||
fmAds.first().google_ad?.let {
|
||||
val adView = AdView(requireContext())
|
||||
|
||||
adView.adUnitId = HOME_THEME_2_BANNER_AD
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, AdSize.AUTO_HEIGHT))
|
||||
adView.adUnitId = HOME_THEME_2_BANNER_AD
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, AdSize.AUTO_HEIGHT))
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun iniViews() {
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.util.Log
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.media3.common.MediaItem
|
||||
import androidx.media3.common.PlaybackException
|
||||
import androidx.media3.common.Player
|
||||
@@ -15,6 +16,8 @@ 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.advertisements.AdsRepository
|
||||
import com.woka.advertisements.models.ForPage
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityFmactivityBinding
|
||||
@@ -25,6 +28,7 @@ import com.woka.utils.TAG
|
||||
import com.woka.utils.WokaBaseActivity
|
||||
import com.woka.utils.hide
|
||||
import com.woka.utils.show
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
@@ -205,19 +209,28 @@ class FMActivity : WokaBaseActivity() {
|
||||
}
|
||||
|
||||
private fun loadGoogleAds() {
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let {ads ->
|
||||
val fmAds = ads.filter { it.slug == ForPage.FM.value }
|
||||
|
||||
val adView = AdView(this)
|
||||
if (fmAds.isNotEmpty()){
|
||||
fmAds.first().google_ad?.let {
|
||||
val adView = AdView(this@FMActivity)
|
||||
|
||||
adView.adUnitId = GAME_BANNER_AD
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, 60))
|
||||
adView.adUnitId = GAME_BANNER_AD
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, 60))
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateVolumeButtons(){
|
||||
|
||||
@@ -26,6 +26,7 @@ import androidx.core.app.ActivityCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.media3.common.MediaItem
|
||||
import androidx.media3.common.PlaybackException
|
||||
import androidx.media3.common.Player
|
||||
@@ -35,6 +36,8 @@ 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.advertisements.AdsRepository
|
||||
import com.woka.advertisements.models.ForPage
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityKaraokePlayerrBinding
|
||||
@@ -485,18 +488,28 @@ class KaraokePlayerActivity : WokaBaseActivity() {
|
||||
|
||||
private fun loadGoogleAds() {
|
||||
|
||||
val adView = AdView(this)
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let { ads ->
|
||||
val fmAds = ads.filter { it.slug == ForPage.KARAOKE_PLAYER.value }
|
||||
|
||||
adView.adUnitId = GAME_BANNER_AD
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, 100))
|
||||
if (fmAds.isNotEmpty()){
|
||||
fmAds.first().google_ad?.let {
|
||||
val adView = AdView(this@KaraokePlayerActivity)
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
adView.adUnitId = GAME_BANNER_AD
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, 100))
|
||||
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun playStopPlayingAudio() {
|
||||
|
||||
@@ -76,6 +76,7 @@ class KaraokeActivity : WokaBaseActivity() {
|
||||
private lateinit var playerLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
private var customAdLoaded = false
|
||||
private var shallLoadGoogleAd = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -535,7 +536,7 @@ class KaraokeActivity : WokaBaseActivity() {
|
||||
)
|
||||
}
|
||||
|
||||
if (!customAdLoaded){
|
||||
if (!customAdLoaded && shallLoadGoogleAd){
|
||||
loadGoogleAds()
|
||||
}
|
||||
}
|
||||
@@ -574,43 +575,45 @@ class KaraokeActivity : WokaBaseActivity() {
|
||||
private fun loadAds(){
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let { ads ->
|
||||
val theme1ads = ads.filter { it.for_page == ForPage.KARAOKE.value}
|
||||
val theme1ads = ads.filter { it.slug == ForPage.KARAOKE.value}
|
||||
|
||||
if (theme1ads.isNotEmpty()){
|
||||
val adDetails = theme1ads.first()
|
||||
theme1ads.first().advertisement?.let {adDetails ->
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
customAdLoaded = true
|
||||
|
||||
customAdLoaded = true
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
binding.adButtonView.show()
|
||||
|
||||
binding.adButtonView.show()
|
||||
binding.trailerView.show()
|
||||
adjustTrailerImage()
|
||||
|
||||
binding.trailerView.show()
|
||||
adjustTrailerImage()
|
||||
|
||||
adDetails.banner_image?.let {url ->
|
||||
binding.trailerImage.loadImage(url)
|
||||
}
|
||||
|
||||
adDetails.button_image?.let {url ->
|
||||
binding.adButtonImg.loadImage(url)
|
||||
}
|
||||
|
||||
adDetails.ad_link?.let {url ->
|
||||
binding.adBtn.setOnClickListener {
|
||||
AdClicksHelper.addClick(adDetails.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
adDetails.banner_image?.let {url ->
|
||||
binding.trailerImage.loadImage(url)
|
||||
}
|
||||
|
||||
binding.trailerImage.setOnClickListener {
|
||||
binding.adBtn.performClick()
|
||||
adDetails.button_image?.let {url ->
|
||||
binding.adButtonImg.loadImage(url)
|
||||
}
|
||||
|
||||
adDetails.ad_link?.let {url ->
|
||||
binding.adBtn.setOnClickListener {
|
||||
AdClicksHelper.addClick(adDetails.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
}
|
||||
|
||||
binding.trailerImage.setOnClickListener {
|
||||
binding.adBtn.performClick()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shallLoadGoogleAd = theme1ads.first().google_ad != null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,18 +144,18 @@ class ShopFragment1 : Fragment() {
|
||||
private fun loadAds(categoryList: MutableList<BaseCategory>) {
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let { ads ->
|
||||
val superShopAds = ads.filter { it.for_page == ForPage.SHOP_SUPER_CATEGORY.value }
|
||||
val superShopAds = ads.filter { it.slug == ForPage.SHOP_SUPER_CATEGORY.value }
|
||||
|
||||
if (superShopAds.isNotEmpty()) {
|
||||
val adDetails = superShopAds.first()
|
||||
superShopAds.first().advertisement?.let {adDetails ->
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
adId = adDetails.id
|
||||
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
adId = adDetails.id
|
||||
categoryList.add(0, BaseCategory(-1, adDetails.banner_image, adDetails.title))
|
||||
adLink = adDetails.ad_link
|
||||
|
||||
categoryList.add(0, BaseCategory(-1, adDetails.banner_image, adDetails.title))
|
||||
adLink = adDetails.ad_link
|
||||
|
||||
adapter.notifyItemInserted(0)
|
||||
adapter.notifyItemInserted(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ class WebSeriesFragment : Fragment() {
|
||||
private lateinit var playerLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
private var isAdLoaded = false
|
||||
private var shallLoadGoogleAd = false
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
@@ -281,7 +282,9 @@ class WebSeriesFragment : Fragment() {
|
||||
|
||||
binding.trailerView.show()
|
||||
|
||||
loadGoogleAds()
|
||||
if (!isAdLoaded && shallLoadGoogleAd){
|
||||
loadGoogleAds()
|
||||
}
|
||||
|
||||
adjustMasilaImage()
|
||||
|
||||
@@ -404,42 +407,44 @@ class WebSeriesFragment : Fragment() {
|
||||
private fun loadCustomAds(){
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let { ads ->
|
||||
val theme1ads = ads.filter { it.for_page == ForPage.WEB_SERIES.value}
|
||||
val theme1ads = ads.filter { it.slug == ForPage.WEB_SERIES.value}
|
||||
|
||||
if (theme1ads.isNotEmpty()){
|
||||
val adDetails = theme1ads.first()
|
||||
theme1ads.first().advertisement?.let {adDetails ->
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
isAdLoaded = true
|
||||
|
||||
isAdLoaded = true
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerTxt.hide()
|
||||
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerTxt.hide()
|
||||
binding.adButtonView.show()
|
||||
|
||||
binding.adButtonView.show()
|
||||
|
||||
adDetails.banner_image?.let {url ->
|
||||
Glide.with(binding.masilaImage)
|
||||
.load(url)
|
||||
.into(binding.masilaImage)
|
||||
}
|
||||
|
||||
adDetails.button_image?.let {url ->
|
||||
binding.adButtonImg.loadImage(url)
|
||||
}
|
||||
|
||||
adDetails.ad_link?.let {url ->
|
||||
binding.adBtn.setOnClickListener {
|
||||
AdClicksHelper.addClick(adDetails.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
adDetails.banner_image?.let {url ->
|
||||
Glide.with(binding.masilaImage)
|
||||
.load(url)
|
||||
.into(binding.masilaImage)
|
||||
}
|
||||
|
||||
binding.masilaImage.setOnClickListener {
|
||||
binding.adBtn.performClick()
|
||||
adDetails.button_image?.let {url ->
|
||||
binding.adButtonImg.loadImage(url)
|
||||
}
|
||||
|
||||
adDetails.ad_link?.let {url ->
|
||||
binding.adBtn.setOnClickListener {
|
||||
AdClicksHelper.addClick(adDetails.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
}
|
||||
|
||||
binding.masilaImage.setOnClickListener {
|
||||
binding.adBtn.performClick()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shallLoadGoogleAd = theme1ads.first().google_ad != null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,13 @@ import android.webkit.WebSettings
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
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.advertisements.AdsRepository
|
||||
import com.woka.advertisements.models.ForPage
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityGamePlayerBinding
|
||||
@@ -22,6 +25,7 @@ import com.woka.userdata.UserRepository
|
||||
import com.woka.userdata.userDataModels.VideoViewRequestData
|
||||
import com.woka.utils.DecisionDialog
|
||||
import com.woka.utils.WokaBaseActivity
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class GamePlayerActivity : WokaBaseActivity() {
|
||||
|
||||
@@ -172,18 +176,27 @@ class GamePlayerActivity : WokaBaseActivity() {
|
||||
}
|
||||
|
||||
private fun loadGoogleAds() {
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let { ads ->
|
||||
val fmAds = ads.filter { it.slug == ForPage.GAME_PLAYER.value }
|
||||
|
||||
val adView = AdView(this)
|
||||
if (fmAds.isNotEmpty()){
|
||||
fmAds.first().google_ad?.let {
|
||||
val adView = AdView(this@GamePlayerActivity)
|
||||
|
||||
adView.adUnitId = GAME_BANNER_AD
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, 60))
|
||||
adView.adUnitId = GAME_BANNER_AD
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, 60))
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import com.woka.databinding.ActivityGamesBinding
|
||||
import com.woka.databinding.DialogModuleShowerBinding
|
||||
import com.woka.googleads.GAME_BANNER_AD
|
||||
import com.woka.googleads.GAME_TRAILER_AD
|
||||
import com.woka.googleads.HOME_THEME_2_BANNER_AD
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.userPreference.UserType
|
||||
import com.woka.utils.NoSignInDialog
|
||||
@@ -69,6 +70,7 @@ class GamesActivity : WokaBaseActivity() {
|
||||
private lateinit var noSignInDialog: NoSignInDialog
|
||||
|
||||
private var customAdLoaded = false
|
||||
private var shallLoadGoogleAd = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -184,7 +186,23 @@ class GamesActivity : WokaBaseActivity() {
|
||||
|
||||
private fun showAdAndOpenGame(gameData: GameData){
|
||||
gameData.game_url?.let {
|
||||
interstitialAds?.showNewAd(this){
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let { ads ->
|
||||
val fmAds = ads.filter { it.slug == ForPage.GAME_INTERSTITIAL.value }
|
||||
|
||||
if (fmAds.isNotEmpty()){
|
||||
fmAds.first().google_ad?.let {_ ->
|
||||
interstitialAds?.showNewAd(this@GamesActivity){
|
||||
startActivity(Intent(this@GamesActivity, GamePlayerActivity::class.java).apply {
|
||||
putExtra(GamePlayerActivity.EXTRA_GAME_PLAYER_DATA, GamePlayerData(gameData.id, it, gameData.screen_orientation == "Landscape"))
|
||||
})
|
||||
}
|
||||
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startActivity(Intent(this@GamesActivity, GamePlayerActivity::class.java).apply {
|
||||
putExtra(GamePlayerActivity.EXTRA_GAME_PLAYER_DATA, GamePlayerData(gameData.id, it, gameData.screen_orientation == "Landscape"))
|
||||
})
|
||||
@@ -453,7 +471,7 @@ class GamesActivity : WokaBaseActivity() {
|
||||
)
|
||||
}
|
||||
|
||||
if (!customAdLoaded){
|
||||
if (!customAdLoaded && shallLoadGoogleAd){
|
||||
loadGoogleAds()
|
||||
}
|
||||
}
|
||||
@@ -466,43 +484,45 @@ class GamesActivity : WokaBaseActivity() {
|
||||
private fun loadAds(){
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let { ads ->
|
||||
val theme1ads = ads.filter { it.for_page == ForPage.GAMES.value}
|
||||
val theme1ads = ads.filter { it.slug == ForPage.GAMES.value}
|
||||
|
||||
if (theme1ads.isNotEmpty()){
|
||||
val adDetails = theme1ads.first()
|
||||
theme1ads.first().advertisement?.let {adDetails ->
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
|
||||
AdClicksHelper.addImpression(adDetails.id)
|
||||
customAdLoaded = true
|
||||
|
||||
customAdLoaded = true
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
|
||||
binding.trailerBtn.hide()
|
||||
binding.trailerName.hide()
|
||||
binding.adButtonView.show()
|
||||
|
||||
binding.adButtonView.show()
|
||||
binding.trailerView.show()
|
||||
adjustTrailerImage()
|
||||
|
||||
binding.trailerView.show()
|
||||
adjustTrailerImage()
|
||||
|
||||
adDetails.banner_image?.let {url ->
|
||||
binding.trailerImage.loadImage(url)
|
||||
}
|
||||
|
||||
adDetails.button_image?.let {url ->
|
||||
binding.adButtonImg.loadImage(url)
|
||||
}
|
||||
|
||||
adDetails.ad_link?.let {url ->
|
||||
binding.adBtn.setOnClickListener {
|
||||
AdClicksHelper.addClick(adDetails.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
adDetails.banner_image?.let {url ->
|
||||
binding.trailerImage.loadImage(url)
|
||||
}
|
||||
|
||||
binding.trailerImage.setOnClickListener {
|
||||
binding.adBtn.performClick()
|
||||
adDetails.button_image?.let {url ->
|
||||
binding.adButtonImg.loadImage(url)
|
||||
}
|
||||
|
||||
adDetails.ad_link?.let {url ->
|
||||
binding.adBtn.setOnClickListener {
|
||||
AdClicksHelper.addClick(adDetails.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
}
|
||||
|
||||
binding.trailerImage.setOnClickListener {
|
||||
binding.adBtn.performClick()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shallLoadGoogleAd = theme1ads.first().google_ad != null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user