Skip to content

Commit

Permalink
refactor: remove extra loading dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
goofyz committed Dec 30, 2023
1 parent bb43b61 commit 48e6a87
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.osfans.trime.util.appContext
import com.osfans.trime.util.formatDateTime
import com.osfans.trime.util.withLoadingDialog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.Calendar
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -70,7 +71,7 @@ class ProfileFragment :
registerDocumentTreeLauncher()
}
get<Preference>("profile_sync_user_data")?.setOnPreferenceClickListener {
lifecycleScope.withLoadingDialog(context, 200L, R.string.sync_progress) {
lifecycleScope.launch {
withContext(Dispatchers.IO) {
Rime.syncRimeUserData()
RimeWrapper.deploy()
Expand Down
13 changes: 0 additions & 13 deletions app/src/main/java/com/osfans/trime/ui/main/Pickers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.symbol.TabManager
import com.osfans.trime.ime.util.UiUtil
import com.osfans.trime.ui.components.CoroutineChoiceDialog
import com.osfans.trime.util.ProgressBarDialogIndeterminate
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

Expand Down Expand Up @@ -101,18 +98,8 @@ fun Context.schemaPicker(
.filterIndexed { i, _ -> checked[i] }
.toTypedArray(),
)
val loading = ProgressBarDialogIndeterminate(titleId = R.string.deploy_progress).create()
val job =
launch {
delay(200L)
loading.show()
}
withContext(Dispatchers.Default) {
RimeWrapper.deploy()
job.cancelAndJoin()
if (loading.isShowing) {
loading.dismiss()
}
}
}
}
Expand Down
42 changes: 21 additions & 21 deletions app/src/main/java/com/osfans/trime/ui/main/PrefMainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import com.osfans.trime.ui.setup.SetupActivity
import com.osfans.trime.util.ProgressBarDialogIndeterminate
import com.osfans.trime.util.applyTranslucentSystemBars
import com.osfans.trime.util.briefResultLogDialog
import com.osfans.trime.util.withLoadingDialog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -143,26 +142,7 @@ class PrefMainActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.preference__menu_deploy -> {
lifecycleScope.withLoadingDialog(
context = this,
titleId = R.string.deploy_progress,
) {
withContext(Dispatchers.IO) {
Runtime.getRuntime().exec(arrayOf("logcat", "-c"))
}
val deployResult =
withContext(Dispatchers.Default) {
// All functions that implement the DirectoryChangeListener.Listener
// interface are called here.
// To refresh directory settings.
return@withContext RimeWrapper.deploy()
}
if (deployResult) {
briefResultLogDialog("rime.trime", "W", 1)
} else {
ToastUtils.showLong("Rime is already deploying/starting")
}
}
deploy()
true
}
R.id.preference__menu_about -> {
Expand All @@ -173,6 +153,26 @@ class PrefMainActivity : AppCompatActivity() {
}
}

private fun deploy() {
lifecycleScope.launch {
withContext(Dispatchers.IO) {
Runtime.getRuntime().exec(arrayOf("logcat", "-c"))
}
val deployResult =
withContext(Dispatchers.Default) {
// All functions that implement the DirectoryChangeListener.Listener
// interface are called here.
// To refresh directory settings.
return@withContext RimeWrapper.deploy()
}
if (deployResult) {
briefResultLogDialog("rime.trime", "W", 1)
} else {
ToastUtils.showLong("Rime is already deploying/starting")
}
}
}

override fun onResume() {
super.onResume()
requestExternalStoragePermission()
Expand Down

0 comments on commit 48e6a87

Please sign in to comment.