-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/30-player-profile' into develop
- Loading branch information
Showing
267 changed files
with
3,738 additions
and
1,125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<!-- AdMob --> | ||
<string name="app_id">ca-app-pub-3793327349392749~1846337901</string> | ||
<string name="setup_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string> | ||
<string name="setup_interstitial_unit_id">ca-app-pub-3940256099942544/1033173712</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
android/DartsScorecard/app/src/main/java/nl/entreco/dartsscorecard/DscLogger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
android/DartsScorecard/app/src/main/java/nl/entreco/dartsscorecard/ad/AdBindings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package nl.entreco.dartsscorecard.ad | ||
|
||
import android.databinding.BindingAdapter | ||
import android.view.View | ||
import com.google.android.gms.ads.AdView | ||
|
||
/** | ||
* Created by Entreco on 29/12/2017. | ||
*/ | ||
abstract class AdBindings { | ||
companion object { | ||
@JvmStatic | ||
@BindingAdapter("viewModel") | ||
fun loadAd(view: AdView, viewModel: AdViewModel?) { | ||
viewModel?.provideAdd(view) | ||
} | ||
|
||
@JvmStatic | ||
@BindingAdapter("showAd") | ||
fun showAd(view: View, show: Boolean) { | ||
view.visibility = if (show) View.VISIBLE else View.GONE | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
android/DartsScorecard/app/src/main/java/nl/entreco/dartsscorecard/ad/AdLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package nl.entreco.dartsscorecard.ad | ||
|
||
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 javax.inject.Inject | ||
import javax.inject.Named | ||
|
||
/** | ||
* Created by Entreco on 29/12/2017. | ||
*/ | ||
class AdLoader @Inject constructor() : AdListener() { | ||
|
||
interface AdListener { | ||
fun onAdLoaded() | ||
fun onAdFailed() | ||
} | ||
|
||
private val adRequest by lazy { AdRequest.Builder().build() } | ||
private var listener: AdListener? = null | ||
|
||
override fun onAdLoaded() { | ||
super.onAdLoaded() | ||
listener?.onAdLoaded() | ||
} | ||
|
||
override fun onAdFailedToLoad(p0: Int) { | ||
super.onAdFailedToLoad(p0) | ||
listener?.onAdFailed() | ||
} | ||
|
||
fun loadAd(view: AdView, adListener: AdListener) { | ||
listener = adListener | ||
view.adListener = this | ||
view.loadAd(adRequest) | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
android/DartsScorecard/app/src/main/java/nl/entreco/dartsscorecard/ad/AdViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package nl.entreco.dartsscorecard.ad | ||
|
||
import android.arch.lifecycle.Lifecycle | ||
import android.arch.lifecycle.LifecycleObserver | ||
import android.arch.lifecycle.OnLifecycleEvent | ||
import android.databinding.ObservableBoolean | ||
import com.google.android.gms.ads.AdView | ||
import nl.entreco.dartsscorecard.BuildConfig | ||
import nl.entreco.dartsscorecard.base.BaseViewModel | ||
import nl.entreco.dartsscorecard.di.viewmodel.ActivityScope | ||
import nl.entreco.domain.ad.FetchPurchasedItemsResponse | ||
import nl.entreco.domain.ad.FetchPurchasedItemsUsecase | ||
import nl.entreco.domain.common.log.Logger | ||
import nl.entreco.domain.purchases.connect.ConnectToBillingUsecase | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
import javax.inject.Inject | ||
import javax.inject.Named | ||
|
||
@ActivityScope | ||
class AdViewModel @Inject constructor( | ||
@ActivityScope private val lifeCycle: Lifecycle, | ||
@ActivityScope private val connectToBillingUsecase: ConnectToBillingUsecase, | ||
private val fetchPurchasedItemsUsecase: FetchPurchasedItemsUsecase, | ||
private val adLoader: AdLoader, | ||
private val interstitialLoader: InterstitialLoader, | ||
private val logger: Logger, | ||
@Named("debugMode") private val debug: Boolean = BuildConfig.DEBUG) : BaseViewModel(), LifecycleObserver { | ||
|
||
val showAd = ObservableBoolean(false) | ||
private var serveAds = AtomicBoolean(false) // Let's give the user no Ads by default | ||
|
||
init { | ||
lifeCycle.addObserver(this) | ||
} | ||
|
||
fun provideAdd(view: AdView) { | ||
if(!debug) { | ||
adLoader.loadAd(view, object : AdLoader.AdListener { | ||
override fun onAdLoaded() { | ||
showAd.set(serveAds.get()) | ||
} | ||
|
||
override fun onAdFailed() { | ||
showAd.set(false) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
fun provideInterstitial() { | ||
if (!debug && serveAds.get()) { | ||
interstitialLoader.showInterstitial() | ||
} | ||
} | ||
|
||
private fun checkIfUserHasPurchasedItems() { | ||
connectToBillingUsecase.bind { connected -> | ||
if (connected) { | ||
fetchPurchasedItemsUsecase.exec(onPurchasesRetrieved(), onPurchasesError()) | ||
} | ||
} | ||
} | ||
|
||
private fun onPurchasesRetrieved(): (FetchPurchasedItemsResponse) -> Unit { | ||
return { response -> | ||
serveAds.set(response.serveAds) | ||
} | ||
} | ||
|
||
private fun onPurchasesError(): (Throwable) -> Unit { | ||
return { err -> | ||
logger.w("Unable to fetchPurchasedItems, $err") | ||
} | ||
} | ||
|
||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) | ||
fun bind() { | ||
checkIfUserHasPurchasedItems() | ||
} | ||
|
||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) | ||
fun unbind() { | ||
connectToBillingUsecase.unbind() | ||
} | ||
|
||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) | ||
fun destroy() { | ||
lifeCycle.removeObserver(this) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
android/DartsScorecard/app/src/main/java/nl/entreco/dartsscorecard/ad/InterstitialLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package nl.entreco.dartsscorecard.ad | ||
|
||
import com.google.android.gms.ads.AdListener | ||
import com.google.android.gms.ads.AdRequest | ||
import com.google.android.gms.ads.InterstitialAd | ||
import javax.inject.Inject | ||
import javax.inject.Named | ||
|
||
|
||
class InterstitialLoader @Inject constructor( | ||
@Named("interstitialId") private val interstitialId: String, | ||
private val interstitial: InterstitialAd) : AdListener() { | ||
|
||
private val adRequest: AdRequest by lazy { AdRequest.Builder().build() } | ||
|
||
init { | ||
interstitial.adUnitId = interstitialId | ||
interstitial.adListener = this | ||
interstitial.loadAd(adRequest) | ||
} | ||
|
||
fun showInterstitial() { | ||
if (interstitial.isLoaded) { | ||
interstitial.show() | ||
} | ||
} | ||
|
||
override fun onAdClosed() { | ||
super.onAdClosed() | ||
interstitial.loadAd(adRequest) | ||
} | ||
} |
Oops, something went wrong.