Commit 6d73cc3c by huangzhicong

修复起始页由于storage存储线程导致的崩溃问题

parent 6b4b220c
...@@ -17,7 +17,7 @@ import kotlinx.coroutines.Dispatchers ...@@ -17,7 +17,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 import kotlinx.coroutines.runBlocking
class StartFragment : Fragment() { class StartFragment : Fragment() {
companion object { companion object {
...@@ -50,22 +50,18 @@ class StartFragment : Fragment() { ...@@ -50,22 +50,18 @@ class StartFragment : Fragment() {
if (url.isEmpty()) { if (url.isEmpty()) {
findNavController().navigate( findNavController().navigate(
R.id.action_startFragment_to_mainFragment, R.id.action_startFragment_to_mainFragment,
MainFragment.createStartBundle(url) MainFragment.createStartBundle()
) )
return@setOnClickListener return@setOnClickListener
} }
lifecycleScope.launch(Dispatchers.IO) { val storageKey = stringPreferencesKey(STORAGE_URL)
val storageKey = stringPreferencesKey(STORAGE_URL) runBlocking {
context?.dataStore?.edit { context?.dataStore?.edit { it[storageKey] = url }
it[storageKey] = url
}
withContext(Dispatchers.Main) {
findNavController().navigate(
R.id.action_startFragment_to_mainFragment,
MainFragment.createStartBundle(url)
)
}
} }
findNavController().navigate(
R.id.action_startFragment_to_mainFragment,
MainFragment.createStartBundle(url)
)
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment