Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
IBMS
/
nativeview
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d8200ebf
authored
Feb 22, 2022
by
huangzhicong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复storage接口回调没有执行在主线程的问题
parent
ccd0ad5f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
12 deletions
+25
-12
app/src/main/java/com/maxrocky/nativeview/contract/StorageContract.kt
+25
-12
No files found.
app/src/main/java/com/maxrocky/nativeview/contract/StorageContract.kt
View file @
d8200ebf
...
@@ -12,6 +12,7 @@ import kotlinx.coroutines.Dispatchers
...
@@ -12,6 +12,7 @@ import kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.flow.collect
import
kotlinx.coroutines.flow.collect
import
kotlinx.coroutines.flow.map
import
kotlinx.coroutines.flow.map
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
class
StorageContract
(
fragment
:
Fragment
,
proxy
:
WebViewProxy
)
:
IContract
(
fragment
,
proxy
){
class
StorageContract
(
fragment
:
Fragment
,
proxy
:
WebViewProxy
)
:
IContract
(
fragment
,
proxy
){
companion
object
{
companion
object
{
...
@@ -32,12 +33,16 @@ class StorageContract(fragment: Fragment, proxy: WebViewProxy) : IContract(fragm
...
@@ -32,12 +33,16 @@ class StorageContract(fragment: Fragment, proxy: WebViewProxy) : IContract(fragm
val
storageKey
=
stringPreferencesKey
(
key
)
val
storageKey
=
stringPreferencesKey
(
key
)
maxrocky
[
storageKey
]
=
value
maxrocky
[
storageKey
]
=
value
val
data
=
StorageResult
(
key
,
value
)
val
data
=
StorageResult
(
key
,
value
)
proxy
.
success
(
STORAGE_METHOD
,
storageResult
,
data
)
withContext
(
Dispatchers
.
Main
)
{
storageResult
.
reset
()
proxy
.
success
(
STORAGE_METHOD
,
storageResult
,
data
)
storageResult
.
reset
()
}
}
}
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
proxy
.
failed
(
STORAGE_METHOD
,
storageResult
,
e
.
message
?:
""
)
withContext
(
Dispatchers
.
Main
)
{
storageResult
.
reset
()
proxy
.
failed
(
STORAGE_METHOD
,
storageResult
,
e
.
message
?:
""
)
storageResult
.
reset
()
}
}
}
}
}
}
}
...
@@ -48,12 +53,16 @@ class StorageContract(fragment: Fragment, proxy: WebViewProxy) : IContract(fragm
...
@@ -48,12 +53,16 @@ class StorageContract(fragment: Fragment, proxy: WebViewProxy) : IContract(fragm
try
{
try
{
context
.
dataStore
.
data
.
map
{
it
[
stringPreferencesKey
(
key
)]
?:
""
}.
collect
{
storageValue
->
context
.
dataStore
.
data
.
map
{
it
[
stringPreferencesKey
(
key
)]
?:
""
}.
collect
{
storageValue
->
val
data
=
StorageResult
(
key
,
storageValue
)
val
data
=
StorageResult
(
key
,
storageValue
)
proxy
.
success
(
ACQUIRE_METHOD
,
acquireResult
,
data
)
withContext
(
Dispatchers
.
Main
)
{
acquireResult
.
reset
()
proxy
.
success
(
ACQUIRE_METHOD
,
acquireResult
,
data
)
acquireResult
.
reset
()
}
}
}
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
proxy
.
failed
(
ACQUIRE_METHOD
,
acquireResult
,
e
.
message
?:
""
)
withContext
(
Dispatchers
.
Main
)
{
acquireResult
.
reset
()
proxy
.
failed
(
ACQUIRE_METHOD
,
acquireResult
,
e
.
message
?:
""
)
acquireResult
.
reset
()
}
}
}
}
}
}
}
...
@@ -69,12 +78,16 @@ class StorageContract(fragment: Fragment, proxy: WebViewProxy) : IContract(fragm
...
@@ -69,12 +78,16 @@ class StorageContract(fragment: Fragment, proxy: WebViewProxy) : IContract(fragm
}
}
val
storageValue
=
maxrocky
.
remove
(
storageKey
)
val
storageValue
=
maxrocky
.
remove
(
storageKey
)
val
data
=
StorageResult
(
key
,
storageValue
)
val
data
=
StorageResult
(
key
,
storageValue
)
proxy
.
success
(
CLEAR_METHOD
,
clearResult
,
data
)
withContext
(
Dispatchers
.
Main
)
{
clearResult
.
reset
()
proxy
.
success
(
CLEAR_METHOD
,
clearResult
,
data
)
clearResult
.
reset
()
}
}
}
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
proxy
.
failed
(
CLEAR_METHOD
,
clearResult
,
e
.
message
?:
""
)
withContext
(
Dispatchers
.
Main
)
{
clearResult
.
reset
()
proxy
.
failed
(
CLEAR_METHOD
,
clearResult
,
e
.
message
?:
""
)
clearResult
.
reset
()
}
}
}
}
}
}
}
...
...
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