Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaozhan committed Oct 23, 2021
2 parents 5eee969 + bf58f83 commit 9c77e4b
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 73 deletions.
44 changes: 23 additions & 21 deletions ad/src/google/java/com/github/mustafaozhan/ad/AdManagerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,42 @@ import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
import com.google.android.gms.ads.rewarded.RewardedAd
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback

class AdManagerImpl : AdManager {
class AdManagerImpl(private val context: Context) : AdManager {

override fun initMobileAds(context: Context) {
init {
kermit.d { "AdManagerImpl init" }
MobileAds.initialize(context)
MobileAds.setAppVolume(0.0f)
MobileAds.setAppMuted(true)
}

override fun loadBannerAd(
viewGroup: ViewGroup,
override fun getBannerAd(
width: Int,
adId: String
) = with(viewGroup) {
): ViewGroup {
var adWidthPixels = width.toFloat()

if (adWidthPixels == 0f) {
adWidthPixels = resources.displayMetrics.widthPixels.toFloat()
adWidthPixels = context.resources.displayMetrics.widthPixels.toFloat()
}

removeAllViews()
addView(
AdView(viewGroup.context).apply {
adSize = AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
context,
(adWidthPixels / resources.displayMetrics.density).toInt()
)
adUnitId = adId
loadAd(AdRequest.Builder().build())
}
)
return AdView(context).apply {
adSize = AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
context,
(adWidthPixels / resources.displayMetrics.density).toInt()
)
adUnitId = adId
loadAd(getAdRequest())
}
}

override fun showInterstitialAd(
activity: Activity,
adId: String
) = InterstitialAd.load(
activity,
context,
adId,
AdRequest.Builder().build(),
getAdRequest(),
object : InterstitialAdLoadCallback() {
override fun onAdFailedToLoad(adError: LoadAdError) {
kermit.d { "InterstitialAd onAdFailedToLoad ${adError.message}" }
Expand All @@ -68,9 +68,9 @@ class AdManagerImpl : AdManager {
onAdLoaded: () -> Unit,
onReward: () -> Unit
) = RewardedAd.load(
activity,
context,
adId,
AdRequest.Builder().build(),
getAdRequest(),
object : RewardedAdLoadCallback() {
override fun onAdFailedToLoad(adError: LoadAdError) {
kermit.d { "RewardedAd onRewardedAdFailedToLoad" }
Expand All @@ -88,4 +88,6 @@ class AdManagerImpl : AdManager {
}
}
)

private fun getAdRequest() = AdRequest.Builder().build()
}
12 changes: 5 additions & 7 deletions ad/src/huawei/java/com/github/mustafaozhan/ad/AdManagerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package com.github.mustafaozhan.ad
import android.app.Activity
import android.content.Context
import android.view.ViewGroup
import android.widget.FrameLayout

class AdManagerImpl : AdManager {
class AdManagerImpl(private val context: Context) : AdManager {

override fun initMobileAds(context: Context) = Unit

override fun loadBannerAd(
viewGroup: ViewGroup,
adId: String
) = Unit
override fun getBannerAd(width: Int, adId: String): ViewGroup {
return FrameLayout(context)
}

override fun showInterstitialAd(
activity: Activity,
Expand Down
9 changes: 3 additions & 6 deletions ad/src/main/java/com/github/mustafaozhan/ad/AdManager.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.github.mustafaozhan.ad

import android.app.Activity
import android.content.Context
import android.view.ViewGroup

interface AdManager {

fun initMobileAds(context: Context)

fun loadBannerAd(
viewGroup: ViewGroup,
fun getBannerAd(
width: Int,
adId: String
)
): ViewGroup

fun showInterstitialAd(
activity: Activity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package com.github.mustafaozhan.ccc.android.app

import android.app.Application
import com.github.mustafaozhan.ccc.android.di.getPlatformModule
import com.github.mustafaozhan.ccc.android.di.platformModule
import com.github.mustafaozhan.ccc.client.di.initAndroid
import com.github.mustafaozhan.logmob.initCrashlytics
import com.github.mustafaozhan.logmob.initLogger
Expand All @@ -18,7 +18,7 @@ class CCCApplication : Application() {
initLogger()
initAndroid(
context = this,
platformModule = getPlatformModule(this)
platformModule = platformModule
)
initCrashlytics(this, enableAnalytics = true)
kermit.d { "CCCApplication onCreate" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package com.github.mustafaozhan.ccc.android.di

import android.content.Context
import com.github.mustafaozhan.ad.AdManager
import com.github.mustafaozhan.ad.AdManagerImpl
import com.github.mustafaozhan.billing.BillingManager
import com.github.mustafaozhan.billing.BillingManagerImpl
import org.koin.dsl.module

fun getPlatformModule(context: Context) = module {
var platformModule = module {
single<BillingManager> { BillingManagerImpl(get()) }
single<AdManager> {
AdManagerImpl().also {
it.initMobileAds(context)
}
}
single<AdManager> { AdManagerImpl(get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class CalculatorFragment : BaseVBFragment<FragmentCalculatorBinding>() {
}

private fun initViews() = with(binding) {
adManager.setBannerAd(
viewGroup = adViewContainer,
adViewContainer.setBannerAd(
adManager = adManager,
adId = getString(R.string.android_banner_ad_unit_id_calculator),
isExpired = calculatorViewModel.isRewardExpired()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class CurrenciesFragment : BaseVBFragment<FragmentCurrenciesBinding>() {
}

private fun initViews() = with(binding) {
adManager.setBannerAd(
viewGroup = adViewContainer,
adViewContainer.setBannerAd(
adManager = adManager,
adId = getString(R.string.android_banner_ad_unit_id_currencies),
isExpired = currenciesViewModel.isRewardExpired()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class SettingsFragment : BaseVBFragment<FragmentSettingsBinding>() {
}

private fun initViews() = with(binding) {
adManager.setBannerAd(
viewGroup = adViewContainer,
adViewContainer.setBannerAd(
adManager = adManager,
adId = getString(R.string.android_banner_ad_unit_id_settings),
isExpired = settingsViewModel.isRewardExpired()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package com.github.mustafaozhan.ccc.android.util
import android.annotation.SuppressLint
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -45,15 +45,16 @@ fun View.hideKeyboard() = context?.getSystemService(Context.INPUT_METHOD_SERVICE
?.castTo<InputMethodManager>()
?.hideSoftInputFromWindow(windowToken, 0)

fun AdManager.setBannerAd(
viewGroup: ViewGroup,
fun FrameLayout.setBannerAd(
adManager: AdManager,
adId: String,
isExpired: Boolean
) = if (isExpired) {
loadBannerAd(viewGroup, adId)
viewGroup.visible()
removeAllViews()
addView(adManager.getBannerAd(width, adId))
visible()
} else {
viewGroup.gone()
gone()
}

fun <T> Fragment.getNavigationResult(
Expand Down
8 changes: 8 additions & 0 deletions backend/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* Copyright (c) 2021 Mustafa Ozhan. All rights reserved.
*/
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile


plugins {
with(Plugins) {
Expand Down Expand Up @@ -68,3 +70,9 @@ tasks.register<Jar>("fatJar") {
tasks.named<ProcessResources>("jvmProcessResources") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
2 changes: 1 addition & 1 deletion basemob
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@Suppress("SpellCheckingInspection")
object Versions {
const val KOTLIN = "1.5.31"
const val ANDROID_GRADLE_PLUGIN = "7.2.0-alpha01"
const val ANDROID_GRADLE_PLUGIN = "7.2.0-alpha02"
const val ANDROID_MATERIAL = "1.4.0"
const val CONSTRAINT_LAYOUT = "2.1.1"
const val KTOR = "1.6.4"
Expand All @@ -31,7 +31,7 @@ object Versions {
const val MOKO_RESOURCES = "0.17.2"
const val DEPENDENCY_UPDATES = "0.39.0"
const val BUILD_HEALTH = "0.78.0"
const val BUILD_KONFIG = "0.10.2"
const val BUILD_KONFIG = "0.11.0"
const val WORK_RUNTIME = "2.7.0"
const val SPLASH_SCREEN = "1.0.0-alpha02"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ package com.github.mustafaozhan.ccc.client.di

import android.content.Context
import com.github.mustafaozhan.ccc.client.base.BaseViewModel
import com.github.mustafaozhan.ccc.client.di.module.androidModule
import com.github.mustafaozhan.ccc.client.di.module.clientModule
import com.github.mustafaozhan.ccc.client.di.module.getAndroidModule
import com.github.mustafaozhan.ccc.common.di.modules.apiModule
import com.github.mustafaozhan.ccc.common.di.modules.getDatabaseModule
import com.github.mustafaozhan.ccc.common.di.modules.getSettingsModule
import com.github.mustafaozhan.logmob.kermit
import org.koin.android.ext.koin.androidContext
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.KoinApplication
import org.koin.core.context.startKoin
Expand All @@ -24,8 +25,9 @@ fun initAndroid(
context: Context,
platformModule: Module
): KoinApplication = startKoin {
androidContext(context)
modules(
getAndroidModule(context),
androidModule,
platformModule,
clientModule,
apiModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import org.koin.dsl.module

private const val KEY_APPLICATION_PREFERENCES = "application_preferences"

fun getAndroidModule(context: Context) = module {
single { context }
val androidModule = module {
single { provideSharedPreferences(get()) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ data class MainData(
companion object {
internal const val AD_DELAY_INITIAL: Long = 60000
internal const val AD_DELAY_NORMAL: Long = 180000
internal const val REVIEW_DELAY: Long = 10000
internal const val REVIEW_DELAY: Long = 20000
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.github.mustafaozhan.ccc.client.di.module

import com.github.mustafaozhan.ccc.common.di.nsUserDefaults
import com.github.mustafaozhan.ccc.common.di.NativeDependencyWrapper
import org.koin.dsl.module
import platform.Foundation.NSUserDefaults

fun getIOSModule(userDefaults: NSUserDefaults) = module {
// https://github.com/InsertKoinIO/koin/issues/1016
// todo koin doesn't support to have it as single then use with get() for Objective-C classes
// single { userDefaults }
nsUserDefaults = userDefaults
single { NativeDependencyWrapper(userDefaults) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ import com.russhwolf.settings.AppleSettings
import com.russhwolf.settings.Settings
import com.squareup.sqldelight.drivers.native.NativeSqliteDriver
import org.koin.core.module.Module
import platform.Foundation.NSUserDefaults

lateinit var nsUserDefaults: NSUserDefaults

actual fun Module.getSettingsDefinition() = single<Settings> {
AppleSettings(nsUserDefaults)
AppleSettings(get<NativeDependencyWrapper>().userDefaults)
}

actual fun Module.getDatabaseDefinition(databaseName: String) = single {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.mustafaozhan.ccc.common.di

import platform.Foundation.NSUserDefaults

data class NativeDependencyWrapper(val userDefaults: NSUserDefaults)
2 changes: 1 addition & 1 deletion logmob

0 comments on commit 9c77e4b

Please sign in to comment.