forked from upstream-mirrors/quik
Merge pull request #640 from Inhishonor/emoji-sync
Add a dedicated emoji reaction sync progress bar
This commit is contained in:
@@ -247,7 +247,7 @@ class EmojiReactionRepositoryImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun deleteAndReparseAllEmojiReactions(realm: Realm) {
|
override fun deleteAndReparseAllEmojiReactions(realm: Realm, onProgress: (SyncRepository.SyncProgress) -> Unit) {
|
||||||
val startTime = System.currentTimeMillis()
|
val startTime = System.currentTimeMillis()
|
||||||
|
|
||||||
realm.delete(EmojiReaction::class.java)
|
realm.delete(EmojiReaction::class.java)
|
||||||
@@ -271,6 +271,9 @@ class EmojiReactionRepositoryImpl @Inject constructor(
|
|||||||
.sort("date", Sort.ASCENDING) // parse oldest to newest to handle reactions & removals properly
|
.sort("date", Sort.ASCENDING) // parse oldest to newest to handle reactions & removals properly
|
||||||
.findAll()
|
.findAll()
|
||||||
|
|
||||||
|
val max = allMessages?.count() ?: 0
|
||||||
|
var progress = 0
|
||||||
|
|
||||||
allMessages.forEach { message ->
|
allMessages.forEach { message ->
|
||||||
val text = message.getText(false)
|
val text = message.getText(false)
|
||||||
val parsedReaction = parseEmojiReaction(text)
|
val parsedReaction = parseEmojiReaction(text)
|
||||||
@@ -286,6 +289,18 @@ class EmojiReactionRepositoryImpl @Inject constructor(
|
|||||||
targetMessage,
|
targetMessage,
|
||||||
realm,
|
realm,
|
||||||
)
|
)
|
||||||
|
progress++
|
||||||
|
// Update the progress every 25 messages, and then at completion
|
||||||
|
// that way we don't spam the UI
|
||||||
|
if (progress % 25 == 0 || progress == max) {
|
||||||
|
onProgress(
|
||||||
|
SyncRepository.SyncProgress.ParsingEmojis(
|
||||||
|
max = max,
|
||||||
|
progress = progress,
|
||||||
|
indeterminate = false
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -229,10 +229,14 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
syncProgress.onNext(SyncRepository.SyncProgress.Running(0, 0, true))
|
syncProgress.onNext(SyncRepository.SyncProgress.ParsingEmojis(0, 0, true))
|
||||||
|
|
||||||
// Now that we have all the messages, we can scan for emoji reactions
|
// Now that we have all the messages, we can scan for emoji reactions
|
||||||
reactions.deleteAndReparseAllEmojiReactions(realm)
|
reactions.deleteAndReparseAllEmojiReactions(
|
||||||
|
realm,
|
||||||
|
onProgress = { progress ->
|
||||||
|
syncProgress.onNext(progress)
|
||||||
|
})
|
||||||
|
|
||||||
realm.insert(SyncLog())
|
realm.insert(SyncLog())
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@@ -35,5 +35,8 @@ interface EmojiReactionRepository {
|
|||||||
realm: Realm,
|
realm: Realm,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun deleteAndReparseAllEmojiReactions(realm: Realm)
|
fun deleteAndReparseAllEmojiReactions(
|
||||||
|
realm: Realm,
|
||||||
|
onProgress: (SyncRepository.SyncProgress) -> Unit
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ interface SyncRepository {
|
|||||||
sealed class SyncProgress {
|
sealed class SyncProgress {
|
||||||
object Idle : SyncProgress()
|
object Idle : SyncProgress()
|
||||||
data class Running(val max: Int, val progress: Int, val indeterminate: Boolean) : SyncProgress()
|
data class Running(val max: Int, val progress: Int, val indeterminate: Boolean) : SyncProgress()
|
||||||
|
data class ParsingEmojis(val max: Int, val progress: Int, val indeterminate: Boolean) : SyncProgress()
|
||||||
}
|
}
|
||||||
|
|
||||||
val syncProgress: Observable<SyncProgress>
|
val syncProgress: Observable<SyncProgress>
|
||||||
|
|||||||
@@ -337,6 +337,17 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
syncingProgress.isIndeterminate = state.syncing.indeterminate
|
syncingProgress.isIndeterminate = state.syncing.indeterminate
|
||||||
snackbar.isVisible = false
|
snackbar.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is SyncRepository.SyncProgress.ParsingEmojis -> {
|
||||||
|
syncing.isVisible = true
|
||||||
|
syncingLabel.setText(getString(R.string.main_sync_emojis))
|
||||||
|
syncingProgress.max = state.syncing.max
|
||||||
|
progressAnimator.apply {
|
||||||
|
setIntValues(syncingProgress.progress, state.syncing.progress)
|
||||||
|
}.start()
|
||||||
|
syncingProgress.isIndeterminate = state.syncing.indeterminate
|
||||||
|
snackbar.isVisible = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
when {
|
when {
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ class MainViewModel @Inject constructor(
|
|||||||
Realm.getDefaultInstance().executeTransactionAsync { realm ->
|
Realm.getDefaultInstance().executeTransactionAsync { realm ->
|
||||||
val emojiSyncNeeded = realm.where(EmojiSyncNeeded::class.java).findFirst()
|
val emojiSyncNeeded = realm.where(EmojiSyncNeeded::class.java).findFirst()
|
||||||
if (emojiSyncNeeded != null) {
|
if (emojiSyncNeeded != null) {
|
||||||
reactions.deleteAndReparseAllEmojiReactions(realm)
|
reactions.deleteAndReparseAllEmojiReactions(realm) { /* No progress ui needed here */ }
|
||||||
emojiSyncNeeded.deleteFromRealm()
|
emojiSyncNeeded.deleteFromRealm()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,6 +214,13 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
|||||||
progressAnimator.apply { setIntValues(syncingProgress.progress, state.syncProgress.progress) }.start()
|
progressAnimator.apply { setIntValues(syncingProgress.progress, state.syncProgress.progress) }.start()
|
||||||
syncingProgress.isIndeterminate = state.syncProgress.indeterminate
|
syncingProgress.isIndeterminate = state.syncProgress.indeterminate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is SyncRepository.SyncProgress.ParsingEmojis -> {
|
||||||
|
syncingProgress.isVisible = true
|
||||||
|
syncingProgress.max = state.syncProgress.max
|
||||||
|
progressAnimator.apply { setIntValues(syncingProgress.progress, state.syncProgress.progress) }.start()
|
||||||
|
syncingProgress.isIndeterminate = state.syncProgress.indeterminate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@
|
|||||||
<string name="main_menu_edit_message">Edit message</string>
|
<string name="main_menu_edit_message">Edit message</string>
|
||||||
<string name="main_menu_rename_conversation">Rename conversation</string>
|
<string name="main_menu_rename_conversation">Rename conversation</string>
|
||||||
<string name="main_syncing">Syncing messages…</string>
|
<string name="main_syncing">Syncing messages…</string>
|
||||||
|
<string name="main_sync_emojis">Parsing emoji reactions…</string>
|
||||||
<string name="main_sender_you">You: %s</string>
|
<string name="main_sender_you">You: %s</string>
|
||||||
<string name="main_sender_draft">Draft: %s</string>
|
<string name="main_sender_draft">Draft: %s</string>
|
||||||
<string name="main_message_results_title">Results in messages</string>
|
<string name="main_message_results_title">Results in messages</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user