forked from GitHub-Mirror/riotX-android
Start thinking about navigation. WIP
This commit is contained in:
parent
aec620fb50
commit
337fd075dd
@ -0,0 +1,39 @@
|
||||
package im.vector.riotredesign.core
|
||||
|
||||
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.home.HomeNavigator
|
||||
|
||||
class HomePermalinkNavigator(private val navigator: HomeNavigator) {
|
||||
|
||||
fun launch(deepLink: String?) {
|
||||
val uri = deepLink?.let { Uri.parse(it) }
|
||||
launch(uri)
|
||||
}
|
||||
|
||||
fun launch(deepLink: Uri?) {
|
||||
if (deepLink == null) {
|
||||
return
|
||||
}
|
||||
val permalinkData = PermalinkParser.parse(deepLink)
|
||||
when (permalinkData) {
|
||||
is PermalinkData.EventLink -> {
|
||||
navigator.openRoomDetail(permalinkData.roomIdOrAlias, permalinkData.eventId)
|
||||
}
|
||||
is PermalinkData.RoomLink -> {
|
||||
navigator.openRoomDetail(permalinkData.roomIdOrAlias, null )
|
||||
}
|
||||
is PermalinkData.GroupLink -> {
|
||||
navigator.openGroupDetail(permalinkData.groupId)
|
||||
}
|
||||
is PermalinkData.UserLink -> {
|
||||
navigator.openUserDetail(permalinkData.userId)
|
||||
}
|
||||
is PermalinkData.FallbackLink -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package im.vector.riotredesign.features.home
|
||||
|
||||
import im.vector.matrix.android.api.permalinks.PermalinkData
|
||||
import im.vector.matrix.android.api.session.group.model.GroupSummary
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
|
||||
@ -9,6 +10,8 @@ sealed class HomeActions {
|
||||
|
||||
data class SelectGroup(val groupSummary: GroupSummary) : HomeActions()
|
||||
|
||||
data class PermalinkClicked(val permalinkData: PermalinkData) : HomeActions()
|
||||
|
||||
object RoomDisplayed : HomeActions()
|
||||
|
||||
}
|
@ -18,11 +18,11 @@ import im.vector.riotredesign.features.home.room.detail.LoadingRoomDetailFragmen
|
||||
import im.vector.riotredesign.features.home.room.detail.RoomDetailFragment
|
||||
import kotlinx.android.synthetic.main.activity_home.*
|
||||
import org.koin.standalone.StandAloneContext.loadKoinModules
|
||||
import timber.log.Timber
|
||||
|
||||
|
||||
class HomeActivity : RiotActivity(), HomeNavigator, ToolbarConfigurable {
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
loadKoinModules(listOf(HomeModule(this).definition))
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -64,7 +64,9 @@ class HomeActivity : RiotActivity(), HomeNavigator, ToolbarConfigurable {
|
||||
}
|
||||
}
|
||||
|
||||
override fun openRoomDetail(roomId: String) {
|
||||
// HomeNavigator *******************************************************************************
|
||||
|
||||
override fun openRoomDetail(roomId: String, eventId: String?) {
|
||||
val roomDetailFragment = RoomDetailFragment.newInstance(roomId)
|
||||
if (drawerLayout.isDrawerOpen(Gravity.LEFT)) {
|
||||
closeDrawerLayout(Gravity.LEFT) { replaceFragment(roomDetailFragment, R.id.homeDetailFragmentContainer) }
|
||||
@ -73,6 +75,14 @@ class HomeActivity : RiotActivity(), HomeNavigator, ToolbarConfigurable {
|
||||
}
|
||||
}
|
||||
|
||||
override fun openGroupDetail(groupId: String) {
|
||||
Timber.v("Open group detail $groupId")
|
||||
}
|
||||
|
||||
override fun openUserDetail(userId: String) {
|
||||
Timber.v("Open user detail $userId")
|
||||
}
|
||||
|
||||
private fun closeDrawerLayout(gravity: Int, actionOnClose: () -> Unit) {
|
||||
drawerLayout.addDrawerListener(object : DrawerLayout.SimpleDrawerListener() {
|
||||
override fun onDrawerClosed(p0: View) {
|
||||
|
@ -2,6 +2,10 @@ package im.vector.riotredesign.features.home
|
||||
|
||||
interface HomeNavigator {
|
||||
|
||||
fun openRoomDetail(roomId: String)
|
||||
fun openRoomDetail(roomId: String, eventId: String?)
|
||||
|
||||
fun openGroupDetail(groupId: String)
|
||||
|
||||
fun openUserDetail(userId: String)
|
||||
|
||||
}
|
@ -47,11 +47,11 @@ class RoomListFragment : RiotFragment(), RoomSummaryController.Callback {
|
||||
private fun renderState(state: HomeViewState) {
|
||||
when (state.asyncRooms) {
|
||||
is Incomplete -> renderLoading()
|
||||
is Success -> renderSuccess(state)
|
||||
is Fail -> renderFailure(state.asyncRooms.error)
|
||||
is Success -> renderSuccess(state)
|
||||
is Fail -> renderFailure(state.asyncRooms.error)
|
||||
}
|
||||
if (state.shouldOpenRoomDetail && state.selectedRoom != null) {
|
||||
homeNavigator.openRoomDetail(state.selectedRoom.roomId)
|
||||
homeNavigator.openRoomDetail(state.selectedRoom.roomId, null)
|
||||
viewModel.accept(HomeActions.RoomDisplayed)
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,7 @@ class RoomListFragment : RiotFragment(), RoomSummaryController.Callback {
|
||||
private fun renderFailure(error: Throwable) {
|
||||
val message = when (error) {
|
||||
is Failure.NetworkConnection -> getString(R.string.error_no_network)
|
||||
else -> getString(R.string.error_common)
|
||||
else -> getString(R.string.error_common)
|
||||
}
|
||||
stateView.state = StateView.State.Error(message)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user