From 7ed7860051bc1eea5cf74337631b4812f9e60abf Mon Sep 17 00:00:00 2001 From: fedrunov Date: Fri, 7 Jan 2022 13:40:55 +0100 Subject: [PATCH 1/8] toolbar builder draft implementation --- .../src/main/res/values/styles_toolbar.xml | 10 ++-- .../app/core/platform/VectorBaseActivity.kt | 5 +- .../app/core/platform/VectorBaseFragment.kt | 5 ++ .../im/vector/app/core/utils/ToolbarConfig.kt | 60 +++++++++++++++++++ .../contactsbook/ContactsBookFragment.kt | 13 ++-- .../CreateDirectRoomByQrCodeFragment.kt | 11 ++-- .../features/qrcode/QrCodeScannerFragment.kt | 9 +-- .../res/layout/fragment_contacts_book.xml | 44 +------------- .../res/layout/fragment_qr_code_scanner.xml | 52 ++-------------- 9 files changed, 97 insertions(+), 112 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/core/utils/ToolbarConfig.kt diff --git a/library/ui-styles/src/main/res/values/styles_toolbar.xml b/library/ui-styles/src/main/res/values/styles_toolbar.xml index 9f6ba102edd..ca4c5d9b5c7 100644 --- a/library/ui-styles/src/main/res/values/styles_toolbar.xml +++ b/library/ui-styles/src/main/res/values/styles_toolbar.xml @@ -6,10 +6,12 @@ 0dp - @style/Widget.Vector.TextView.ActionBarTitle + @style/Widget.Vector.TextView.ActionBarTitle - @style/Widget.Vector.TextView.ActionBarSubTitle + @style/Widget.Vector.TextView.ActionBarSubTitle + + ?vctr_content_secondary @@ -24,14 +26,14 @@ diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt index 21419d55cfa..3b21ecd94d3 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt @@ -62,6 +62,7 @@ import im.vector.app.core.extensions.restart import im.vector.app.core.extensions.setTextOrHide import im.vector.app.core.extensions.singletonEntryPoint import im.vector.app.core.extensions.toMvRxBundle +import im.vector.app.core.utils.ToolbarConfig import im.vector.app.core.utils.toast import im.vector.app.features.MainActivity import im.vector.app.features.MainActivityArgs @@ -500,7 +501,7 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver /** * Configure the Toolbar, with default back button. */ - protected fun configureToolbar(toolbar: MaterialToolbar, displayBack: Boolean = true) { + protected fun configureToolbar(toolbar: MaterialToolbar, displayBack: Boolean) { setSupportActionBar(toolbar) supportActionBar?.let { it.setDisplayShowHomeEnabled(displayBack) @@ -618,4 +619,6 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver toast(getString(R.string.not_implemented)) } } + + fun configureToolbar(toolbar: MaterialToolbar): ToolbarConfig = ToolbarConfig(this, toolbar) } diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt index 64443139f1c..bf019c226b2 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt @@ -42,6 +42,7 @@ import im.vector.app.core.dialogs.UnrecognizedCertificateDialog import im.vector.app.core.error.ErrorFormatter import im.vector.app.core.extensions.singletonEntryPoint import im.vector.app.core.extensions.toMvRxBundle +import im.vector.app.core.utils.ToolbarConfig import im.vector.app.features.analytics.VectorAnalytics import im.vector.app.features.navigation.Navigator import im.vector.lib.ui.styles.dialogs.MaterialProgressDialog @@ -222,6 +223,10 @@ abstract class VectorBaseFragment : Fragment(), MavericksView } } + //we need to decide if we want to use vectorBaseActivity here + //the problem is that it casts getActivity() result to non nullable type, so in case if it will return null, NullPointerException will be thrown + protected fun configureToolbar(toolbar: MaterialToolbar) = (activity as? VectorBaseActivity<*>)?.configureToolbar(toolbar) ?: ToolbarConfig(null, toolbar) + /* ========================================================================================== * ViewEvents * ========================================================================================== */ diff --git a/vector/src/main/java/im/vector/app/core/utils/ToolbarConfig.kt b/vector/src/main/java/im/vector/app/core/utils/ToolbarConfig.kt new file mode 100644 index 00000000000..e9a09697bff --- /dev/null +++ b/vector/src/main/java/im/vector/app/core/utils/ToolbarConfig.kt @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022 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.app.core.utils + +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes +import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.content.res.AppCompatResources +import com.google.android.material.appbar.MaterialToolbar + +class ToolbarConfig(val activity: AppCompatActivity?, val toolbar: MaterialToolbar) { + private var titleRes: Int? = null + private var title: String? = null + private var subtitleRes: Int? = null + private var subtitle: String? = null + private var customBackResId: Int? = null + private var isBackAllowed: Boolean = true + private var useCloseButton: Boolean = false + + fun withTitle(@StringRes titleRes: Int) = apply {this.titleRes = titleRes } + fun withTitle(title: String) = apply {this.title = title} + fun withSubtitle(@StringRes subtitleRes: Int) = apply {this.subtitleRes = subtitleRes } + fun withSubtitle(subtitle: String) = apply {this.subtitle = subtitle} + + fun allowBack(isBackAllowed: Boolean) = apply { this.isBackAllowed = isBackAllowed } + fun setBackAsClose(useCloseButton: Boolean) = apply { this.useCloseButton = useCloseButton } + fun withCustomBackIcon(@DrawableRes customBackResId: Int) = apply { this.customBackResId = customBackResId } + + fun configure(){ + if (activity == null) { + return + } + activity.setSupportActionBar(toolbar) + toolbar.title = titleRes?.let { activity.getString(it) } + toolbar.subtitle = subtitleRes?.let { activity.getString(it) } + + activity.supportActionBar?.let { + it.setDisplayShowHomeEnabled(isBackAllowed) + it.setDisplayHomeAsUpEnabled(isBackAllowed) + } + + customBackResId?.let { + toolbar.navigationIcon = AppCompatResources.getDrawable(activity, it) + } + } +} diff --git a/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookFragment.kt b/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookFragment.kt index 5310fccb3a6..e72254fd012 100644 --- a/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookFragment.kt +++ b/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookFragment.kt @@ -24,6 +24,7 @@ import androidx.core.view.isVisible import androidx.lifecycle.lifecycleScope import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.withState +import im.vector.app.R import im.vector.app.core.extensions.cleanup import im.vector.app.core.extensions.configureWith import im.vector.app.core.extensions.exhaustive @@ -67,13 +68,17 @@ class ContactsBookFragment @Inject constructor( setupFilterView() setupConsentView() setupOnlyBoundContactsView() - setupCloseView() contactsBookViewModel.observeViewEvents { when (it) { is ContactsBookViewEvents.Failure -> showFailure(it.throwable) is ContactsBookViewEvents.OnPoliciesRetrieved -> showConsentDialog(it) }.exhaustive } + configureToolbar(views.phoneBookToolbar) + .withTitle(R.string.contacts_book_title) + .allowBack(true) + .withCustomBackIcon(R.drawable.ic_x_18dp) + .configure() } private fun setupConsentView() { @@ -119,12 +124,6 @@ class ContactsBookFragment @Inject constructor( views.phoneBookRecyclerView.configureWith(contactsBookController) } - private fun setupCloseView() { - views.phoneBookClose.debouncedClicks { - sharedActionViewModel.post(UserListSharedAction.GoBack) - } - } - override fun invalidate() = withState(contactsBookViewModel) { state -> views.phoneBookSearchForMatrixContacts.isVisible = state.filteredMappedContacts.isNotEmpty() && state.identityServerUrl != null && !state.userConsent views.phoneBookOnlyBoundContacts.isVisible = state.isBoundRetrieved diff --git a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomByQrCodeFragment.kt b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomByQrCodeFragment.kt index 96401604f31..9cd384f3cd5 100644 --- a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomByQrCodeFragment.kt +++ b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomByQrCodeFragment.kt @@ -63,12 +63,11 @@ class CreateDirectRoomByQrCodeFragment @Inject constructor() : VectorBaseFragmen override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - setupToolbar(views.qrScannerToolbar) - - views.qrScannerClose.debouncedClicks { - requireActivity().onBackPressed() - } - views.qrScannerTitle.text = getString(R.string.add_by_qr_code) + configureToolbar(views.qrScannerToolbar) + .withTitle(R.string.add_by_qr_code) + .allowBack(true) + .withCustomBackIcon(R.drawable.ic_x_18dp) + .configure() } override fun onResume() { diff --git a/vector/src/main/java/im/vector/app/features/qrcode/QrCodeScannerFragment.kt b/vector/src/main/java/im/vector/app/features/qrcode/QrCodeScannerFragment.kt index 95d3ce4a07d..ef7269e1959 100644 --- a/vector/src/main/java/im/vector/app/features/qrcode/QrCodeScannerFragment.kt +++ b/vector/src/main/java/im/vector/app/features/qrcode/QrCodeScannerFragment.kt @@ -38,10 +38,11 @@ class QrCodeScannerFragment @Inject constructor() : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - views.qrScannerClose.debouncedClicks { - requireActivity().onBackPressed() - } - views.qrScannerTitle.text = getString(R.string.verification_scan_their_code) + configureToolbar(views.qrScannerToolbar) + .withTitle(R.string.verification_scan_their_code) + .allowBack(true) + .withCustomBackIcon(R.drawable.ic_x_18dp) + .configure() } override fun onResume() { diff --git a/vector/src/main/res/layout/fragment_contacts_book.xml b/vector/src/main/res/layout/fragment_contacts_book.xml index ad23fc9f8f6..78f61eb39da 100644 --- a/vector/src/main/res/layout/fragment_contacts_book.xml +++ b/vector/src/main/res/layout/fragment_contacts_book.xml @@ -19,49 +19,7 @@ - - - - - - - - - - + android:layout_height="?actionBarSize" /> + app:layout_constraintTop_toBottomOf="@id/appBarLayout"> - - - - - - - - - - + android:layout_height="?actionBarSize" + app:title="@string/add_by_qr_code" /> @@ -69,7 +27,7 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/appBarLayout" /> + app:layout_constraintTop_toBottomOf="@id/appBarLayout2" /> From d85ab01b103b53f0290395b88ff90198ffa5afa5 Mon Sep 17 00:00:00 2001 From: fedrunov Date: Mon, 10 Jan 2022 10:00:35 +0100 Subject: [PATCH 2/8] removed debuging leftovers --- vector/src/main/res/layout/fragment_qr_code_scanner.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vector/src/main/res/layout/fragment_qr_code_scanner.xml b/vector/src/main/res/layout/fragment_qr_code_scanner.xml index 87574fe5568..c17c0d90da1 100644 --- a/vector/src/main/res/layout/fragment_qr_code_scanner.xml +++ b/vector/src/main/res/layout/fragment_qr_code_scanner.xml @@ -5,7 +5,7 @@ android:layout_height="match_parent"> + app:layout_constraintTop_toBottomOf="@id/appBarLayout" /> From 27db4a5a577c362c5de5fecdf7533b111fa0aa86 Mon Sep 17 00:00:00 2001 From: fedrunov Date: Thu, 13 Jan 2022 16:44:11 +0100 Subject: [PATCH 3/8] toolbar helper class changed from builder pattern to just proxy, majority of toolbars refactored from using custom title and close to a built-in widgets. Toolbar style now applies text appearance for every toolbar's title and subtitle --- changelog.d/4884.misc | 3 + .../src/main/res/values/styles_toolbar.xml | 8 +- .../core/platform/SimpleFragmentActivity.kt | 2 +- .../app/core/platform/ToolbarConfigurable.kt | 24 ------ .../app/core/platform/VectorBaseActivity.kt | 24 +++--- .../app/core/platform/VectorBaseFragment.kt | 24 +++--- .../im/vector/app/core/utils/ToolbarConfig.kt | 75 ++++++++++++------- .../preview/AttachmentsPreviewActivity.kt | 8 +- .../app/features/call/VectorCallActivity.kt | 18 ++--- .../call/transfer/CallTransferActivity.kt | 3 +- .../contactsbook/ContactsBookFragment.kt | 8 +- .../CreateDirectRoomByQrCodeFragment.kt | 8 +- .../vector/app/features/home/HomeActivity.kt | 7 -- .../app/features/home/HomeDetailFragment.kt | 9 +-- .../home/room/detail/RoomDetailActivity.kt | 7 -- .../home/room/detail/RoomDetailFragment.kt | 3 +- .../home/room/detail/search/SearchActivity.kt | 3 +- .../room/filtered/FilteredRoomsActivity.kt | 3 +- .../app/features/login/LoginActivity.kt | 8 +- .../app/features/login/LoginWebFragment.kt | 5 +- .../app/features/login2/LoginWebFragment2.kt | 5 +- .../features/media/BigImageViewerActivity.kt | 9 +-- .../features/onboarding/OnboardingActivity.kt | 8 +- .../ftueauth/FtueAuthWebFragment.kt | 3 +- .../im/vector/app/features/pin/PinActivity.kt | 8 +- .../poll/create/CreatePollFragment.kt | 8 +- .../features/qrcode/QrCodeScannerFragment.kt | 8 +- .../features/rageshake/BugReportActivity.kt | 3 +- .../reactions/EmojiReactionPickerActivity.kt | 3 +- .../roomdirectory/PublicRoomsFragment.kt | 8 +- .../createroom/CreateRoomActivity.kt | 8 +- .../createroom/CreateRoomFragment.kt | 12 +-- .../picker/RoomDirectoryPickerFragment.kt | 15 +--- .../roompreview/RoomPreviewActivity.kt | 8 +- .../RoomPreviewNoPreviewFragment.kt | 1 + .../RoomMemberProfileActivity.kt | 9 +-- .../RoomMemberProfileFragment.kt | 1 + .../roomprofile/RoomProfileActivity.kt | 9 +-- .../roomprofile/RoomProfileFragment.kt | 1 + .../roomprofile/alias/RoomAliasFragment.kt | 1 + .../banned/RoomBannedMemberListFragment.kt | 1 + .../members/RoomMemberListFragment.kt | 1 + .../RoomNotificationSettingsFragment.kt | 1 + .../permissions/RoomPermissionsFragment.kt | 1 + .../settings/RoomSettingsFragment.kt | 1 + .../uploads/RoomUploadsFragment.kt | 1 + .../settings/VectorSettingsActivity.kt | 3 +- .../features/share/IncomingShareActivity.kt | 8 +- .../spaces/explore/SpaceDirectoryFragment.kt | 13 +--- .../leave/SpaceLeaveAdvancedActivity.kt | 9 +-- .../leave/SpaceLeaveAdvancedFragment.kt | 1 + .../spaces/manage/SpaceAddRoomFragment.kt | 12 +-- .../spaces/manage/SpaceManageActivity.kt | 9 +-- .../spaces/manage/SpaceManageRoomsFragment.kt | 10 ++- .../spaces/manage/SpaceSettingsFragment.kt | 1 + .../spaces/people/SpacePeopleFragment.kt | 15 ++-- .../features/usercode/ScanUserCodeFragment.kt | 8 +- .../features/usercode/ShowUserCodeFragment.kt | 6 +- .../userdirectory/UserListFragment.kt | 12 +-- .../features/webview/VectorWebViewActivity.kt | 3 +- .../app/features/widgets/WidgetActivity.kt | 12 +-- vector/src/main/res/layout/activity_call.xml | 7 +- .../res/layout/fragment_contacts_book.xml | 3 +- ...ent_create_direct_room_directory_users.xml | 45 +---------- .../main/res/layout/fragment_create_poll.xml | 44 +---------- .../main/res/layout/fragment_create_room.xml | 42 +---------- .../main/res/layout/fragment_home_detail.xml | 4 +- .../res/layout/fragment_matrix_profile.xml | 2 +- .../fragment_qr_code_scanner_with_button.xml | 46 +----------- .../fragment_recyclerview_with_search.xml | 38 +--------- .../main/res/layout/fragment_room_detail.xml | 6 +- .../fragment_room_preview_no_preview.xml | 2 +- .../layout/fragment_room_setting_generic.xml | 2 +- .../main/res/layout/fragment_room_uploads.xml | 2 +- .../res/layout/fragment_space_add_rooms.xml | 38 +--------- .../layout/fragment_space_leave_advanced.xml | 26 +------ .../res/layout/fragment_space_preview.xml | 2 +- .../fragment_space_restricted_select.xml | 8 +- .../res/layout/fragment_user_code_show.xml | 42 +---------- .../res/layout/fragment_user_directory.xml | 2 +- .../main/res/layout/fragment_user_list.xml | 45 +---------- 81 files changed, 232 insertions(+), 680 deletions(-) create mode 100644 changelog.d/4884.misc delete mode 100644 vector/src/main/java/im/vector/app/core/platform/ToolbarConfigurable.kt diff --git a/changelog.d/4884.misc b/changelog.d/4884.misc new file mode 100644 index 00000000000..3315aeba0c4 --- /dev/null +++ b/changelog.d/4884.misc @@ -0,0 +1,3 @@ +Toolbar management rework. Toolbar title's and subtitle's text appearance now controlled by theme without local overrides. Helper class introduced to +help with toolbar configuration. Toolbar title, subtitle and navigation button widgets are removed where it is possible and replaced with built-in +toolbar widgets. \ No newline at end of file diff --git a/library/ui-styles/src/main/res/values/styles_toolbar.xml b/library/ui-styles/src/main/res/values/styles_toolbar.xml index ca4c5d9b5c7..d26af187ec5 100644 --- a/library/ui-styles/src/main/res/values/styles_toolbar.xml +++ b/library/ui-styles/src/main/res/values/styles_toolbar.xml @@ -27,13 +27,15 @@ diff --git a/vector/src/main/java/im/vector/app/core/platform/SimpleFragmentActivity.kt b/vector/src/main/java/im/vector/app/core/platform/SimpleFragmentActivity.kt index a70b2d66e63..684aab9b047 100644 --- a/vector/src/main/java/im/vector/app/core/platform/SimpleFragmentActivity.kt +++ b/vector/src/main/java/im/vector/app/core/platform/SimpleFragmentActivity.kt @@ -30,7 +30,7 @@ abstract class SimpleFragmentActivity : VectorBaseActivity() { final override fun getCoordinatorLayout() = views.coordinatorLayout override fun initUiAndData() { - configureToolbar(views.toolbar) + setupToolbar(views.toolbar) waitingView = views.waitingView.waitingView } diff --git a/vector/src/main/java/im/vector/app/core/platform/ToolbarConfigurable.kt b/vector/src/main/java/im/vector/app/core/platform/ToolbarConfigurable.kt deleted file mode 100644 index 9aca8dd17fe..00000000000 --- a/vector/src/main/java/im/vector/app/core/platform/ToolbarConfigurable.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.app.core.platform - -import com.google.android.material.appbar.MaterialToolbar - -interface ToolbarConfigurable { - - fun configure(toolbar: MaterialToolbar) -} diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt index 3b21ecd94d3..2aaab6fda73 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt @@ -116,6 +116,8 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver .launchIn(lifecycleScope) } + var toolbar: ToolbarConfig? = null + /* ========================================================================================== * Views * ========================================================================================== */ @@ -498,18 +500,6 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver */ protected fun isFirstCreation() = savedInstanceState == null - /** - * Configure the Toolbar, with default back button. - */ - protected fun configureToolbar(toolbar: MaterialToolbar, displayBack: Boolean) { - setSupportActionBar(toolbar) - supportActionBar?.let { - it.setDisplayShowHomeEnabled(displayBack) - it.setDisplayHomeAsUpEnabled(displayBack) - it.title = null - } - } - // ============================================================================================== // Handle loading view (also called waiting view or spinner view) // ============================================================================================== @@ -620,5 +610,13 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver } } - fun configureToolbar(toolbar: MaterialToolbar): ToolbarConfig = ToolbarConfig(this, toolbar) + /** + * Sets toolbar as actionBar + * + * @return Instance of [ToolbarConfig] with set of helper methods to configure toolbar + * */ + fun setupToolbar(toolbar: MaterialToolbar) = ToolbarConfig(this, toolbar).also { + this.toolbar = it + it.setup() + } } diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt index bf019c226b2..38451dd43eb 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt @@ -68,6 +68,12 @@ abstract class VectorBaseFragment : Fragment(), MavericksView private var progress: AlertDialog? = null + /** + * [ToolbarConfig] instance from host activity + * */ + protected var toolbar: ToolbarConfig? = null + get() = (activity as? VectorBaseActivity<*>)?.toolbar + private set /* ========================================================================================== * View model * ========================================================================================== */ @@ -213,20 +219,16 @@ abstract class VectorBaseFragment : Fragment(), MavericksView * Toolbar * ========================================================================================== */ + /** - * Configure the Toolbar. - */ - protected fun setupToolbar(toolbar: MaterialToolbar) { - val parentActivity = vectorBaseActivity - if (parentActivity is ToolbarConfigurable) { - parentActivity.configure(toolbar) - } + * Sets toolbar as actionBar for current activity + * + * @return Instance of [ToolbarConfig] with set of helper methods to configure toolbar + * */ + protected fun setupToolbar(toolbar: MaterialToolbar): ToolbarConfig { + return vectorBaseActivity.setupToolbar(toolbar) } - //we need to decide if we want to use vectorBaseActivity here - //the problem is that it casts getActivity() result to non nullable type, so in case if it will return null, NullPointerException will be thrown - protected fun configureToolbar(toolbar: MaterialToolbar) = (activity as? VectorBaseActivity<*>)?.configureToolbar(toolbar) ?: ToolbarConfig(null, toolbar) - /* ========================================================================================== * ViewEvents * ========================================================================================== */ diff --git a/vector/src/main/java/im/vector/app/core/utils/ToolbarConfig.kt b/vector/src/main/java/im/vector/app/core/utils/ToolbarConfig.kt index e9a09697bff..878c41082e5 100644 --- a/vector/src/main/java/im/vector/app/core/utils/ToolbarConfig.kt +++ b/vector/src/main/java/im/vector/app/core/utils/ToolbarConfig.kt @@ -16,45 +16,70 @@ package im.vector.app.core.utils -import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.content.res.AppCompatResources import com.google.android.material.appbar.MaterialToolbar +import im.vector.app.R +/** + * Helper class to configure toolbar. + * Wraps [MaterialToolbar] providing set of methods to configure it + */ class ToolbarConfig(val activity: AppCompatActivity?, val toolbar: MaterialToolbar) { - private var titleRes: Int? = null - private var title: String? = null - private var subtitleRes: Int? = null - private var subtitle: String? = null private var customBackResId: Int? = null - private var isBackAllowed: Boolean = true - private var useCloseButton: Boolean = false - - fun withTitle(@StringRes titleRes: Int) = apply {this.titleRes = titleRes } - fun withTitle(title: String) = apply {this.title = title} - fun withSubtitle(@StringRes subtitleRes: Int) = apply {this.subtitleRes = subtitleRes } - fun withSubtitle(subtitle: String) = apply {this.subtitle = subtitle} - - fun allowBack(isBackAllowed: Boolean) = apply { this.isBackAllowed = isBackAllowed } - fun setBackAsClose(useCloseButton: Boolean) = apply { this.useCloseButton = useCloseButton } - fun withCustomBackIcon(@DrawableRes customBackResId: Int) = apply { this.customBackResId = customBackResId } - fun configure(){ + fun setup() { if (activity == null) { return } activity.setSupportActionBar(toolbar) - toolbar.title = titleRes?.let { activity.getString(it) } - toolbar.subtitle = subtitleRes?.let { activity.getString(it) } + } - activity.supportActionBar?.let { - it.setDisplayShowHomeEnabled(isBackAllowed) - it.setDisplayHomeAsUpEnabled(isBackAllowed) - } + /** + * Delegating property for [toolbar.title] + * */ + var title: CharSequence? by toolbar::title + + /** + * Delegating property for [toolbar.subtitle] + * */ + var subtitle: CharSequence? by toolbar::subtitle + + /** + * Sets toolbar's title text + * */ + fun setTitle(title: CharSequence?) = apply { toolbar.title = title } + + /** + * Sets toolbar's title text using provided string resource + * */ + fun setTitle(@StringRes titleRes: Int) = apply { toolbar.setTitle(titleRes)} + + /** + * Sets toolbar's subtitle text + * */ + fun setSubtitle(subtitle: String?) = apply { toolbar.subtitle = subtitle } + + /** + * Sets toolbar's title text using provided string resource + * */ + fun setSubtitle(@StringRes subtitleRes: Int) = apply { toolbar.subtitle = activity?.getString(subtitleRes) } - customBackResId?.let { - toolbar.navigationIcon = AppCompatResources.getDrawable(activity, it) + /** + * Enables/disables navigate back button + * + * @param isAllowed defines if back button is enabled. Default [true] + * @param useCross defines if cross icon should be used instead of arrow. Default [false] + * */ + fun allowBack(isAllowed: Boolean = true, useCross: Boolean = false) = apply { + activity?.supportActionBar?.let { + it.setDisplayShowHomeEnabled(isAllowed) + it.setDisplayHomeAsUpEnabled(isAllowed) + if (isAllowed && useCross) { + val navResId = customBackResId ?: R.drawable.ic_x_18dp + toolbar.navigationIcon = AppCompatResources.getDrawable(activity, navResId) + } } } } diff --git a/vector/src/main/java/im/vector/app/features/attachments/preview/AttachmentsPreviewActivity.kt b/vector/src/main/java/im/vector/app/features/attachments/preview/AttachmentsPreviewActivity.kt index a52036011f7..7ddba0d2295 100644 --- a/vector/src/main/java/im/vector/app/features/attachments/preview/AttachmentsPreviewActivity.kt +++ b/vector/src/main/java/im/vector/app/features/attachments/preview/AttachmentsPreviewActivity.kt @@ -19,17 +19,15 @@ package im.vector.app.features.attachments.preview import android.content.Context import android.content.Intent -import com.google.android.material.appbar.MaterialToolbar import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleBinding import im.vector.app.features.themes.ActivityOtherThemes import org.matrix.android.sdk.api.session.content.ContentAttachmentData @AndroidEntryPoint -class AttachmentsPreviewActivity : VectorBaseActivity(), ToolbarConfigurable { +class AttachmentsPreviewActivity : VectorBaseActivity() { companion object { private const val EXTRA_FRAGMENT_ARGS = "EXTRA_FRAGMENT_ARGS" @@ -72,8 +70,4 @@ class AttachmentsPreviewActivity : VectorBaseActivity(), setResult(RESULT_OK, resultIntent) finish() } - - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar) - } } diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt index 995dc3d5e8c..22f1fc40a23 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt @@ -126,7 +126,7 @@ class VectorCallActivity : VectorBaseActivity(), CallContro if (savedInstanceState != null) { (supportFragmentManager.findFragmentByTag(FRAGMENT_DIAL_PAD_TAG) as? CallDialPadBottomSheet)?.callback = dialPadCallback } - setSupportActionBar(views.callToolbar) + setupToolbar(views.callToolbar) configureCallViews() callViewModel.onEach { @@ -257,18 +257,18 @@ class VectorCallActivity : VectorBaseActivity(), CallContro views.fullscreenRenderer.isVisible = false views.pipRendererWrapper.isVisible = false views.callInfoGroup.isVisible = true - views.callToolbar.setSubtitle(R.string.call_ringing) + toolbar?.setSubtitle(R.string.call_ringing) configureCallInfo(state) } is CallState.Answering -> { views.fullscreenRenderer.isVisible = false views.pipRendererWrapper.isVisible = false views.callInfoGroup.isVisible = true - views.callToolbar.setSubtitle(R.string.call_connecting) + toolbar?.setSubtitle(R.string.call_connecting) configureCallInfo(state) } is CallState.Connected -> { - views.callToolbar.subtitle = state.formattedDuration + toolbar?.subtitle = state.formattedDuration if (callState.iceConnectionState == MxPeerConnectionState.CONNECTED) { if (state.isLocalOnHold || state.isRemoteOnHold) { views.smallIsHeldIcon.isVisible = true @@ -280,11 +280,11 @@ class VectorCallActivity : VectorBaseActivity(), CallContro views.callActionText.setText(R.string.call_resume_action) views.callActionText.isVisible = true views.callActionText.setOnClickListener { callViewModel.handle(VectorCallViewActions.ToggleHoldResume) } - views.callToolbar.setSubtitle(R.string.call_held_by_you) + toolbar?.setSubtitle(R.string.call_held_by_you) } else { views.callActionText.isInvisible = true state.callInfo?.opponentUserItem?.let { - views.callToolbar.subtitle = getString(R.string.call_held_by_user, it.getBestName()) + toolbar?.subtitle = getString(R.string.call_held_by_user, it.getBestName()) } } } else if (state.transferee !is VectorCallViewState.TransfereeState.NoTransferee) { @@ -316,14 +316,14 @@ class VectorCallActivity : VectorBaseActivity(), CallContro views.pipRendererWrapper.isVisible = false views.callInfoGroup.isVisible = true configureCallInfo(state) - views.callToolbar.setSubtitle(R.string.call_connecting) + toolbar?.setSubtitle(R.string.call_connecting) } } is CallState.Ended -> { views.fullscreenRenderer.isVisible = false views.pipRendererWrapper.isVisible = false views.callInfoGroup.isVisible = true - views.callToolbar.setSubtitle(R.string.call_ended) + toolbar?.setSubtitle(R.string.call_ended) configureCallInfo(state) } else -> { @@ -410,7 +410,7 @@ class VectorCallActivity : VectorBaseActivity(), CallContro avatarRenderer.renderBlur(it, views.bgCallView, sampling = 20, rounded = false, colorFilter = colorFilter, addPlaceholder = false) if (state.transferee is VectorCallViewState.TransfereeState.NoTransferee) { views.participantNameText.setTextOrHide(null) - views.callToolbar.title = if (state.isVideoCall) { + toolbar?.title = if (state.isVideoCall) { getString(R.string.video_call_with_participant, it.getBestName()) } else { getString(R.string.audio_call_with_participant, it.getBestName()) diff --git a/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferActivity.kt b/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferActivity.kt index c03b526f8c2..959e96cc4c0 100644 --- a/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferActivity.kt @@ -70,7 +70,8 @@ class CallTransferActivity : VectorBaseActivity() { CallTransferPagerAdapter.DIAL_PAD_INDEX -> tab.text = getString(R.string.call_dial_pad_title) } }.attach() - configureToolbar(views.callTransferToolbar) + setupToolbar(views.callTransferToolbar) + .allowBack() views.callTransferToolbar.title = getString(R.string.call_transfer_title) setupConnectAction() } diff --git a/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookFragment.kt b/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookFragment.kt index e72254fd012..ebd00897369 100644 --- a/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookFragment.kt +++ b/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookFragment.kt @@ -24,7 +24,6 @@ import androidx.core.view.isVisible import androidx.lifecycle.lifecycleScope import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.withState -import im.vector.app.R import im.vector.app.core.extensions.cleanup import im.vector.app.core.extensions.configureWith import im.vector.app.core.extensions.exhaustive @@ -68,17 +67,14 @@ class ContactsBookFragment @Inject constructor( setupFilterView() setupConsentView() setupOnlyBoundContactsView() + setupToolbar(views.phoneBookToolbar) + .allowBack(useCross = true) contactsBookViewModel.observeViewEvents { when (it) { is ContactsBookViewEvents.Failure -> showFailure(it.throwable) is ContactsBookViewEvents.OnPoliciesRetrieved -> showConsentDialog(it) }.exhaustive } - configureToolbar(views.phoneBookToolbar) - .withTitle(R.string.contacts_book_title) - .allowBack(true) - .withCustomBackIcon(R.drawable.ic_x_18dp) - .configure() } private fun setupConsentView() { diff --git a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomByQrCodeFragment.kt b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomByQrCodeFragment.kt index 9cd384f3cd5..766a6f5156c 100644 --- a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomByQrCodeFragment.kt +++ b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomByQrCodeFragment.kt @@ -63,11 +63,9 @@ class CreateDirectRoomByQrCodeFragment @Inject constructor() : VectorBaseFragmen override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - configureToolbar(views.qrScannerToolbar) - .withTitle(R.string.add_by_qr_code) - .allowBack(true) - .withCustomBackIcon(R.drawable.ic_x_18dp) - .configure() + setupToolbar(views.qrScannerToolbar) + .setTitle(R.string.add_by_qr_code) + .allowBack(useCross = true) } override fun onResume() { diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt index 031802995de..ccf131cd8fa 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt @@ -32,7 +32,6 @@ import androidx.fragment.app.FragmentManager import androidx.lifecycle.lifecycleScope import com.airbnb.mvrx.Mavericks import com.airbnb.mvrx.viewModel -import com.google.android.material.appbar.MaterialToolbar import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.android.AndroidEntryPoint import im.vector.app.AppStateHandler @@ -42,7 +41,6 @@ import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.hideKeyboard import im.vector.app.core.extensions.registerStartForActivityResult import im.vector.app.core.extensions.replaceFragment -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.pushers.PushersManager import im.vector.app.databinding.ActivityHomeBinding @@ -96,7 +94,6 @@ data class HomeActivityArgs( @AndroidEntryPoint class HomeActivity : VectorBaseActivity(), - ToolbarConfigurable, NavigationInterceptor, SpaceInviteBottomSheet.InteractionListener, MatrixToBottomSheet.InteractionListener { @@ -478,10 +475,6 @@ class HomeActivity : serverBackupStatusViewModel.refreshRemoteStateIfNeeded() } - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar, false) - } - override fun getMenuRes() = R.menu.home override fun onPrepareOptionsMenu(menu: Menu): Boolean { diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt index 712055435fa..a07409d063d 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt @@ -33,7 +33,6 @@ import im.vector.app.R import im.vector.app.RoomGroupingMethod import im.vector.app.core.extensions.commitTransaction import im.vector.app.core.extensions.toMvRxBundle -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.resources.ColorProvider @@ -314,11 +313,9 @@ class HomeDetailFragment @Inject constructor( } private fun setupToolbar() { - val parentActivity = vectorBaseActivity - if (parentActivity is ToolbarConfigurable) { - parentActivity.configure(views.groupToolbar) - } - views.groupToolbar.title = "" + setupToolbar(views.groupToolbar) + .setTitle(null) + views.groupToolbarAvatarImageView.debouncedClicks { sharedActionViewModel.post(HomeActivitySharedAction.OpenDrawer) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt index 05dbd724d12..0d767251b56 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt @@ -27,13 +27,11 @@ import androidx.fragment.app.FragmentManager import androidx.lifecycle.lifecycleScope import com.airbnb.mvrx.Mavericks import com.airbnb.mvrx.viewModel -import com.google.android.material.appbar.MaterialToolbar import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.endKeepScreenOn import im.vector.app.core.extensions.hideKeyboard import im.vector.app.core.extensions.keepScreenOn import im.vector.app.core.extensions.replaceFragment -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivityRoomDetailBinding import im.vector.app.features.home.room.breadcrumbs.BreadcrumbsFragment @@ -50,7 +48,6 @@ import javax.inject.Inject @AndroidEntryPoint class RoomDetailActivity : VectorBaseActivity(), - ToolbarConfigurable, MatrixToBottomSheet.InteractionListener { override fun getBinding(): ActivityRoomDetailBinding { @@ -156,10 +153,6 @@ class RoomDetailActivity : super.onDestroy() } - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar) - } - private val drawerListener = object : DrawerLayout.SimpleDrawerListener() { override fun onDrawerStateChanged(newState: Int) { hideKeyboard() diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 566cb2d2ded..8ae29760172 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -359,6 +359,7 @@ class RoomDetailFragment @Inject constructor( keyboardStateUtils = KeyboardStateUtils(requireActivity()) lazyLoadedViews.bind(views) setupToolbar(views.roomToolbar) + .allowBack() setupRecyclerView() setupComposer() setupNotificationView() @@ -1494,7 +1495,7 @@ class RoomDetailFragment @Inject constructor( views.roomToolbarSubtitleView.apply { setTextOrHide(subtitle) if (typingMessage.isNullOrBlank()) { - setTextColor(colorProvider.getColorFromAttribute(R.attr.vctr_content_primary)) + setTextColor(colorProvider.getColorFromAttribute(R.attr.vctr_content_secondary)) setTypeface(null, Typeface.NORMAL) } else { setTextColor(colorProvider.getColorFromAttribute(R.attr.colorPrimary)) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchActivity.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchActivity.kt index bc1dc088dff..eed596cda08 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchActivity.kt @@ -40,7 +40,8 @@ class SearchActivity : VectorBaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - configureToolbar(views.searchToolbar) + setupToolbar(views.searchToolbar) + .allowBack() } override fun initUiAndData() { diff --git a/vector/src/main/java/im/vector/app/features/home/room/filtered/FilteredRoomsActivity.kt b/vector/src/main/java/im/vector/app/features/home/room/filtered/FilteredRoomsActivity.kt index 5f8ccc794ae..5b1ff83af0b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/filtered/FilteredRoomsActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/filtered/FilteredRoomsActivity.kt @@ -42,7 +42,8 @@ class FilteredRoomsActivity : VectorBaseActivity() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - configureToolbar(views.filteredRoomsToolbar) + setupToolbar(views.filteredRoomsToolbar) + .allowBack() if (isFirstCreation()) { val params = RoomListParams(RoomListDisplayMode.FILTERED) replaceFragment(views.filteredRoomsFragmentContainer, RoomListFragment::class.java, params, FRAGMENT_TAG) diff --git a/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt b/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt index 5ab08ffff79..2fb8978d125 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt @@ -29,7 +29,6 @@ import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentTransaction import com.airbnb.mvrx.viewModel import com.airbnb.mvrx.withState -import com.google.android.material.appbar.MaterialToolbar import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.android.AndroidEntryPoint import im.vector.app.R @@ -37,7 +36,6 @@ import im.vector.app.core.extensions.POP_BACK_STACK_EXCLUSIVE import im.vector.app.core.extensions.addFragment import im.vector.app.core.extensions.addFragmentToBackstack import im.vector.app.core.extensions.exhaustive -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivityLoginBinding import im.vector.app.features.home.HomeActivity @@ -53,7 +51,7 @@ import org.matrix.android.sdk.api.extensions.tryOrNull * The LoginActivity manages the fragment navigation and also display the loading View */ @AndroidEntryPoint -open class LoginActivity : VectorBaseActivity(), ToolbarConfigurable, UnlockedActivity { +open class LoginActivity : VectorBaseActivity(), UnlockedActivity { private val loginViewModel: LoginViewModel by viewModel() @@ -346,10 +344,6 @@ open class LoginActivity : VectorBaseActivity(), ToolbarCo } } - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar) - } - companion object { private const val FRAGMENT_REGISTRATION_STAGE_TAG = "FRAGMENT_REGISTRATION_STAGE_TAG" private const val FRAGMENT_LOGIN_TAG = "FRAGMENT_LOGIN_TAG" diff --git a/vector/src/main/java/im/vector/app/features/login/LoginWebFragment.kt b/vector/src/main/java/im/vector/app/features/login/LoginWebFragment.kt index daa97d732f1..ca21e96d20c 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginWebFragment.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginWebFragment.kt @@ -64,6 +64,7 @@ class LoginWebFragment @Inject constructor( super.onViewCreated(view, savedInstanceState) setupToolbar(views.loginWebToolbar) + .allowBack() } override fun updateWithState(state: LoginViewState) { @@ -78,7 +79,7 @@ class LoginWebFragment @Inject constructor( } private fun setupTitle(state: LoginViewState) { - views.loginWebToolbar.title = when (state.signMode) { + toolbar?.title = when (state.signMode) { SignMode.SignIn -> getString(R.string.login_signin) else -> getString(R.string.login_signup) } @@ -149,7 +150,7 @@ class LoginWebFragment @Inject constructor( override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { super.onPageStarted(view, url, favicon) - views.loginWebToolbar.subtitle = url + toolbar?.subtitle = url } override fun onPageFinished(view: WebView, url: String) { diff --git a/vector/src/main/java/im/vector/app/features/login2/LoginWebFragment2.kt b/vector/src/main/java/im/vector/app/features/login2/LoginWebFragment2.kt index 080cce49581..ebe59ee1b91 100644 --- a/vector/src/main/java/im/vector/app/features/login2/LoginWebFragment2.kt +++ b/vector/src/main/java/im/vector/app/features/login2/LoginWebFragment2.kt @@ -65,6 +65,7 @@ class LoginWebFragment2 @Inject constructor( super.onViewCreated(view, savedInstanceState) setupToolbar(views.loginWebToolbar) + .allowBack() } override fun updateWithState(state: LoginViewState2) { @@ -79,7 +80,7 @@ class LoginWebFragment2 @Inject constructor( } private fun setupTitle(state: LoginViewState2) { - views.loginWebToolbar.title = when (state.signMode) { + toolbar?.title = when (state.signMode) { SignMode2.SignIn -> getString(R.string.login_signin) else -> getString(R.string.login_signup) } @@ -150,7 +151,7 @@ class LoginWebFragment2 @Inject constructor( override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { super.onPageStarted(view, url, favicon) - views.loginWebToolbar.subtitle = url + toolbar?.subtitle = url } override fun onPageFinished(view: WebView, url: String) { diff --git a/vector/src/main/java/im/vector/app/features/media/BigImageViewerActivity.kt b/vector/src/main/java/im/vector/app/features/media/BigImageViewerActivity.kt index 84454ee509f..a6b166815c5 100644 --- a/vector/src/main/java/im/vector/app/features/media/BigImageViewerActivity.kt +++ b/vector/src/main/java/im/vector/app/features/media/BigImageViewerActivity.kt @@ -38,12 +38,9 @@ class BigImageViewerActivity : VectorBaseActivity override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setSupportActionBar(views.bigImageViewerToolbar) - supportActionBar?.apply { - title = intent.getStringExtra(EXTRA_TITLE) - setHomeButtonEnabled(true) - setDisplayHomeAsUpEnabled(true) - } + setupToolbar(views.bigImageViewerToolbar) + .setTitle(intent.getStringExtra(EXTRA_TITLE)) + .allowBack() val uri = sessionHolder.getSafeActiveSession() ?.contentUrlResolver() diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingActivity.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingActivity.kt index f0cf9464a66..4165d4cb65a 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingActivity.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingActivity.kt @@ -19,10 +19,8 @@ package im.vector.app.features.onboarding import android.content.Context import android.content.Intent import android.net.Uri -import com.google.android.material.appbar.MaterialToolbar import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.lazyViewModel -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.lifecycleAwareLazy import im.vector.app.databinding.ActivityLoginBinding @@ -31,7 +29,7 @@ import im.vector.app.features.pin.UnlockedActivity import javax.inject.Inject @AndroidEntryPoint -class OnboardingActivity : VectorBaseActivity(), ToolbarConfigurable, UnlockedActivity { +class OnboardingActivity : VectorBaseActivity(), UnlockedActivity { private val onboardingVariant by lifecycleAwareLazy { onboardingVariantFactory.create(this, views = views, onboardingViewModel = lazyViewModel(), loginViewModel2 = lazyViewModel()) @@ -43,10 +41,6 @@ class OnboardingActivity : VectorBaseActivity(), ToolbarCo override fun getCoordinatorLayout() = views.coordinatorLayout - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar) - } - override fun onNewIntent(intent: Intent?) { super.onNewIntent(intent) onboardingVariant.onNewIntent(intent) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthWebFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthWebFragment.kt index d479439a0f3..879830a1c0a 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthWebFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthWebFragment.kt @@ -69,6 +69,7 @@ class FtueAuthWebFragment @Inject constructor( super.onViewCreated(view, savedInstanceState) setupToolbar(views.loginWebToolbar) + .allowBack() } override fun updateWithState(state: OnboardingViewState) { @@ -83,7 +84,7 @@ class FtueAuthWebFragment @Inject constructor( } private fun setupTitle(state: OnboardingViewState) { - views.loginWebToolbar.title = when (state.signMode) { + toolbar?.title = when (state.signMode) { SignMode.SignIn -> getString(R.string.login_signin) else -> getString(R.string.login_signup) } diff --git a/vector/src/main/java/im/vector/app/features/pin/PinActivity.kt b/vector/src/main/java/im/vector/app/features/pin/PinActivity.kt index ef797990744..faf15d8006a 100644 --- a/vector/src/main/java/im/vector/app/features/pin/PinActivity.kt +++ b/vector/src/main/java/im/vector/app/features/pin/PinActivity.kt @@ -19,15 +19,13 @@ package im.vector.app.features.pin import android.content.Context import android.content.Intent import com.airbnb.mvrx.Mavericks -import com.google.android.material.appbar.MaterialToolbar import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleBinding @AndroidEntryPoint -class PinActivity : VectorBaseActivity(), ToolbarConfigurable, UnlockedActivity { +class PinActivity : VectorBaseActivity(), UnlockedActivity { companion object { fun newIntent(context: Context, args: PinArgs): Intent { @@ -47,8 +45,4 @@ class PinActivity : VectorBaseActivity(), ToolbarConfigur addFragment(views.simpleFragmentContainer, PinFragment::class.java, fragmentArgs) } } - - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar) - } } diff --git a/vector/src/main/java/im/vector/app/features/poll/create/CreatePollFragment.kt b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollFragment.kt index dc82579f15d..5c0d2b6cb09 100644 --- a/vector/src/main/java/im/vector/app/features/poll/create/CreatePollFragment.kt +++ b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollFragment.kt @@ -48,15 +48,13 @@ class CreatePollFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - vectorBaseActivity.setSupportActionBar(views.createPollToolbar) + + setupToolbar(views.createPollToolbar) + .allowBack(useCross = true) views.createPollRecyclerView.configureWith(controller, disableItemAnimation = true) controller.callback = this - views.createPollClose.debouncedClicks { - requireActivity().finish() - } - views.createPollButton.debouncedClicks { viewModel.handle(CreatePollAction.OnCreatePoll) } diff --git a/vector/src/main/java/im/vector/app/features/qrcode/QrCodeScannerFragment.kt b/vector/src/main/java/im/vector/app/features/qrcode/QrCodeScannerFragment.kt index ef7269e1959..a7231a0c5b7 100644 --- a/vector/src/main/java/im/vector/app/features/qrcode/QrCodeScannerFragment.kt +++ b/vector/src/main/java/im/vector/app/features/qrcode/QrCodeScannerFragment.kt @@ -38,11 +38,9 @@ class QrCodeScannerFragment @Inject constructor() : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - configureToolbar(views.qrScannerToolbar) - .withTitle(R.string.verification_scan_their_code) - .allowBack(true) - .withCustomBackIcon(R.drawable.ic_x_18dp) - .configure() + setupToolbar(views.qrScannerToolbar) + .setTitle(R.string.verification_scan_their_code) + .allowBack(useCross = true) } override fun onResume() { diff --git a/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt b/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt index b27c2e9818b..b61eb275409 100755 --- a/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt +++ b/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt @@ -45,7 +45,8 @@ class BugReportActivity : VectorBaseActivity() { private var reportType: ReportType = ReportType.BUG_REPORT override fun initUiAndData() { - configureToolbar(views.bugReportToolbar) + setupToolbar(views.bugReportToolbar) + .allowBack() setupViews() if (bugReporter.screenshot != null) { diff --git a/vector/src/main/java/im/vector/app/features/reactions/EmojiReactionPickerActivity.kt b/vector/src/main/java/im/vector/app/features/reactions/EmojiReactionPickerActivity.kt index d377c74ad70..98241994618 100644 --- a/vector/src/main/java/im/vector/app/features/reactions/EmojiReactionPickerActivity.kt +++ b/vector/src/main/java/im/vector/app/features/reactions/EmojiReactionPickerActivity.kt @@ -79,7 +79,8 @@ class EmojiReactionPickerActivity : VectorBaseActivity(), ToolbarConfigurable { +class CreateRoomActivity : VectorBaseActivity() { private lateinit var sharedActionViewModel: RoomDirectorySharedActionViewModel @@ -43,10 +41,6 @@ class CreateRoomActivity : VectorBaseActivity(), ToolbarC override fun getCoordinatorLayout() = views.coordinatorLayout - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar) - } - override fun initUiAndData() { if (isFirstCreation()) { addFragment( diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt index 1244a0f64e7..225dd75a130 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt @@ -82,14 +82,13 @@ class CreateRoomFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - vectorBaseActivity.setSupportActionBar(views.createRoomToolbar) sharedActionViewModel = activityViewModelProvider.get(RoomDirectorySharedActionViewModel::class.java) setupRoomJoinRuleSharedActionViewModel() setupWaitingView() setupRecyclerView() - views.createRoomClose.debouncedClicks { - sharedActionViewModel.post(RoomDirectorySharedAction.Back) - } + setupToolbar(views.createRoomToolbar) + .setTitle(if (args.isSpace) R.string.create_new_space else R.string.create_new_room) + .allowBack(useCross = true) viewModel.observeViewEvents { when (it) { CreateRoomViewEvents.Quit -> vectorBaseActivity.onBackPressed() @@ -98,11 +97,6 @@ class CreateRoomFragment @Inject constructor( } } - override fun onResume() { - super.onResume() - views.createRoomTitle.text = getString(if (args.isSpace) R.string.create_new_space else R.string.create_new_room) - } - private fun setupRoomJoinRuleSharedActionViewModel() { roomJoinRuleSharedActionViewModel = activityViewModelProvider.get(RoomJoinRuleSharedActionViewModel::class.java) roomJoinRuleSharedActionViewModel diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt index 2707b87c1f1..28140d32a34 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/picker/RoomDirectoryPickerFragment.kt @@ -20,7 +20,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.appcompat.app.AppCompatActivity import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState @@ -55,12 +54,9 @@ class RoomDirectoryPickerFragment @Inject constructor(private val roomDirectoryP override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - vectorBaseActivity.setSupportActionBar(views.toolbar) - - vectorBaseActivity.supportActionBar?.let { - it.setDisplayShowHomeEnabled(true) - it.setDisplayHomeAsUpEnabled(true) - } + setupToolbar(views.toolbar) + .setTitle(R.string.select_room_directory) + .allowBack() sharedActionViewModel = activityViewModelProvider.get(RoomDirectorySharedActionViewModel::class.java) setupRecyclerView() @@ -109,11 +105,6 @@ class RoomDirectoryPickerFragment @Inject constructor(private val roomDirectoryP pickerViewModel.handle(RoomDirectoryPickerAction.RemoveServer(roomDirectoryServer)) } - override fun onResume() { - super.onResume() - (activity as? AppCompatActivity)?.supportActionBar?.setTitle(R.string.select_room_directory) - } - override fun retry() { Timber.v("Retry") pickerViewModel.handle(RoomDirectoryPickerAction.Retry) diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewActivity.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewActivity.kt index 394d738b268..291783a7f99 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewActivity.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewActivity.kt @@ -19,10 +19,8 @@ package im.vector.app.features.roomdirectory.roompreview import android.content.Context import android.content.Intent import android.os.Parcelable -import com.google.android.material.appbar.MaterialToolbar import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleBinding import im.vector.app.features.roomdirectory.RoomDirectoryData @@ -52,7 +50,7 @@ data class RoomPreviewData( } @AndroidEntryPoint -class RoomPreviewActivity : VectorBaseActivity(), ToolbarConfigurable { +class RoomPreviewActivity : VectorBaseActivity(){ companion object { private const val ARG = "ARG" @@ -81,10 +79,6 @@ class RoomPreviewActivity : VectorBaseActivity(), Toolbar override fun getCoordinatorLayout() = views.coordinatorLayout - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar) - } - override fun initUiAndData() { if (isFirstCreation()) { val args = intent.getParcelableExtra(ARG) diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt index 52617e2f1d4..6d0195fae37 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt @@ -64,6 +64,7 @@ class RoomPreviewNoPreviewFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setupToolbar(views.roomPreviewNoPreviewToolbar) + .allowBack() views.roomPreviewNoPreviewJoin.commonClicked = { roomPreviewViewModel.handle(RoomPreviewAction.Join) } } diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileActivity.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileActivity.kt index 2d925270b36..e2365d9a271 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileActivity.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileActivity.kt @@ -22,10 +22,8 @@ import android.content.Intent import android.widget.Toast import com.airbnb.mvrx.Mavericks import com.airbnb.mvrx.viewModel -import com.google.android.material.appbar.MaterialToolbar import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleBinding import im.vector.app.features.room.RequireActiveMembershipViewEvents @@ -33,8 +31,7 @@ import im.vector.app.features.room.RequireActiveMembershipViewModel @AndroidEntryPoint class RoomMemberProfileActivity : - VectorBaseActivity(), - ToolbarConfigurable { + VectorBaseActivity(){ companion object { fun newIntent(context: Context, args: RoomMemberProfileArgs): Intent { @@ -63,10 +60,6 @@ class RoomMemberProfileActivity : } } - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar) - } - private fun handleRoomLeft(roomLeft: RequireActiveMembershipViewEvents.RoomLeft) { if (roomLeft.leftMessage != null) { Toast.makeText(this, roomLeft.leftMessage, Toast.LENGTH_LONG).show() diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt index 0243b44a8c8..d5feffd1ffe 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt @@ -91,6 +91,7 @@ class RoomMemberProfileFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setupToolbar(views.matrixProfileToolbar) + .allowBack() val headerView = views.matrixProfileHeaderView.let { it.layoutResource = R.layout.view_stub_room_member_profile_header it.inflate() diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt index 7b920076924..4c6d2ed2e3d 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt @@ -23,12 +23,10 @@ import android.widget.Toast import androidx.lifecycle.lifecycleScope import com.airbnb.mvrx.Mavericks import com.airbnb.mvrx.viewModel -import com.google.android.material.appbar.MaterialToolbar import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment import im.vector.app.core.extensions.addFragmentToBackstack import im.vector.app.core.extensions.exhaustive -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleBinding import im.vector.app.features.home.room.detail.RoomDetailPendingActionStore @@ -47,8 +45,7 @@ import javax.inject.Inject @AndroidEntryPoint class RoomProfileActivity : - VectorBaseActivity(), - ToolbarConfigurable { + VectorBaseActivity() { companion object { @@ -157,8 +154,4 @@ class RoomProfileActivity : private fun openRoomNotificationSettings() { addFragmentToBackstack(views.simpleFragmentContainer, RoomNotificationSettingsFragment::class.java, roomProfileArgs) } - - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar) - } } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt index ee4d0601c61..217c18a6653 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt @@ -107,6 +107,7 @@ class RoomProfileFragment @Inject constructor( headerViews = ViewStubRoomProfileHeaderBinding.bind(headerView) setupWaitingView() setupToolbar(views.matrixProfileToolbar) + .allowBack() setupRecyclerView() appBarStateChangeListener = MatrixItemAppBarStateChangeListener( headerView, diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasFragment.kt index 3128a590cea..e48ce54e6c2 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasFragment.kt @@ -68,6 +68,7 @@ class RoomAliasFragment @Inject constructor( controller.callback = this setupToolbar(views.roomSettingsToolbar) + .allowBack() views.roomSettingsRecyclerView.configureWith(controller, hasFixedSize = true) views.waitingView.waitingStatusText.setText(R.string.please_wait) views.waitingView.waitingStatusText.isVisible = true diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/banned/RoomBannedMemberListFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/banned/RoomBannedMemberListFragment.kt index c9fc8892424..5cd4da009a2 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/banned/RoomBannedMemberListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/banned/RoomBannedMemberListFragment.kt @@ -59,6 +59,7 @@ class RoomBannedMemberListFragment @Inject constructor( super.onViewCreated(view, savedInstanceState) roomMemberListController.callback = this setupToolbar(views.roomSettingsToolbar) + .allowBack() setupSearchView() views.roomSettingsRecyclerView.configureWith(roomMemberListController, hasFixedSize = true) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListFragment.kt index ba7e020ebe3..d7a9ecf39b9 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListFragment.kt @@ -58,6 +58,7 @@ class RoomMemberListFragment @Inject constructor( super.onViewCreated(view, savedInstanceState) roomMemberListController.callback = this setupToolbar(views.roomSettingGeneric.roomSettingsToolbar) + .allowBack() setupSearchView() setupInviteUsersButton() views.roomSettingGeneric.roomSettingsRecyclerView.configureWith(roomMemberListController, hasFixedSize = true) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsFragment.kt index ce0fde32c65..320fdfd8331 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsFragment.kt @@ -50,6 +50,7 @@ class RoomNotificationSettingsFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setupToolbar(views.roomSettingsToolbar) + .allowBack() roomNotificationSettingsController.callback = this views.roomSettingsRecyclerView.configureWith(roomNotificationSettingsController, hasFixedSize = true) setupWaitingView() diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/permissions/RoomPermissionsFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/permissions/RoomPermissionsFragment.kt index acf01321c93..0d5ac7dea88 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/permissions/RoomPermissionsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/permissions/RoomPermissionsFragment.kt @@ -58,6 +58,7 @@ class RoomPermissionsFragment @Inject constructor( controller.callback = this setupToolbar(views.roomSettingsToolbar) + .allowBack() views.roomSettingsRecyclerView.configureWith(controller, hasFixedSize = true) views.waitingView.waitingStatusText.setText(R.string.please_wait) views.waitingView.waitingStatusText.isVisible = true diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsFragment.kt index 3fa0bbaa5b9..51f6b247d48 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsFragment.kt @@ -85,6 +85,7 @@ class RoomSettingsFragment @Inject constructor( setupRoomJoinRuleSharedActionViewModel() controller.callback = this setupToolbar(views.roomSettingsToolbar) + .allowBack() views.roomSettingsRecyclerView.configureWith(controller, hasFixedSize = true) views.waitingView.waitingStatusText.setText(R.string.please_wait) views.waitingView.waitingStatusText.isVisible = true diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/uploads/RoomUploadsFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/uploads/RoomUploadsFragment.kt index 3716d9682ce..3370125dc7d 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/uploads/RoomUploadsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/uploads/RoomUploadsFragment.kt @@ -68,6 +68,7 @@ class RoomUploadsFragment @Inject constructor( }.attach() setupToolbar(views.roomUploadsToolbar) + .allowBack() viewModel.observeViewEvents { when (it) { diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsActivity.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsActivity.kt index f502da24ffe..725c4ceabcc 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsActivity.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsActivity.kt @@ -63,7 +63,8 @@ class VectorSettingsActivity : VectorBaseActivity @Inject lateinit var session: Session override fun initUiAndData() { - configureToolbar(views.settingsToolbar) + setupToolbar(views.settingsToolbar) + .allowBack() if (isFirstCreation()) { // display the fragment diff --git a/vector/src/main/java/im/vector/app/features/share/IncomingShareActivity.kt b/vector/src/main/java/im/vector/app/features/share/IncomingShareActivity.kt index 294f1d4d916..439d9b64fa5 100644 --- a/vector/src/main/java/im/vector/app/features/share/IncomingShareActivity.kt +++ b/vector/src/main/java/im/vector/app/features/share/IncomingShareActivity.kt @@ -16,15 +16,13 @@ package im.vector.app.features.share -import com.google.android.material.appbar.MaterialToolbar import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleBinding @AndroidEntryPoint -class IncomingShareActivity : VectorBaseActivity(), ToolbarConfigurable { +class IncomingShareActivity : VectorBaseActivity() { override fun getBinding() = ActivitySimpleBinding.inflate(layoutInflater) @@ -35,8 +33,4 @@ class IncomingShareActivity : VectorBaseActivity(), Toolb addFragment(views.simpleFragmentContainer, IncomingShareFragment::class.java) } } - - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar, displayBack = false) - } } diff --git a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryFragment.kt b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryFragment.kt index f6303237903..40fa49b7a8a 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryFragment.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryFragment.kt @@ -100,12 +100,9 @@ class SpaceDirectoryFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - vectorBaseActivity.setSupportActionBar(views.toolbar) + setupToolbar(views.toolbar) + .allowBack() - vectorBaseActivity.supportActionBar?.let { - it.setDisplayShowHomeEnabled(true) - it.setDisplayHomeAsUpEnabled(true) - } epoxyController.listener = this views.spaceDirectoryList.configureWith(epoxyController) epoxyVisibilityTracker.attach(views.spaceDirectoryList) @@ -132,13 +129,11 @@ class SpaceDirectoryFragment @Inject constructor( if (currentParentId == null) { // it's the root - val title = getString(R.string.space_explore_activity_title) - views.toolbar.title = title + toolbar?.setTitle(R.string.space_explore_activity_title) } else { - val title = state.currentRootSummary?.name + toolbar?.title = state.currentRootSummary?.name ?: state.currentRootSummary?.canonicalAlias ?: getString(R.string.space_explore_activity_title) - views.toolbar.title = title } spaceCardRenderer.render(state.currentRootSummary, emptyList(), this, views.spaceCard) diff --git a/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedActivity.kt b/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedActivity.kt index 6076388289e..a3ce8cea310 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedActivity.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedActivity.kt @@ -26,7 +26,6 @@ import com.airbnb.mvrx.Loading import com.airbnb.mvrx.Mavericks import com.airbnb.mvrx.Success import com.airbnb.mvrx.viewModel -import com.google.android.material.appbar.MaterialToolbar import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.android.AndroidEntryPoint import im.vector.app.R @@ -34,15 +33,13 @@ import im.vector.app.core.error.ErrorFormatter import im.vector.app.core.extensions.hideKeyboard import im.vector.app.core.extensions.replaceFragment import im.vector.app.core.extensions.setTextOrHide -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleLoadingBinding import im.vector.app.features.spaces.SpaceBottomSheetSettingsArgs import javax.inject.Inject @AndroidEntryPoint -class SpaceLeaveAdvancedActivity : VectorBaseActivity(), - ToolbarConfigurable { +class SpaceLeaveAdvancedActivity : VectorBaseActivity() { override fun getBinding(): ActivitySimpleLoadingBinding = ActivitySimpleLoadingBinding.inflate(layoutInflater) @@ -113,8 +110,4 @@ class SpaceLeaveAdvancedActivity : VectorBaseActivity(), - ToolbarConfigurable { +class SpaceManageActivity : VectorBaseActivity() { private lateinit var sharedDirectoryActionViewModel: RoomDirectorySharedActionViewModel @@ -188,8 +185,4 @@ class SpaceManageActivity : VectorBaseActivity(), } } } - - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar) - } } diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsFragment.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsFragment.kt index 125686d200a..43657b6eb8d 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsFragment.kt @@ -66,8 +66,11 @@ class SpaceManageRoomsFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + setupToolbar(views.addRoomToSpaceToolbar) - views.appBarTitle.text = getString(R.string.space_manage_rooms_and_spaces) + .setTitle(R.string.space_manage_rooms_and_spaces) + .allowBack() + views.createNewRoom.isVisible = false epoxyController.listener = this views.roomList.configureWith(epoxyController, hasFixedSize = true, dividerDrawable = R.drawable.divider_horizontal) @@ -111,14 +114,15 @@ class SpaceManageRoomsFragment @Inject constructor( epoxyController.setData(state) state.spaceSummary.invoke()?.let { - views.appBarSpaceInfo.text = it.displayName + toolbar?.subtitle = it.displayName } + if (state.selectedRooms.isNotEmpty()) { if (currentActionMode == null) { views.addRoomToSpaceToolbar.isVisible = true vectorBaseActivity.startSupportActionMode(this) } else { - currentActionMode?.title = "${state.selectedRooms.size} selected" + toolbar?.title = "${state.selectedRooms.size} selected" } // views.addRoomToSpaceToolbar.isVisible = false // views.addRoomToSpaceToolbar.startActionMode(this) diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceSettingsFragment.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceSettingsFragment.kt index a3d0252c19c..266d08fd12e 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceSettingsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceSettingsFragment.kt @@ -85,6 +85,7 @@ class SpaceSettingsFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setupToolbar(views.roomSettingsToolbar) + .allowBack() // roomProfileSharedActionViewModel = activityViewModelProvider.get(RoomProfileSharedActionViewModel::class.java) // setupRoomHistoryVisibilitySharedActionViewModel() setupRoomJoinRuleSharedActionViewModel() diff --git a/vector/src/main/java/im/vector/app/features/spaces/people/SpacePeopleFragment.kt b/vector/src/main/java/im/vector/app/features/spaces/people/SpacePeopleFragment.kt index c5cfed69743..5b2d6bed7b4 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/people/SpacePeopleFragment.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/people/SpacePeopleFragment.kt @@ -64,9 +64,9 @@ class SpacePeopleFragment @Inject constructor( } override fun invalidate() = withState(membersViewModel) { memberListState -> - views.appBarTitle.text = getString(R.string.bottom_action_people) val memberCount = (memberListState.roomSummary.invoke()?.otherMemberIds?.size ?: 0) + 1 - views.appBarSpaceInfo.text = resources.getQuantityString(R.plurals.room_title_members, memberCount, memberCount) + + toolbar?.subtitle = resources.getQuantityString(R.plurals.room_title_members, memberCount, memberCount) // views.listBuildingProgress.isVisible = true epoxyController.setData(memberListState) } @@ -78,17 +78,12 @@ class SpacePeopleFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + + setupToolbar(views.addRoomToSpaceToolbar) + .allowBack() setupRecyclerView() setupSearchView() - views.addRoomToSpaceToolbar.navigationIcon = drawableProvider.getDrawable( - R.drawable.ic_close_24dp, - colorProvider.getColorFromAttribute(R.attr.vctr_content_primary) - ) - views.addRoomToSpaceToolbar.setNavigationOnClickListener { - sharedActionViewModel.post(SpacePeopleSharedAction.Dismiss) - } - viewModel.observeViewEvents { handleViewEvents(it) } diff --git a/vector/src/main/java/im/vector/app/features/usercode/ScanUserCodeFragment.kt b/vector/src/main/java/im/vector/app/features/usercode/ScanUserCodeFragment.kt index 389256871e9..a7d632bd7b2 100644 --- a/vector/src/main/java/im/vector/app/features/usercode/ScanUserCodeFragment.kt +++ b/vector/src/main/java/im/vector/app/features/usercode/ScanUserCodeFragment.kt @@ -55,6 +55,10 @@ class ScanUserCodeFragment @Inject constructor() : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + + setupToolbar(views.qrScannerToolbar) + .allowBack(useCross = true) + views.userCodeMyCodeButton.debouncedClicks { sharedViewModel.handle(UserCodeActions.SwitchMode(UserCodeState.Mode.SHOW)) } @@ -62,10 +66,6 @@ class ScanUserCodeFragment @Inject constructor() : views.userCodeOpenGalleryButton.debouncedClicks { MultiPicker.get(MultiPicker.IMAGE).single().startWith(pickImageActivityResultLauncher) } - - views.userCodeClose.debouncedClicks { - requireActivity().onBackPressed() - } } private val openCameraActivityResultLauncher = registerForPermissionsResult { allGranted, _ -> diff --git a/vector/src/main/java/im/vector/app/features/usercode/ShowUserCodeFragment.kt b/vector/src/main/java/im/vector/app/features/usercode/ShowUserCodeFragment.kt index b794b23d0ef..a31b0d3a25b 100644 --- a/vector/src/main/java/im/vector/app/features/usercode/ShowUserCodeFragment.kt +++ b/vector/src/main/java/im/vector/app/features/usercode/ShowUserCodeFragment.kt @@ -52,9 +52,9 @@ class ShowUserCodeFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - views.showUserCodeClose.debouncedClicks { - sharedViewModel.handle(UserCodeActions.DismissAction) - } + setupToolbar(views.showUserCodeToolBar) + .allowBack(useCross = true) + views.showUserCodeScanButton.debouncedClicks { if (checkPermissions(PERMISSIONS_FOR_TAKING_PHOTO, requireActivity(), openCameraActivityResultLauncher)) { doOpenQRCodeScanner() diff --git a/vector/src/main/java/im/vector/app/features/userdirectory/UserListFragment.kt b/vector/src/main/java/im/vector/app/features/userdirectory/UserListFragment.kt index 721bce4af9a..6ac6270fc7b 100644 --- a/vector/src/main/java/im/vector/app/features/userdirectory/UserListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/userdirectory/UserListFragment.kt @@ -72,9 +72,9 @@ class UserListFragment @Inject constructor( super.onViewCreated(view, savedInstanceState) sharedActionViewModel = activityViewModelProvider.get(UserListSharedActionViewModel::class.java) if (args.showToolbar) { - views.userListTitle.text = args.title - vectorBaseActivity.setSupportActionBar(views.userListToolbar) - setupCloseView() + setupToolbar(views.userListToolbar) + .setTitle(args.title) + .allowBack(useCross = true) views.userListToolbar.isVisible = true } else { views.userListToolbar.isVisible = false @@ -153,12 +153,6 @@ class UserListFragment @Inject constructor( views.userListSearch.requestFocus() } - private fun setupCloseView() { - views.userListClose.debouncedClicks { - requireActivity().finish() - } - } - override fun invalidate() = withState(viewModel) { userListController.setData(it) } diff --git a/vector/src/main/java/im/vector/app/features/webview/VectorWebViewActivity.kt b/vector/src/main/java/im/vector/app/features/webview/VectorWebViewActivity.kt index ab7913a99c6..fd26fff017f 100644 --- a/vector/src/main/java/im/vector/app/features/webview/VectorWebViewActivity.kt +++ b/vector/src/main/java/im/vector/app/features/webview/VectorWebViewActivity.kt @@ -44,7 +44,8 @@ class VectorWebViewActivity : VectorBaseActivity() } override fun initUiAndData() { - configureToolbar(views.webviewToolbar) + setupToolbar(views.webviewToolbar) + .allowBack() waitingView = views.simpleWebviewLoader views.simpleWebview.settings.apply { diff --git a/vector/src/main/java/im/vector/app/features/widgets/WidgetActivity.kt b/vector/src/main/java/im/vector/app/features/widgets/WidgetActivity.kt index 1e6d130c67c..963bd9521c8 100644 --- a/vector/src/main/java/im/vector/app/features/widgets/WidgetActivity.kt +++ b/vector/src/main/java/im/vector/app/features/widgets/WidgetActivity.kt @@ -22,11 +22,9 @@ import android.content.Intent import androidx.core.view.isVisible import com.airbnb.mvrx.Mavericks import com.airbnb.mvrx.viewModel -import com.google.android.material.appbar.MaterialToolbar import dagger.hilt.android.AndroidEntryPoint import im.vector.app.R import im.vector.app.core.extensions.addFragment -import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivityWidgetBinding import im.vector.app.features.widgets.permissions.RoomWidgetPermissionBottomSheet @@ -36,8 +34,7 @@ import org.matrix.android.sdk.api.session.events.model.Content import java.io.Serializable @AndroidEntryPoint -class WidgetActivity : VectorBaseActivity(), - ToolbarConfigurable { +class WidgetActivity : VectorBaseActivity() { companion object { private const val WIDGET_FRAGMENT_TAG = "WIDGET_FRAGMENT_TAG" @@ -77,7 +74,8 @@ class WidgetActivity : VectorBaseActivity(), finish() return } - configure(views.toolbar) + setupToolbar(views.toolbar) + .allowBack() views.toolbar.isVisible = widgetArgs.kind.nameRes != 0 viewModel.observeViewEvents { when (it) { @@ -129,8 +127,4 @@ class WidgetActivity : VectorBaseActivity(), } finish() } - - override fun configure(toolbar: MaterialToolbar) { - configureToolbar(toolbar) - } } diff --git a/vector/src/main/res/layout/activity_call.xml b/vector/src/main/res/layout/activity_call.xml index 2238f96c9fe..5734e5f92ab 100644 --- a/vector/src/main/res/layout/activity_call.xml +++ b/vector/src/main/res/layout/activity_call.xml @@ -41,10 +41,10 @@ android:layout_width="@dimen/call_pip_width" android:layout_height="@dimen/call_pip_height" android:layout_marginEnd="16dp" - app:layout_goneMarginEnd="0dp" app:cardCornerRadius="@dimen/call_pip_radius" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent"> + app:layout_constraintEnd_toEndOf="parent" + app:layout_goneMarginEnd="0dp"> + android:layout_height="?actionBarSize" + app:title="@string/contacts_book_title"/> - - - - - - - - - - + android:layout_height="?actionBarSize" + app:title="@string/direct_chats_header" /> - - - - - - - - - - + app:title="@string/create_poll_title" /> diff --git a/vector/src/main/res/layout/fragment_create_room.xml b/vector/src/main/res/layout/fragment_create_room.xml index 5607f2be698..7deb1786e16 100644 --- a/vector/src/main/res/layout/fragment_create_room.xml +++ b/vector/src/main/res/layout/fragment_create_room.xml @@ -19,46 +19,8 @@ - - - - - - - - - - + android:layout_height="?actionBarSize" + app:title="@string/direct_chats_header" /> diff --git a/vector/src/main/res/layout/fragment_home_detail.xml b/vector/src/main/res/layout/fragment_home_detail.xml index 7bdcbca5d50..b534b10dba4 100644 --- a/vector/src/main/res/layout/fragment_home_detail.xml +++ b/vector/src/main/res/layout/fragment_home_detail.xml @@ -86,19 +86,19 @@ @@ -16,49 +15,8 @@ - - - - - - - - - - - + android:layout_height="?actionBarSize" + app:title="@string/user_code_scan" /> - - - - - - - - - - + app:title="@string/bottom_action_people" + app:layout_scrollFlags="scroll|exitUntilCollapsed|snap|enterAlways"/> - - - - - - - - - - + android:minHeight="0dp" + app:title="@string/space_add_existing_rooms"/> - - - - - - - - + app:title="@string/pick_tings_to_leave" + app:layout_scrollFlags="scroll|exitUntilCollapsed|snap|enterAlways"/> + android:text="@string/select_spaces" + android:textAppearance="@style/Widget.Vector.TextView.ActionBarTitle" /> @@ -92,8 +92,8 @@ android:paddingEnd="16dp">