From 61bb4c04271b9407e5107da880f77d46d41972e4 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 15 Jul 2019 17:22:46 +0200 Subject: [PATCH] Introduce CreateRoomActivity, a simple container for [CreateRoomFragment] --- vector/src/main/AndroidManifest.xml | 1 + .../vector/riotx/core/di/ScreenComponent.kt | 3 + .../home/room/list/RoomListFragment.kt | 4 +- .../features/navigation/DefaultNavigator.kt | 6 ++ .../riotx/features/navigation/Navigator.kt | 2 + .../createroom/CreateRoomActivity.kt | 72 +++++++++++++++++++ 6 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 vector/src/main/java/im/vector/riotx/features/roomdirectory/createroom/CreateRoomActivity.kt diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index c7cf4c2b0e..e0deced966 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -58,6 +58,7 @@ + diff --git a/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt b/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt index c54cb9425f..a42eec4940 100644 --- a/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt +++ b/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt @@ -51,6 +51,7 @@ import im.vector.riotx.features.rageshake.RageShake import im.vector.riotx.features.reactions.EmojiReactionPickerActivity import im.vector.riotx.features.roomdirectory.PublicRoomsFragment import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity +import im.vector.riotx.features.roomdirectory.createroom.CreateRoomActivity import im.vector.riotx.features.roomdirectory.createroom.CreateRoomFragment import im.vector.riotx.features.roomdirectory.picker.RoomDirectoryPickerFragment import im.vector.riotx.features.roomdirectory.roompreview.RoomPreviewNoPreviewFragment @@ -136,6 +137,8 @@ interface ScreenComponent { fun inject(filteredRoomsActivity: FilteredRoomsActivity) + fun inject(createRoomActivity: CreateRoomActivity) + fun inject(vectorInviteView: VectorInviteView) fun inject(videoMediaViewerActivity: VideoMediaViewerActivity) 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 082a70e384..491b0f4e68 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 @@ -266,9 +266,9 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Listener, O roomListViewModel.accept(RoomListActions.ToggleCategory(roomCategory)) } + // TODO Pass title override fun createRoom() { - // TODO Create an Activity to host CreateRoomFragment - navigator.openRoomDirectory(requireActivity()) + navigator.openCreateRoom(requireActivity()) } } \ No newline at end of file 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 1184fa5e53..c9af93a369 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 @@ -29,6 +29,7 @@ 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.settings.VectorSettingsActivity import timber.log.Timber @@ -62,6 +63,11 @@ class DefaultNavigator @Inject constructor() : Navigator { context.startActivity(intent) } + override fun openCreateRoom(context: Context) { + val intent = CreateRoomActivity.getIntent(context) + context.startActivity(intent) + } + override fun openRoomsFiltering(context: Context) { val intent = FilteredRoomsActivity.newIntent(context) context.startActivity(intent) 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 d4ad546c08..48f771184e 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 @@ -27,6 +27,8 @@ interface Navigator { fun openRoomPreview(publicRoom: PublicRoom, context: Context) + fun openCreateRoom(context: Context) + fun openRoomDirectory(context: Context) fun openRoomsFiltering(context: Context) diff --git a/vector/src/main/java/im/vector/riotx/features/roomdirectory/createroom/CreateRoomActivity.kt b/vector/src/main/java/im/vector/riotx/features/roomdirectory/createroom/CreateRoomActivity.kt new file mode 100644 index 0000000000..ffc342d8a4 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/roomdirectory/createroom/CreateRoomActivity.kt @@ -0,0 +1,72 @@ +/* + * 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.roomdirectory.createroom + +import android.content.Context +import android.content.Intent +import android.os.Bundle +import androidx.appcompat.widget.Toolbar +import androidx.lifecycle.ViewModelProviders +import im.vector.riotx.R +import im.vector.riotx.core.di.ScreenComponent +import im.vector.riotx.core.extensions.addFragment +import im.vector.riotx.core.extensions.observeEvent +import im.vector.riotx.core.platform.ToolbarConfigurable +import im.vector.riotx.core.platform.VectorBaseActivity +import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity +import im.vector.riotx.features.roomdirectory.RoomDirectoryNavigationViewModel + +/** + * Simple container for [CreateRoomFragment] + */ +class CreateRoomActivity : VectorBaseActivity(), ToolbarConfigurable { + + private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel + + override fun getLayoutRes() = R.layout.activity_simple + + override fun configure(toolbar: Toolbar) { + configureToolbar(toolbar) + } + + override fun initUiAndData() { + if (isFirstCreation()) { + addFragment(CreateRoomFragment(), R.id.simpleFragmentContainer) + } + } + + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + navigationViewModel = ViewModelProviders.of(this, viewModelFactory).get(RoomDirectoryNavigationViewModel::class.java) + navigationViewModel.navigateTo.observeEvent(this) { navigation -> + when (navigation) { + is RoomDirectoryActivity.Navigation.Back -> finish() + } + } + } + + companion object { + fun getIntent(context: Context): Intent { + return Intent(context, CreateRoomActivity::class.java) + } + } + +} \ No newline at end of file