Commit 6d73cc3c by huangzhicong

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

parent 6b4b220c
......@@ -17,7 +17,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.runBlocking
class StartFragment : Fragment() {
companion object {
......@@ -50,22 +50,18 @@ class StartFragment : Fragment() {
if (url.isEmpty()) {
findNavController().navigate(
R.id.action_startFragment_to_mainFragment,
MainFragment.createStartBundle(url)
MainFragment.createStartBundle()
)
return@setOnClickListener
}
lifecycleScope.launch(Dispatchers.IO) {
val storageKey = stringPreferencesKey(STORAGE_URL)
context?.dataStore?.edit {
it[storageKey] = url
}
withContext(Dispatchers.Main) {
findNavController().navigate(
R.id.action_startFragment_to_mainFragment,
MainFragment.createStartBundle(url)
)
}
val storageKey = stringPreferencesKey(STORAGE_URL)
runBlocking {
context?.dataStore?.edit { it[storageKey] = 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