mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Show sync progress in SettingsController
This commit is contained in:
@@ -84,6 +84,7 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
// Show the syncing UI
|
||||
disposables += syncRepository.syncProgress
|
||||
.sample(16, TimeUnit.MILLISECONDS)
|
||||
.distinctUntilChanged()
|
||||
.subscribe { syncing -> newState { copy(syncing = syncing) } }
|
||||
|
||||
|
||||
@@ -18,15 +18,13 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.settings
|
||||
|
||||
import android.app.ProgressDialog
|
||||
import android.animation.ObjectAnimator
|
||||
import android.app.TimePickerDialog
|
||||
import android.content.Context
|
||||
import android.text.format.DateFormat
|
||||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import com.bluelinelabs.conductor.RouterTransaction
|
||||
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
|
||||
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler
|
||||
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.jakewharton.rxbinding2.view.longClicks
|
||||
@@ -44,6 +42,7 @@ import com.moez.QKSMS.feature.settings.about.AboutController
|
||||
import com.moez.QKSMS.feature.settings.swipe.SwipeActionsController
|
||||
import com.moez.QKSMS.feature.themepicker.ThemePickerController
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.repository.SyncRepository
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import io.reactivex.Observable
|
||||
@@ -70,14 +69,7 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
||||
private val startTimeSelectedSubject: Subject<Pair<Int, Int>> = PublishSubject.create()
|
||||
private val endTimeSelectedSubject: Subject<Pair<Int, Int>> = PublishSubject.create()
|
||||
|
||||
// TODO remove this
|
||||
private val progressDialog by lazy {
|
||||
ProgressDialog(activity).apply {
|
||||
isIndeterminate = true
|
||||
setCancelable(false)
|
||||
setCanceledOnTouchOutside(false)
|
||||
}
|
||||
}
|
||||
private val progressAnimator by lazy { ObjectAnimator.ofInt(syncingProgress, "progress", 0, 0) }
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
@@ -130,9 +122,6 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
||||
override fun mmsSizeSelected(): Observable<Int> = mmsSizeDialog.adapter.menuItemClicks
|
||||
|
||||
override fun render(state: SettingsState) {
|
||||
if (progressDialog.isShowing && !state.syncing) progressDialog.dismiss()
|
||||
else if (!progressDialog.isShowing && state.syncing) progressDialog.show()
|
||||
|
||||
themePreview.setBackgroundTint(state.theme)
|
||||
night.summary = state.nightModeSummary
|
||||
nightModeDialog.adapter.selectedItem = state.nightModeId
|
||||
@@ -160,6 +149,17 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
||||
|
||||
mmsSize.summary = state.maxMmsSizeSummary
|
||||
mmsSizeDialog.adapter.selectedItem = state.maxMmsSizeId
|
||||
|
||||
when (state.syncProgress) {
|
||||
is SyncRepository.SyncProgress.Idle -> syncingProgress.isVisible = false
|
||||
|
||||
is SyncRepository.SyncProgress.Running -> {
|
||||
syncingProgress.isVisible = true
|
||||
syncingProgress.max = state.syncProgress.max
|
||||
progressAnimator.apply { setIntValues(syncingProgress.progress, state.syncProgress.progress) }.start()
|
||||
syncingProgress.isIndeterminate = state.syncProgress.indeterminate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun showQksmsPlusSnackbar() {
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.moez.QKSMS.common.util.BillingManager
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.DateFormatter
|
||||
import com.moez.QKSMS.interactor.SyncMessages
|
||||
import com.moez.QKSMS.repository.SyncRepository
|
||||
import com.moez.QKSMS.util.NightModeManager
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
@@ -34,6 +35,7 @@ import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class SettingsPresenter @Inject constructor(
|
||||
@@ -44,7 +46,8 @@ class SettingsPresenter @Inject constructor(
|
||||
private val navigator: Navigator,
|
||||
private val nightModeManager: NightModeManager,
|
||||
private val prefs: Preferences,
|
||||
private val syncMessages: SyncMessages
|
||||
private val syncMessages: SyncMessages,
|
||||
private val syncRepo: SyncRepository
|
||||
) : QkPresenter<SettingsView, SettingsState>(SettingsState(theme = colors.theme().theme)) {
|
||||
|
||||
init {
|
||||
@@ -107,6 +110,11 @@ class SettingsPresenter @Inject constructor(
|
||||
newState { copy(maxMmsSizeSummary = mmsSizeLabels[index], maxMmsSizeId = maxMmsSize) }
|
||||
}
|
||||
|
||||
disposables += syncRepo.syncProgress
|
||||
.sample(16, TimeUnit.MILLISECONDS)
|
||||
.distinctUntilChanged()
|
||||
.subscribe { syncProgress -> newState { copy(syncProgress = syncProgress) } }
|
||||
|
||||
disposables += syncMessages
|
||||
}
|
||||
|
||||
@@ -155,12 +163,7 @@ class SettingsPresenter @Inject constructor(
|
||||
|
||||
R.id.mmsSize -> view.showMmsSizePicker()
|
||||
|
||||
R.id.sync -> {
|
||||
newState { copy(syncing = true) }
|
||||
syncMessages.execute(Unit) {
|
||||
newState { copy(syncing = false) }
|
||||
}
|
||||
}
|
||||
R.id.sync -> syncMessages.execute(Unit)
|
||||
|
||||
R.id.about -> view.showAbout()
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.settings
|
||||
|
||||
import com.moez.QKSMS.repository.SyncRepository
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
|
||||
data class SettingsState(
|
||||
val syncing: Boolean = false,
|
||||
val theme: Int = 0,
|
||||
val nightModeSummary: String = "",
|
||||
val nightModeId: Int = Preferences.NIGHT_MODE_OFF,
|
||||
@@ -40,5 +40,6 @@ data class SettingsState(
|
||||
val stripUnicodeEnabled: Boolean = false,
|
||||
val mobileOnly: Boolean = false,
|
||||
val maxMmsSizeSummary: String = "100KB",
|
||||
val maxMmsSizeId: Int = 100
|
||||
val maxMmsSizeId: Int = 100,
|
||||
val syncProgress: SyncRepository.SyncProgress = SyncRepository.SyncProgress.Idle()
|
||||
)
|
||||
@@ -186,6 +186,17 @@
|
||||
app:summary="@string/settings_sync_summary"
|
||||
app:title="@string/settings_sync_title" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/syncingProgress"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="72dp"
|
||||
android:indeterminate="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/about"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user