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
c13b5df5
Commit
c13b5df5
authored
Nov 15, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
390e2591
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
82 additions
and
47 deletions
+82
-47
DocumentFragment.kt
...ase/pdfreaderallpdfreader/ui/document/DocumentFragment.kt
+10
-8
DocumentEx.kt
...java/com/base/pdfreaderallpdfreader/ui/main/DocumentEx.kt
+40
-26
MainActivity.kt
...va/com/base/pdfreaderallpdfreader/ui/main/MainActivity.kt
+2
-0
RecentFragment.kt
...se/pdfreaderallpdfreader/ui/main/recent/RecentFragment.kt
+3
-0
PdfActivity.kt
...java/com/base/pdfreaderallpdfreader/ui/pdf/PdfActivity.kt
+8
-4
MediaStoreUtils.kt
...a/com/base/pdfreaderallpdfreader/utils/MediaStoreUtils.kt
+0
-7
UriUtils.kt
...ain/java/com/base/pdfreaderallpdfreader/utils/UriUtils.kt
+15
-0
activity_pdf.xml
app/src/main/res/layout/activity_pdf.xml
+4
-2
No files found.
app/src/main/java/com/base/pdfreaderallpdfreader/ui/document/DocumentFragment.kt
View file @
c13b5df5
...
...
@@ -32,6 +32,7 @@ import com.base.pdfreaderallpdfreader.ui.view.DialogCallBack
import
com.base.pdfreaderallpdfreader.ui.view.DocumentDialog.showDocumentHomeMoreDialog
import
com.base.pdfreaderallpdfreader.ui.view.PdfDialog.showPdfHomeMoreDialog
import
com.base.pdfreaderallpdfreader.ui.word.WordActivity
import
com.base.pdfreaderallpdfreader.utils.LogEx
import
com.base.pdfreaderallpdfreader.utils.PdfBoxUtils.checkPdfEncryption
import
com.base.pdfreaderallpdfreader.utils.SpStringUtils
import
com.base.pdfreaderallpdfreader.utils.SpStringUtils.BOOKMARK_KEY
...
...
@@ -44,6 +45,7 @@ class DocumentFragment() : Fragment(), DialogCallBack {
private
var
type
=
TYPE_PDF
private
val
TAG
=
"DocumentFragment"
private
lateinit
var
binding
:
FragmentDocumentBinding
private
var
adapter
:
DocumentAdapter
?
=
null
...
...
@@ -99,8 +101,9 @@ class DocumentFragment() : Fragment(), DialogCallBack {
binding
.
ivTop
.
isVisible
=
false
}
binding
.
swipeRefreshLayout
.
setOnRefreshListener
{
initData
()
initData
(
"swipeRefreshLayout"
)
}
binding
.
swipeRefreshLayout
.
isRefreshing
=
true
}
override
fun
onResume
()
{
...
...
@@ -108,19 +111,17 @@ class DocumentFragment() : Fragment(), DialogCallBack {
if
(
type
==
TYPE_PDF
)
{
if
(
pdfNeedRefresh
)
{
pdfNeedRefresh
=
false
initData
()
initData
(
"onResume"
)
}
}
else
{
initData
()
initData
(
"onResume"
)
}
}
private
fun
initData
()
{
binding
.
swipeRefreshLayout
.
isRefreshing
=
true
private
fun
initData
(
where
:
String
=
""
)
{
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
requireContext
().
updateMediaStore
()
LogEx
.
logDebug
(
TAG
,
"initData $type where=$where"
)
val
list
:
List
<
DocumentBean
>
when
(
type
)
{
...
...
@@ -187,7 +188,8 @@ class DocumentFragment() : Fragment(), DialogCallBack {
val
newFile
=
File
(
file
.
parentFile
,
newName
)
val
result
=
file
.
renameTo
(
newFile
)
if
(
result
)
{
initData
()
requireContext
().
updateMediaStore
()
initData
(
"renameDocumentBean"
)
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
...
...
app/src/main/java/com/base/pdfreaderallpdfreader/ui/main/DocumentEx.kt
View file @
c13b5df5
...
...
@@ -4,6 +4,7 @@ import android.content.Context
import
android.media.MediaScannerConnection
import
android.net.Uri
import
android.os.Environment
import
com.base.pdfreaderallpdfreader.R
import
com.base.pdfreaderallpdfreader.bean.ConstObject
import
com.base.pdfreaderallpdfreader.bean.ConstObject.MIME_TYPE_DOC
import
com.base.pdfreaderallpdfreader.bean.ConstObject.MIME_TYPE_DOCX
...
...
@@ -25,20 +26,18 @@ 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.UriUtils.isUriValid
import
com.base.pdfreaderallpdfreader.utils.getMediaFile
import
java.io.File
import
java.io.FileOutputStream
import
java.io.IOException
fun
Context
.
upDateDemoStore
()
{
val
demoFile
=
File
(
filesDir
,
"demo"
)
MediaScannerConnection
.
scanFile
(
this
,
arrayOf
(
demoFile
.
absolutePath
),
null
)
{
path
:
String
?,
uri
:
Uri
?
->
}
}
fun
getDocumentAppDir
():
File
{
val
appDir
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOCUMENTS
),
context
.
packageName
)
val
appDir
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOCUMENTS
),
context
.
getString
(
R
.
string
.
app_name
)
)
if
(!
appDir
.
exists
())
appDir
.
exists
()
return
appDir
...
...
@@ -109,7 +108,6 @@ fun getPPtDemo(): DocumentBean {
}
fun
getAllDocument
(
context
:
Context
):
MutableList
<
DocumentBean
>
{
context
.
upDateDemoStore
()
if
(!
ConstObject
.
haveSaveDemo
)
{
context
.
saveAssetsFile
()
...
...
@@ -128,7 +126,7 @@ fun getAllDocument(context: Context): MutableList<DocumentBean> {
val
list
=
context
.
getMediaFile
(
selectionArgs
=
selectionArgs
).
filter
{
if
(
context
.
checkStorePermission
())
{
true
isUriValid
(
context
,
it
.
uri
)
}
else
{
!
Uri
.
EMPTY
.
equals
(
it
.
uri
)
}
...
...
@@ -140,11 +138,6 @@ 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
()
if
(
File
(
pptDemo
.
path
).
exists
())
{
...
...
@@ -194,14 +187,19 @@ fun getPdfDocument(context: Context): MutableList<DocumentBean> {
val
selectionArgs
=
arrayOf
(
MIME_TYPE_PDF
)
val
list
=
context
.
getMediaFile
(
selectionArgs
=
selectionArgs
)
val
list
=
context
.
getMediaFile
(
selectionArgs
=
selectionArgs
).
filter
{
if
(
context
.
checkStorePermission
())
{
isUriValid
(
context
,
it
.
uri
)
}
else
{
!
Uri
.
EMPTY
.
equals
(
it
.
uri
)
}
}
val
documentList
=
list
.
map
{
val
demoDocumentBean
=
DocumentBean
(
it
.
path
,
uri
=
it
.
uri
,
type
=
TYPE_PDF
)
context
.
pdfCheck
(
demoDocumentBean
)
demoDocumentBean
}
var
new
=
if
(
context
.
checkStorePermission
())
documentList
else
documentList
.
filter
{
it
.
uri
!=
null
}
new
=
new
.
toMutableList
()
val
new
=
documentList
.
toMutableList
()
if
(
context
.
checkStorePermission
())
{
val
pdfDemo
=
getPdfDemo
(
context
)
if
(
File
(
pdfDemo
.
path
).
exists
())
{
...
...
@@ -220,12 +218,18 @@ fun getWordDocument(context: Context): MutableList<DocumentBean> {
MIME_TYPE_DOC
,
MIME_TYPE_DOCX
,
)
val
list
=
context
.
getMediaFile
(
selectionArgs
=
selectionArgs
)
val
list
=
context
.
getMediaFile
(
selectionArgs
=
selectionArgs
).
filter
{
if
(
context
.
checkStorePermission
())
{
isUriValid
(
context
,
it
.
uri
)
}
else
{
!
Uri
.
EMPTY
.
equals
(
it
.
uri
)
}
}
val
documentList
=
list
.
map
{
DocumentBean
(
it
.
path
,
uri
=
it
.
uri
,
type
=
TYPE_WORD
)
}
va
r
new
=
if
(
context
.
checkStorePermission
())
documentList
else
documentList
.
filter
{
it
.
uri
==
null
}
new
=
new
.
toMutableList
()
va
l
new
=
documentList
.
toMutableList
()
if
(
context
.
checkStorePermission
())
{
val
wordDemo
=
getWordDemo
()
if
(
File
(
wordDemo
.
path
).
exists
())
{
...
...
@@ -244,12 +248,17 @@ fun getExcelDocument(context: Context): MutableList<DocumentBean> {
MIME_TYPE_XLS
,
MIME_TYPE_XLSX
,
)
val
list
=
context
.
getMediaFile
(
selectionArgs
=
selectionArgs
)
val
list
=
context
.
getMediaFile
(
selectionArgs
=
selectionArgs
).
filter
{
if
(
context
.
checkStorePermission
())
{
isUriValid
(
context
,
it
.
uri
)
}
else
{
!
Uri
.
EMPTY
.
equals
(
it
.
uri
)
}
}
val
documentList
=
list
.
map
{
DocumentBean
(
it
.
path
,
uri
=
it
.
uri
,
type
=
TYPE_EXCEL
)
}
var
new
=
if
(
context
.
checkStorePermission
())
documentList
else
documentList
.
filter
{
it
.
uri
==
null
}
new
=
new
.
toMutableList
()
val
new
=
documentList
.
toMutableList
()
if
(
context
.
checkStorePermission
())
{
val
excelDemo
=
getExcelDemo
()
if
(
File
(
excelDemo
.
path
).
exists
())
{
...
...
@@ -268,12 +277,17 @@ fun getPptDocument(context: Context): MutableList<DocumentBean> {
MIME_TYPE_PPT
,
MIME_TYPE_PPTX
,
)
val
list
=
context
.
getMediaFile
(
selectionArgs
=
selectionArgs
)
val
list
=
context
.
getMediaFile
(
selectionArgs
=
selectionArgs
).
filter
{
if
(
context
.
checkStorePermission
())
{
isUriValid
(
context
,
it
.
uri
)
}
else
{
!
Uri
.
EMPTY
.
equals
(
it
.
uri
)
}
}
val
documentList
=
list
.
map
{
DocumentBean
(
it
.
path
,
uri
=
it
.
uri
,
type
=
TYPE_PPT
)
}
var
new
=
if
(
context
.
checkStorePermission
())
documentList
else
documentList
.
filter
{
it
.
uri
==
null
}
new
=
new
.
toMutableList
()
val
new
=
documentList
.
toMutableList
()
if
(
context
.
checkStorePermission
())
{
val
pptDemo
=
getPPtDemo
()
if
(
File
(
pptDemo
.
path
).
exists
())
{
...
...
app/src/main/java/com/base/pdfreaderallpdfreader/ui/main/MainActivity.kt
View file @
c13b5df5
...
...
@@ -110,6 +110,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
launcher
.
launch
(
arrayOf
(
Manifest
.
permission
.
POST_NOTIFICATIONS
))
{}
}
}
updateMediaStore
()
}
addDeskShortCut
()
...
...
app/src/main/java/com/base/pdfreaderallpdfreader/ui/main/recent/RecentFragment.kt
View file @
c13b5df5
...
...
@@ -21,6 +21,7 @@ import com.base.pdfreaderallpdfreader.utils.LogEx
import
com.base.pdfreaderallpdfreader.utils.PdfBoxUtils.checkPdfEncryption
import
com.base.pdfreaderallpdfreader.utils.SpStringUtils
import
com.base.pdfreaderallpdfreader.utils.SpStringUtils.BOOKMARK_KEY
import
com.base.pdfreaderallpdfreader.utils.updateMediaStore
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
...
...
@@ -90,6 +91,7 @@ class RecentFragment() : Fragment(), DialogCallBack {
override
fun
deleteDocument
(
item
:
DocumentBean
)
{
val
flag
=
File
(
item
.
path
).
delete
()
if
(
flag
)
{
requireContext
().
updateMediaStore
()
adapter
?.
remove
(
item
)
}
}
...
...
@@ -107,6 +109,7 @@ class RecentFragment() : Fragment(), DialogCallBack {
val
newFile
=
File
(
file
.
parentFile
,
newName
)
val
result
=
file
.
renameTo
(
newFile
)
if
(
result
)
{
requireContext
().
updateMediaStore
()
initData
()
}
}
catch
(
e
:
Exception
)
{
...
...
app/src/main/java/com/base/pdfreaderallpdfreader/ui/pdf/PdfActivity.kt
View file @
c13b5df5
...
...
@@ -482,14 +482,14 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>() {
private
fun
createPdfUI
()
{
if
(
muPDFCore
==
null
)
return
val
countPages
=
muPDFCore
?.
countPages
()
val
countPages
:
Int
?
=
muPDFCore
?.
countPages
()
binding
.
tvPageCount
.
text
=
"1/${countPages}"
binding
.
mupdfReaderView
.
setListener
(
object
:
MuPDFReaderViewListener
{
@SuppressLint
(
"SetTextI18n"
)
override
fun
onMoveToChild
(
i
:
Int
)
{
binding
.
tvPageCount
.
text
=
"${i + 1}/$countPages
}
"
binding
.
tvPageCount
.
text
=
"${i + 1}/$countPages"
pdfPageAdapter
.
changeSelectPager
(
i
)
binding
.
rvPager
.
scrollToPosition
(
i
)
setVerticalSeekbar
(
i
+
1
,
countPages
?:
0
)
...
...
@@ -646,7 +646,9 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>() {
if
(
item
.
state
==
0
)
{
activity
.
startActivity
(
Intent
(
activity
,
PdfActivity
::
class
.
java
).
apply
{
putExtra
(
"path"
,
item
.
path
)
if
(
item
.
path
.
isEmpty
())
{
//处理uri错误的情况
putExtra
(
"uri"
,
item
.
uri
.
toString
())
}
})
}
if
(
item
.
state
==
1
)
{
...
...
@@ -664,7 +666,9 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>() {
fun
jumpSplit
(
activity
:
Activity
,
path
:
String
,
uri
:
String
?
=
null
,
pwd
:
String
?
=
null
)
{
activity
.
startActivity
(
Intent
(
activity
,
PdfSplitActivity
::
class
.
java
).
apply
{
putExtra
(
"path"
,
path
)
if
(
path
.
isEmpty
())
{
putExtra
(
"uri"
,
uri
)
}
putExtra
(
"pwd"
,
pwd
)
})
}
...
...
app/src/main/java/com/base/pdfreaderallpdfreader/utils/MediaStoreUtils.kt
View file @
c13b5df5
...
...
@@ -45,13 +45,6 @@ fun Context.updateMediaStore(
)
{
path
:
String
?,
uri
:
Uri
?
->
}
}
fun
Context
.
upDateDemoStore
()
{
val
demoFile
=
File
(
filesDir
,
"demo"
)
MediaScannerConnection
.
scanFile
(
this
,
arrayOf
(
demoFile
.
absolutePath
)
,
null
)
{
path
:
String
?,
uri
:
Uri
?
->
}
}
//图片视频音频不用这个查
fun
Context
.
getMediaFile
(
selectionArgs
:
Array
<
String
>?
=
null
):
ArrayList
<
MediaBean
>
{
...
...
app/src/main/java/com/base/pdfreaderallpdfreader/utils/UriUtils.kt
View file @
c13b5df5
...
...
@@ -5,6 +5,7 @@ import android.net.Uri
import
com.tom_roush.pdfbox.io.IOUtils
import
java.io.InputStream
object
UriUtils
{
fun
readFileToByteArray
(
context
:
Context
,
uri
:
Uri
):
ByteArray
?
{
...
...
@@ -26,4 +27,18 @@ object UriUtils {
}
}
}
fun
isUriValid
(
context
:
Context
,
uri
:
Uri
?):
Boolean
{
if
(
uri
==
null
)
{
return
false
}
val
contentResolver
=
context
.
contentResolver
val
cursor
=
contentResolver
.
query
(
uri
,
null
,
null
,
null
,
null
)
if
(
cursor
!=
null
)
{
val
hasData
=
cursor
.
moveToFirst
()
cursor
.
close
()
return
hasData
}
return
false
}
}
\ No newline at end of file
app/src/main/res/layout/activity_pdf.xml
View file @
c13b5df5
...
...
@@ -170,9 +170,11 @@
android:layout_marginStart=
"28dp"
android:layout_marginTop=
"28dp"
android:background=
"@drawable/bg_54585b_5"
android:gravity=
"center"
android:includeFontPadding=
"false"
android:paddingHorizontal=
"2dp"
android:paddingVertical=
"2dp"
android:minWidth=
"40dp"
android:paddingHorizontal=
"5dp"
android:paddingVertical=
"3dp"
android:textColor=
"@color/white"
android:textSize=
"12sp"
app:layout_constraintStart_toStartOf=
"parent"
...
...
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