Commit 20700db5 authored by wanglei's avatar wanglei

白包接开屏广告和原生高级广告

parent 4dda6061
...@@ -3,20 +3,7 @@ ...@@ -3,20 +3,7 @@
<component name="deploymentTargetDropDown"> <component name="deploymentTargetDropDown">
<value> <value>
<entry key="app"> <entry key="app">
<State> <State />
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="adb-3426369207001D6-FYisxI._adb-tls-connect._tcp" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-03-27T10:49:46.632111500Z" />
</State>
</entry> </entry>
</value> </value>
</component> </component>
......
...@@ -35,21 +35,25 @@ ...@@ -35,21 +35,25 @@
<activity <activity
android:launchMode="singleTop"
android:name=".kokoInternalstorage.KoInternalkoActivity" android:name=".kokoInternalstorage.KoInternalkoActivity"
android:exported="false" android:exported="false"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:launchMode="singleTop"
android:name=".kokodup.KoDupFilekoActivity" android:name=".kokodup.KoDupFilekoActivity"
android:exported="false" android:exported="false"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:launchMode="singleTop"
android:name=".kokolistfile.KoListFilekoActivity" android:name=".kokolistfile.KoListFilekoActivity"
android:exported="false" android:exported="false"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:launchMode="singleTop"
android:name=".kokogridfile.KoGridFilekoActivity" android:name=".kokogridfile.KoGridFilekoActivity"
android:exported="false" android:exported="false"
android:screenOrientation="portrait" android:screenOrientation="portrait"
...@@ -66,6 +70,7 @@ ...@@ -66,6 +70,7 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true" android:exported="true"
......
...@@ -112,7 +112,9 @@ abstract class CommonViewModel : ViewModel() { ...@@ -112,7 +112,9 @@ abstract class CommonViewModel : ViewModel() {
if (filter(file)) { if (filter(file)) {
resultList.add(file.koFileDatako(context)) resultList.add(file.koFileDatako(context))
if (resultList.size == 20 && !firstSend) { if (resultList.size == 20 && !firstSend) {
onDo.invoke(resultList) val mainList = arrayListOf<KoFileDatako>()
mainList.addAll(resultList)
onDo.invoke(mainList)
resultList.clear() resultList.clear()
firstSend = true firstSend = true
} }
......
...@@ -11,8 +11,10 @@ import androidx.core.view.ViewCompat ...@@ -11,8 +11,10 @@ import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.google.android.gms.ads.MobileAds import com.google.android.gms.ads.MobileAds
import com.google.android.ump.FormError
import com.zxhy.fastfilemanagerpro.databinding.ActivityKokoLaunchBinding import com.zxhy.fastfilemanagerpro.databinding.ActivityKokoLaunchBinding
import com.zxhy.fastfilemanagerpro.kokoads.GoogleMobileAdsConsentManager import com.zxhy.fastfilemanagerpro.kokoads.GoogleMobileAdsConsentManager
import com.zxhy.fastfilemanagerpro.kokoads.KokoOpenAdManager
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
...@@ -25,6 +27,7 @@ class KokoLaunchActivity : AppCompatActivity() { ...@@ -25,6 +27,7 @@ class KokoLaunchActivity : AppCompatActivity() {
private lateinit var binding: ActivityKokoLaunchBinding private lateinit var binding: ActivityKokoLaunchBinding
private val isAdsInitializeCalled = AtomicBoolean(false) private val isAdsInitializeCalled = AtomicBoolean(false)
private lateinit var googleMobileAdsConsentManager: GoogleMobileAdsConsentManager private lateinit var googleMobileAdsConsentManager: GoogleMobileAdsConsentManager
private lateinit var kokoOpenAdManager: KokoOpenAdManager
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
...@@ -36,40 +39,49 @@ class KokoLaunchActivity : AppCompatActivity() { ...@@ -36,40 +39,49 @@ class KokoLaunchActivity : AppCompatActivity() {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets insets
} }
kokoOpenAdManager = (application as MyApplication).kokoOpenAdManager
(application as MyApplication).kokoOpenAdManager.adShowComplete = { showed -> val job = lifecycleScope.launch(Dispatchers.Main) {
if (showed) { while (binding.ProgressBar.progress != 100) {
printTaskActivity() binding.ProgressBar.progress += 2
startActivity(Intent(this, MainActivity::class.java)) delay(50)
} else {
lifecycleScope.launch(Dispatchers.Main) {
while (binding.ProgressBar.progress != 100) {
binding.ProgressBar.progress += 2
delay(50)
}
startActivity(Intent(this@KokoLaunchActivity, MainActivity::class.java))
finish()
}
} }
startActivity(Intent(this@KokoLaunchActivity, MainActivity::class.java))
finish()
} }
setDebugAdsConsent()
(application as MyApplication).kokoOpenAdManager.showAdIfAvailable(this)
kokoOpenAdManager.adLoadComplete = { loaded ->
if (loaded) {
job.cancel()
kokoOpenAdManager.showAdIfAvailable(this@KokoLaunchActivity)
}
}
kokoOpenAdManager.adShowing = {
job.cancel()
}
kokoOpenAdManager.adShowComplete = {
job.cancel()
kokoOpenAdManager.clearAllCallBack()
startActivity(Intent(this@KokoLaunchActivity, MainActivity::class.java))
finish()
}
setDebugAdsConsent {}
} }
/** /**
* 设置Debug广告同意 * 设置Debug广告同意
*/ */
private fun setDebugAdsConsent() { private fun setDebugAdsConsent(gatherConsentAction: (consentError: FormError?) -> Unit) {
googleMobileAdsConsentManager = googleMobileAdsConsentManager =
GoogleMobileAdsConsentManager.getInstance(applicationContext) GoogleMobileAdsConsentManager.getInstance(applicationContext)
//获取广告同意设置 //获取广告同意设置
googleMobileAdsConsentManager.gatherConsent(this) { consentError -> googleMobileAdsConsentManager.gatherConsent(this) { consentError ->
if (consentError != null) { gatherConsentAction.invoke(consentError)
}
if (googleMobileAdsConsentManager.canRequestAds) { if (googleMobileAdsConsentManager.canRequestAds) {
initializeMobileAdsSdk() initializeMobileAdsSdk()
......
package com.zxhy.fastfilemanagerpro package com.zxhy.fastfilemanagerpro
import android.content.Intent import android.content.Intent
import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.MenuItem import android.view.MenuItem
...@@ -12,6 +13,7 @@ import androidx.appcompat.app.AppCompatActivity ...@@ -12,6 +13,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.navigation.NavOptions
import androidx.navigation.findNavController import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment import androidx.navigation.fragment.NavHostFragment
import com.google.android.gms.ads.AdListener import com.google.android.gms.ads.AdListener
...@@ -50,17 +52,6 @@ class MainActivity : AppCompatActivity() { ...@@ -50,17 +52,6 @@ class MainActivity : AppCompatActivity() {
val navHostFragment = val navHostFragment =
supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment
navHostFragment.navController.addOnDestinationChangedListener { controller, destination, arguments ->
when (destination.id) {
R.id.koManagerkoFragment -> {
binding.bnv.selectedItemId = R.id.nav_manager
}
R.id.koHomekoFragment -> {
binding.bnv.selectedItemId = R.id.nav_home
}
}
}
binding.bnv.setOnItemSelectedListener(object : AdapterView.OnItemSelectedListener, binding.bnv.setOnItemSelectedListener(object : AdapterView.OnItemSelectedListener,
NavigationBarView.OnItemSelectedListener { NavigationBarView.OnItemSelectedListener {
...@@ -81,13 +72,28 @@ class MainActivity : AppCompatActivity() { ...@@ -81,13 +72,28 @@ class MainActivity : AppCompatActivity() {
when (item.itemId) { when (item.itemId) {
R.id.nav_manager -> { R.id.nav_manager -> {
runCatching { runCatching {
findNavController(R.id.container).navigate(R.id.action_koHomekoFragment_to_koManagerkoFragment) val navOptions = NavOptions.Builder()
.setLaunchSingleTop(true)
.setPopUpTo(R.id.koHomekoFragment, true)
.build()
navHostFragment.navController.navigate(
R.id.action_koHomekoFragment_to_koManagerkoFragment, null,
navOptions
)
} }
} }
R.id.nav_home -> { R.id.nav_home -> {
runCatching { runCatching {
findNavController(R.id.container).navigate(R.id.action_koManagerkoFragment_to_koHomekoFragment) val navOptions = NavOptions.Builder()
.setLaunchSingleTop(true)
.setPopUpTo(R.id.koManagerkoFragment, true)
.build()
navHostFragment.navController.navigate(
R.id.action_koManagerkoFragment_to_koHomekoFragment,
null,
navOptions
)
} }
} }
} }
...@@ -104,18 +110,16 @@ class MainActivity : AppCompatActivity() { ...@@ -104,18 +110,16 @@ class MainActivity : AppCompatActivity() {
} }
} }
override fun onRestart() { override fun onRestart() {
super.onRestart() super.onRestart()
startActivity(Intent(this, KokoLaunchActivity::class.java)) (application as MyApplication).kokoOpenAdManager.showAdIfAvailable(this)
} }
fun setSystemBarColor(@ColorRes colorRes: Int) { override fun onDestroy() {
// color_b3000000 权限窗口颜色 super.onDestroy()
window.statusBarColor = ContextCompat.getColor(this, colorRes)
} }
companion object { companion object {
const val ADMOB_AD_UNIT_ID = "ca-app-pub-3940256099942544/2247696110" const val ADMOB_AD_UNIT_ID = "ca-app-pub-3940256099942544/2247696110"
} }
......
...@@ -36,6 +36,7 @@ class GoogleMobileAdsConsentManager private constructor(context: Context) { ...@@ -36,6 +36,7 @@ class GoogleMobileAdsConsentManager private constructor(context: Context) {
val params = val params =
ConsentRequestParameters.Builder().setConsentDebugSettings(debugSettings).build() ConsentRequestParameters.Builder().setConsentDebugSettings(debugSettings).build()
consentInformation.requestConsentInfoUpdate(activity, params, consentInformation.requestConsentInfoUpdate(activity, params,
{//同意信息上传成功回调 {//同意信息上传成功回调
UserMessagingPlatform.loadAndShowConsentFormIfRequired(activity) { formError -> UserMessagingPlatform.loadAndShowConsentFormIfRequired(activity) { formError ->
...@@ -47,6 +48,7 @@ class GoogleMobileAdsConsentManager private constructor(context: Context) { ...@@ -47,6 +48,7 @@ class GoogleMobileAdsConsentManager private constructor(context: Context) {
consentGatheringComplete.invoke(requestConsentError) consentGatheringComplete.invoke(requestConsentError)
} }
) )
} }
......
...@@ -22,7 +22,16 @@ class KokoOpenAdManager { ...@@ -22,7 +22,16 @@ class KokoOpenAdManager {
private var isShowingAd = false private var isShowingAd = false
private var loadTime: Long = 0//广告加载的时间 private var loadTime: Long = 0//广告加载的时间
var adShowing: (() -> Unit)? = null
var adShowComplete: ((showed: Boolean) -> Unit)? = null var adShowComplete: ((showed: Boolean) -> Unit)? = null
var adLoadComplete: ((loaded: Boolean) -> Unit)? = null
fun clearAllCallBack() {
adShowing = null
adShowComplete = null
adLoadComplete = null
}
/** /**
* 广告加载回调 * 广告加载回调
...@@ -32,10 +41,12 @@ class KokoOpenAdManager { ...@@ -32,10 +41,12 @@ class KokoOpenAdManager {
appOpenAd = ad appOpenAd = ad
isLoadingAd = false isLoadingAd = false
loadTime = Date().time loadTime = Date().time
adLoadComplete?.invoke(true)
} }
override fun onAdFailedToLoad(loadAdError: LoadAdError) { override fun onAdFailedToLoad(loadAdError: LoadAdError) {
isLoadingAd = false isLoadingAd = false
adLoadComplete?.invoke(true)
} }
} }
...@@ -44,6 +55,7 @@ class KokoOpenAdManager { ...@@ -44,6 +55,7 @@ class KokoOpenAdManager {
*/ */
inner class MyFullScreenContentCallback(val activity: Activity) : FullScreenContentCallback() { inner class MyFullScreenContentCallback(val activity: Activity) : FullScreenContentCallback() {
override fun onAdShowedFullScreenContent() { override fun onAdShowedFullScreenContent() {
adShowing?.invoke()
Log.d(LOG_TAG, "onAdShowedFullScreenContent.") Log.d(LOG_TAG, "onAdShowedFullScreenContent.")
} }
...@@ -93,11 +105,14 @@ class KokoOpenAdManager { ...@@ -93,11 +105,14 @@ class KokoOpenAdManager {
* 显示广告 * 显示广告
*/ */
fun showAdIfAvailable(activity: Activity) { fun showAdIfAvailable(activity: Activity) {
val TAG = "showAdIfAvailable"
if (isShowingAd) { if (isShowingAd) {
Log.e(TAG, "isShowingAd=${isShowingAd}")
return return
} }
if (!existOpenAdCanShow()) { if (!existOpenAdCanShow()) {
Log.e(TAG, "existOpenAdCanShow=false")
adShowComplete?.invoke(false) adShowComplete?.invoke(false)
if (googleMobileAdsConsentManager.canRequestAds) { if (googleMobileAdsConsentManager.canRequestAds) {
loadAd(activity) loadAd(activity)
...@@ -108,11 +123,12 @@ class KokoOpenAdManager { ...@@ -108,11 +123,12 @@ class KokoOpenAdManager {
appOpenAd?.fullScreenContentCallback = MyFullScreenContentCallback(activity) appOpenAd?.fullScreenContentCallback = MyFullScreenContentCallback(activity)
isShowingAd = true isShowingAd = true
Log.e(TAG, "调用展示广告")
appOpenAd?.show(activity) appOpenAd?.show(activity)
} }
/** /**
* 检查已有广告是否显示 * 检查已有广告是否显示
*/ */
fun existOpenAdCanShow(): Boolean { fun existOpenAdCanShow(): Boolean {
return appOpenAd != null && adLoadLessInterval(1) return appOpenAd != null && adLoadLessInterval(1)
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
<com.google.android.gms.ads.nativead.MediaView <com.google.android.gms.ads.nativead.MediaView
android:id="@+id/ad_media" android:id="@+id/ad_media"
android:layout_width="250dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/tv_app_name" android:id="@+id/tv_app_name"
...@@ -272,7 +272,7 @@ ...@@ -272,7 +272,7 @@
<FrameLayout <FrameLayout
android:id="@+id/fl_ad" android:id="@+id/fl_ad"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="140dp"
android:layout_marginHorizontal="20dp" android:layout_marginHorizontal="20dp"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
......
<resources> <resources>
<string name="app_name">fastFileManagerPro</string> <string name="app_name">Fast File Manager Pro</string>
<string name="permission_tips">There are no permissions We need to get permission to read all files.</string> <string name="permission_tips">There are no permissions We need to get permission to read all files.</string>
</resources> </resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment