Low priority and favorite are exclusive (iso Element Web)
This commit is contained in:
parent
5a6683574c
commit
8d73e8c905
@ -61,12 +61,20 @@ abstract class BottomSheetRoomPreviewItem : VectorEpoxyModel<BottomSheetRoomPrev
|
|||||||
holder.roomLowPriority.setOnClickListener {
|
holder.roomLowPriority.setOnClickListener {
|
||||||
// Immediate echo
|
// Immediate echo
|
||||||
setLowPriorityState(holder, !izLowPriority)
|
setLowPriorityState(holder, !izLowPriority)
|
||||||
|
if (!izLowPriority) {
|
||||||
|
// If we put the room in low priority, it will also remove the favorite tag
|
||||||
|
setFavoriteState(holder, false)
|
||||||
|
}
|
||||||
// And do the action
|
// And do the action
|
||||||
lowPriorityClickListener?.invoke()
|
lowPriorityClickListener?.invoke()
|
||||||
}
|
}
|
||||||
holder.roomFavorite.setOnClickListener {
|
holder.roomFavorite.setOnClickListener {
|
||||||
// Immediate echo
|
// Immediate echo
|
||||||
setFavoriteState(holder, !izFavorite)
|
setFavoriteState(holder, !izFavorite)
|
||||||
|
if (!izFavorite) {
|
||||||
|
// If we put the room in favorite, it will also remove the low priority tag
|
||||||
|
setLowPriorityState(holder, false)
|
||||||
|
}
|
||||||
// And do the action
|
// And do the action
|
||||||
favoriteClickListener?.invoke()
|
favoriteClickListener?.invoke()
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package im.vector.app.features.home.room.list
|
package im.vector.app.features.home.room.list
|
||||||
|
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MvRxViewModelFactory
|
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
@ -23,6 +24,8 @@ import im.vector.app.core.extensions.exhaustive
|
|||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
import im.vector.app.core.utils.DataSource
|
import im.vector.app.core.utils.DataSource
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.MatrixCallback
|
import org.matrix.android.sdk.api.MatrixCallback
|
||||||
import org.matrix.android.sdk.api.NoOpMatrixCallback
|
import org.matrix.android.sdk.api.NoOpMatrixCallback
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
@ -30,6 +33,7 @@ import org.matrix.android.sdk.api.session.Session
|
|||||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
import org.matrix.android.sdk.api.session.room.model.tag.RoomTag
|
import org.matrix.android.sdk.api.session.room.model.tag.RoomTag
|
||||||
|
import org.matrix.android.sdk.internal.util.awaitCallback
|
||||||
import org.matrix.android.sdk.rx.rx
|
import org.matrix.android.sdk.rx.rx
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -173,18 +177,38 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleToggleTag(action: RoomListAction.ToggleTag) {
|
private fun handleToggleTag(action: RoomListAction.ToggleTag) {
|
||||||
session.getRoom(action.roomId)?.let {
|
session.getRoom(action.roomId)?.let { room ->
|
||||||
val callback = object : MatrixCallback<Unit> {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
override fun onFailure(failure: Throwable) {
|
try {
|
||||||
|
if (room.roomSummary()?.hasTag(action.tag) == false) {
|
||||||
|
// Favorite and low priority tags are exclusive, so maybe delete the other tag first
|
||||||
|
action.tag.otherTag()
|
||||||
|
?.takeIf { room.roomSummary()?.hasTag(it).orFalse() }
|
||||||
|
?.let { tagToRemove ->
|
||||||
|
awaitCallback<Unit> { room.deleteTag(tagToRemove, it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the tag. We do not handle the order for the moment
|
||||||
|
awaitCallback<Unit> {
|
||||||
|
room.addTag(action.tag, 0.5, it)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
awaitCallback<Unit> {
|
||||||
|
room.deleteTag(action.tag, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (failure: Throwable) {
|
||||||
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
_viewEvents.post(RoomListViewEvents.Failure(failure))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (it.roomSummary()?.hasTag(action.tag) == false) {
|
}
|
||||||
// Set the tag. We do not handle the order for the moment
|
}
|
||||||
it.addTag(action.tag, 0.5, callback)
|
|
||||||
} else {
|
private fun String.otherTag(): String? {
|
||||||
it.deleteTag(action.tag, callback)
|
return when (this) {
|
||||||
}
|
RoomTag.ROOM_TAG_FAVOURITE -> RoomTag.ROOM_TAG_LOW_PRIORITY
|
||||||
|
RoomTag.ROOM_TAG_LOW_PRIORITY -> RoomTag.ROOM_TAG_FAVOURITE
|
||||||
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user