Skip to content

Commit 48e6a87

Browse files
committed
refactor: remove extra loading dialog
1 parent bb43b61 commit 48e6a87

3 files changed

Lines changed: 23 additions & 35 deletions

File tree

app/src/main/java/com/osfans/trime/ui/fragments/ProfileFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.osfans.trime.util.appContext
3232
import com.osfans.trime.util.formatDateTime
3333
import com.osfans.trime.util.withLoadingDialog
3434
import kotlinx.coroutines.Dispatchers
35+
import kotlinx.coroutines.launch
3536
import kotlinx.coroutines.withContext
3637
import java.util.Calendar
3738
import java.util.concurrent.TimeUnit
@@ -70,7 +71,7 @@ class ProfileFragment :
7071
registerDocumentTreeLauncher()
7172
}
7273
get<Preference>("profile_sync_user_data")?.setOnPreferenceClickListener {
73-
lifecycleScope.withLoadingDialog(context, 200L, R.string.sync_progress) {
74+
lifecycleScope.launch {
7475
withContext(Dispatchers.IO) {
7576
Rime.syncRimeUserData()
7677
RimeWrapper.deploy()

app/src/main/java/com/osfans/trime/ui/main/Pickers.kt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import com.osfans.trime.ime.core.Trime
1818
import com.osfans.trime.ime.symbol.TabManager
1919
import com.osfans.trime.ime.util.UiUtil
2020
import com.osfans.trime.ui.components.CoroutineChoiceDialog
21-
import com.osfans.trime.util.ProgressBarDialogIndeterminate
2221
import kotlinx.coroutines.Dispatchers
23-
import kotlinx.coroutines.cancelAndJoin
24-
import kotlinx.coroutines.delay
2522
import kotlinx.coroutines.launch
2623
import kotlinx.coroutines.withContext
2724

@@ -101,18 +98,8 @@ fun Context.schemaPicker(
10198
.filterIndexed { i, _ -> checked[i] }
10299
.toTypedArray(),
103100
)
104-
val loading = ProgressBarDialogIndeterminate(titleId = R.string.deploy_progress).create()
105-
val job =
106-
launch {
107-
delay(200L)
108-
loading.show()
109-
}
110101
withContext(Dispatchers.Default) {
111102
RimeWrapper.deploy()
112-
job.cancelAndJoin()
113-
if (loading.isShowing) {
114-
loading.dismiss()
115-
}
116103
}
117104
}
118105
}

app/src/main/java/com/osfans/trime/ui/main/PrefMainActivity.kt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import com.osfans.trime.ui.setup.SetupActivity
3333
import com.osfans.trime.util.ProgressBarDialogIndeterminate
3434
import com.osfans.trime.util.applyTranslucentSystemBars
3535
import com.osfans.trime.util.briefResultLogDialog
36-
import com.osfans.trime.util.withLoadingDialog
3736
import kotlinx.coroutines.Dispatchers
3837
import kotlinx.coroutines.launch
3938
import kotlinx.coroutines.withContext
@@ -143,26 +142,7 @@ class PrefMainActivity : AppCompatActivity() {
143142
override fun onOptionsItemSelected(item: MenuItem): Boolean {
144143
return when (item.itemId) {
145144
R.id.preference__menu_deploy -> {
146-
lifecycleScope.withLoadingDialog(
147-
context = this,
148-
titleId = R.string.deploy_progress,
149-
) {
150-
withContext(Dispatchers.IO) {
151-
Runtime.getRuntime().exec(arrayOf("logcat", "-c"))
152-
}
153-
val deployResult =
154-
withContext(Dispatchers.Default) {
155-
// All functions that implement the DirectoryChangeListener.Listener
156-
// interface are called here.
157-
// To refresh directory settings.
158-
return@withContext RimeWrapper.deploy()
159-
}
160-
if (deployResult) {
161-
briefResultLogDialog("rime.trime", "W", 1)
162-
} else {
163-
ToastUtils.showLong("Rime is already deploying/starting")
164-
}
165-
}
145+
deploy()
166146
true
167147
}
168148
R.id.preference__menu_about -> {
@@ -173,6 +153,26 @@ class PrefMainActivity : AppCompatActivity() {
173153
}
174154
}
175155

156+
private fun deploy() {
157+
lifecycleScope.launch {
158+
withContext(Dispatchers.IO) {
159+
Runtime.getRuntime().exec(arrayOf("logcat", "-c"))
160+
}
161+
val deployResult =
162+
withContext(Dispatchers.Default) {
163+
// All functions that implement the DirectoryChangeListener.Listener
164+
// interface are called here.
165+
// To refresh directory settings.
166+
return@withContext RimeWrapper.deploy()
167+
}
168+
if (deployResult) {
169+
briefResultLogDialog("rime.trime", "W", 1)
170+
} else {
171+
ToastUtils.showLong("Rime is already deploying/starting")
172+
}
173+
}
174+
}
175+
176176
override fun onResume() {
177177
super.onResume()
178178
requestExternalStoragePermission()

0 commit comments

Comments
 (0)