mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 20:52:46 +01:00
Fix ads tile (#1905)
This commit is contained in:
parent
c4689fcbb3
commit
7b13684137
@ -222,17 +222,31 @@ class PreferencesRepository @Inject constructor(
|
|||||||
get() = selectedDashboardTilesPreference.asFlow()
|
get() = selectedDashboardTilesPreference.asFlow()
|
||||||
.map { set ->
|
.map { set ->
|
||||||
set.map { DashboardItem.Tile.valueOf(it) }
|
set.map { DashboardItem.Tile.valueOf(it) }
|
||||||
.plus(listOf(DashboardItem.Tile.ACCOUNT, DashboardItem.Tile.ADMIN_MESSAGE))
|
.plus(
|
||||||
|
listOfNotNull(
|
||||||
|
DashboardItem.Tile.ACCOUNT,
|
||||||
|
DashboardItem.Tile.ADMIN_MESSAGE,
|
||||||
|
DashboardItem.Tile.ADS.takeIf { isAdsEnabled }
|
||||||
|
)
|
||||||
|
)
|
||||||
.toSet()
|
.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
var selectedDashboardTiles: Set<DashboardItem.Tile>
|
var selectedDashboardTiles: Set<DashboardItem.Tile>
|
||||||
get() = selectedDashboardTilesPreference.get()
|
get() = selectedDashboardTilesPreference.get()
|
||||||
.map { DashboardItem.Tile.valueOf(it) }
|
.map { DashboardItem.Tile.valueOf(it) }
|
||||||
.plus(listOf(DashboardItem.Tile.ACCOUNT, DashboardItem.Tile.ADMIN_MESSAGE))
|
.plus(
|
||||||
|
listOfNotNull(
|
||||||
|
DashboardItem.Tile.ACCOUNT,
|
||||||
|
DashboardItem.Tile.ADMIN_MESSAGE,
|
||||||
|
DashboardItem.Tile.ADS.takeIf { isAdsEnabled }
|
||||||
|
)
|
||||||
|
)
|
||||||
.toSet()
|
.toSet()
|
||||||
set(value) {
|
set(value) {
|
||||||
val filteredValue = value.filterNot { it == DashboardItem.Tile.ACCOUNT }
|
val filteredValue = value.filterNot {
|
||||||
|
it == DashboardItem.Tile.ACCOUNT || it == DashboardItem.Tile.ADMIN_MESSAGE
|
||||||
|
}
|
||||||
.map { it.name }
|
.map { it.name }
|
||||||
.toSet()
|
.toSet()
|
||||||
|
|
||||||
@ -288,6 +302,11 @@ class PreferencesRepository @Inject constructor(
|
|||||||
get() = sharedPref.getBoolean(PREF_KEY_PERSONALIZED_ADS_ENABLED, false)
|
get() = sharedPref.getBoolean(PREF_KEY_PERSONALIZED_ADS_ENABLED, false)
|
||||||
set(value) = sharedPref.edit { putBoolean(PREF_KEY_PERSONALIZED_ADS_ENABLED, value) }
|
set(value) = sharedPref.edit { putBoolean(PREF_KEY_PERSONALIZED_ADS_ENABLED, value) }
|
||||||
|
|
||||||
|
val isAdsEnabledFlow = flowSharedPref.getBoolean(
|
||||||
|
context.getString(R.string.pref_key_ads_enabled),
|
||||||
|
context.resources.getBoolean(R.bool.pref_default_ads_enabled)
|
||||||
|
).asFlow()
|
||||||
|
|
||||||
var isAdsEnabled: Boolean
|
var isAdsEnabled: Boolean
|
||||||
get() = getBoolean(
|
get() = getBoolean(
|
||||||
R.string.pref_key_ads_enabled,
|
R.string.pref_key_ads_enabled,
|
||||||
|
@ -57,7 +57,11 @@ class DashboardPresenter @Inject constructor(
|
|||||||
showContent(false)
|
showContent(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
preferencesRepository.selectedDashboardTilesFlow
|
merge(
|
||||||
|
preferencesRepository.selectedDashboardTilesFlow,
|
||||||
|
preferencesRepository.isAdsEnabledFlow
|
||||||
|
.map { preferencesRepository.selectedDashboardTiles }
|
||||||
|
)
|
||||||
.onEach { loadData(tilesToLoad = it) }
|
.onEach { loadData(tilesToLoad = it) }
|
||||||
.launch("dashboard_pref")
|
.launch("dashboard_pref")
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import io.github.wulkanowy.ui.base.ErrorHandler
|
|||||||
import io.github.wulkanowy.ui.modules.Destination
|
import io.github.wulkanowy.ui.modules.Destination
|
||||||
import io.github.wulkanowy.ui.modules.account.AccountView
|
import io.github.wulkanowy.ui.modules.account.AccountView
|
||||||
import io.github.wulkanowy.ui.modules.account.accountdetails.AccountDetailsView
|
import io.github.wulkanowy.ui.modules.account.accountdetails.AccountDetailsView
|
||||||
import io.github.wulkanowy.ui.modules.dashboard.DashboardItem
|
|
||||||
import io.github.wulkanowy.ui.modules.grade.GradeView
|
import io.github.wulkanowy.ui.modules.grade.GradeView
|
||||||
import io.github.wulkanowy.ui.modules.message.MessageView
|
import io.github.wulkanowy.ui.modules.message.MessageView
|
||||||
import io.github.wulkanowy.ui.modules.schoolandteachers.SchoolAndTeachersView
|
import io.github.wulkanowy.ui.modules.schoolandteachers.SchoolAndTeachersView
|
||||||
@ -168,13 +167,12 @@ class MainPresenter @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onPrivacyAgree(isPersonalizedAds: Boolean) {
|
fun onPrivacyAgree(isPersonalizedAds: Boolean) {
|
||||||
preferencesRepository.isAdsEnabled = true
|
|
||||||
preferencesRepository.isAgreeToProcessData = true
|
preferencesRepository.isAgreeToProcessData = true
|
||||||
preferencesRepository.isPersonalizedAdsEnabled = isPersonalizedAds
|
preferencesRepository.isPersonalizedAdsEnabled = isPersonalizedAds
|
||||||
|
|
||||||
adsHelper.initialize()
|
adsHelper.initialize()
|
||||||
|
|
||||||
preferencesRepository.selectedDashboardTiles += DashboardItem.Tile.ADS
|
preferencesRepository.isAdsEnabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onPrivacySelected() {
|
fun onPrivacySelected() {
|
||||||
|
@ -50,11 +50,6 @@ class AdsFragment : PreferenceFragmentCompat(), MainView.TitledView, AdsView {
|
|||||||
presenter.onConsentSelected(newValue as Boolean)
|
presenter.onConsentSelected(newValue as Boolean)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
findPreference<SwitchPreferenceCompat>(getString(R.string.pref_key_ads_enabled))?.setOnPreferenceChangeListener { _, newValue ->
|
|
||||||
presenter.onAddEnabled(newValue as Boolean)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showAd(ad: RewardedInterstitialAd) {
|
override fun showAd(ad: RewardedInterstitialAd) {
|
||||||
|
@ -4,7 +4,6 @@ import io.github.wulkanowy.data.repositories.PreferencesRepository
|
|||||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||||
import io.github.wulkanowy.ui.base.BasePresenter
|
import io.github.wulkanowy.ui.base.BasePresenter
|
||||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||||
import io.github.wulkanowy.ui.modules.dashboard.DashboardItem
|
|
||||||
import io.github.wulkanowy.utils.AdsHelper
|
import io.github.wulkanowy.utils.AdsHelper
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@ -48,7 +47,6 @@ class AdsPresenter @Inject constructor(
|
|||||||
} else {
|
} else {
|
||||||
view?.showProcessingDataSummary(null)
|
view?.showProcessingDataSummary(null)
|
||||||
view?.setCheckedAdsEnabled(false)
|
view?.setCheckedAdsEnabled(false)
|
||||||
onAddEnabled(false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,12 +75,4 @@ class AdsPresenter @Inject constructor(
|
|||||||
view?.setCheckedProcessingData(true)
|
view?.setCheckedProcessingData(true)
|
||||||
view?.showProcessingDataSummary(true)
|
view?.showProcessingDataSummary(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onAddEnabled(isEnabled: Boolean) {
|
|
||||||
if (isEnabled) {
|
|
||||||
preferencesRepository.selectedDashboardTiles += DashboardItem.Tile.ADS
|
|
||||||
} else {
|
|
||||||
preferencesRepository.selectedDashboardTiles -= DashboardItem.Tile.ADS
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ class AdsHelper @Inject constructor(
|
|||||||
|
|
||||||
return suspendCoroutine {
|
return suspendCoroutine {
|
||||||
val adView = AdView(context).apply {
|
val adView = AdView(context).apply {
|
||||||
adSize = AdSize.getPortraitAnchoredAdaptiveBannerAdSize(context, width)
|
setAdSize(AdSize.getPortraitAnchoredAdaptiveBannerAdSize(context, width))
|
||||||
adUnitId = BuildConfig.DASHBOARD_TILE_AD_ID
|
adUnitId = BuildConfig.DASHBOARD_TILE_AD_ID
|
||||||
adListener = object : AdListener() {
|
adListener = object : AdListener() {
|
||||||
override fun onAdFailedToLoad(loadAdError: LoadAdError) {
|
override fun onAdFailedToLoad(loadAdError: LoadAdError) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user