From b44ddcfd61fa18c33de64b47283f2162e74a0223 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 15 Jan 2020 14:57:21 +0100 Subject: [PATCH] Clean code after Benoit's review #2 --- .../internal/session/profile/ProfileModule.kt | 4 ++-- vector/src/main/AndroidManifest.xml | 8 ++++++- ...fileItemAction.kt => ProfileActionItem.kt} | 2 +- .../epoxy/profiles/ProfileItemExtensions.kt | 4 ++-- ...leItemSection.kt => ProfileSectionItem.kt} | 2 +- .../RoomListQuickActionsEpoxyController.kt | 2 -- .../features/navigation/DefaultNavigator.kt | 22 +++++++++++-------- .../RoomMemberProfileFragment.kt | 6 ++--- 8 files changed, 28 insertions(+), 22 deletions(-) rename vector/src/main/java/im/vector/riotx/core/epoxy/profiles/{ProfileItemAction.kt => ProfileActionItem.kt} (96%) rename vector/src/main/java/im/vector/riotx/core/epoxy/profiles/{ProfileItemSection.kt => ProfileSectionItem.kt} (93%) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/profile/ProfileModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/profile/ProfileModule.kt index a3084033a3..7005a5341f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/profile/ProfileModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/profile/ProfileModule.kt @@ -38,8 +38,8 @@ internal abstract class ProfileModule { } @Binds - abstract fun bindProfileService(userService: DefaultProfileService): ProfileService + abstract fun bindProfileService(service: DefaultProfileService): ProfileService @Binds - abstract fun bindGetProfileTask(getProfileInfoTask: DefaultGetProfileInfoTask): GetProfileInfoTask + abstract fun bindGetProfileTask(task: DefaultGetProfileInfoTask): GetProfileInfoTask } diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index febdefdb16..a0d4402767 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -125,7 +125,13 @@ - + + + + diff --git a/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemAction.kt b/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileActionItem.kt similarity index 96% rename from vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemAction.kt rename to vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileActionItem.kt index 6d80a095d4..0a7dcb0de7 100644 --- a/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemAction.kt +++ b/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileActionItem.kt @@ -30,7 +30,7 @@ import im.vector.riotx.core.extensions.setTextOrHide import im.vector.riotx.features.themes.ThemeUtils @EpoxyModelClass(layout = R.layout.item_profile_action) -abstract class ProfileItemAction : VectorEpoxyModel() { +abstract class ProfileActionItem : VectorEpoxyModel() { @EpoxyAttribute lateinit var title: String diff --git a/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemExtensions.kt b/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemExtensions.kt index 78a7bea014..3a9fff52af 100644 --- a/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemExtensions.kt +++ b/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemExtensions.kt @@ -22,7 +22,7 @@ import com.airbnb.epoxy.EpoxyController import im.vector.riotx.core.epoxy.DividerItem_ fun EpoxyController.buildProfileSection(title: String) { - profileItemSection { + profileSectionItem { id("section_$title") title(title) } @@ -38,7 +38,7 @@ fun EpoxyController.buildProfileAction( divider: Boolean = true, action: () -> Unit ) { - profileItemAction { + profileActionItem { iconRes(icon) id("action_$id") subtitle(subtitle) diff --git a/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemSection.kt b/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileSectionItem.kt similarity index 93% rename from vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemSection.kt rename to vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileSectionItem.kt index f24fd96ebd..ea3e66ad03 100644 --- a/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemSection.kt +++ b/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileSectionItem.kt @@ -24,7 +24,7 @@ import im.vector.riotx.core.epoxy.VectorEpoxyHolder import im.vector.riotx.core.epoxy.VectorEpoxyModel @EpoxyModelClass(layout = R.layout.item_profile_section) -abstract class ProfileItemSection: VectorEpoxyModel() { +abstract class ProfileSectionItem: VectorEpoxyModel() { @EpoxyAttribute lateinit var title: String diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt b/vector/src/main/java/im/vector/riotx/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt index 2b7d87267e..0948490d12 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/list/actions/RoomListQuickActionsEpoxyController.kt @@ -64,8 +64,6 @@ class RoomListQuickActionsEpoxyController @Inject constructor(private val avatar id("leave_separator") } RoomListQuickActionsSharedAction.Leave(roomSummary.roomId).toBottomSheetItem(5) - - // Leave } } diff --git a/vector/src/main/java/im/vector/riotx/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/riotx/features/navigation/DefaultNavigator.kt index 4551b179a5..7ca6e94d70 100644 --- a/vector/src/main/java/im/vector/riotx/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/riotx/features/navigation/DefaultNavigator.kt @@ -56,16 +56,9 @@ class DefaultNavigator @Inject constructor( fatalError("Trying to open an unknown room $roomId", vectorPreferences.failFast()) return } - val args = RoomDetailArgs(roomId, eventId) val intent = RoomDetailActivity.newIntent(context, args) - if (buildTask) { - val stackBuilder = TaskStackBuilder.create(context) - stackBuilder.addNextIntentWithParentStack(intent) - stackBuilder.startActivities() - } else { - context.startActivity(intent) - } + startActivity(context, intent, buildTask) } override fun openNotJoinedRoom(context: Context, roomIdOrAlias: String?, eventId: String?, buildTask: Boolean) { @@ -86,7 +79,8 @@ class DefaultNavigator @Inject constructor( override fun openRoomMemberProfile(userId: String, roomId: String?, context: Context, buildTask: Boolean) { val args = RoomMemberProfileArgs(userId = userId, roomId = roomId) - context.startActivity(RoomMemberProfileActivity.newIntent(context, args)) + val intent = RoomMemberProfileActivity.newIntent(context, args) + startActivity(context, intent, buildTask) } override fun openRoomForSharing(activity: Activity, roomId: String, sharedData: SharedData) { @@ -141,4 +135,14 @@ class DefaultNavigator @Inject constructor( override fun openRoomProfile(context: Context, roomId: String) { context.startActivity(RoomProfileActivity.newIntent(context, roomId)) } + + private fun startActivity(context: Context, intent: Intent, buildTask: Boolean) { + if (buildTask) { + val stackBuilder = TaskStackBuilder.create(context) + stackBuilder.addNextIntentWithParentStack(intent) + stackBuilder.startActivities() + } else { + context.startActivity(intent) + } + } } diff --git a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileFragment.kt b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileFragment.kt index b8a6f247b2..23db6b53a8 100644 --- a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileFragment.kt @@ -15,8 +15,6 @@ * */ -@file:Suppress("DEPRECATION") - package im.vector.riotx.features.roommemberprofile import android.os.Bundle @@ -80,8 +78,8 @@ class RoomMemberProfileFragment @Inject constructor( .subscribe { dismissLoadingDialog() when (it) { - is RoomMemberProfileViewEvents.Loading -> showLoadingDialog(it.message) - is RoomMemberProfileViewEvents.Failure -> showErrorInSnackbar(it.throwable) + is RoomMemberProfileViewEvents.Loading -> showLoadingDialog(it.message) + is RoomMemberProfileViewEvents.Failure -> showErrorInSnackbar(it.throwable) } } .disposeOnDestroyView()