Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
S
Super PDF 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
Super PDF Reader
Commits
8ad6118d
Commit
8ad6118d
authored
Jun 16, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件遍历方式获取文件
parent
d34ac4e8
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
49 deletions
+59
-49
MainActivity.kt
app/src/main/java/com/base/superpdfreader/MainActivity.kt
+2
-3
DocumentAdapter.kt
...n/java/com/base/superpdfreader/adapter/DocumentAdapter.kt
+12
-16
DocumentListFragment.kt
.../com/base/superpdfreader/fragment/DocumentListFragment.kt
+21
-12
FileHelp.kt
app/src/main/java/com/base/superpdfreader/helps/FileHelp.kt
+19
-17
MediaStoreHelp.kt
...main/java/com/base/superpdfreader/helps/MediaStoreHelp.kt
+4
-0
DocumentDetailDialog.kt
...java/com/base/superpdfreader/view/DocumentDetailDialog.kt
+1
-1
No files found.
app/src/main/java/com/base/superpdfreader/MainActivity.kt
View file @
8ad6118d
...
@@ -2,7 +2,6 @@ package com.base.superpdfreader
...
@@ -2,7 +2,6 @@ package com.base.superpdfreader
import
android.annotation.SuppressLint
import
android.annotation.SuppressLint
import
android.graphics.Color
import
android.graphics.Color
import
android.util.Log
import
androidx.core.content.ContextCompat
import
androidx.core.content.ContextCompat
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.FragmentActivity
import
androidx.fragment.app.FragmentActivity
...
@@ -11,7 +10,7 @@ import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
...
@@ -11,7 +10,7 @@ import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import
com.base.superpdfreader.databinding.ActivityMainBinding
import
com.base.superpdfreader.databinding.ActivityMainBinding
import
com.base.superpdfreader.databinding.ItemTabBinding
import
com.base.superpdfreader.databinding.ItemTabBinding
import
com.base.superpdfreader.fragment.DocumentListFragment
import
com.base.superpdfreader.fragment.DocumentListFragment
import
com.base.superpdfreader.fragment.DocumentListFragment.Companion.MODE_
DP
F
import
com.base.superpdfreader.fragment.DocumentListFragment.Companion.MODE_
PD
F
import
com.base.superpdfreader.fragment.DocumentListFragment.Companion.MODE_EXCEL
import
com.base.superpdfreader.fragment.DocumentListFragment.Companion.MODE_EXCEL
import
com.base.superpdfreader.fragment.DocumentListFragment.Companion.MODE_PPT
import
com.base.superpdfreader.fragment.DocumentListFragment.Companion.MODE_PPT
import
com.base.superpdfreader.fragment.DocumentListFragment.Companion.MODE_WORD
import
com.base.superpdfreader.fragment.DocumentListFragment.Companion.MODE_WORD
...
@@ -30,7 +29,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
...
@@ -30,7 +29,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
private
val
pages
=
arrayListOf
<
DocumentListFragment
>()
private
val
pages
=
arrayListOf
<
DocumentListFragment
>()
private
val
pdfFragment
by
lazy
{
private
val
pdfFragment
by
lazy
{
DocumentListFragment
().
apply
{
UI_MODE
=
MODE_
DP
F
}
DocumentListFragment
().
apply
{
UI_MODE
=
MODE_
PD
F
}
}
}
private
val
wordFragment
by
lazy
{
private
val
wordFragment
by
lazy
{
DocumentListFragment
().
apply
{
UI_MODE
=
MODE_WORD
}
DocumentListFragment
().
apply
{
UI_MODE
=
MODE_WORD
}
...
...
app/src/main/java/com/base/superpdfreader/adapter/DocumentAdapter.kt
View file @
8ad6118d
...
@@ -10,12 +10,10 @@ import com.base.superpdfreader.bean.DocumentBean
...
@@ -10,12 +10,10 @@ import com.base.superpdfreader.bean.DocumentBean
import
com.base.superpdfreader.databinding.ItemDocumentBinding
import
com.base.superpdfreader.databinding.ItemDocumentBinding
import
com.base.superpdfreader.view.XmlEx.inflate
import
com.base.superpdfreader.view.XmlEx.inflate
import
java.io.File
import
java.io.File
import
java.nio.file.Files
import
java.nio.file.attribute.FileTime
class
DocumentAdapter
(
val
itemClick
:
(
bean
:
DocumentBean
)
->
Unit
)
:
RecyclerView
.
Adapter
<
DocumentAdapter
.
DDD
>()
{
class
DocumentAdapter
(
val
itemClick
:
(
bean
:
DocumentBean
)
->
Unit
)
:
RecyclerView
.
Adapter
<
DocumentAdapter
.
DDD
>()
{
private
val
hasData
=
HashSet
<
File
>()
private
val
docList
=
ArrayList
<
DocumentBean
>()
private
val
docList
=
ArrayList
<
DocumentBean
>()
class
DDD
(
view
:
View
)
:
ViewHolder
(
view
)
class
DDD
(
view
:
View
)
:
ViewHolder
(
view
)
...
@@ -43,19 +41,17 @@ class DocumentAdapter(val itemClick: (bean: DocumentBean) -> Unit) : RecyclerVie
...
@@ -43,19 +41,17 @@ class DocumentAdapter(val itemClick: (bean: DocumentBean) -> Unit) : RecyclerVie
@SuppressLint
(
"NotifyDataSetChanged"
)
@SuppressLint
(
"NotifyDataSetChanged"
)
fun
addData
(
type
:
String
,
drawable
:
Int
,
list
:
List
<
File
>)
{
fun
addData
(
type
:
String
,
drawable
:
Int
,
list
:
List
<
File
>)
{
list
.
forEach
{
file
->
val
beans
=
list
.
map
{
file
->
val
flag
=
hasData
.
add
(
file
)
val
bean
=
DocumentBean
(
if
(
flag
)
{
drawable
,
val
bean
=
DocumentBean
(
file
.
name
,
drawable
,
file
.
lastModified
(),
file
.
name
,
file
.
length
(),
file
.
lastModified
(),
file
.
absolutePath
,
type
file
.
length
(),
)
file
.
absolutePath
,
type
bean
)
docList
.
add
(
bean
)
}
}
}
docList
.
addAll
(
beans
)
notifyDataSetChanged
()
notifyDataSetChanged
()
}
}
...
...
app/src/main/java/com/base/superpdfreader/fragment/DocumentListFragment.kt
View file @
8ad6118d
...
@@ -9,16 +9,18 @@ import com.base.superpdfreader.adapter.DocumentAdapter
...
@@ -9,16 +9,18 @@ import com.base.superpdfreader.adapter.DocumentAdapter
import
com.base.superpdfreader.databinding.FragmentDocumentListBinding
import
com.base.superpdfreader.databinding.FragmentDocumentListBinding
import
com.base.superpdfreader.helps.BaseFragment
import
com.base.superpdfreader.helps.BaseFragment
import
com.base.superpdfreader.helps.FileHelp.loadDocument
import
com.base.superpdfreader.helps.FileHelp.loadDocument
import
com.base.superpdfreader.helps.LogEx
import
com.base.superpdfreader.helps.PermissionHelp.checkStorePermission
import
com.base.superpdfreader.helps.PermissionHelp.checkStorePermission
import
com.base.superpdfreader.helps.PermissionHelp.requestStorePermission
import
com.base.superpdfreader.helps.PermissionHelp.requestStorePermission
import
com.base.superpdfreader.view.DocumentDetailDialog.showDocumentDetailDialog
import
com.base.superpdfreader.view.DocumentDetailDialog.showDocumentDetailDialog
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.async
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
class
DocumentListFragment
()
:
BaseFragment
<
FragmentDocumentListBinding
>()
{
class
DocumentListFragment
()
:
BaseFragment
<
FragmentDocumentListBinding
>()
{
var
UI_MODE
:
String
=
MODE_DPF
private
val
TAG
=
"DocumentListFragment"
var
UI_MODE
:
String
=
MODE_PDF
private
lateinit
var
adapter
:
DocumentAdapter
private
lateinit
var
adapter
:
DocumentAdapter
public
override
val
binding
:
FragmentDocumentListBinding
by
lazy
{
public
override
val
binding
:
FragmentDocumentListBinding
by
lazy
{
...
@@ -28,20 +30,24 @@ class DocumentListFragment() : BaseFragment<FragmentDocumentListBinding>() {
...
@@ -28,20 +30,24 @@ class DocumentListFragment() : BaseFragment<FragmentDocumentListBinding>() {
override
fun
setView
()
{
override
fun
setView
()
{
when
(
UI_MODE
)
{
when
(
UI_MODE
)
{
MODE_DPF
->
{
MODE_PDF
->
{
binding
.
tvAllow
.
background
=
ContextCompat
.
getDrawable
(
requireContext
(),
R
.
drawable
.
bg_allow_pdf
)
binding
.
tvAllow
.
background
=
ContextCompat
.
getDrawable
(
requireContext
(),
R
.
drawable
.
bg_allow_pdf
)
}
}
MODE_WORD
->
{
MODE_WORD
->
{
binding
.
tvAllow
.
background
=
ContextCompat
.
getDrawable
(
requireContext
(),
R
.
drawable
.
bg_allow_word
)
binding
.
tvAllow
.
background
=
ContextCompat
.
getDrawable
(
requireContext
(),
R
.
drawable
.
bg_allow_word
)
}
}
MODE_PPT
->
{
MODE_PPT
->
{
binding
.
tvAllow
.
background
=
ContextCompat
.
getDrawable
(
requireContext
(),
R
.
drawable
.
bg_allow_ppt
)
binding
.
tvAllow
.
background
=
ContextCompat
.
getDrawable
(
requireContext
(),
R
.
drawable
.
bg_allow_ppt
)
}
}
MODE_EXCEL
->
{
MODE_EXCEL
->
{
binding
.
tvAllow
.
background
=
ContextCompat
.
getDrawable
(
requireContext
(),
R
.
drawable
.
bg_allow_excel
)
binding
.
tvAllow
.
background
=
ContextCompat
.
getDrawable
(
requireContext
(),
R
.
drawable
.
bg_allow_excel
)
}
}
}
}
adapter
=
DocumentAdapter
{
bean
->
adapter
=
DocumentAdapter
{
bean
->
...
@@ -72,13 +78,15 @@ class DocumentListFragment() : BaseFragment<FragmentDocumentListBinding>() {
...
@@ -72,13 +78,15 @@ class DocumentListFragment() : BaseFragment<FragmentDocumentListBinding>() {
private
fun
initData
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
private
fun
initData
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
when
(
UI_MODE
)
{
when
(
UI_MODE
)
{
MODE_
DP
F
->
{
MODE_
PD
F
->
{
loadDocument
(
filter
=
{
loadDocument
(
filter
=
{
it
.
path
.
contains
(
".pdf"
)
val
fileType
=
it
.
path
.
substring
(
it
.
path
.
length
-
4
,
it
.
path
.
length
)
val
flag
=
fileType
==
".pdf"
LogEx
.
logDebug
(
TAG
,
"fileType=$fileType flag=$flag"
)
flag
})
{
files
->
})
{
files
->
launch
(
Dispatchers
.
Main
)
{
launch
(
Dispatchers
.
Main
)
{
adapter
.
addData
(
MODE_
DP
F
,
R
.
mipmap
.
pdf
,
files
)
adapter
.
addData
(
MODE_
PD
F
,
R
.
mipmap
.
pdf
,
files
)
}
}
}
}
}
}
...
@@ -95,6 +103,7 @@ class DocumentListFragment() : BaseFragment<FragmentDocumentListBinding>() {
...
@@ -95,6 +103,7 @@ class DocumentListFragment() : BaseFragment<FragmentDocumentListBinding>() {
MODE_PPT
->
{
MODE_PPT
->
{
loadDocument
(
filter
=
{
loadDocument
(
filter
=
{
it
.
path
.
contains
(
".ppt"
)
it
.
path
.
contains
(
".ppt"
)
})
{
files
->
})
{
files
->
launch
(
Dispatchers
.
Main
)
{
launch
(
Dispatchers
.
Main
)
{
...
@@ -121,7 +130,7 @@ class DocumentListFragment() : BaseFragment<FragmentDocumentListBinding>() {
...
@@ -121,7 +130,7 @@ class DocumentListFragment() : BaseFragment<FragmentDocumentListBinding>() {
}
}
companion
object
{
companion
object
{
const
val
MODE_
DP
F
=
"PDF"
const
val
MODE_
PD
F
=
"PDF"
const
val
MODE_WORD
=
"WORD"
const
val
MODE_WORD
=
"WORD"
const
val
MODE_PPT
=
"PPT"
const
val
MODE_PPT
=
"PPT"
const
val
MODE_EXCEL
=
"EXCEL"
const
val
MODE_EXCEL
=
"EXCEL"
...
...
app/src/main/java/com/base/superpdfreader/helps/FileHelp.kt
View file @
8ad6118d
package
com.base.superpdfreader.helps
package
com.base.superpdfreader.helps
import
android.os.Environment
import
android.os.Environment
import
android.provider.MediaStore
import
android.util.Log
import
android.util.Log
import
androidx.lifecycle.LifecycleCoroutineScope
import
androidx.lifecycle.LifecycleCoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
...
@@ -15,33 +16,28 @@ object FileHelp {
...
@@ -15,33 +16,28 @@ object FileHelp {
filter
:
(
file
:
File
)
->
Boolean
,
filter
:
(
file
:
File
)
->
Boolean
,
eachFile
:
(
eachFiles
:
List
<
File
>)
->
Unit
eachFile
:
(
eachFiles
:
List
<
File
>)
->
Unit
)
{
)
{
var
firstSend
=
true
val
resultList
=
arrayListOf
<
File
>()
val
resultList
=
arrayListOf
<
File
>()
val
root
=
Environment
.
getExternalStorageDirectory
()
val
root
=
Environment
.
getExternalStorageDirectory
()
loadFileByFilter
(
root
,
filter
=
filter
,
onDo
=
{
loadFileByFilter
(
root
,
filter
=
filter
,
onDo
=
{
Log
.
e
(
TAG
,
"file=$it"
)
if
(
firstSend
)
{
if
(
resultList
.
size
==
5
)
{
//第一次发送
val
mainList
=
arrayListOf
<
File
>()
firstSend
=
false
mainList
.
addAll
(
resultList
)
eachFile
.
invoke
(
listOf
(
it
))
resultList
.
clear
()
Log
.
e
(
TAG
,
"size=${mainList.size}"
)
//这里onDo切换到main主协程,避免IO协程里的数据和main协程里的数据共用同一对象
eachFile
.
invoke
(
mainList
)
}
else
{
}
else
{
//间隔发送
resultList
.
add
(
it
)
resultList
.
add
(
it
)
if
(
resultList
.
size
==
5
)
{
val
mainList
=
arrayListOf
<
File
>()
mainList
.
addAll
(
mainList
)
//这里onDo切换到main主协程,避免IO协程里的数据和main协程里的数据共用同一对象
eachFile
.
invoke
(
mainList
)
resultList
.
clear
()
}
}
}
})
})
eachFile
.
invoke
(
resultList
)
eachFile
.
invoke
(
resultList
)
}
}
fun
loadFileByFilter
(
private
fun
loadFileByFilter
(
folder
:
File
,
folder
:
File
,
filter
:
(
file
:
File
)
->
Boolean
,
filter
:
(
file
:
File
)
->
Boolean
,
onDo
:
((
file
:
File
)
->
Unit
)?
onDo
:
((
file
:
File
)
->
Unit
)?
...
@@ -54,7 +50,11 @@ object FileHelp {
...
@@ -54,7 +50,11 @@ object FileHelp {
if
(
it
.
isDirectory
)
{
if
(
it
.
isDirectory
)
{
linkList
.
add
(
it
)
linkList
.
add
(
it
)
}
else
{
}
else
{
onDo
?.
invoke
(
it
)
val
flag
=
filter
(
it
)
LogEx
.
logDebug
(
TAG
,
"$it flag=$flag"
)
if
(
flag
)
{
onDo
?.
invoke
(
it
)
}
}
}
}
}
...
@@ -67,7 +67,9 @@ object FileHelp {
...
@@ -67,7 +67,9 @@ object FileHelp {
if
(
it
.
isDirectory
)
{
if
(
it
.
isDirectory
)
{
linkList
.
add
(
it
)
linkList
.
add
(
it
)
}
else
{
}
else
{
if
(
filter
(
it
))
{
val
flag
=
filter
(
it
)
LogEx
.
logDebug
(
TAG
,
"$it flag=$flag"
)
if
(
flag
)
{
onDo
?.
invoke
(
it
)
onDo
?.
invoke
(
it
)
}
}
}
}
...
...
app/src/main/java/com/base/superpdfreader/helps/MediaStoreHelp.kt
0 → 100644
View file @
8ad6118d
package
com.base.superpdfreader.helps
object
MediaStoreHelp
{
}
\ No newline at end of file
app/src/main/java/com/base/superpdfreader/view/DocumentDetailDialog.kt
View file @
8ad6118d
...
@@ -27,7 +27,7 @@ object DocumentDetailDialog {
...
@@ -27,7 +27,7 @@ object DocumentDetailDialog {
binding
.
tvName
.
text
=
bean
.
name
binding
.
tvName
.
text
=
bean
.
name
binding
.
tvInfo
.
text
=
"Last modified: ${bean.info(true)}"
binding
.
tvInfo
.
text
=
"Last modified: ${bean.info(true)}"
when
(
UI_MODE
)
{
when
(
UI_MODE
)
{
DocumentListFragment
.
MODE_
DP
F
->
{
DocumentListFragment
.
MODE_
PD
F
->
{
binding
.
ivDocument
.
setImageResource
(
R
.
mipmap
.
pdf
)
binding
.
ivDocument
.
setImageResource
(
R
.
mipmap
.
pdf
)
binding
.
ivOpen
.
setImageResource
(
R
.
mipmap
.
openfileh
)
binding
.
ivOpen
.
setImageResource
(
R
.
mipmap
.
openfileh
)
binding
.
ivEmail
.
setImageResource
(
R
.
mipmap
.
emailh
)
binding
.
ivEmail
.
setImageResource
(
R
.
mipmap
.
emailh
)
...
...
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