Toggle Low priority tag (#1490)

This commit is contained in:
Benoit Marty 2020-10-23 14:58:31 +02:00
parent 83925322cb
commit 5a6683574c
12 changed files with 76 additions and 12 deletions

View file

@ -7,6 +7,7 @@ Features ✨:
Improvements 🙌:
- Rework sending Event management (#154)
- New room creation screen: set topic and avatar in the room creation form (#2078)
- Toggle Low priority tag (#1490)
Bugfix 🐛:
- Messages encrypted with no way to decrypt after SDK update from 0.18 to 1.0.0 (#2252)

View file

@ -63,8 +63,13 @@ data class RoomSummary constructor(
val hasNewMessages: Boolean
get() = notificationCount != 0
val isLowPriority: Boolean
get() = hasTag(RoomTag.ROOM_TAG_LOW_PRIORITY)
val isFavorite: Boolean
get() = tags.any { it.name == RoomTag.ROOM_TAG_FAVOURITE }
get() = hasTag(RoomTag.ROOM_TAG_FAVOURITE)
fun hasTag(tag: String) = tags.any { it.name == tag }
val canStartCall: Boolean
get() = joinedMembersCount == 2

View file

@ -44,8 +44,10 @@ abstract class BottomSheetRoomPreviewItem : VectorEpoxyModel<BottomSheetRoomPrev
@EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer
@EpoxyAttribute lateinit var matrixItem: MatrixItem
@EpoxyAttribute lateinit var stringProvider: StringProvider
@EpoxyAttribute var izLowPriority: Boolean = false
@EpoxyAttribute var izFavorite: Boolean = false
@EpoxyAttribute var settingsClickListener: ClickListener? = null
@EpoxyAttribute var lowPriorityClickListener: ClickListener? = null
@EpoxyAttribute var favoriteClickListener: ClickListener? = null
override fun bind(holder: Holder) {
@ -53,8 +55,15 @@ abstract class BottomSheetRoomPreviewItem : VectorEpoxyModel<BottomSheetRoomPrev
avatarRenderer.render(matrixItem, holder.avatar)
holder.avatar.onClick(settingsClickListener)
holder.roomName.setTextOrHide(matrixItem.displayName)
setLowPriorityState(holder, izLowPriority)
setFavoriteState(holder, izFavorite)
holder.roomLowPriority.setOnClickListener {
// Immediate echo
setLowPriorityState(holder, !izLowPriority)
// And do the action
lowPriorityClickListener?.invoke()
}
holder.roomFavorite.setOnClickListener {
// Immediate echo
setFavoriteState(holder, !izFavorite)
@ -64,6 +73,18 @@ abstract class BottomSheetRoomPreviewItem : VectorEpoxyModel<BottomSheetRoomPrev
holder.roomSettings.onClick(settingsClickListener)
}
private fun setLowPriorityState(holder: Holder, isLowPriority: Boolean) {
val tintColor: Int
if (isLowPriority) {
holder.roomLowPriority.contentDescription = stringProvider.getString(R.string.room_list_quick_actions_low_priority_remove)
tintColor = ContextCompat.getColor(holder.view.context, R.color.riotx_accent)
} else {
holder.roomLowPriority.contentDescription = stringProvider.getString(R.string.room_list_quick_actions_low_priority_add)
tintColor = ThemeUtils.getColor(holder.view.context, R.attr.riotx_text_secondary)
}
ImageViewCompat.setImageTintList(holder.roomLowPriority, ColorStateList.valueOf(tintColor))
}
private fun setFavoriteState(holder: Holder, isFavorite: Boolean) {
val tintColor: Int
if (isFavorite) {
@ -81,6 +102,7 @@ abstract class BottomSheetRoomPreviewItem : VectorEpoxyModel<BottomSheetRoomPrev
class Holder : VectorEpoxyHolder() {
val avatar by bind<ImageView>(R.id.bottomSheetRoomPreviewAvatar)
val roomName by bind<TextView>(R.id.bottomSheetRoomPreviewName)
val roomLowPriority by bind<ImageView>(R.id.bottomSheetRoomPreviewLowPriority)
val roomFavorite by bind<ImageView>(R.id.bottomSheetRoomPreviewFavorite)
val roomSettings by bind<View>(R.id.bottomSheetRoomPreviewSettings)
}

View file

@ -27,7 +27,7 @@ sealed class RoomListAction : VectorViewModelAction {
data class RejectInvitation(val roomSummary: RoomSummary) : RoomListAction()
data class FilterWith(val filter: String) : RoomListAction()
data class ChangeRoomNotificationState(val roomId: String, val notificationState: RoomNotificationState) : RoomListAction()
data class ToggleFavorite(val roomId: String) : RoomListAction()
data class ToggleTag(val roomId: String, val tag: String) : RoomListAction()
data class LeaveRoom(val roomId: String) : RoomListAction()
object MarkAllRoomsRead : RoomListAction()
}

View file

@ -52,6 +52,7 @@ import kotlinx.android.synthetic.main.fragment_room_list.*
import org.matrix.android.sdk.api.failure.Failure
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.tag.RoomTag
import org.matrix.android.sdk.api.session.room.notification.RoomNotificationState
import javax.inject.Inject
@ -233,7 +234,10 @@ class RoomListFragment @Inject constructor(
navigator.openRoomProfile(requireActivity(), quickAction.roomId)
}
is RoomListQuickActionsSharedAction.Favorite -> {
roomListViewModel.handle(RoomListAction.ToggleFavorite(quickAction.roomId))
roomListViewModel.handle(RoomListAction.ToggleTag(quickAction.roomId, RoomTag.ROOM_TAG_FAVOURITE))
}
is RoomListQuickActionsSharedAction.LowPriority -> {
roomListViewModel.handle(RoomListAction.ToggleTag(quickAction.roomId, RoomTag.ROOM_TAG_LOW_PRIORITY))
}
is RoomListQuickActionsSharedAction.Leave -> {
AlertDialog.Builder(requireContext())

View file

@ -70,7 +70,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
is RoomListAction.MarkAllRoomsRead -> handleMarkAllRoomsRead()
is RoomListAction.LeaveRoom -> handleLeaveRoom(action)
is RoomListAction.ChangeRoomNotificationState -> handleChangeNotificationMode(action)
is RoomListAction.ToggleFavorite -> handleToggleFavorite(action)
is RoomListAction.ToggleTag -> handleToggleTag(action)
}.exhaustive
}
@ -172,18 +172,18 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
})
}
private fun handleToggleFavorite(action: RoomListAction.ToggleFavorite) {
private fun handleToggleTag(action: RoomListAction.ToggleTag) {
session.getRoom(action.roomId)?.let {
val callback = object : MatrixCallback<Unit> {
override fun onFailure(failure: Throwable) {
_viewEvents.post(RoomListViewEvents.Failure(failure))
}
}
if (it.roomSummary()?.isFavorite == false) {
// Set favorite tag. We do not handle the order for the moment
it.addTag(RoomTag.ROOM_TAG_FAVOURITE, 0.5, callback)
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 {
it.deleteTag(RoomTag.ROOM_TAG_FAVOURITE, callback)
it.deleteTag(action.tag, callback)
}
}
}

View file

@ -89,8 +89,9 @@ class RoomListQuickActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), R
sharedActionViewModel.post(quickAction)
// Do not dismiss for all the actions
when (quickAction) {
is RoomListQuickActionsSharedAction.Favorite -> Unit
else -> dismiss()
is RoomListQuickActionsSharedAction.LowPriority -> Unit
is RoomListQuickActionsSharedAction.Favorite -> Unit
else -> dismiss()
}
}

View file

@ -47,9 +47,11 @@ class RoomListQuickActionsEpoxyController @Inject constructor(
avatarRenderer(avatarRenderer)
matrixItem(roomSummary.toMatrixItem())
stringProvider(stringProvider)
izLowPriority(roomSummary.isLowPriority)
izFavorite(roomSummary.isFavorite)
settingsClickListener { listener?.didSelectMenuAction(RoomListQuickActionsSharedAction.Settings(roomSummary.roomId)) }
favoriteClickListener { listener?.didSelectMenuAction(RoomListQuickActionsSharedAction.Favorite(roomSummary.roomId)) }
lowPriorityClickListener { listener?.didSelectMenuAction(RoomListQuickActionsSharedAction.LowPriority(roomSummary.roomId)) }
}
// Notifications

View file

@ -52,6 +52,10 @@ sealed class RoomListQuickActionsSharedAction(
R.drawable.ic_room_actions_settings
)
data class LowPriority(val roomId: String) : RoomListQuickActionsSharedAction(
R.string.room_list_quick_actions_low_priority_add,
R.drawable.ic_low_priority_24)
data class Favorite(val roomId: String) : RoomListQuickActionsSharedAction(
R.string.room_list_quick_actions_favorite_add,
R.drawable.ic_star_24dp)

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M13.6185,0.6704C12.7246,-0.2235 11.2754,-0.2235 10.3815,0.6704L0.6704,10.3815C-0.2235,11.2754 -0.2235,12.7246 0.6704,13.6185L10.3815,23.3296C11.2754,24.2235 12.7246,24.2235 13.6185,23.3296L23.3296,13.6185C24.2235,12.7246 24.2235,11.2754 23.3296,10.3815L13.6185,0.6704ZM11.9999,5C12.5522,5 12.9999,5.4477 12.9999,6V15.5564L15.7781,12.7782C16.1686,12.3877 16.8018,12.3877 17.1923,12.7782C17.5829,13.1687 17.5829,13.8019 17.1923,14.1924L12.8362,18.5486C12.6574,18.8205 12.3496,19 11.9999,19C11.7189,19 11.465,18.8841 11.2833,18.6974L11.2782,18.6924L6.7782,14.1924C6.3877,13.8019 6.3877,13.1687 6.7782,12.7782C7.1688,12.3877 7.8019,12.3877 8.1925,12.7782L10.9999,15.5857V6C10.9999,5.4477 11.4477,5 11.9999,5Z"
android:fillColor="#000000"
android:fillType="evenOdd"/>
</vector>

View file

@ -38,11 +38,24 @@
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/bottomSheetRoomPreviewAvatar"
app:layout_constraintEnd_toStartOf="@+id/bottomSheetRoomPreviewFavorite"
app:layout_constraintEnd_toStartOf="@+id/bottomSheetRoomPreviewLowPriority"
app:layout_constraintStart_toEndOf="@id/bottomSheetRoomPreviewAvatar"
app:layout_constraintTop_toTopOf="@id/bottomSheetRoomPreviewAvatar"
tools:text="@tools:sample/full_names" />
<ImageView
android:id="@+id/bottomSheetRoomPreviewLowPriority"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="?attr/selectableItemBackground"
android:scaleType="centerInside"
android:src="@drawable/ic_low_priority_24"
app:layout_constraintBottom_toBottomOf="@+id/bottomSheetRoomPreviewAvatar"
app:layout_constraintEnd_toStartOf="@+id/bottomSheetRoomPreviewFavorite"
app:layout_constraintTop_toTopOf="@id/bottomSheetRoomPreviewAvatar"
tools:contentDescription="@string/room_list_quick_actions_low_priority_add"
tools:tint="?riotx_text_secondary" />
<ImageView
android:id="@+id/bottomSheetRoomPreviewFavorite"
android:layout_width="48dp"

View file

@ -1883,6 +1883,8 @@
<string name="room_list_quick_actions_settings">"Settings"</string>
<string name="room_list_quick_actions_favorite_add">"Add to favorites"</string>
<string name="room_list_quick_actions_favorite_remove">"Remove from favorites"</string>
<string name="room_list_quick_actions_low_priority_add">"Add to low priority"</string>
<string name="room_list_quick_actions_low_priority_remove">"Remove from low priority"</string>
<string name="room_list_quick_actions_leave">"Leave the room"</string>
<string name="notice_member_no_changes">"%1$s made no changes"</string>
<string name="notice_member_no_changes_by_you">"You made no changes"</string>