Introduce Navigator
This commit is contained in:
parent
6244913ab9
commit
e70a483d6b
|
@ -18,6 +18,7 @@ package im.vector.riotredesign.core.di
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Context.MODE_PRIVATE
|
||||
import androidx.fragment.app.Fragment
|
||||
import im.vector.matrix.android.api.Matrix
|
||||
import im.vector.riotredesign.core.error.ErrorFormatter
|
||||
import im.vector.riotredesign.core.resources.LocaleProvider
|
||||
|
@ -27,6 +28,8 @@ import im.vector.riotredesign.features.home.HomeRoomListObservableStore
|
|||
import im.vector.riotredesign.features.home.group.SelectedGroupStore
|
||||
import im.vector.riotredesign.features.home.room.list.AlphabeticalRoomComparator
|
||||
import im.vector.riotredesign.features.home.room.list.ChronologicalRoomComparator
|
||||
import im.vector.riotredesign.features.navigation.DefaultNavigator
|
||||
import im.vector.riotredesign.features.navigation.Navigator
|
||||
import im.vector.riotredesign.features.notifications.NotificationDrawerManager
|
||||
import org.koin.dsl.module.module
|
||||
|
||||
|
@ -78,5 +81,9 @@ class AppModule(private val context: Context) {
|
|||
Matrix.getInstance().currentSession!!
|
||||
}
|
||||
|
||||
factory { (fragment: Fragment) ->
|
||||
DefaultNavigator(fragment) as Navigator
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -294,7 +294,7 @@ abstract class VectorBaseActivity : BaseMvRxActivity() {
|
|||
* ========================================================================================== */
|
||||
|
||||
fun notImplemented(message: String = "") {
|
||||
toast(getString(R.string.not_implemented) + message.takeIf { message.isNotBlank() }.run { ": $message" })
|
||||
toast(getString(R.string.not_implemented) + message.takeIf { message.isNotBlank() }?.let { ": $it" })
|
||||
}
|
||||
|
||||
}
|
|
@ -28,9 +28,11 @@ import butterknife.Unbinder
|
|||
import com.airbnb.mvrx.BaseMvRxFragment
|
||||
import com.airbnb.mvrx.MvRx
|
||||
import com.bumptech.glide.util.Util.assertMainThread
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import im.vector.riotredesign.features.navigation.Navigator
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.disposables.Disposable
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.core.parameter.parametersOf
|
||||
import timber.log.Timber
|
||||
|
||||
abstract class VectorBaseFragment : BaseMvRxFragment(), OnBackPressed {
|
||||
|
@ -42,6 +44,12 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), OnBackPressed {
|
|||
activity as VectorBaseActivity
|
||||
}
|
||||
|
||||
/* ==========================================================================================
|
||||
* Navigator
|
||||
* ========================================================================================== */
|
||||
|
||||
protected val navigator: Navigator by inject { parametersOf(this) }
|
||||
|
||||
/* ==========================================================================================
|
||||
* Life cycle
|
||||
* ========================================================================================== */
|
||||
|
|
|
@ -52,7 +52,7 @@ class HomeDrawerFragment : VectorBaseFragment() {
|
|||
}
|
||||
}
|
||||
homeDrawerHeaderSettingsView.setOnClickListener {
|
||||
startActivity(VectorSettingsActivity.getIntent(requireContext(), "TODO"))
|
||||
navigator.openSettings()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,7 +53,7 @@ class HomeModule {
|
|||
}
|
||||
|
||||
scope(HOME_SCOPE) {
|
||||
HomePermalinkHandler(get())
|
||||
HomePermalinkHandler(get(), get())
|
||||
}
|
||||
|
||||
// Fragment scopes
|
||||
|
|
|
@ -21,8 +21,7 @@ import androidx.fragment.app.FragmentManager
|
|||
import im.vector.matrix.android.api.session.group.model.GroupSummary
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.extensions.replaceFragment
|
||||
import im.vector.riotredesign.features.home.room.detail.RoomDetailActivity
|
||||
import im.vector.riotredesign.features.home.room.detail.RoomDetailArgs
|
||||
import im.vector.riotredesign.features.navigation.Navigator
|
||||
import kotlinx.android.synthetic.main.activity_home.*
|
||||
import timber.log.Timber
|
||||
|
||||
|
@ -43,14 +42,13 @@ class HomeNavigator {
|
|||
}
|
||||
|
||||
fun openRoomDetail(roomId: String,
|
||||
eventId: String?) {
|
||||
eventId: String?,
|
||||
navigator: Navigator) {
|
||||
Timber.v("Open room detail $roomId - $eventId")
|
||||
activity?.let {
|
||||
//TODO enable eventId permalink. It doesn't work enough at the moment.
|
||||
it.drawerLayout?.closeDrawer(GravityCompat.START)
|
||||
val args = RoomDetailArgs(roomId)
|
||||
val roomDetailIntent = RoomDetailActivity.newIntent(it, args)
|
||||
it.startActivity(roomDetailIntent)
|
||||
navigator.openRoom(roomId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,10 @@ package im.vector.riotredesign.features.home
|
|||
import android.net.Uri
|
||||
import im.vector.matrix.android.api.permalinks.PermalinkData
|
||||
import im.vector.matrix.android.api.permalinks.PermalinkParser
|
||||
import im.vector.riotredesign.features.navigation.Navigator
|
||||
|
||||
class HomePermalinkHandler(private val navigator: HomeNavigator) {
|
||||
class HomePermalinkHandler(private val homeNavigator: HomeNavigator,
|
||||
private val navigator: Navigator) {
|
||||
|
||||
fun launch(deepLink: String?) {
|
||||
val uri = deepLink?.let { Uri.parse(it) }
|
||||
|
@ -34,16 +36,16 @@ class HomePermalinkHandler(private val navigator: HomeNavigator) {
|
|||
val permalinkData = PermalinkParser.parse(deepLink)
|
||||
when (permalinkData) {
|
||||
is PermalinkData.EventLink -> {
|
||||
navigator.openRoomDetail(permalinkData.roomIdOrAlias, permalinkData.eventId)
|
||||
homeNavigator.openRoomDetail(permalinkData.roomIdOrAlias, permalinkData.eventId, navigator)
|
||||
}
|
||||
is PermalinkData.RoomLink -> {
|
||||
navigator.openRoomDetail(permalinkData.roomIdOrAlias, null)
|
||||
homeNavigator.openRoomDetail(permalinkData.roomIdOrAlias, null, navigator)
|
||||
}
|
||||
is PermalinkData.GroupLink -> {
|
||||
navigator.openGroupDetail(permalinkData.groupId)
|
||||
homeNavigator.openGroupDetail(permalinkData.groupId)
|
||||
}
|
||||
is PermalinkData.UserLink -> {
|
||||
navigator.openUserDetail(permalinkData.userId)
|
||||
homeNavigator.openUserDetail(permalinkData.userId)
|
||||
}
|
||||
is PermalinkData.FallbackLink -> {
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ import im.vector.riotredesign.core.epoxy.LayoutManagerStateRestorer
|
|||
import im.vector.riotredesign.core.extensions.observeEvent
|
||||
import im.vector.riotredesign.core.platform.StateView
|
||||
import im.vector.riotredesign.core.platform.VectorBaseFragment
|
||||
import im.vector.riotredesign.features.home.HomeNavigator
|
||||
import im.vector.riotredesign.features.roomdirectory.RoomDirectoryActivity
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import kotlinx.android.synthetic.main.fragment_room_list.*
|
||||
|
@ -59,7 +58,6 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback {
|
|||
|
||||
private val roomListParams: RoomListParams by args()
|
||||
private val roomController by inject<RoomSummaryController>()
|
||||
private val homeNavigator by inject<HomeNavigator>()
|
||||
private val roomListViewModel: RoomListViewModel by fragmentViewModel()
|
||||
|
||||
override fun getLayoutResId() = R.layout.fragment_room_list
|
||||
|
@ -70,15 +68,14 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback {
|
|||
setupCreateRoomButton()
|
||||
roomListViewModel.subscribe { renderState(it) }
|
||||
roomListViewModel.openRoomLiveData.observeEvent(this) {
|
||||
homeNavigator.openRoomDetail(it, null)
|
||||
navigator.openRoom(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupCreateRoomButton() {
|
||||
createRoomButton.setImageResource(R.drawable.ic_add_white)
|
||||
createRoomButton.setOnClickListener {
|
||||
// Start Activity for now
|
||||
startActivity(Intent(requireActivity(), RoomDirectoryActivity::class.java))
|
||||
navigator.openRoomDirectory()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* 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.riotredesign.features.navigation
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import androidx.fragment.app.Fragment
|
||||
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
|
||||
import im.vector.riotredesign.features.home.room.detail.RoomDetailActivity
|
||||
import im.vector.riotredesign.features.home.room.detail.RoomDetailArgs
|
||||
import im.vector.riotredesign.features.roomdirectory.RoomDirectoryActivity
|
||||
import im.vector.riotredesign.features.roomdirectory.roompreview.RoomPreviewActivity
|
||||
import im.vector.riotredesign.features.settings.VectorSettingsActivity
|
||||
|
||||
class DefaultNavigator(private val fraqment: Fragment) : Navigator {
|
||||
|
||||
val activity: Activity = fraqment.requireActivity()
|
||||
|
||||
override fun openRoom(roomId: String) {
|
||||
val args = RoomDetailArgs(roomId)
|
||||
val intent = RoomDetailActivity.newIntent(activity, args)
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
|
||||
override fun openRoomPreview(publicRoom: PublicRoom) {
|
||||
val intent = RoomPreviewActivity.getIntent(activity, publicRoom)
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
|
||||
override fun openRoomDirectory() {
|
||||
val intent = Intent(activity, RoomDirectoryActivity::class.java)
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
|
||||
override fun openSettings() {
|
||||
val intent = VectorSettingsActivity.getIntent(activity, "TODO")
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
}
|
|
@ -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.riotredesign.features.navigation
|
||||
|
||||
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
|
||||
|
||||
interface Navigator {
|
||||
|
||||
fun openRoom(roomId: String)
|
||||
|
||||
fun openRoomPreview(publicRoom: PublicRoom)
|
||||
|
||||
fun openRoomDirectory()
|
||||
|
||||
fun openSettings()
|
||||
|
||||
}
|
|
@ -30,8 +30,6 @@ import im.vector.riotredesign.R
|
|||
import im.vector.riotredesign.core.error.ErrorFormatter
|
||||
import im.vector.riotredesign.core.extensions.addFragmentToBackstack
|
||||
import im.vector.riotredesign.core.platform.VectorBaseFragment
|
||||
import im.vector.riotredesign.features.home.room.detail.RoomDetailActivity
|
||||
import im.vector.riotredesign.features.home.room.detail.RoomDetailArgs
|
||||
import im.vector.riotredesign.features.roomdirectory.picker.RoomDirectoryPickerFragment
|
||||
import im.vector.riotredesign.features.roomdirectory.roompreview.RoomPreviewActivity
|
||||
import io.reactivex.rxkotlin.subscribeBy
|
||||
|
@ -122,14 +120,12 @@ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback
|
|||
|
||||
when (joinState) {
|
||||
JoinState.JOINED -> {
|
||||
val args = RoomDetailArgs(publicRoom.roomId)
|
||||
val roomDetailIntent = RoomDetailActivity.newIntent(requireActivity(), args)
|
||||
requireActivity().startActivity(roomDetailIntent)
|
||||
navigator.openRoom(publicRoom.roomId)
|
||||
}
|
||||
JoinState.NOT_JOINED,
|
||||
JoinState.JOINING_ERROR -> {
|
||||
// ROOM PREVIEW
|
||||
requireActivity().startActivity(RoomPreviewActivity.getIntent(requireActivity(), publicRoom))
|
||||
navigator.openRoomPreview(publicRoom)
|
||||
}
|
||||
else -> {
|
||||
Snackbar.make(publicRoomsCoordinator, getString(R.string.please_wait), Snackbar.LENGTH_SHORT)
|
||||
|
|
|
@ -93,8 +93,10 @@ class RoomPreviewNoPreviewFragment : VectorBaseFragment() {
|
|||
roomPreviewNoPreviewError.setTextOrHide(errorFormatter.toHumanReadable(state.lastError))
|
||||
|
||||
if (state.roomJoinState == JoinState.JOINED) {
|
||||
// TODO Quit this screen and open the room
|
||||
vectorBaseActivity.notImplemented("Open newly join room")
|
||||
// Quit this screen
|
||||
requireActivity().finish()
|
||||
// Open room
|
||||
navigator.openRoom(roomPreviewData.roomId)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue