Commit d613a963 authored by wanglei's avatar wanglei

...处理弹窗问题

parent 8e11824f
......@@ -61,6 +61,7 @@
<activity
android:name=".ui.main.MainActivity"
android:exported="false"
android:launchMode="singleTask"
android:theme="@style/Theme.PdfReaderAllPdfReader.NoActionBar" />
<activity
android:name=".ui.language.LanguageActivity"
......
......@@ -20,7 +20,9 @@ import com.base.pdfreaderallpdfreader.bean.DocumentBean.Companion.TYPE_WORD
import com.base.pdfreaderallpdfreader.bean.MediaBean
import com.base.pdfreaderallpdfreader.helper.MyApplication.Companion.context
import com.base.pdfreaderallpdfreader.utils.AssetUtils.readByteArrayFromAsset
import com.base.pdfreaderallpdfreader.utils.LogEx
import com.base.pdfreaderallpdfreader.utils.PdfBoxUtils.checkPdfEncryption
import com.base.pdfreaderallpdfreader.utils.PermissionUtils.checkStorePermission
import com.base.pdfreaderallpdfreader.utils.SpStringUtils
import com.base.pdfreaderallpdfreader.utils.SpStringUtils.BOOKMARK_KEY
import com.base.pdfreaderallpdfreader.utils.getMediaFile
......@@ -42,9 +44,15 @@ fun getDocumentAppDir(): File {
return appDir
}
fun getDemoDir(): File {
val demoFile = File(getDocumentAppDir(), "demo")
if (!demoFile.exists()) {
demoFile.mkdirs()
}
return demoFile
}
fun Context.saveAssetsFile() {
val demoFile = File(filesDir, "demo")
demoFile.mkdirs()
arrayOf(
"DEMO.pdf",
"DEMO.docx",
......@@ -52,7 +60,7 @@ fun Context.saveAssetsFile() {
"DEMO.pptx"
).forEach {
val file = File(demoFile, it)
val file = File(getDemoDir(), it)
if (file.exists() && file.length() != 0L) {
return
}
......@@ -70,44 +78,44 @@ fun Context.saveAssetsFile() {
fun getPdfDemo(context: Context): DocumentBean {
val demoDocumentBean = DocumentBean()
demoDocumentBean.type = TYPE_PDF
val demoFile = File(context.filesDir, "demo")
val demoFile = getDemoDir()
demoDocumentBean.path = demoFile.listFiles()?.find { it.name.contains(".pdf") }?.absolutePath ?: ""
context.pdfCheck(demoDocumentBean)
return demoDocumentBean
}
fun getWordDemo(context: Context): DocumentBean {
fun getWordDemo(): DocumentBean {
val demoDocumentBean = DocumentBean()
demoDocumentBean.type = TYPE_WORD
val demoFile = File(context.filesDir, "demo")
val demoFile = getDemoDir()
demoDocumentBean.path = demoFile.listFiles()?.find { it.name.contains(".docx") }?.absolutePath ?: ""
return demoDocumentBean
}
fun getExcelDemo(context: Context): DocumentBean {
fun getExcelDemo(): DocumentBean {
val demoDocumentBean = DocumentBean()
demoDocumentBean.type = TYPE_EXCEL
val demoFile = File(context.filesDir, "demo")
val demoFile = getDemoDir()
demoDocumentBean.path = demoFile.listFiles()?.find { it.name.contains(".xlsx") }?.absolutePath ?: ""
return demoDocumentBean
}
fun getPPtDemo(context: Context): DocumentBean {
fun getPPtDemo(): DocumentBean {
val demoDocumentBean = DocumentBean()
demoDocumentBean.type = TYPE_PPT
val demoFile = File(context.filesDir, "demo")
val demoFile = getDemoDir()
demoDocumentBean.path = demoFile.listFiles()?.find { it.name.contains(".pptx") }?.absolutePath ?: ""
return demoDocumentBean
}
fun getAllDocument(context: Context): MutableList<DocumentBean> {
context.upDateDemoStore()
if (!ConstObject.haveSaveDemo) {
context.saveAssetsFile()
ConstObject.haveSaveDemo = true
}
val selectionArgs = arrayOf(
MIME_TYPE_PDF,
MIME_TYPE_DOC,
......@@ -118,7 +126,13 @@ fun getAllDocument(context: Context): MutableList<DocumentBean> {
MIME_TYPE_PPTX,
)
val list = context.getMediaFile(selectionArgs = selectionArgs)
val list = context.getMediaFile(selectionArgs = selectionArgs).filter {
if (context.checkStorePermission()) {
true
} else {
!Uri.EMPTY.equals(it.uri)
}
}
val documentList = list.map {
val documentBean = DocumentBean(it.path, uri = it.uri, type = getDocumentType(it))
if (documentBean.type == TYPE_PDF) {
......@@ -126,23 +140,32 @@ fun getAllDocument(context: Context): MutableList<DocumentBean> {
}
documentBean
}
LogEx.logDebug("getAllDocument", "documentList size=${documentList.size}")
documentList.forEach { document ->
LogEx.logDebug("getAllDocument", "document=$document")
}
val new = documentList.toMutableList()
val pptDemo = getPPtDemo(context)
val pptDemo = getPPtDemo()
if (File(pptDemo.path).exists()) {
new.add(0, pptDemo)
}
val excelDemo = getExcelDemo(context)
val excelDemo = getExcelDemo()
if (File(excelDemo.path).exists()) {
new.add(0, excelDemo)
}
val wordDemp = getWordDemo(context)
if (File(wordDemp.path).exists()) {
new.add(0, wordDemp)
val wordDemo = getWordDemo()
if (File(wordDemo.path).exists()) {
new.add(0, wordDemo)
}
val pdfDemo = getPdfDemo(context)
if (File(pdfDemo.path).exists()) {
new.add(0, pdfDemo)
}
// new.forEach { document ->
// LogEx.logDebug("getAllDocument", "document=$document")
// }
return new
}
......@@ -150,11 +173,19 @@ fun getPdfFastSize(context: Context): Int {
val selectionArgs = arrayOf(
MIME_TYPE_PDF
)
val list = context.getMediaFile(selectionArgs = selectionArgs)
val list = context.getMediaFile(selectionArgs = selectionArgs).filter {
if (context.checkStorePermission()) {
true
} else {
it.uri.toString().isNotEmpty()
}
}
var size = list.size
val pdfDemo = getPdfDemo(context)
if (File(pdfDemo.path).exists()) {
size += 1
if (context.checkStorePermission()) {
val pdfDemo = getPdfDemo(context)
if (File(pdfDemo.path).exists()) {
size += 1
}
}
return size
}
......@@ -173,10 +204,13 @@ fun getPdfDocument(context: Context): MutableList<DocumentBean> {
context.pdfCheck(demoDocumentBean)
demoDocumentBean
}
val new = documentList.toMutableList()
val pdfDemo = getPdfDemo(context)
if (File(pdfDemo.path).exists()) {
new.add(0, pdfDemo)
var new = if (context.checkStorePermission()) documentList else documentList.filter { it.uri != null }
new = new.toMutableList()
if (context.checkStorePermission()) {
val pdfDemo = getPdfDemo(context)
if (File(pdfDemo.path).exists()) {
new.add(0, pdfDemo)
}
}
return new
}
......@@ -194,10 +228,13 @@ fun getWordDocument(context: Context): MutableList<DocumentBean> {
val documentList = list.map {
DocumentBean(it.path, uri = it.uri, type = TYPE_WORD)
}
val new = documentList.toMutableList()
val wordDemo = getWordDemo(context)
if (File(wordDemo.path).exists()) {
new.add(0, wordDemo)
var new = if (context.checkStorePermission()) documentList else documentList.filter { it.uri == null }
new = new.toMutableList()
if (context.checkStorePermission()) {
val wordDemo = getWordDemo()
if (File(wordDemo.path).exists()) {
new.add(0, wordDemo)
}
}
return new
}
......@@ -215,10 +252,13 @@ fun getExcelDocument(context: Context): MutableList<DocumentBean> {
val documentList = list.map {
DocumentBean(it.path, uri = it.uri, type = TYPE_EXCEL)
}
val new = documentList.toMutableList()
val excelDemo = getExcelDemo(context)
if (File(excelDemo.path).exists()) {
new.add(0, excelDemo)
var new = if (context.checkStorePermission()) documentList else documentList.filter { it.uri == null }
new = new.toMutableList()
if (context.checkStorePermission()) {
val excelDemo = getExcelDemo()
if (File(excelDemo.path).exists()) {
new.add(0, excelDemo)
}
}
return new
}
......@@ -236,15 +276,17 @@ fun getPptDocument(context: Context): MutableList<DocumentBean> {
val documentList = list.map {
DocumentBean(it.path, uri = it.uri, type = TYPE_PPT)
}
val new = documentList.toMutableList()
val pptDemo = getPPtDemo(context)
if (File(pptDemo.path).exists()) {
new.add(0, pptDemo)
var new = if (context.checkStorePermission()) documentList else documentList.filter { it.uri == null }
new = new.toMutableList()
if (context.checkStorePermission()) {
val pptDemo = getPPtDemo()
if (File(pptDemo.path).exists()) {
new.add(0, pptDemo)
}
}
return new
}
fun recentFilter(recentList: List<String>, documentBean: DocumentBean) {
val findLastTime = recentList.filter { it.contains(documentBean.path) }.map {
it.split("_/_")[1].toLong()
......@@ -279,4 +321,5 @@ fun saveBookmarkChange(addRemove: Boolean, path: String) {
} else {
SpStringUtils.deleteSpString(BOOKMARK_KEY, path)
}
}
\ No newline at end of file
}
......@@ -32,7 +32,6 @@ import com.base.pdfreaderallpdfreader.helper.ConfigHelper
import com.base.pdfreaderallpdfreader.ui.feedback.FeedbackActivity
import com.base.pdfreaderallpdfreader.ui.language.LanguageActivity
import com.base.pdfreaderallpdfreader.ui.pdf.PdfActivity
import com.base.pdfreaderallpdfreader.ui.search.SearchActivity
import com.base.pdfreaderallpdfreader.ui.view.MainDialog.showAppExitDialog
import com.base.pdfreaderallpdfreader.ui.view.MainDialog.showNotificationDialog
import com.base.pdfreaderallpdfreader.ui.view.MainDialog.showStoragePermission
......@@ -100,9 +99,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
binding.includeMain.tvTittle.text = spannableString
binding.tvPdfReader.text = spannableString
if (!checkStorePermission()) {
showStoragePermission(launcher)
} else {
if (checkStorePermission()) {
val flag = checkNotificationPermission()
LogEx.logDebug(TAG, "checkNotificationPermission flag=$flag")
if (!flag) {
......@@ -115,15 +112,19 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}
addDeskShortCut()
}
private var jumpPermission: Boolean = false
override fun onResume() {
super.onResume()
LogEx.logDebug(TAG, "onResume")
if (checkStorePermission()) {
showMainBanner()
if (!jumpPermission) {
showMainBanner()
}
jumpPermission = false
} else {
showStoragePermission(launcher, jumpAction = { jumpPermission = true })
}
}
......@@ -152,34 +153,22 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
startActivity(Intent(this, LanguageActivity::class.java))
}
binding.includeMain.includeContentMain.ivScan.setOnClickListener {
if (checkStorePermission()) {
starAdGmsScan()
} else {
showStoragePermission(launcher)
}
showStoragePermission(launcher)
}
binding.includeMain.ivSearch.setOnClickListener {
if (checkStorePermission()) {
startActivity(Intent(this, SearchActivity::class.java))
} else {
showStoragePermission(launcher)
}
showStoragePermission(launcher)
}
binding.llFileManager.setOnClickListener {
if (checkStorePermission()) {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.setType("application/pdf")
intent.flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION
launcher.launch(intent) {
val uri = it.data?.data
uri?.let {
jumpUriPdf(uri)
}
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.setType("application/pdf")
intent.flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION
launcher.launch(intent) {
val uri = it.data?.data
uri?.let {
jumpUriPdf(uri)
}
} else {
showStoragePermission(launcher)
}
}
binding.llRate.setOnClickListener {
......@@ -308,19 +297,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
private fun showMainBanner() {
if (!bannerShowed) {
bannerShowed = true
AdmobBannerUtils.showCollapsibleBannerAd(this, binding.includeMain.includeContentMain.flBanner) {
//通知弹窗
// if (!todayShowNotificationDialog && !checkNotificationPermission()) {
// todayShowNotificationDialog = true
// showNotificationDialog(launcher)
// } else {
// if (!ConstObject.setDefault) {
// showDefaultBottomDialog()
// } else {
// showRateDialog()
// }
// }
}
LogEx.logDebug(TAG, "showMainBanner")
AdmobBannerUtils.showCollapsibleBannerAd(this, binding.includeMain.includeContentMain.flBanner) {}
}
}
......
......@@ -17,7 +17,6 @@ import com.base.pdfreaderallpdfreader.ui.document.DocumentActivity
import com.base.pdfreaderallpdfreader.ui.main.MainActivity
import com.base.pdfreaderallpdfreader.ui.main.getPdfFastSize
import com.base.pdfreaderallpdfreader.ui.pdf.PdfActivity
import com.base.pdfreaderallpdfreader.ui.pdf.PdfSelectActivity
import com.base.pdfreaderallpdfreader.ui.pdf.PdfSelectActivity.Companion.jumpPdfSelect
import com.base.pdfreaderallpdfreader.utils.PermissionUtils.checkStorePermission
import kotlinx.coroutines.Dispatchers
......
......@@ -51,6 +51,9 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.File
/**
* 经过测试没有权限即使内部储存的文件也会打开失败
*/
class PdfActivity : BaseActivity<ActivityPdfBinding>() {
private val TAG = "PdfActivity"
......
......@@ -31,7 +31,7 @@ object MainDialog {
fun Context.showStoragePermission(
launcher: ActivityLauncher,
launcherAction: ((flag: Boolean) -> Unit)? = null,
noLauncherAction: (() -> Unit)? = null,
jumpAction: (() -> Unit)? = null,
dismissAction: (() -> Unit)? = null,
): BottomSheetDialog {
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
......@@ -48,6 +48,7 @@ object MainDialog {
binding.tvAllow.setOnClickListener {
dialog.dismiss()
jumpAction?.invoke()
requestStoragePermission(launcher) {
launcherAction?.invoke(it)
}
......
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