Show progress when conversation is loading

Potentially related to #1079
This commit is contained in:
Moez Bhatti
2018-06-06 13:47:41 -04:00
parent 1aeddec7bd
commit d6fa04f56d
5 changed files with 27 additions and 2 deletions
@@ -41,6 +41,7 @@ fun ImageView.setTint(color: Int) {
}
fun ProgressBar.setTint(color: Int) {
indeterminateTintList = ColorStateList.valueOf(color)
progressTintList = ColorStateList.valueOf(color)
}
@@ -126,6 +126,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
message.supportsInputContent = true
theme
.doOnNext { loading.setTint(it.theme) }
.doOnNext { send.setBackgroundTint(it.theme) }
.doOnNext { send.setTint(it.textPrimary) }
.doOnNext { messageAdapter.theme = it }
@@ -165,7 +166,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
toolbarTitle.setVisible(!state.editingMode)
chips.setVisible(state.editingMode)
contacts.setVisible(state.contactsVisible)
composeBar.setVisible(!state.contactsVisible)
composeBar.setVisible(!state.contactsVisible && !state.loading)
// Don't set the adapters unless needed
if (state.editingMode && chips.adapter == null) chips.adapter = chipsAdapter
@@ -187,6 +188,8 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
chipsAdapter.data = state.selectedContacts
contactsAdapter.data = state.contacts
loading.setVisible(state.loading)
sendAsGroup.setVisible(state.editingMode && state.selectedContacts.size >= 2)
sendAsGroupSwitch.isChecked = state.sendAsGroup
@@ -34,6 +34,7 @@ data class ComposeState(
val selectedContacts: List<Contact> = ArrayList(),
val sendAsGroup: Boolean = true,
val conversationtitle: String = "",
val loading: Boolean = false,
val query: String = "",
val searchSelectionId: Long = -1,
val searchSelectionPosition: Int = 0,
@@ -149,7 +149,14 @@ class ComposeViewModel @Inject constructor(
.skipUntil(state.filter { state -> state.editingMode })
.takeUntil(state.filter { state -> !state.editingMode })
.map { contacts -> contacts.map { it.numbers.firstOrNull()?.address ?: "" } }
.mapNotNull { addresses -> messageRepo.getOrCreateConversation(addresses) }
.observeOn(Schedulers.computation())
.doOnNext { newState { copy(loading = true) } }
.mapNotNull { addresses ->
val conversation = messageRepo.getOrCreateConversation(addresses)
newState { copy(loading = false) }
conversation
}
.observeOn(AndroidSchedulers.mainThread())
.mergeWith(initialConversation)
.filter { conversation -> conversation.isLoaded }
.doOnNext { conversation ->
@@ -54,6 +54,19 @@
app:textColor="tertiary"
app:textSize="secondary" />
<ProgressBar
android:id="@+id/loading"
style="?android:attr/progressBarStyleLarge"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginTop="16dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar"
tools:progress="45"
tools:progressTint="@color/tools_theme" />
<android.support.v7.widget.RecyclerView
android:id="@+id/contacts"
android:layout_width="0dp"