Commit fbda7798 authored by wanglei's avatar wanglei

...

parent efd153f0
...@@ -24,7 +24,6 @@ object AdmobHelper { ...@@ -24,7 +24,6 @@ object AdmobHelper {
const val native_limit_click = "native_limit_click" const val native_limit_click = "native_limit_click"
//是否展示多语言 //是否展示多语言
val showLanPage = "showLanPage" val showLanPage = "showLanPage"
...@@ -55,9 +54,6 @@ object AdmobHelper { ...@@ -55,9 +54,6 @@ object AdmobHelper {
//可请求时间段间隔时间 //可请求时间段间隔时间
const val ad_request_period_interval = "ad_request_period_interval" const val ad_request_period_interval = "ad_request_period_interval"
//展示广告关闭时赋值
var lastShowedOnHiddenTime = 0L
var isAdInit = AtomicBoolean(false) var isAdInit = AtomicBoolean(false)
fun initAdmobAd() { fun initAdmobAd() {
...@@ -67,6 +63,28 @@ object AdmobHelper { ...@@ -67,6 +63,28 @@ object AdmobHelper {
} }
} }
//上次展示广告时间关闭赋值
var lastShowedOnHiddenTime = 0L
get() {
return AppPreferences.getInstance().getLong("lastShowedOnHiddenTime", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("lastShowedOnHiddenTime", value, true)
}
/**
* 通用广告条件判断
*/
fun canCommonShowAd(): Boolean {
val interval = AppPreferences.getInstance().getString("ad_interval", "10").toInt()
if (System.currentTimeMillis() - lastShowedOnHiddenTime < interval * 1000L) {
return false
}
return true
}
//上次scan展示ad时间 //上次scan展示ad时间
var lastScanShowAd = 0L var lastScanShowAd = 0L
get() { get() {
...@@ -113,4 +131,5 @@ object AdmobHelper { ...@@ -113,4 +131,5 @@ object AdmobHelper {
return System.currentTimeMillis() - lastCloseDocumentShowAd > interval * 1000L return System.currentTimeMillis() - lastCloseDocumentShowAd > interval * 1000L
} }
} }
\ No newline at end of file
...@@ -3,6 +3,8 @@ package com.base.pdfviewerscannerwhite.ui.document.pdf ...@@ -3,6 +3,8 @@ package com.base.pdfviewerscannerwhite.ui.document.pdf
import android.content.Intent import android.content.Intent
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.artifex.mupdfdemo.MuPDFCore import com.artifex.mupdfdemo.MuPDFCore
import com.base.pdfviewerscannerwhite.ads.AdmobHelper
import com.base.pdfviewerscannerwhite.ads.admob.AdmobInterstitialUtils
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_MERGE_PDF import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_MERGE_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_SAVE_PDF import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_SAVE_PDF
import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_SPLIT_PDF import com.base.pdfviewerscannerwhite.bean.ConstObject.DO_SPLIT_PDF
...@@ -43,6 +45,17 @@ class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() { ...@@ -43,6 +45,17 @@ class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() {
} }
} }
fun progressFinishAd(next: () -> Unit) {
if (AdmobHelper.canCommonShowAd()) {
AdmobInterstitialUtils.showInterstitialAd(this) {
next.invoke()
}
} else {
next.invoke()
}
}
override fun initView() { override fun initView() {
pdfPresenter = PdfPresenter(this) pdfPresenter = PdfPresenter(this)
initSpPa() initSpPa()
...@@ -51,14 +64,17 @@ class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() { ...@@ -51,14 +64,17 @@ class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() {
when (doWhat) { when (doWhat) {
DO_SPLIT_PDF -> { DO_SPLIT_PDF -> {
progressFinishAction = { progressFinishAction = {
if (resultFile != null) { progressFinishAd {
startActivity(Intent(this, PdfActivity::class.java).apply { if (resultFile != null) {
putExtra("path", resultFile?.absolutePath ?: "") startActivity(Intent(this, PdfActivity::class.java).apply {
}) putExtra("path", resultFile?.absolutePath ?: "")
} else { })
toast("split pdf failed") } else {
toast("split pdf failed")
}
finish()
} }
finish()
} }
pdfPresenter.splitPdf(srcPath, newPath, splitIndex, finishAction = { pdfPresenter.splitPdf(srcPath, newPath, splitIndex, finishAction = {
resultFile = it resultFile = it
...@@ -70,10 +86,12 @@ class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() { ...@@ -70,10 +86,12 @@ class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() {
muPDFCore?.save() muPDFCore?.save()
muPDFCore = null muPDFCore = null
progressFinishAction = { progressFinishAction = {
startActivity(Intent(this, PdfActivity::class.java).apply { progressFinishAd {
putExtra("path", srcPath) startActivity(Intent(this, PdfActivity::class.java).apply {
}) putExtra("path", srcPath)
finish() })
finish()
}
} }
lifecycleScope.launch { lifecycleScope.launch {
delay(Random.nextLong(1500, 2500)) delay(Random.nextLong(1500, 2500))
...@@ -84,10 +102,12 @@ class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() { ...@@ -84,10 +102,12 @@ class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() {
DO_MERGE_PDF -> { DO_MERGE_PDF -> {
progressFinishAction = { progressFinishAction = {
startActivity(Intent(this, PdfActivity::class.java).apply { progressFinishAd {
putExtra("path", newPath) startActivity(Intent(this, PdfActivity::class.java).apply {
}) putExtra("path", newPath)
finish() })
finish()
}
} }
pdfPresenter.mergePdf(newPath) { pdfPresenter.mergePdf(newPath) {
isFinishBoolean = true isFinishBoolean = true
......
...@@ -121,10 +121,13 @@ object PdfDialog { ...@@ -121,10 +121,13 @@ object PdfDialog {
binding.tvLock.text = getString(R.string.lock_pdf) binding.tvLock.text = getString(R.string.lock_pdf)
} }
binding.llLock.setOnClickListener { binding.llLock.setOnClickListener {
showPdfPwdDialog(state = item.state, path = item.path, firstDialog = dialog, encryptionAction = { showPdfPwdDialog(state = item.state, path = item.path,
dialog.dismiss() firstDialog = dialog,
mainActivity.mainPresenter.changePdfLock(item, documentPageFragment) isCheckPwd = false,
}) encryptionAction = {
dialog.dismiss()
mainActivity.mainPresenter.changePdfLock(item, documentPageFragment)
})
} }
dialog.setOnDismissListener { dialog.setOnDismissListener {
} }
...@@ -237,19 +240,31 @@ object PdfDialog { ...@@ -237,19 +240,31 @@ object PdfDialog {
val pwd = binding.edit.text.toString() val pwd = binding.edit.text.toString()
if (!isCheckPwd) { if (!isCheckPwd) {
dialog.dismiss()
firstDialog?.dismiss() //加锁逻辑
if (state == 0) { if (state == 0) {
PdfBoxUtils.setPassword(path, pwd, pwd) PdfBoxUtils.setPassword(path, pwd, pwd)
toast("Success Encryption") toast("Success Encryption")
encryptionAction?.invoke() encryptionAction?.invoke()
dialog.dismiss()
firstDialog?.dismiss()
} }
//解锁逻辑
if (state == 1) { if (state == 1) {
PdfBoxUtils.clearPassword(path, pwd) val result = PdfBoxUtils.checkPwd(path, pwd, uri)
toast("clear Encryption") LogEx.logDebug("checkPwd", "result=$result")
encryptionAction?.invoke() if (result) {
PdfBoxUtils.clearPassword(path, pwd)
toast("clear Encryption")
encryptionAction?.invoke()
dialog.dismiss()
firstDialog?.dismiss()
} else {
binding.tvErrorTip.visibility = View.VISIBLE
}
} }
} else { } else {
//验证密码逻辑
val result = PdfBoxUtils.checkPwd(path, pwd, uri) val result = PdfBoxUtils.checkPwd(path, pwd, uri)
if (!result) { if (!result) {
binding.tvErrorTip.visibility = View.VISIBLE binding.tvErrorTip.visibility = View.VISIBLE
......
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