Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
Pdf one 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 one Reader
Commits
03a68214
Commit
03a68214
authored
Nov 13, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...处理数据刷新
parent
d040b8f7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
28 deletions
+81
-28
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+10
-0
MyApplication.kt
app/src/main/java/com/base/pdfoneread/ui/MyApplication.kt
+6
-0
DocumentActivity.kt
.../java/com/base/pdfoneread/ui/document/DocumentActivity.kt
+20
-11
DocumentEx.kt
...c/main/java/com/base/pdfoneread/ui/document/DocumentEx.kt
+12
-4
HomeFragment.kt
...src/main/java/com/base/pdfoneread/ui/main/HomeFragment.kt
+18
-4
MainActivity.kt
...src/main/java/com/base/pdfoneread/ui/main/MainActivity.kt
+3
-9
file_paths.xml
app/src/main/res/xml/file_paths.xml
+12
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
03a68214
...
@@ -88,6 +88,16 @@
...
@@ -88,6 +88,16 @@
android:screenOrientation=
"portrait"
android:screenOrientation=
"portrait"
tools:ignore=
"DiscouragedApi,LockedOrientationActivity"
/>
tools:ignore=
"DiscouragedApi,LockedOrientationActivity"
/>
<provider
android:name=
"androidx.core.content.FileProvider"
android:authorities=
"${applicationId}.provider"
android:exported=
"false"
android:grantUriPermissions=
"true"
>
<meta-data
android:name=
"android.support.FILE_PROVIDER_PATHS"
android:resource=
"@xml/file_paths"
/>
</provider>
<meta-data
<meta-data
android:name=
"com.google.android.gms.ads.APPLICATION_ID"
android:name=
"com.google.android.gms.ads.APPLICATION_ID"
android:value=
"ca-app-pub-3940256099942544~3347511713"
/>
android:value=
"ca-app-pub-3940256099942544~3347511713"
/>
...
...
app/src/main/java/com/base/pdfoneread/ui/MyApplication.kt
View file @
03a68214
package
com.base.pdfoneread.ui
package
com.base.pdfoneread.ui
import
android.app.Application
import
android.app.Application
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.SupervisorJob
class
MyApplication
:
Application
()
{
class
MyApplication
:
Application
()
{
companion
object
{
companion
object
{
lateinit
var
appContext
:
MyApplication
lateinit
var
appContext
:
MyApplication
//全局协程作用域
val
appScope
=
CoroutineScope
(
Dispatchers
.
IO
+
SupervisorJob
())
}
}
override
fun
onCreate
()
{
override
fun
onCreate
()
{
...
...
app/src/main/java/com/base/pdfoneread/ui/document/DocumentActivity.kt
View file @
03a68214
...
@@ -21,14 +21,19 @@ import com.base.pdfoneread.ui.views.DialogCallBack
...
@@ -21,14 +21,19 @@ import com.base.pdfoneread.ui.views.DialogCallBack
import
com.base.pdfoneread.ui.views.DocumentDialog.showDocumentHomeMoreDialog
import
com.base.pdfoneread.ui.views.DocumentDialog.showDocumentHomeMoreDialog
import
com.base.pdfoneread.ui.views.PdfDialog.showPdfHomeMoreDialog
import
com.base.pdfoneread.ui.views.PdfDialog.showPdfHomeMoreDialog
import
com.base.pdfoneread.utils.BarUtils
import
com.base.pdfoneread.utils.BarUtils
import
com.base.pdfoneread.utils.LogEx
import
com.base.pdfoneread.utils.PdfBoxUtils.checkPdfEncryption
import
com.base.pdfoneread.utils.PdfBoxUtils.checkPdfEncryption
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.cancel
import
kotlinx.coroutines.flow.collectLatest
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
import
java.io.File
import
java.io.File
class
DocumentActivity
:
BaseActivity
<
ActivityDocumentBinding
>(),
DialogCallBack
{
class
DocumentActivity
:
BaseActivity
<
ActivityDocumentBinding
>(),
DialogCallBack
{
private
val
TAG
=
"DocumentActivity"
var
type
:
String
=
""
var
type
:
String
=
""
override
val
binding
:
ActivityDocumentBinding
by
lazy
{
override
val
binding
:
ActivityDocumentBinding
by
lazy
{
...
@@ -141,6 +146,14 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
...
@@ -141,6 +146,14 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
initData
()
initData
()
}
}
initPreData
()
initPreData
()
lifecycleScope
.
launch
{
isRefreshOver
.
collectLatest
{
value
->
LogEx
.
logDebug
(
TAG
,
"value=$value"
)
initData
()
//刷新结束不再监听
cancel
()
}
}
}
}
@SuppressLint
(
"NotifyDataSetChanged"
)
@SuppressLint
(
"NotifyDataSetChanged"
)
...
@@ -192,15 +205,8 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
...
@@ -192,15 +205,8 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
else
->
getGlobalAllList
()
else
->
getGlobalAllList
()
}
}
if
(
list
.
isEmpty
())
{
binding
.
swipeRefreshLayout
.
isRefreshing
=
true
runOnUI
(
list
)
}
else
{
binding
.
llEmpty
.
visibility
=
View
.
GONE
adapter
?.
submitList
(
getRvAdList
(
list
))
}
if
(
isRefreshing
.
get
())
{
initData
()
}
}
}
...
@@ -214,7 +220,11 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
...
@@ -214,7 +220,11 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
TYPE_PPT
->
getPptDocument
(
context
)
TYPE_PPT
->
getPptDocument
(
context
)
else
->
getAllDocument
(
context
)
else
->
getAllDocument
(
context
)
}
}
launch
(
Dispatchers
.
Main
)
{
runOnUI
(
list
)
}
private
fun
runOnUI
(
list
:
List
<
DocumentBean
>)
{
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
if
(
list
.
isEmpty
())
{
if
(
list
.
isEmpty
())
{
binding
.
llEmpty
.
visibility
=
View
.
VISIBLE
binding
.
llEmpty
.
visibility
=
View
.
VISIBLE
adapter
?.
submitList
(
listOf
())
adapter
?.
submitList
(
listOf
())
...
@@ -224,7 +234,6 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
...
@@ -224,7 +234,6 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
}
}
binding
.
swipeRefreshLayout
.
isRefreshing
=
false
binding
.
swipeRefreshLayout
.
isRefreshing
=
false
}
}
}
}
//region DialogCallBack
//region DialogCallBack
...
...
app/src/main/java/com/base/pdfoneread/ui/document/DocumentEx.kt
View file @
03a68214
...
@@ -21,19 +21,24 @@ import com.base.pdfoneread.bean.DocumentBean.Companion.TYPE_PPT
...
@@ -21,19 +21,24 @@ import com.base.pdfoneread.bean.DocumentBean.Companion.TYPE_PPT
import
com.base.pdfoneread.bean.DocumentBean.Companion.TYPE_WORD
import
com.base.pdfoneread.bean.DocumentBean.Companion.TYPE_WORD
import
com.base.pdfoneread.bean.DocumentBean.Companion.deepCopy
import
com.base.pdfoneread.bean.DocumentBean.Companion.deepCopy
import
com.base.pdfoneread.bean.MediaBean
import
com.base.pdfoneread.bean.MediaBean
import
com.base.pdfoneread.ui.MyApplication.Companion.appScope
import
com.base.pdfoneread.utils.AssetUtils.readByteArrayFromAsset
import
com.base.pdfoneread.utils.AssetUtils.readByteArrayFromAsset
import
com.base.pdfoneread.utils.LogEx
import
com.base.pdfoneread.utils.PdfBoxUtils.checkPdfEncryption
import
com.base.pdfoneread.utils.PdfBoxUtils.checkPdfEncryption
import
com.base.pdfoneread.utils.SpStringUtils
import
com.base.pdfoneread.utils.SpStringUtils
import
com.base.pdfoneread.utils.SpStringUtils.BOOKMARK_KEY
import
com.base.pdfoneread.utils.SpStringUtils.BOOKMARK_KEY
import
com.base.pdfoneread.utils.getMediaFile
import
com.base.pdfoneread.utils.getMediaFile
import
kotlinx.coroutines.DelicateCoroutinesApi
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.flow.MutableSharedFlow
import
kotlinx.coroutines.flow.MutableStateFlow
import
kotlinx.coroutines.launch
import
java.io.File
import
java.io.File
import
java.io.FileOutputStream
import
java.io.FileOutputStream
import
java.io.IOException
import
java.io.IOException
import
java.util.concurrent.CopyOnWriteArrayList
import
java.util.concurrent.CopyOnWriteArrayList
import
java.util.concurrent.atomic.AtomicBoolean
import
java.util.concurrent.atomic.AtomicBoolean
var
isRefresh
ing
:
AtomicBoolean
=
AtomicBoolean
(
false
)
var
isRefresh
Over
:
MutableSharedFlow
<
Boolean
>
=
MutableSharedFlow
(
)
/**
/**
* 全局数据数据
* 全局数据数据
...
@@ -53,7 +58,6 @@ var GlobalExcelList = CopyOnWriteArrayList<DocumentBean>()
...
@@ -53,7 +58,6 @@ var GlobalExcelList = CopyOnWriteArrayList<DocumentBean>()
var
GlobalPptList
=
CopyOnWriteArrayList
<
DocumentBean
>()
var
GlobalPptList
=
CopyOnWriteArrayList
<
DocumentBean
>()
fun
cleanGlobalData
()
{
fun
cleanGlobalData
()
{
isRefreshing
.
compareAndSet
(
false
,
true
)
GlobalPdfList
.
clear
()
GlobalPdfList
.
clear
()
GlobalWordList
.
clear
()
GlobalWordList
.
clear
()
GlobalExcelList
.
clear
()
GlobalExcelList
.
clear
()
...
@@ -201,7 +205,7 @@ fun getAllDocument(context: Context): MutableList<DocumentBean> {
...
@@ -201,7 +205,7 @@ fun getAllDocument(context: Context): MutableList<DocumentBean> {
new
.
add
(
0
,
pdfDemo
)
new
.
add
(
0
,
pdfDemo
)
GlobalPdfList
.
add
(
0
,
pdfDemo
)
GlobalPdfList
.
add
(
0
,
pdfDemo
)
}
}
isRefreshing
.
compareAndSet
(
true
,
false
)
appScope
.
launch
{
isRefreshOver
.
emit
(
true
)
}
return
new
return
new
}
}
...
@@ -241,6 +245,7 @@ fun getPdfDocument(context: Context): MutableList<DocumentBean> {
...
@@ -241,6 +245,7 @@ fun getPdfDocument(context: Context): MutableList<DocumentBean> {
new
.
add
(
0
,
pdfDemo
)
new
.
add
(
0
,
pdfDemo
)
GlobalPdfList
.
add
(
0
,
deepCopy
(
pdfDemo
))
GlobalPdfList
.
add
(
0
,
deepCopy
(
pdfDemo
))
}
}
appScope
.
launch
{
isRefreshOver
.
emit
(
true
)
}
return
new
return
new
}
}
...
@@ -266,6 +271,7 @@ fun getWordDocument(context: Context): MutableList<DocumentBean> {
...
@@ -266,6 +271,7 @@ fun getWordDocument(context: Context): MutableList<DocumentBean> {
new
.
add
(
0
,
wordDemo
)
new
.
add
(
0
,
wordDemo
)
GlobalWordList
.
add
(
0
,
deepCopy
(
wordDemo
))
GlobalWordList
.
add
(
0
,
deepCopy
(
wordDemo
))
}
}
appScope
.
launch
{
isRefreshOver
.
emit
(
true
)
}
return
new
return
new
}
}
...
@@ -292,6 +298,7 @@ fun getExcelDocument(context: Context): MutableList<DocumentBean> {
...
@@ -292,6 +298,7 @@ fun getExcelDocument(context: Context): MutableList<DocumentBean> {
new
.
add
(
0
,
excelDemo
)
new
.
add
(
0
,
excelDemo
)
GlobalExcelList
.
add
(
0
,
deepCopy
(
excelDemo
))
GlobalExcelList
.
add
(
0
,
deepCopy
(
excelDemo
))
}
}
appScope
.
launch
{
isRefreshOver
.
emit
(
true
)
}
return
new
return
new
}
}
...
@@ -317,6 +324,7 @@ fun getPptDocument(context: Context): MutableList<DocumentBean> {
...
@@ -317,6 +324,7 @@ fun getPptDocument(context: Context): MutableList<DocumentBean> {
new
.
add
(
0
,
pptDemo
)
new
.
add
(
0
,
pptDemo
)
GlobalPptList
.
add
(
0
,
deepCopy
(
pptDemo
))
GlobalPptList
.
add
(
0
,
deepCopy
(
pptDemo
))
}
}
appScope
.
launch
{
isRefreshOver
.
emit
(
true
)
}
return
new
return
new
}
}
...
...
app/src/main/java/com/base/pdfoneread/ui/main/HomeFragment.kt
View file @
03a68214
...
@@ -39,8 +39,10 @@ import com.base.pdfoneread.ui.document.GlobalWordList
...
@@ -39,8 +39,10 @@ import com.base.pdfoneread.ui.document.GlobalWordList
import
com.base.pdfoneread.ui.document.getAllDocument
import
com.base.pdfoneread.ui.document.getAllDocument
import
com.base.pdfoneread.ui.document.getGlobalAllList
import
com.base.pdfoneread.ui.document.getGlobalAllList
import
com.base.pdfoneread.utils.LogEx
import
com.base.pdfoneread.utils.LogEx
import
com.base.pdfoneread.utils.PermissionUtils.checkStorePermission
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
import
java.util.concurrent.atomic.AtomicBoolean
class
HomeFragment
()
:
Fragment
()
{
class
HomeFragment
()
:
Fragment
()
{
...
@@ -51,7 +53,7 @@ class HomeFragment() : Fragment() {
...
@@ -51,7 +53,7 @@ class HomeFragment() : Fragment() {
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
LogEx
.
logDebug
(
TAG
,
"onCreate"
)
LogEx
.
logDebug
(
TAG
,
"onCreate"
)
}
}
override
fun
onCreateView
(
override
fun
onCreateView
(
...
@@ -122,17 +124,21 @@ class HomeFragment() : Fragment() {
...
@@ -122,17 +124,21 @@ class HomeFragment() : Fragment() {
override
fun
onDestroyView
()
{
override
fun
onDestroyView
()
{
super
.
onDestroyView
()
super
.
onDestroyView
()
LogEx
.
logDebug
(
TAG
,
"onDestroyView"
)
LogEx
.
logDebug
(
TAG
,
"onDestroyView"
)
}
}
override
fun
onDestroy
()
{
override
fun
onDestroy
()
{
super
.
onDestroy
()
super
.
onDestroy
()
LogEx
.
logDebug
(
TAG
,
"onDestroy"
)
LogEx
.
logDebug
(
TAG
,
"onDestroy"
)
}
}
fun
refreshData
(
where
:
String
=
""
)
{
private
var
isRefreshing
:
AtomicBoolean
=
AtomicBoolean
(
false
)
private
fun
refreshData
(
where
:
String
=
""
)
{
if
(
isRefreshing
.
get
())
return
LogEx
.
logDebug
(
TAG
,
"refreshData where=$where"
)
LogEx
.
logDebug
(
TAG
,
"refreshData where=$where"
)
isRefreshing
.
compareAndSet
(
false
,
true
)
kotlin
.
runCatching
{
kotlin
.
runCatching
{
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
getAllDocument
(
requireContext
())
getAllDocument
(
requireContext
())
...
@@ -155,10 +161,18 @@ class HomeFragment() : Fragment() {
...
@@ -155,10 +161,18 @@ class HomeFragment() : Fragment() {
adapter
.
submitList
(
groupList
)
adapter
.
submitList
(
groupList
)
binding
.
swipeRefreshLayout
.
isRefreshing
=
false
binding
.
swipeRefreshLayout
.
isRefreshing
=
false
isRefreshing
.
compareAndSet
(
true
,
false
)
}
}
}
}
}
}
}
override
fun
onResume
()
{
super
.
onResume
()
if
(
requireContext
().
checkStorePermission
())
{
refreshData
()
}
}
}
...
...
app/src/main/java/com/base/pdfoneread/ui/main/MainActivity.kt
View file @
03a68214
...
@@ -47,18 +47,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
...
@@ -47,18 +47,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
changeHomeRvIcon
()
changeHomeRvIcon
()
if
(!
checkStorePermission
())
{
if
(!
checkStorePermission
())
{
showStoragePermission
(
launcher
)
{
showStoragePermission
(
launcher
)
{}
refreshHomeData
()
}
}
}
}
}
private
fun
refreshHomeData
()
{
override
fun
onResume
()
{
val
fragment
=
getNavCurrentFragment
()
super
.
onResume
()
if
(
fragment
is
HomeFragment
)
{
fragment
.
refreshData
()
}
}
}
override
fun
initListener
()
{
override
fun
initListener
()
{
...
...
app/src/main/res/xml/file_paths.xml
0 → 100644
View file @
03a68214
<?xml version="1.0" encoding="utf-8"?>
<paths
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<cache-path
name=
"cache_files"
path=
"."
/>
<external-path
name=
"extern_files"
path=
"."
/>
<files-path
name=
"files"
path=
"."
/>
</paths>
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