Added custom ads to fm, more, notifications, mylist and blogs screen.
Added interstitial ad to LiveStreamPlayerActivity AdiImageView failure callback to handle error on Home1Fragment custom ads testing code to load ads everytime user visits Home1Fragment
This commit is contained in:
@@ -12,6 +12,12 @@ object AdsRepository {
|
||||
@Volatile
|
||||
private var adsData: List<AdResult>? = null
|
||||
|
||||
// testing purpose remove this function
|
||||
suspend fun loadNewAds(){
|
||||
adsData = null
|
||||
getADs()
|
||||
}
|
||||
|
||||
suspend fun getADs(): List<AdResult>?{
|
||||
if (adsData != null){
|
||||
return adsData
|
||||
|
||||
@@ -14,6 +14,7 @@ enum class ForPage(val value: String) {
|
||||
GAME_PLAYER("game-web-view"),
|
||||
KARAOKE_PLAYER("karaoke-player"),
|
||||
|
||||
BLOGS("shop-listing"),
|
||||
MY_LIST_AND_NOTIFICATION("my-list"),
|
||||
MORE("more"),
|
||||
LIVE_TV_ADS("live-tv-ad"),
|
||||
|
||||
@@ -39,4 +39,10 @@ const val SHOP = "ca-app-pub-5699008063638916/3861755438"
|
||||
const val GAME_PLAYER = "ca-app-pub-5699008063638916/3679353228"
|
||||
|
||||
// my list
|
||||
const val MY_LIST = "ca-app-pub-5699008063638916/6836037599"
|
||||
const val MY_LIST = "ca-app-pub-5699008063638916/6836037599"
|
||||
|
||||
// blogs
|
||||
const val BLOGS = "ca-app-pub-5699008063638916/1117904532"
|
||||
|
||||
// live stream video
|
||||
const val LIVE_STREAM_VIDEO = "ca-app-pub-5699008063638916/7062735475"
|
||||
@@ -193,6 +193,11 @@ class Home1Fragment : Fragment() {
|
||||
}
|
||||
|
||||
binding.playerView.show()
|
||||
|
||||
// remove this : for testing purpose
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.loadNewAds()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
@@ -611,7 +616,10 @@ class Home1Fragment : Fragment() {
|
||||
adClickHelper.addImpression(adDetails.id)
|
||||
|
||||
adDetails.banner_image?.let {url ->
|
||||
binding.imgAd.loadImage(url)
|
||||
binding.imgAd.loadImage(url,
|
||||
failureListener = {
|
||||
binding.adView.hide()
|
||||
})
|
||||
binding.adView.show()
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.InsetDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.LayoutInflater
|
||||
@@ -31,6 +32,7 @@ import com.woka.advertisements.AdsRepository
|
||||
import com.woka.advertisements.models.ForPage
|
||||
import com.woka.audiobooks.AudioBookRepository
|
||||
import com.woka.audiobooks.models.audiodata.AudioBookData
|
||||
import com.woka.database.helpers.AdClicksHelper
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.DialogModuleShowerBinding
|
||||
@@ -143,7 +145,7 @@ class MyListFragment : Fragment() {
|
||||
|
||||
if (userPrefs?.userType != UserType.GUEST) {
|
||||
loadFavoriteList()
|
||||
loadGoogleAds()
|
||||
loadAds()
|
||||
} else {
|
||||
binding.noSignInView.show()
|
||||
}
|
||||
@@ -326,12 +328,29 @@ class MyListFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadGoogleAds() {
|
||||
private fun loadAds() {
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let { ads ->
|
||||
val fmAds = ads.filter { it.slug == ForPage.MY_LIST_AND_NOTIFICATION.value }
|
||||
|
||||
if (fmAds.isNotEmpty()){
|
||||
|
||||
fmAds.first().advertisement?.let {adv ->
|
||||
AdClicksHelper.addImpression(adv.id)
|
||||
|
||||
binding.imgCustomAd.show()
|
||||
binding.imgCustomAd.loadImage(adv.banner_image)
|
||||
binding.imgCustomAd.setOnClickListener {
|
||||
adv.ad_link?.let {url ->
|
||||
AdClicksHelper.addClick(adv.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
}
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
|
||||
fmAds.first().google_ad?.let {
|
||||
val adView = AdView(requireContext())
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.woka.home.notifications
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.core.view.ViewCompat
|
||||
@@ -13,6 +14,7 @@ import com.woka.R
|
||||
import com.woka.advertisements.AdsRepository
|
||||
import com.woka.advertisements.models.ForPage
|
||||
import com.woka.audiobooks.views.AudioBooksActivity
|
||||
import com.woka.database.helpers.AdClicksHelper
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityNotificationsBinding
|
||||
@@ -144,6 +146,23 @@ class NotificationsActivity : WokaBaseActivity() {
|
||||
val fmAds = ads.filter { it.slug == ForPage.MY_LIST_AND_NOTIFICATION.value }
|
||||
|
||||
if (fmAds.isNotEmpty()){
|
||||
|
||||
fmAds.first().advertisement?.let {adv ->
|
||||
AdClicksHelper.addImpression(adv.id)
|
||||
|
||||
binding.imgCustomAd.show()
|
||||
binding.imgCustomAd.loadImage(adv.banner_image)
|
||||
binding.imgCustomAd.setOnClickListener {
|
||||
adv.ad_link?.let {url ->
|
||||
AdClicksHelper.addClick(adv.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
}
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
|
||||
fmAds.first().google_ad?.let {
|
||||
val adView = AdView(this@NotificationsActivity)
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.woka.home.views
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
@@ -18,6 +20,7 @@ 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.AdClicksHelper
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityFmactivityBinding
|
||||
@@ -80,7 +83,7 @@ class FMActivity : WokaBaseActivity() {
|
||||
|
||||
setObservers()
|
||||
|
||||
loadGoogleAds()
|
||||
loadAds()
|
||||
|
||||
playbackStartTime = System.currentTimeMillis()
|
||||
}
|
||||
@@ -208,12 +211,29 @@ class FMActivity : WokaBaseActivity() {
|
||||
})
|
||||
}
|
||||
|
||||
private fun loadGoogleAds() {
|
||||
private fun loadAds() {
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let {ads ->
|
||||
val fmAds = ads.filter { it.slug == ForPage.FM.value }
|
||||
|
||||
if (fmAds.isNotEmpty()){
|
||||
|
||||
fmAds.first().advertisement?.let {adv ->
|
||||
AdClicksHelper.addImpression(adv.id)
|
||||
|
||||
binding.imgCustomAd.show()
|
||||
binding.imgCustomAd.loadImage(adv.banner_image)
|
||||
binding.imgCustomAd.setOnClickListener {
|
||||
adv.ad_link?.let {url ->
|
||||
AdClicksHelper.addClick(adv.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
}
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
|
||||
fmAds.first().google_ad?.let {
|
||||
val adView = AdView(this@FMActivity)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.InsetDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.WindowManager
|
||||
@@ -22,11 +23,11 @@ import com.woka.R
|
||||
import com.woka.WokaApp.Companion.userPrefs
|
||||
import com.woka.advertisements.AdsRepository
|
||||
import com.woka.advertisements.models.ForPage
|
||||
import com.woka.database.helpers.AdClicksHelper
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityMoreHomeBinding
|
||||
import com.woka.databinding.DialogBlogsBinding
|
||||
import com.woka.googleads.FM
|
||||
import com.woka.googleads.MORE_ACTIVITY
|
||||
import com.woka.modules.blogs.BlogsAdapter
|
||||
import com.woka.modules.blogs.BlogsRepository
|
||||
@@ -102,6 +103,23 @@ class MoreHomeActivity : WokaBaseActivity() {
|
||||
val fmAds = ads.filter { it.slug == ForPage.MORE.value }
|
||||
|
||||
if (fmAds.isNotEmpty()){
|
||||
|
||||
fmAds.first().advertisement?.let {adv ->
|
||||
AdClicksHelper.addImpression(adv.id)
|
||||
|
||||
binding.imgCustomAd.show()
|
||||
binding.imgCustomAd.loadImage(adv.banner_image)
|
||||
binding.imgCustomAd.setOnClickListener {
|
||||
adv.ad_link?.let {url ->
|
||||
AdClicksHelper.addClick(adv.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
}
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
|
||||
fmAds.first().google_ad?.let {
|
||||
val adView1 = AdView(this@MoreHomeActivity)
|
||||
adView1.adUnitId = MORE_ACTIVITY
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
package com.woka.modules.blogs.view
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.InsetDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.WindowManager
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.core.view.ViewCompat
|
||||
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.WokaApp
|
||||
import com.woka.advertisements.AdsRepository
|
||||
import com.woka.advertisements.models.ForPage
|
||||
import com.woka.database.helpers.AdClicksHelper
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityBlogsBinding
|
||||
import com.woka.databinding.DialogBlogsBinding
|
||||
import com.woka.googleads.BLOGS
|
||||
import com.woka.modules.blogs.BlogsGridAdapter
|
||||
import com.woka.modules.blogs.BlogsRepository
|
||||
import com.woka.modules.blogs.models.Blog
|
||||
@@ -24,6 +34,7 @@ import com.woka.utils.WokaBaseActivity
|
||||
import com.woka.utils.hide
|
||||
import com.woka.utils.lightStatusBar
|
||||
import com.woka.utils.show
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class BlogsActivity : WokaBaseActivity() {
|
||||
|
||||
@@ -56,6 +67,8 @@ class BlogsActivity : WokaBaseActivity() {
|
||||
initBlogDialog()
|
||||
|
||||
setObservers()
|
||||
|
||||
loadAds()
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@@ -174,4 +187,46 @@ class BlogsActivity : WokaBaseActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadAds() {
|
||||
lifecycleScope.launch {
|
||||
AdsRepository.getADs()?.let { ads ->
|
||||
val fmAds = ads.filter { it.slug == ForPage.BLOGS.value }
|
||||
|
||||
if (fmAds.isNotEmpty()){
|
||||
|
||||
fmAds.first().advertisement?.let {adv ->
|
||||
AdClicksHelper.addImpression(adv.id)
|
||||
|
||||
binding.imgCustomAd.show()
|
||||
binding.imgCustomAd.loadImage(adv.banner_image)
|
||||
binding.imgCustomAd.setOnClickListener {
|
||||
adv.ad_link?.let {url ->
|
||||
AdClicksHelper.addClick(adv.id)
|
||||
startActivity(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
)
|
||||
}
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
|
||||
fmAds.first().google_ad?.let {
|
||||
val adView = AdView(this@BlogsActivity)
|
||||
|
||||
adView.adUnitId = BLOGS
|
||||
adView.setAdSize(AdSize(AdSize.FULL_WIDTH, 60))
|
||||
|
||||
binding.adsContainer.removeAllViews()
|
||||
binding.adsContainer.addView(adView)
|
||||
|
||||
adView.loadAd(
|
||||
AdRequest.Builder()
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ class SplashFragment : Fragment(), Observer<ApiResult<UserDataResponse>?> {
|
||||
|
||||
clickEvents()
|
||||
|
||||
loadGoogleAds()
|
||||
// loadGoogleAds()
|
||||
}
|
||||
|
||||
private fun loadGoogleAds() {
|
||||
|
||||
@@ -11,6 +11,10 @@ import androidx.activity.enableEdgeToEdge
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import com.google.android.gms.ads.AdRequest
|
||||
import com.google.android.gms.ads.LoadAdError
|
||||
import com.google.android.gms.ads.interstitial.InterstitialAd
|
||||
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
|
||||
import com.jwplayer.pub.api.JWPlayer
|
||||
import com.jwplayer.pub.api.configuration.PlayerConfig
|
||||
import com.jwplayer.pub.api.events.EventType
|
||||
@@ -20,6 +24,7 @@ import com.jwplayer.pub.api.media.playlists.PlaylistItem
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.ContentType
|
||||
import com.woka.databinding.ActivityLiveStreamPlayerBinding
|
||||
import com.woka.googleads.LIVE_STREAM_VIDEO
|
||||
import com.woka.players.KeepScreenOnHandler
|
||||
import com.woka.players.models.PlayBackState
|
||||
import com.woka.userdata.UserRepository
|
||||
@@ -57,6 +62,9 @@ class LiveStreamPlayerActivity : WokaBaseActivity(), FullscreenHandler {
|
||||
private var playbackStartTime: Long = 0
|
||||
private var totalPlaybackDuration: Long = 0
|
||||
|
||||
// make false to make ads working
|
||||
private var initialAdLoaded = true
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
@@ -160,6 +168,22 @@ class LiveStreamPlayerActivity : WokaBaseActivity(), FullscreenHandler {
|
||||
}
|
||||
|
||||
private fun addListeners() {
|
||||
player.addListener(EventType.READY, VideoPlayerEvents.OnReadyListener {
|
||||
if (initialAdLoaded.not()){
|
||||
InterstitialAd.load(this@LiveStreamPlayerActivity, LIVE_STREAM_VIDEO,
|
||||
AdRequest.Builder().build(), object : InterstitialAdLoadCallback() {
|
||||
override fun onAdFailedToLoad(adError: LoadAdError) {
|
||||
|
||||
}
|
||||
|
||||
override fun onAdLoaded(interstitialAd: InterstitialAd) {
|
||||
interstitialAd.show(this@LiveStreamPlayerActivity)
|
||||
initialAdLoaded = true
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
player.addListener(EventType.PLAY, VideoPlayerEvents.OnPlayListener {
|
||||
playbackState = PlayBackState.PLAY
|
||||
binding.playerView.show()
|
||||
|
||||
@@ -195,7 +195,7 @@ class PlayerActivity : WokaBaseActivity(), FullscreenHandler {
|
||||
|
||||
config = PlayerConfig.Builder()
|
||||
.playlist(videoPlayList?.playlist)
|
||||
.advertisingConfig(imaAdvertising)
|
||||
// .advertisingConfig(imaAdvertising)
|
||||
.build()
|
||||
|
||||
// to keep up the screen om when video is being played
|
||||
|
||||
@@ -66,7 +66,7 @@ class AdiImageView: FrameLayout {
|
||||
|
||||
}
|
||||
|
||||
fun loadImage(url: String?, successListener: (() -> Unit)? = null) {
|
||||
fun loadImage(url: String?, successListener: (() -> Unit)? = null, failureListener: (() -> Unit)? = null) {
|
||||
imageView?.let {
|
||||
|
||||
progressView?.show()
|
||||
@@ -82,6 +82,7 @@ class AdiImageView: FrameLayout {
|
||||
): Boolean {
|
||||
progressView?.hide()
|
||||
imageView?.setImageDrawable(errorSrc)
|
||||
failureListener?.invoke()
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
android:id="@+id/rv_blogs"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="0dp"
|
||||
|
||||
tools:listitem="@layout/blog_view_holder_grid"
|
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
@@ -114,6 +114,9 @@
|
||||
|
||||
android:layout_marginTop="10dp"
|
||||
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/ads_container"
|
||||
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
@@ -165,6 +168,23 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ads_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
|
||||
<com.woka.utils.AdiImageView
|
||||
android:id="@+id/img_custom_ad"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_50sdp"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -166,8 +166,16 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="15dp"
|
||||
/>
|
||||
android:layout_marginTop="15dp">
|
||||
|
||||
<com.woka.utils.AdiImageView
|
||||
android:id="@+id/img_custom_ad"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_50sdp"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -147,8 +147,14 @@
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="@color/white"
|
||||
/>
|
||||
android:background="@color/white">
|
||||
<com.woka.utils.AdiImageView
|
||||
android:id="@+id/img_custom_ad"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_160sdp"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/blogs_txt"
|
||||
|
||||
@@ -180,7 +180,15 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
/>
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
|
||||
<com.woka.utils.AdiImageView
|
||||
android:id="@+id/img_custom_ad"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_50sdp"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -481,8 +481,16 @@
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:layout_marginBottom="25dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
/>
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
|
||||
<com.woka.utils.AdiImageView
|
||||
android:id="@+id/img_custom_ad"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_50sdp"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user