Commit bc34ac4c authored by wanglei's avatar wanglei

...

parent 3064c296
......@@ -35,6 +35,7 @@ class MyApplication : Application() {
var pdfSplitLanguage: String = Locale.ENGLISH.language
var wordLanguage: String = Locale.ENGLISH.language
var umpCanAd: Boolean = true
@JvmField
var PAUSED_VALUE = 0
......
......@@ -7,40 +7,41 @@ import android.graphics.Color
import android.os.Build
import androidx.activity.result.contract.ActivityResultContracts
import androidx.lifecycle.lifecycleScope
import com.base.pdfviewerscannerwhite.BuildConfig
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.ads.AdmobHelper.initAdmobAd
import com.base.pdfviewerscannerwhite.ads.admob.AdmobOpenUtils
import com.base.pdfviewerscannerwhite.bean.ConstObject.haveSelectLanguage
import com.base.pdfviewerscannerwhite.bean.ConstObject.ifAgreePrivacy
import com.base.pdfviewerscannerwhite.databinding.ActivitySplashBinding
import com.base.pdfviewerscannerwhite.databinding.ActivitySplash2Binding
import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.helper.MyApplication
import com.base.pdfviewerscannerwhite.helper.MyApplication.Companion.umpCanAd
import com.base.pdfviewerscannerwhite.service.StayNotificationService.Companion.startStayNotification
import com.base.pdfviewerscannerwhite.ui.main.MainActivity
import com.base.pdfviewerscannerwhite.ui.set.SetLanguageActivity
import com.base.pdfviewerscannerwhite.utils.BarUtils
import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.utils.ToastUtils.toast
import com.base.pdfviewerscannerwhite.utils.UmpUtils
import com.base.pdfviewerscannerwhite.utils.UmpUtils.requestUMP
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import com.cherry.lib.doc.office.system.IFind
import java.util.Calendar
import java.util.concurrent.atomic.AtomicBoolean
@SuppressLint("CustomSplashScreen")
class SplashActivity : BaseActivity<ActivitySplashBinding>(), SplashView {
class SplashActivity : BaseActivity<ActivitySplash2Binding>(), SplashView {
private val TAG = "SplashActivity"
private var job: Job? = null
private lateinit var splashPresenter: SplashPresenter
override val binding: ActivitySplashBinding by lazy {
ActivitySplashBinding.inflate(layoutInflater)
override val binding: ActivitySplash2Binding by lazy {
ActivitySplash2Binding.inflate(layoutInflater)
}
var canAd: Boolean = true
@SuppressLint("SetTextI18n")
override fun initView() {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
......@@ -52,24 +53,63 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(), SplashView {
}
splashPresenter = SplashPresenter(this)
// 获取当前日期
val calendar: Calendar = Calendar.getInstance()
val month: Int = calendar.get(Calendar.MONTH)
// 获取当月的第几天
val dayOfMonth: Int = calendar.get(Calendar.DAY_OF_MONTH)
//是星期几
val dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)
val dayOfWeekName = when (dayOfWeek) {
Calendar.SUNDAY -> R.string.sunday
Calendar.MONDAY -> R.string.monday
Calendar.TUESDAY -> R.string.tuesday
Calendar.WEDNESDAY -> R.string.wednesday
Calendar.THURSDAY -> R.string.thursday
Calendar.FRIDAY -> R.string.friday
Calendar.SATURDAY -> R.string.saturday
else -> 0
}
binding.tvXingqi.text = resources.getString(dayOfWeekName)
val monthName = when (month) {
0 -> "January"
1 -> "February"
2 -> "March"
3 -> "April"
4 -> "May"
5 -> "June"
6 -> "July"
7 -> "August"
8 -> "September"
9 -> "October"
10 -> "November"
11 -> "December"
else -> "Unknown"
}
binding.tvMonthDay.text = "$monthName $dayOfMonth"
val isHotLaunch = intent.extras?.getBoolean("isHotLaunch") ?: false
if (BuildConfig.DEBUG) {
toast("isHotLaunch=$isHotLaunch")
}
ifAgreePrivacy = true
if (ifAgreePrivacy) {
requestUMP(this,
loadAndShowErrorAction = {
LogEx.logDebug(TAG, "loadAndShowErrorAction")
agreePrivacy()
},
formErrorAction = {
LogEx.logDebug(TAG, "formErrorAction")
agreePrivacy()
},
dialogAction = {
LogEx.logDebug(TAG, "dialogAction $it")
canAd = it
if (isHotLaunch) {
agreePrivacy()
} else {
UmpUtils.callback = {
LogEx.logDebug(TAG, "UmpUtils.callback")
umpCanAd = it
agreePrivacy()
})
}
requestUMP(this)
}
}
}
......@@ -80,6 +120,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(), SplashView {
splashPresenter.pauseJumpJob()
}
}, onHidden = {
LogEx.logDebug(TAG, "ad jumpNext")
jumpNext()
})
......@@ -88,43 +129,16 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(), SplashView {
override fun agreePrivacy() {
startStayNotification()
if (canAd) {
if (umpCanAd) {
initAdmobAd()
showAd()
}
startProgressJob()
splashPresenter.startJumpJob = true
splashPresenter.startJumpJob(lifecycleScope)
}
/**
* 跑进度条,进度条不关联跳转逻辑
*/
private fun startProgressJob() {
if (job == null && binding.progressBar.progress != 100) {
job = lifecycleScope.launch(Dispatchers.Main) {
while (isActive) {
binding.progressBar.progress += 1
delay(150)
if (binding.progressBar.progress == 100) {
cancel()
}
}
}
}
}
/**
* 暂停进度条
*/
private fun pauseProgressJob() {
job?.cancel()
job = null
}
override fun onPause() {
super.onPause()
pauseProgressJob()
splashPresenter.pauseJumpJob()
}
......@@ -133,7 +147,6 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(), SplashView {
updateAppLanguage(MyApplication.splashLanguage) {
MyApplication.splashLanguage = it
}
startProgressJob()
splashPresenter.startJumpJob(lifecycleScope)
}
......@@ -145,7 +158,6 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(), SplashView {
}
jump.set(true)
LogEx.logDebug(TAG, "jumpNext")
binding.progressBar.progress = 100
binding.root.postDelayed({
......
......@@ -2,6 +2,7 @@ package com.base.pdfviewerscannerwhite.ui.splash
import androidx.lifecycle.LifecycleCoroutineScope
import com.base.pdfviewerscannerwhite.ads.AdmobHelper.open_ad_loading
import com.base.pdfviewerscannerwhite.bean.ConstObject
import com.base.pdfviewerscannerwhite.utils.AppPreferences
import com.base.pdfviewerscannerwhite.utils.LogEx
import kotlinx.coroutines.Job
......@@ -17,20 +18,26 @@ class SplashPresenter(
var loadingTime = AppPreferences.getInstance().getString(open_ad_loading, "15").toInt()
var startJumpJob: Boolean = false
/**
* 超时跳转
*/
fun startJumpJob(lifecycleCoroutineScope: LifecycleCoroutineScope) {
if (jumpJob == null) {
val startTime = System.currentTimeMillis()
jumpJob = lifecycleCoroutineScope.launch {
LogEx.logDebug(TAG, "open_ad_loading=$loadingTime")
delay(loadingTime * 1000L)
val endTime = System.currentTimeMillis()
LogEx.logDebug(TAG, "超时跳转 time=${endTime - startTime}")
splashView.jumpNext()
loadingTime = 30
if (ConstObject.ifAgreePrivacy && startJumpJob) {
if (jumpJob == null) {
val startTime = System.currentTimeMillis()
jumpJob = lifecycleCoroutineScope.launch {
LogEx.logDebug(TAG, "open_ad_loading=$loadingTime")
delay(loadingTime * 1000L)
val endTime = System.currentTimeMillis()
LogEx.logDebug(TAG, "超时跳转 time=${endTime - startTime}")
splashView.jumpNext()
}
}
}
}
/**
......
package com.base.pdfviewerscannerwhite.utils
import android.content.Context
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.bean.ConstObject
import java.text.SimpleDateFormat
import java.time.LocalDate
import java.time.format.TextStyle
import java.util.Locale
object KotlinExt {
fun Number.toFormatSize(count: Int = 1): String {
......
......@@ -4,39 +4,35 @@ import android.app.Activity
import android.content.Context
import com.base.pdfviewerscannerwhite.BuildConfig
import com.google.android.ump.ConsentDebugSettings
import com.google.android.ump.ConsentForm
import com.google.android.ump.ConsentInformation
import com.google.android.ump.ConsentRequestParameters
import com.google.android.ump.FormError
import com.google.android.ump.UserMessagingPlatform
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
object UmpUtils {
// requireActivity().requestUMP(loadAndShowErrorAction = {
// Toast.makeText(context, "loadAndShowErrorAction", Toast.LENGTH_SHORT).show()
// }, formErrorAction = {
// Toast.makeText(context, "formErrorAction", Toast.LENGTH_SHORT).show()
// },
// dialogAction = {
// Toast.makeText(context, "dialogAction flag=$it", Toast.LENGTH_SHORT).show()
//
// })
private fun Context.umpTest(): ConsentDebugSettings {
val debugSettings = ConsentDebugSettings.Builder(this)
debugSettings.addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
debugSettings.addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231")
debugSettings.setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
//通过TEST-DEVICE-HASHED-ID log过滤ConsentDebugSettings 打印测试id,使用测试id来测试
// debugSettings.addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
debugSettings.addTestDeviceHashedId("73FE7C2634104D50A11BE9B902AA0FA6")
return debugSettings.build()
}
private val TAG = "UmpHelp"
fun requestUMP(
activity: Activity,
loadAndShowErrorAction: (() -> Unit)? = null,//加载弹出错误
formErrorAction: (() -> Unit)? = null,//请求错误
dialogAction: ((flag: Boolean) -> Unit)? = null,//dialog授权
) {
var callBacked: Boolean = false
var callback: ((flag: Boolean) -> Unit)? = null
private val TAG = "UmpUtils"
fun requestUMP(activity: Activity) {
val paramsBuild = ConsentRequestParameters.Builder()
......@@ -49,33 +45,68 @@ object UmpUtils {
paramsBuild.setTagForUnderAgeOfConsent(false)
val params = paramsBuild.build()
val consentInformation = UserMessagingPlatform.getConsentInformation(activity)
val consentInformation: ConsentInformation = UserMessagingPlatform.getConsentInformation(activity)
if (BuildConfig.DEBUG) {
consentInformation.reset()
}
val updateSuccessListener = ConsentInformation.OnConsentInfoUpdateSuccessListener {
UserMessagingPlatform.loadAndShowConsentFormIfRequired(activity)
{ loadAndShowError: FormError? ->
if (loadAndShowError != null) {
if (!callBacked) {
callBacked = true
loadAndShowErrorAction?.invoke()
}
} else {
// Consent has been gathered.
// 授权完成,初始化SDK
if (!callBacked) {
callBacked = true
dialogAction?.invoke(consentInformation.canRequestAds())
}
LogEx.logDebug(TAG, "isConsentFormAvailable=${consentInformation.isConsentFormAvailable}")
if (consentInformation.isConsentFormAvailable) {
MainScope().launch(Dispatchers.Main) {
delay(500)
loadAndShowConsentFormIfRequired(activity, consentInformation)
}
} else {
callback?.invoke(false)
callback = null
}
}
val updateFailureListener = ConsentInformation.OnConsentInfoUpdateFailureListener {
if (!callBacked) {
callBacked = true
formErrorAction?.invoke()
}
LogEx.logDebug(TAG, "message=${it.message} errorCode=${it.errorCode}")
callback?.invoke(false)
callback = null
}
consentInformation.requestConsentInfoUpdate(activity, params, updateSuccessListener, updateFailureListener)
}
fun loadAndShowConsentFormIfRequired(activity: Activity, consentInformation: ConsentInformation) {
UserMessagingPlatform.loadConsentForm(
activity,
object : UserMessagingPlatform.OnConsentFormLoadSuccessListener {
override fun onConsentFormLoadSuccess(consentForm: ConsentForm) {
LogEx.logDebug(TAG, "onConsentFormLoadSuccess")
consentForm.show(activity) {
callback?.invoke(consentInformation.canRequestAds())
callback = null
}
}
},
object : UserMessagingPlatform.OnConsentFormLoadFailureListener {
override fun onConsentFormLoadFailure(p0: FormError) {
//https://groups.google.com/g/google-admob-ads-sdk/c/x-fyDOfMSqU/m/MeZX3mO4AAAJ
LogEx.logDebug(TAG, "onConsentFormLoadFailure ${p0.message} ${p0.errorCode}")
callback?.invoke(consentInformation.canRequestAds())
callback = null
}
})
// UserMessagingPlatform.loadAndShowConsentFormIfRequired(activity) { loadAndShowError: FormError? ->
// LogEx.logDebug(
// TAG,
// "loadAndShowConsentFormIfRequired message=${loadAndShowError?.message} errorCode=${loadAndShowError?.errorCode}"
// )
// if (loadAndShowError != null) {
// callback?.invoke(false)
// callback = null
// } else {
// callback?.invoke(consentInformation.canRequestAds())
// callback = null
// }
// }
}
}
\ No newline at end of file
......@@ -3,29 +3,21 @@
<!-- 设置背景色 -->
<item android:id="@android:id/background">
<shape>
<stroke
android:width="1.5dp"
android:color="#00B8DE" />
<corners android:radius="8dp" />
<solid android:color="#3300B8DE" />
<corners android:radius="2.5dp" />
</shape>
</item>
<!-- 设置进度条颜色 -->
<item
android:id="@android:id/progress"
android:bottom="3dp"
android:end="3dp"
android:start="3dp"
android:top="3dp">
<!-- <scale android:scaleWidth="100%">-->
<clip>
<shape>
<corners android:radius="5dp" />
<solid android:color="#00B8DE" />
</shape>
</clip>
<!-- </scale>-->
</item>
<!-- <item android:id="@android:id/progress">-->
<!-- <scale android:scaleWidth="100%">-->
<!-- <clip>-->
<!-- <shape>-->
<!-- <corners android:radius="2.5dp" />-->
<!-- <solid android:color="#00B8DE" />-->
<!-- </shape>-->
<!-- </clip>-->
<!-- </scale>-->
<!-- </item>-->
</layer-list>
\ No newline at end of file
......@@ -4,6 +4,6 @@
<item
android:gravity="top|center_horizontal"
android:top="220dp">
<bitmap android:src="@mipmap/qdylogo" />
<bitmap android:src="@mipmap/qdyebg" />
</item>
</layer-list>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_bp"
tools:context=".ui.splash.SplashActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginTop="82dp"
android:src="@mipmap/qdylogo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_xingqi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:layout_marginTop="180dp"
android:textColor="#7D7D7F"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Wednesday" />
<TextView
android:id="@+id/tv_month_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="31dp"
android:textColor="#16151A"
android:textSize="45sp"
app:layout_constraintStart_toStartOf="@id/tv_xingqi"
app:layout_constraintTop_toBottomOf="@id/tv_xingqi"
tools:text="October 09" />
<View
android:layout_width="48dp"
android:layout_height="1dp"
android:layout_marginEnd="8dp"
android:background="#CFCFD0"
app:layout_constraintBottom_toBottomOf="@id/tv_app_name"
app:layout_constraintEnd_toStartOf="@id/tv_app_name"
app:layout_constraintTop_toTopOf="@id/tv_app_name" />
<TextView
android:id="@+id/tv_app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:text="@string/app_name"
android:textColor="#7D7D7F"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.45" />
<ImageView
android:id="@+id/iv_document"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="27dp"
android:src="@mipmap/document_all"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_app_name" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
app:layout_constraintStart_toStartOf="@id/iv_document"
app:layout_constraintTop_toBottomOf="@id/iv_document">
<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="151dp"
android:layout_height="15dp"
android:indeterminate="true"
android:indeterminateTint="#00B8DE"
android:indeterminateTintMode="src_atop" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
This diff is collapsed.
......@@ -63,5 +63,12 @@
<string name="delete_password_the_file_is_not_password_protected">Delete password, the file is not password protected</string>
<string name="input_password">Input Password</string>
<string name="password_protected">%1$s password protected</string>
<string name="sunday">Sunday</string>
<string name="monday">Monday</string>
<string name="tuesday">Tuesday</string>
<string name="wednesday">Wednesday</string>
<string name="thursday">Thursday</string>
<string name="friday">Friday</string>
<string name="saturday">Saturday</string>
</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