-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Google AdMob added (FirebaseFree build is AdFree also)
- Loading branch information
1 parent
805bde9
commit 1ff4120
Showing
11 changed files
with
107 additions
and
52 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
52 changes: 52 additions & 0 deletions
52
app/src/firebase/kotlin/info/dvkr/screenstream/ui/activity/AdActivity.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,52 @@ | ||
package info.dvkr.screenstream.ui.activity | ||
|
||
import android.util.DisplayMetrics | ||
import android.view.ViewTreeObserver | ||
import android.widget.FrameLayout | ||
import androidx.annotation.LayoutRes | ||
import com.google.android.gms.ads.* | ||
|
||
|
||
abstract class AdActivity(@LayoutRes contentLayoutId: Int) : AppUpdateActivity(contentLayoutId) { | ||
|
||
private var adView: AdView? = null | ||
|
||
fun loadAd(adViewContainer: FrameLayout) { | ||
MobileAds.initialize(this) {} | ||
adView = AdView(this) | ||
adViewContainer.addView(adView) | ||
adViewContainer.viewTreeObserver.addOnGlobalLayoutListener( | ||
object : ViewTreeObserver.OnGlobalLayoutListener { | ||
override fun onGlobalLayout() { | ||
val outMetrics = DisplayMetrics().also { windowManager.defaultDisplay.getMetrics(it) } | ||
var adWidthPixels = adViewContainer.width.toFloat() | ||
if (adWidthPixels == 0f) adWidthPixels = outMetrics.widthPixels.toFloat() | ||
val adWidth = (adWidthPixels / outMetrics.density).toInt() | ||
val adSize = AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this@AdActivity, adWidth) | ||
|
||
// Device MUST be added to test devices | ||
adView!!.adUnitId = "ca-app-pub-3406399667931208/3206361386" | ||
adView!!.adSize = adSize | ||
adView!!.loadAd(AdRequest.Builder().build()) | ||
|
||
adViewContainer.viewTreeObserver.removeOnGlobalLayoutListener(this) | ||
} | ||
} | ||
) | ||
} | ||
|
||
override fun onPause() { | ||
adView?.pause() | ||
super.onPause() | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
adView?.resume() | ||
} | ||
|
||
override fun onDestroy() { | ||
adView?.destroy() | ||
super.onDestroy() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/firebasefree/kotlin/info/dvkr/screenstream/ui/activity/AdActivity.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,10 @@ | ||
package info.dvkr.screenstream.ui.activity | ||
|
||
import android.widget.FrameLayout | ||
import androidx.annotation.LayoutRes | ||
|
||
|
||
abstract class AdActivity(@LayoutRes contentLayoutId: Int) : AppUpdateActivity(contentLayoutId) { | ||
|
||
fun loadAd(adViewContainer: FrameLayout) {} | ||
} |
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
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
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
34 changes: 0 additions & 34 deletions
34
data/src/main/kotlin/info/dvkr/screenstream/data/state/helper/MediaProjectionHelper.kt
This file was deleted.
Oops, something went wrong.