From fa67509ac286caab09151e83c3ae20858c3aae12 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 14 Nov 2019 15:34:50 +0100 Subject: [PATCH] Room profile: start initializing all the classes + move some packages --- vector/src/main/AndroidManifest.xml | 3 +- .../java/im/vector/riotx/AppStateHandler.kt | 4 +- .../im/vector/riotx/core/di/FragmentModule.kt | 12 +++- .../vector/riotx/core/di/ScreenComponent.kt | 2 +- .../vector/riotx/core/di/VectorComponent.kt | 2 +- .../vector/riotx/core/di/ViewModelModule.kt | 2 +- .../home => core/utils}/UserColor.kt | 2 +- .../createdirect/CreateDirectRoomAction.kt | 2 +- .../createdirect/CreateDirectRoomActivity.kt | 2 +- .../CreateDirectRoomDirectoryUsersFragment.kt | 2 +- .../CreateDirectRoomKnownUsersFragment.kt | 2 +- .../CreateDirectRoomLetterHeaderItem.kt | 2 +- .../CreateDirectRoomSharedAction.kt | 2 +- .../CreateDirectRoomSharedActionViewModel.kt | 2 +- .../createdirect/CreateDirectRoomUserItem.kt | 2 +- .../createdirect/CreateDirectRoomViewModel.kt | 2 +- .../createdirect/CreateDirectRoomViewState.kt | 2 +- .../createdirect/DirectoryUsersController.kt | 2 +- .../createdirect/KnownUsersController.kt | 2 +- .../group => grouplist}/GroupListAction.kt | 3 +- .../group => grouplist}/GroupListFragment.kt | 3 +- .../group => grouplist}/GroupListViewModel.kt | 3 +- .../group => grouplist}/GroupListViewState.kt | 2 +- .../GroupSummaryController.kt | 3 +- .../group => grouplist}/GroupSummaryItem.kt | 3 +- .../SelectedGroupDataSource.kt | 2 +- .../riotx/features/home/AvatarRenderer.kt | 1 + .../features/home/HomeDetailViewModel.kt | 2 +- .../riotx/features/home/HomeDrawerFragment.kt | 2 +- .../home/room/detail/RoomDetailFragment.kt | 24 +++++--- .../helper/MessageInformationDataFactory.kt | 5 +- .../home/room/list/RoomListFragment.kt | 2 +- .../features/navigation/DefaultNavigator.kt | 7 ++- .../riotx/features/navigation/Navigator.kt | 2 +- .../features/roomprofile/RoomProfileAction.kt | 23 ++++++++ .../roomprofile/RoomProfileActivity.kt | 51 +++++++++++++++++ .../roomprofile/RoomProfileController.kt | 31 ++++++++++ .../roomprofile/RoomProfileFragment.kt | 56 +++++++++++++++++++ .../roomprofile/RoomProfileViewModel.kt | 47 ++++++++++++++++ .../roomprofile/RoomProfileViewState.kt | 27 +++++++++ .../main/res/layout/fragment_room_detail.xml | 1 + .../main/res/layout/fragment_room_profile.xml | 14 +++++ 42 files changed, 318 insertions(+), 47 deletions(-) rename vector/src/main/java/im/vector/riotx/{features/home => core/utils}/UserColor.kt (97%) rename vector/src/main/java/im/vector/riotx/features/{home => }/createdirect/CreateDirectRoomAction.kt (95%) rename vector/src/main/java/im/vector/riotx/features/{home => }/createdirect/CreateDirectRoomActivity.kt (98%) rename vector/src/main/java/im/vector/riotx/features/{home => }/createdirect/CreateDirectRoomDirectoryUsersFragment.kt (98%) rename vector/src/main/java/im/vector/riotx/features/{home => }/createdirect/CreateDirectRoomKnownUsersFragment.kt (99%) rename vector/src/main/java/im/vector/riotx/features/{home => }/createdirect/CreateDirectRoomLetterHeaderItem.kt (96%) rename vector/src/main/java/im/vector/riotx/features/{home => }/createdirect/CreateDirectRoomSharedAction.kt (94%) rename vector/src/main/java/im/vector/riotx/features/{home => }/createdirect/CreateDirectRoomSharedActionViewModel.kt (94%) rename vector/src/main/java/im/vector/riotx/features/{home => }/createdirect/CreateDirectRoomUserItem.kt (98%) rename vector/src/main/java/im/vector/riotx/features/{home => }/createdirect/CreateDirectRoomViewModel.kt (99%) rename vector/src/main/java/im/vector/riotx/features/{home => }/createdirect/CreateDirectRoomViewState.kt (96%) rename vector/src/main/java/im/vector/riotx/features/{home => }/createdirect/DirectoryUsersController.kt (98%) rename vector/src/main/java/im/vector/riotx/features/{home => }/createdirect/KnownUsersController.kt (98%) rename vector/src/main/java/im/vector/riotx/features/{home/group => grouplist}/GroupListAction.kt (94%) rename vector/src/main/java/im/vector/riotx/features/{home/group => grouplist}/GroupListFragment.kt (98%) rename vector/src/main/java/im/vector/riotx/features/{home/group => grouplist}/GroupListViewModel.kt (99%) rename vector/src/main/java/im/vector/riotx/features/{home/group => grouplist}/GroupListViewState.kt (95%) rename vector/src/main/java/im/vector/riotx/features/{home/group => grouplist}/GroupSummaryController.kt (97%) rename vector/src/main/java/im/vector/riotx/features/{home/group => grouplist}/GroupSummaryItem.kt (97%) rename vector/src/main/java/im/vector/riotx/features/{home/group => grouplist}/SelectedGroupDataSource.kt (95%) create mode 100644 vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileAction.kt create mode 100644 vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileActivity.kt create mode 100644 vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileController.kt create mode 100644 vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt create mode 100644 vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewModel.kt create mode 100644 vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewState.kt create mode 100644 vector/src/main/res/layout/fragment_room_profile.xml diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index 0c9bac61a1..6c6e918e1b 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -65,7 +65,7 @@ - + @@ -96,6 +96,7 @@ + { val eventId = data.getStringExtra(EmojiReactionPickerActivity.EXTRA_EVENT_ID) - ?: return + ?: return val reaction = data.getStringExtra(EmojiReactionPickerActivity.EXTRA_REACTION_RESULT) - ?: return + ?: return // TODO check if already reacted with that? roomDetailViewModel.handle(RoomDetailAction.SendReaction(eventId, reaction)) } @@ -1176,7 +1181,8 @@ class RoomDetailFragment @Inject constructor( // current user if (composerLayout.composerEditText.text.isNullOrBlank()) { composerLayout.composerEditText.append(Command.EMOTE.command + " ") - composerLayout.composerEditText.setSelection(composerLayout.composerEditText.text?.length ?: 0) + composerLayout.composerEditText.setSelection(composerLayout.composerEditText.text?.length + ?: 0) // vibrate = true } } else { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt index e44e657733..a7e081a165 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt @@ -24,7 +24,7 @@ import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.session.room.timeline.hasBeenEdited import im.vector.riotx.core.extensions.localDateTime import im.vector.riotx.core.resources.ColorProvider -import im.vector.riotx.features.home.getColorFromUserId +import im.vector.riotx.core.utils.getColorFromUserId import im.vector.riotx.core.date.VectorDateFormatter import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData import im.vector.riotx.features.home.room.detail.timeline.item.ReactionInfoData @@ -60,7 +60,8 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses val avatarUrl = event.senderAvatar val memberName = event.getDisambiguatedDisplayName() val formattedMemberName = span(memberName) { - textColor = colorProvider.getColor(getColorFromUserId(event.root.senderId ?: "")) + textColor = colorProvider.getColor(getColorFromUserId(event.root.senderId + ?: "")) } val displayReadMarker = readMarkerVisible && event.hasReadMarker diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListFragment.kt index a5e9a7b4bf..9e6d5533f6 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListFragment.kt @@ -229,7 +229,7 @@ class RoomListFragment @Inject constructor( roomListViewModel.handle(RoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.MUTE)) } is RoomListQuickActionsSharedAction.Settings -> { - vectorBaseActivity.notImplemented("Opening room settings") + navigator.openRoomProfile(requireActivity(), quickAction.roomId) } is RoomListQuickActionsSharedAction.Leave -> { AlertDialog.Builder(requireContext()) 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 685fa04fef..8c5fc57e6d 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 @@ -26,13 +26,14 @@ import im.vector.riotx.core.utils.toast import im.vector.riotx.features.crypto.keysbackup.settings.KeysBackupManageActivity import im.vector.riotx.features.crypto.keysbackup.setup.KeysBackupSetupActivity import im.vector.riotx.features.debug.DebugMenuActivity -import im.vector.riotx.features.home.createdirect.CreateDirectRoomActivity +import im.vector.riotx.features.createdirect.CreateDirectRoomActivity import im.vector.riotx.features.home.room.detail.RoomDetailActivity import im.vector.riotx.features.home.room.detail.RoomDetailArgs import im.vector.riotx.features.home.room.filtered.FilteredRoomsActivity import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity import im.vector.riotx.features.roomdirectory.createroom.CreateRoomActivity import im.vector.riotx.features.roomdirectory.roompreview.RoomPreviewActivity +import im.vector.riotx.features.roomprofile.RoomProfileActivity import im.vector.riotx.features.settings.VectorSettingsActivity import im.vector.riotx.features.share.SharedData import timber.log.Timber @@ -113,7 +114,7 @@ class DefaultNavigator @Inject constructor() : Navigator { Timber.v("Open user detail $userId") } - override fun openRoomSettings(context: Context, roomId: String) { - Timber.v("Open room settings$roomId") + override fun openRoomProfile(context: Context, roomId: String) { + context.startActivity(RoomProfileActivity.newIntent(context, roomId)) } } diff --git a/vector/src/main/java/im/vector/riotx/features/navigation/Navigator.kt b/vector/src/main/java/im/vector/riotx/features/navigation/Navigator.kt index 83c4f7ce20..987dc6364e 100644 --- a/vector/src/main/java/im/vector/riotx/features/navigation/Navigator.kt +++ b/vector/src/main/java/im/vector/riotx/features/navigation/Navigator.kt @@ -51,5 +51,5 @@ interface Navigator { fun openUserDetail(userId: String, context: Context) - fun openRoomSettings(context: Context, roomId: String) + fun openRoomProfile(context: Context, roomId: String) } diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileAction.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileAction.kt new file mode 100644 index 0000000000..979a9d2a57 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileAction.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package im.vector.riotx.features.roomprofile + +import im.vector.riotx.core.platform.VectorViewModelAction + +sealed class RoomProfileAction: VectorViewModelAction { +} diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileActivity.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileActivity.kt new file mode 100644 index 0000000000..2c2d2b795d --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileActivity.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package im.vector.riotx.features.roomprofile + +import android.content.Context +import android.content.Intent +import im.vector.riotx.R +import im.vector.riotx.core.extensions.addFragment +import im.vector.riotx.core.platform.VectorBaseActivity + +class RoomProfileActivity : VectorBaseActivity() { + + companion object { + + private const val EXTRA_ROOM_PROFILE_ARGS = "EXTRA_ROOM_PROFILE_ARGS" + + fun newIntent(context: Context, roomId: String): Intent { + val roomProfileArgs = RoomProfileArgs(roomId) + return Intent(context, RoomProfileActivity::class.java).apply { + putExtra(EXTRA_ROOM_PROFILE_ARGS, roomProfileArgs) + } + } + } + + override fun getLayoutRes() = R.layout.activity_simple + + override fun initUiAndData() { + if (isFirstCreation()) { + val roomProfileArgs: RoomProfileArgs = intent?.extras?.getParcelable(EXTRA_ROOM_PROFILE_ARGS) + ?: return + addFragment(R.id.simpleFragmentContainer, RoomProfileFragment::class.java, roomProfileArgs) + } + } + + +} diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileController.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileController.kt new file mode 100644 index 0000000000..7ef39131f2 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileController.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package im.vector.riotx.features.roomprofile + +import com.airbnb.epoxy.TypedEpoxyController +import javax.inject.Inject + +class RoomProfileController @Inject constructor() + : TypedEpoxyController() { + + override fun buildModels(data: RoomProfileViewState?) { + if (data == null) { + return + } + } +} diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt new file mode 100644 index 0000000000..6501bfc2bb --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package im.vector.riotx.features.roomprofile + +import android.os.Bundle +import android.os.Parcelable +import android.view.View +import com.airbnb.epoxy.EpoxyController +import com.airbnb.mvrx.args +import com.airbnb.mvrx.fragmentViewModel +import com.airbnb.mvrx.withState +import im.vector.riotx.R +import im.vector.riotx.core.platform.VectorBaseFragment +import kotlinx.android.parcel.Parcelize +import javax.inject.Inject + +@Parcelize +data class RoomProfileArgs( + val roomId: String +) : Parcelable + +class RoomProfileFragment @Inject constructor( + private val roomProfileController: RoomProfileController, + val roomProfileViewModelFactory: RoomProfileViewModel.Factory +) : VectorBaseFragment() { + + private val roomProfileArgs: RoomProfileArgs by args() + private val roomProfileViewModel: RoomProfileViewModel by fragmentViewModel() + + override fun getLayoutResId() = R.layout.fragment_room_profile + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + } + + override fun invalidate() = withState(roomProfileViewModel) { + roomProfileController.setData(it) + } + + +} diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewModel.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewModel.kt new file mode 100644 index 0000000000..ca796d1e2e --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewModel.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package im.vector.riotx.features.roomprofile + +import com.airbnb.mvrx.FragmentViewModelContext +import com.airbnb.mvrx.MvRxViewModelFactory +import com.airbnb.mvrx.ViewModelContext +import com.squareup.inject.assisted.Assisted +import com.squareup.inject.assisted.AssistedInject +import im.vector.riotx.core.platform.VectorViewModel + +class RoomProfileViewModel @AssistedInject constructor(@Assisted initialState: RoomProfileViewState) + : VectorViewModel(initialState) { + + @AssistedInject.Factory + interface Factory { + fun create(initialState: RoomProfileViewState): RoomProfileViewModel + } + + companion object : MvRxViewModelFactory { + + @JvmStatic + override fun create(viewModelContext: ViewModelContext, state: RoomProfileViewState): RoomProfileViewModel? { + val fragment: RoomProfileFragment = (viewModelContext as FragmentViewModelContext).fragment() + return fragment.roomProfileViewModelFactory.create(state) + } + } + + override fun handle(action: RoomProfileAction) { + } + +} diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewState.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewState.kt new file mode 100644 index 0000000000..a54fc2c8fb --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewState.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package im.vector.riotx.features.roomprofile + +import com.airbnb.mvrx.MvRxState + +data class RoomProfileViewState( + val roomId: String +) : MvRxState { + + constructor(args: RoomProfileArgs) : this(roomId = args.roomId) +} diff --git a/vector/src/main/res/layout/fragment_room_detail.xml b/vector/src/main/res/layout/fragment_room_detail.xml index 6661674edb..90455f0572 100644 --- a/vector/src/main/res/layout/fragment_room_detail.xml +++ b/vector/src/main/res/layout/fragment_room_detail.xml @@ -18,6 +18,7 @@ app:layout_constraintTop_toTopOf="parent"> diff --git a/vector/src/main/res/layout/fragment_room_profile.xml b/vector/src/main/res/layout/fragment_room_profile.xml new file mode 100644 index 0000000000..2fe7ce2b2f --- /dev/null +++ b/vector/src/main/res/layout/fragment_room_profile.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file