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
Hide 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 @@
android:screenOrientation=
"portrait"
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
android:name=
"com.google.android.gms.ads.APPLICATION_ID"
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
import
android.app.Application
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.SupervisorJob
class
MyApplication
:
Application
()
{
companion
object
{
lateinit
var
appContext
:
MyApplication
//全局协程作用域
val
appScope
=
CoroutineScope
(
Dispatchers
.
IO
+
SupervisorJob
())
}
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
import
com.base.pdfoneread.ui.views.DocumentDialog.showDocumentHomeMoreDialog
import
com.base.pdfoneread.ui.views.PdfDialog.showPdfHomeMoreDialog
import
com.base.pdfoneread.utils.BarUtils
import
com.base.pdfoneread.utils.LogEx
import
com.base.pdfoneread.utils.PdfBoxUtils.checkPdfEncryption
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.cancel
import
kotlinx.coroutines.flow.collectLatest
import
kotlinx.coroutines.launch
import
java.io.File
class
DocumentActivity
:
BaseActivity
<
ActivityDocumentBinding
>(),
DialogCallBack
{
private
val
TAG
=
"DocumentActivity"
var
type
:
String
=
""
override
val
binding
:
ActivityDocumentBinding
by
lazy
{
...
...
@@ -141,6 +146,14 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
initData
()
}
initPreData
()
lifecycleScope
.
launch
{
isRefreshOver
.
collectLatest
{
value
->
LogEx
.
logDebug
(
TAG
,
"value=$value"
)
initData
()
//刷新结束不再监听
cancel
()
}
}
}
@SuppressLint
(
"NotifyDataSetChanged"
)
...
...
@@ -192,15 +205,8 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
else
->
getGlobalAllList
()
}
if
(
list
.
isEmpty
())
{
binding
.
swipeRefreshLayout
.
isRefreshing
=
true
}
else
{
binding
.
llEmpty
.
visibility
=
View
.
GONE
adapter
?.
submitList
(
getRvAdList
(
list
))
}
if
(
isRefreshing
.
get
())
{
initData
()
}
runOnUI
(
list
)
}
...
...
@@ -214,7 +220,11 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
TYPE_PPT
->
getPptDocument
(
context
)
else
->
getAllDocument
(
context
)
}
launch
(
Dispatchers
.
Main
)
{
runOnUI
(
list
)
}
private
fun
runOnUI
(
list
:
List
<
DocumentBean
>)
{
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
if
(
list
.
isEmpty
())
{
binding
.
llEmpty
.
visibility
=
View
.
VISIBLE
adapter
?.
submitList
(
listOf
())
...
...
@@ -224,7 +234,6 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
}
binding
.
swipeRefreshLayout
.
isRefreshing
=
false
}
}
//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
import
com.base.pdfoneread.bean.DocumentBean.Companion.TYPE_WORD
import
com.base.pdfoneread.bean.DocumentBean.Companion.deepCopy
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.LogEx
import
com.base.pdfoneread.utils.PdfBoxUtils.checkPdfEncryption
import
com.base.pdfoneread.utils.SpStringUtils
import
com.base.pdfoneread.utils.SpStringUtils.BOOKMARK_KEY
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.FileOutputStream
import
java.io.IOException
import
java.util.concurrent.CopyOnWriteArrayList
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>()
var
GlobalPptList
=
CopyOnWriteArrayList
<
DocumentBean
>()
fun
cleanGlobalData
()
{
isRefreshing
.
compareAndSet
(
false
,
true
)
GlobalPdfList
.
clear
()
GlobalWordList
.
clear
()
GlobalExcelList
.
clear
()
...
...
@@ -201,7 +205,7 @@ fun getAllDocument(context: Context): MutableList<DocumentBean> {
new
.
add
(
0
,
pdfDemo
)
GlobalPdfList
.
add
(
0
,
pdfDemo
)
}
isRefreshing
.
compareAndSet
(
true
,
false
)
appScope
.
launch
{
isRefreshOver
.
emit
(
true
)
}
return
new
}
...
...
@@ -241,6 +245,7 @@ fun getPdfDocument(context: Context): MutableList<DocumentBean> {
new
.
add
(
0
,
pdfDemo
)
GlobalPdfList
.
add
(
0
,
deepCopy
(
pdfDemo
))
}
appScope
.
launch
{
isRefreshOver
.
emit
(
true
)
}
return
new
}
...
...
@@ -266,6 +271,7 @@ fun getWordDocument(context: Context): MutableList<DocumentBean> {
new
.
add
(
0
,
wordDemo
)
GlobalWordList
.
add
(
0
,
deepCopy
(
wordDemo
))
}
appScope
.
launch
{
isRefreshOver
.
emit
(
true
)
}
return
new
}
...
...
@@ -292,6 +298,7 @@ fun getExcelDocument(context: Context): MutableList<DocumentBean> {
new
.
add
(
0
,
excelDemo
)
GlobalExcelList
.
add
(
0
,
deepCopy
(
excelDemo
))
}
appScope
.
launch
{
isRefreshOver
.
emit
(
true
)
}
return
new
}
...
...
@@ -317,6 +324,7 @@ fun getPptDocument(context: Context): MutableList<DocumentBean> {
new
.
add
(
0
,
pptDemo
)
GlobalPptList
.
add
(
0
,
deepCopy
(
pptDemo
))
}
appScope
.
launch
{
isRefreshOver
.
emit
(
true
)
}
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
import
com.base.pdfoneread.ui.document.getAllDocument
import
com.base.pdfoneread.ui.document.getGlobalAllList
import
com.base.pdfoneread.utils.LogEx
import
com.base.pdfoneread.utils.PermissionUtils.checkStorePermission
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
java.util.concurrent.atomic.AtomicBoolean
class
HomeFragment
()
:
Fragment
()
{
...
...
@@ -51,7 +53,7 @@ class HomeFragment() : Fragment() {
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
LogEx
.
logDebug
(
TAG
,
"onCreate"
)
LogEx
.
logDebug
(
TAG
,
"onCreate"
)
}
override
fun
onCreateView
(
...
...
@@ -122,17 +124,21 @@ class HomeFragment() : Fragment() {
override
fun
onDestroyView
()
{
super
.
onDestroyView
()
LogEx
.
logDebug
(
TAG
,
"onDestroyView"
)
LogEx
.
logDebug
(
TAG
,
"onDestroyView"
)
}
override
fun
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"
)
isRefreshing
.
compareAndSet
(
false
,
true
)
kotlin
.
runCatching
{
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
getAllDocument
(
requireContext
())
...
...
@@ -155,12 +161,20 @@ class HomeFragment() : Fragment() {
adapter
.
submitList
(
groupList
)
binding
.
swipeRefreshLayout
.
isRefreshing
=
false
isRefreshing
.
compareAndSet
(
true
,
false
)
}
}
}
}
override
fun
onResume
()
{
super
.
onResume
()
if
(
requireContext
().
checkStorePermission
())
{
refreshData
()
}
}
fun
changeUIByMain
()
{
val
activity
=
requireActivity
()
as
MainActivity
?
...
...
app/src/main/java/com/base/pdfoneread/ui/main/MainActivity.kt
View file @
03a68214
...
...
@@ -47,18 +47,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
changeHomeRvIcon
()
if
(!
checkStorePermission
())
{
showStoragePermission
(
launcher
)
{
refreshHomeData
()
}
showStoragePermission
(
launcher
)
{}
}
}
private
fun
refreshHomeData
()
{
val
fragment
=
getNavCurrentFragment
()
if
(
fragment
is
HomeFragment
)
{
fragment
.
refreshData
()
}
override
fun
onResume
()
{
super
.
onResume
()
}
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