From 08c864bad7b0842ab51eb440cd2f6e6b3fb67807 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 12 Nov 2019 11:39:47 +0100 Subject: [PATCH 1/2] Add help to reveal the long click on a room --- .../vector/riotx/core/epoxy/HelpFooterItem.kt | 37 +++++++++++++++++++ .../core/resources/UserPreferencesProvider.kt | 8 ++++ .../home/room/list/RoomListFragment.kt | 4 +- .../home/room/list/RoomSummaryController.kt | 23 +++++++++++- .../features/settings/VectorPreferences.kt | 21 +++++++++++ vector/src/main/res/drawable/ic_idea.xml | 10 +++++ .../src/main/res/layout/item_help_footer.xml | 23 ++++++++++++ vector/src/main/res/values/strings_riotX.xml | 2 + 8 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 vector/src/main/java/im/vector/riotx/core/epoxy/HelpFooterItem.kt create mode 100644 vector/src/main/res/drawable/ic_idea.xml create mode 100644 vector/src/main/res/layout/item_help_footer.xml diff --git a/vector/src/main/java/im/vector/riotx/core/epoxy/HelpFooterItem.kt b/vector/src/main/java/im/vector/riotx/core/epoxy/HelpFooterItem.kt new file mode 100644 index 0000000000..2784db5fce --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/core/epoxy/HelpFooterItem.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.core.epoxy + +import android.widget.TextView +import com.airbnb.epoxy.EpoxyAttribute +import com.airbnb.epoxy.EpoxyModelClass +import im.vector.riotx.R + +@EpoxyModelClass(layout = R.layout.item_help_footer) +abstract class HelpFooterItem : VectorEpoxyModel() { + + @EpoxyAttribute + var text: String? = null + + override fun bind(holder: Holder) { + holder.textView.text = text + } + + class Holder : VectorEpoxyHolder() { + val textView by bind(R.id.itemHelpText) + } +} diff --git a/vector/src/main/java/im/vector/riotx/core/resources/UserPreferencesProvider.kt b/vector/src/main/java/im/vector/riotx/core/resources/UserPreferencesProvider.kt index bf3e360699..ac379a8f98 100644 --- a/vector/src/main/java/im/vector/riotx/core/resources/UserPreferencesProvider.kt +++ b/vector/src/main/java/im/vector/riotx/core/resources/UserPreferencesProvider.kt @@ -28,4 +28,12 @@ class UserPreferencesProvider @Inject constructor(private val vectorPreferences: fun shouldShowReadReceipts(): Boolean { return vectorPreferences.showReadReceipts() } + + fun shouldShowLongClickOnRoomHelp(): Boolean { + return vectorPreferences.shouldShowLongClickOnRoomHelp() + } + + fun neverShowLongClickOnRoomHelpAgain() { + vectorPreferences.neverShowLongClickOnRoomHelpAgain() + } } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListFragment.kt index 9c78b8688a..df8bca7a2f 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListFragment.kt @@ -38,8 +38,8 @@ import im.vector.riotx.core.error.ErrorFormatter import im.vector.riotx.core.platform.OnBackPressed import im.vector.riotx.core.platform.StateView import im.vector.riotx.core.platform.VectorBaseFragment -import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsSharedAction import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsBottomSheet +import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsSharedAction import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel import im.vector.riotx.features.home.room.list.widget.FabMenuView import im.vector.riotx.features.notifications.NotificationDrawerManager @@ -345,6 +345,8 @@ class RoomListFragment @Inject constructor( } override fun onRoomLongClicked(room: RoomSummary): Boolean { + roomController.onRoomLongClicked() + RoomListQuickActionsBottomSheet .newInstance(room.roomId) .show(requireActivity().supportFragmentManager, "ROOM_LIST_QUICK_ACTIONS") diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryController.kt b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryController.kt index 3401e041b1..5cd684b275 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryController.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryController.kt @@ -21,15 +21,18 @@ import com.airbnb.epoxy.EpoxyController import im.vector.matrix.android.api.session.room.model.Membership import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.riotx.R +import im.vector.riotx.core.epoxy.helpFooterItem import im.vector.riotx.core.epoxy.noResultItem import im.vector.riotx.core.resources.StringProvider +import im.vector.riotx.core.resources.UserPreferencesProvider import im.vector.riotx.features.home.room.filtered.FilteredRoomFooterItem import im.vector.riotx.features.home.room.filtered.filteredRoomFooterItem import javax.inject.Inject class RoomSummaryController @Inject constructor(private val stringProvider: StringProvider, private val roomSummaryItemFactory: RoomSummaryItemFactory, - private val roomListNameFilter: RoomListNameFilter + private val roomListNameFilter: RoomListNameFilter, + private val userPreferencesProvider: UserPreferencesProvider ) : EpoxyController() { var listener: Listener? = null @@ -47,6 +50,11 @@ class RoomSummaryController @Inject constructor(private val stringProvider: Stri requestModelBuild() } + fun onRoomLongClicked() { + userPreferencesProvider.neverShowLongClickOnRoomHelpAgain() + requestModelBuild() + } + override fun buildModels() { val nonNullViewState = viewState ?: return when (nonNullViewState.displayMode) { @@ -55,6 +63,7 @@ class RoomSummaryController @Inject constructor(private val stringProvider: Stri buildFilteredRooms(nonNullViewState) } else -> { + var showHelp = false val roomSummaries = nonNullViewState.asyncFilteredRooms() roomSummaries?.forEach { (category, summaries) -> if (summaries.isEmpty()) { @@ -70,9 +79,14 @@ class RoomSummaryController @Inject constructor(private val stringProvider: Stri nonNullViewState.joiningErrorRoomsIds, nonNullViewState.rejectingRoomsIds, nonNullViewState.rejectingErrorRoomsIds) + showHelp = userPreferencesProvider.shouldShowLongClickOnRoomHelp() } } } + + if (showHelp) { + buildLongClickHelp() + } } } } @@ -97,6 +111,13 @@ class RoomSummaryController @Inject constructor(private val stringProvider: Stri } } + private fun buildLongClickHelp() { + helpFooterItem { + id("long_click_help") + text(stringProvider.getString(R.string.help_long_click_on_room_for_more_options)) + } + } + private fun addFilterFooter(viewState: RoomListViewState) { filteredRoomFooterItem { id("filter_footer") diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt index 78f57dd548..dd99488465 100755 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt @@ -96,6 +96,9 @@ class VectorPreferences @Inject constructor(private val context: Context) { private const val SETTINGS_VIBRATE_ON_MENTION_KEY = "SETTINGS_VIBRATE_ON_MENTION_KEY" private const val SETTINGS_SEND_MESSAGE_WITH_ENTER = "SETTINGS_SEND_MESSAGE_WITH_ENTER" + // Help + private const val SETTINGS_SHOULD_SHOW_HELP_ON_ROOM_LIST_KEY = "SETTINGS_SHOULD_SHOW_HELP_ON_ROOM_LIST_KEY" + // home private const val SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY = "SETTINGS_PIN_UNREAD_MESSAGES_PREFERENCE_KEY" private const val SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY = "SETTINGS_PIN_MISSED_NOTIFICATIONS_PREFERENCE_KEY" @@ -597,6 +600,24 @@ class VectorPreferences @Inject constructor(private val context: Context) { return defaultPrefs.getBoolean(SETTINGS_SHOW_READ_RECEIPTS_KEY, true) } + /** + * Tells if the help on room list should be shown + * + * @return true if the help on room list should be shown + */ + fun shouldShowLongClickOnRoomHelp(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_SHOULD_SHOW_HELP_ON_ROOM_LIST_KEY, true) + } + + /** + * Prevent help on room list to be shown again + */ + fun neverShowLongClickOnRoomHelpAgain() { + defaultPrefs.edit { + putBoolean(SETTINGS_SHOULD_SHOW_HELP_ON_ROOM_LIST_KEY, false) + } + } + /** * Tells if the message timestamps must be always shown * diff --git a/vector/src/main/res/drawable/ic_idea.xml b/vector/src/main/res/drawable/ic_idea.xml new file mode 100644 index 0000000000..4be057ec6c --- /dev/null +++ b/vector/src/main/res/drawable/ic_idea.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/vector/src/main/res/layout/item_help_footer.xml b/vector/src/main/res/layout/item_help_footer.xml new file mode 100644 index 0000000000..197c9e58ae --- /dev/null +++ b/vector/src/main/res/layout/item_help_footer.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index ad98fa2204..fcd9567de2 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -12,4 +12,6 @@ You are not ignoring any users + Long click on a room to see more options + From dbb41108ef4b7500eb041871ce3e6aff9ec56d4c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 12 Nov 2019 11:50:16 +0100 Subject: [PATCH 2/2] Improve layout --- .../src/main/res/layout/item_help_footer.xml | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/vector/src/main/res/layout/item_help_footer.xml b/vector/src/main/res/layout/item_help_footer.xml index 197c9e58ae..7a1db62872 100644 --- a/vector/src/main/res/layout/item_help_footer.xml +++ b/vector/src/main/res/layout/item_help_footer.xml @@ -1,23 +1,37 @@ - + + - \ No newline at end of file + \ No newline at end of file