Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
pdf all reader
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
pdf all reader
Commits
d613a963
Commit
d613a963
authored
Nov 15, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...处理弹窗问题
parent
8e11824f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
85 deletions
+110
-85
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-0
DocumentEx.kt
...java/com/base/pdfreaderallpdfreader/ui/main/DocumentEx.kt
+82
-39
MainActivity.kt
...va/com/base/pdfreaderallpdfreader/ui/main/MainActivity.kt
+22
-44
HomeFragment.kt
...m/base/pdfreaderallpdfreader/ui/main/home/HomeFragment.kt
+0
-1
PdfActivity.kt
...java/com/base/pdfreaderallpdfreader/ui/pdf/PdfActivity.kt
+3
-0
MainDialog.kt
...java/com/base/pdfreaderallpdfreader/ui/view/MainDialog.kt
+2
-1
No files found.
app/src/main/AndroidManifest.xml
View file @
d613a963
...
...
@@ -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"
...
...
app/src/main/java/com/base/pdfreaderallpdfreader/ui/main/DocumentEx.kt
View file @
d613a963
...
...
@@ -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
Context
.
saveAssetsFile
()
{
val
demoFile
=
File
(
filesDir
,
"demo"
)
fun
getDemoDir
():
File
{
val
demoFile
=
File
(
getDocumentAppDir
(),
"demo"
)
if
(!
demoFile
.
exists
())
{
demoFile
.
mkdirs
()
}
return
demoFile
}
fun
Context
.
saveAssetsFile
()
{
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
wordDem
p
=
getWordDemo
(
context
)
if
(
File
(
wordDem
p
.
path
).
exists
())
{
new
.
add
(
0
,
wordDem
p
)
val
wordDem
o
=
getWordDemo
(
)
if
(
File
(
wordDem
o
.
path
).
exists
())
{
new
.
add
(
0
,
wordDem
o
)
}
val
pdfDemo
=
getPdfDemo
(
context
)
if
(
File
(
pdfDemo
.
path
).
exists
())
{
new
.
add
(
0
,
pdfDemo
)
}
// new.forEach { document ->
// LogEx.logDebug("getAllDocument", "document=$document")
// }
return
new
}
...
...
@@ -150,12 +173,20 @@ 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
if
(
context
.
checkStorePermission
())
{
val
pdfDemo
=
getPdfDemo
(
context
)
if
(
File
(
pdfDemo
.
path
).
exists
())
{
size
+=
1
}
}
return
size
}
...
...
@@ -173,11 +204,14 @@ fun getPdfDocument(context: Context): MutableList<DocumentBean> {
context
.
pdfCheck
(
demoDocumentBean
)
demoDocumentBean
}
val
new
=
documentList
.
toMutableList
()
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,11 +228,14 @@ 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
)
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,11 +252,14 @@ 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
)
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
)
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
()
...
...
@@ -280,3 +322,4 @@ fun saveBookmarkChange(addRemove: Boolean, path: String) {
SpStringUtils
.
deleteSpString
(
BOOKMARK_KEY
,
path
)
}
}
app/src/main/java/com/base/pdfreaderallpdfreader/ui/main/MainActivity.kt
View file @
d613a963
...
...
@@ -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,16 +112,20 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}
addDeskShortCut
()
}
private
var
jumpPermission
:
Boolean
=
false
override
fun
onResume
()
{
super
.
onResume
()
LogEx
.
logDebug
(
TAG
,
"onResume"
)
if
(
checkStorePermission
())
{
if
(!
jumpPermission
)
{
showMainBanner
()
}
jumpPermission
=
false
}
else
{
showStoragePermission
(
launcher
,
jumpAction
=
{
jumpPermission
=
true
})
}
}
override
fun
initListener
()
{
...
...
@@ -152,21 +153,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
startActivity
(
Intent
(
this
,
LanguageActivity
::
class
.
java
))
}
binding
.
includeMain
.
includeContentMain
.
ivScan
.
setOnClickListener
{
if
(
checkStorePermission
())
{
starAdGmsScan
()
}
else
{
showStoragePermission
(
launcher
)
}
}
binding
.
includeMain
.
ivSearch
.
setOnClickListener
{
if
(
checkStorePermission
())
{
startActivity
(
Intent
(
this
,
SearchActivity
::
class
.
java
))
}
else
{
showStoragePermission
(
launcher
)
}
}
binding
.
llFileManager
.
setOnClickListener
{
if
(
checkStorePermission
())
{
val
intent
=
Intent
(
Intent
.
ACTION_OPEN_DOCUMENT
)
intent
.
addCategory
(
Intent
.
CATEGORY_OPENABLE
)
intent
.
setType
(
"application/pdf"
)
...
...
@@ -178,9 +170,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
jumpUriPdf
(
uri
)
}
}
}
else
{
showStoragePermission
(
launcher
)
}
}
binding
.
llRate
.
setOnClickListener
{
showRateDialog
(
true
)
...
...
@@ -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
)
{}
}
}
...
...
app/src/main/java/com/base/pdfreaderallpdfreader/ui/main/home/HomeFragment.kt
View file @
d613a963
...
...
@@ -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
...
...
app/src/main/java/com/base/pdfreaderallpdfreader/ui/pdf/PdfActivity.kt
View file @
d613a963
...
...
@@ -51,6 +51,9 @@ import kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
import
java.io.File
/**
* 经过测试没有权限即使内部储存的文件也会打开失败
*/
class
PdfActivity
:
BaseActivity
<
ActivityPdfBinding
>()
{
private
val
TAG
=
"PdfActivity"
...
...
app/src/main/java/com/base/pdfreaderallpdfreader/ui/view/MainDialog.kt
View file @
d613a963
...
...
@@ -31,7 +31,7 @@ object MainDialog {
fun
Context
.
showStoragePermission
(
launcher
:
ActivityLauncher
,
launcherAction
:
((
flag
:
Boolean
)
->
Unit
)?
=
null
,
noLauncher
Action
:
(()
->
Unit
)?
=
null
,
jump
Action
:
(()
->
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
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment