forked from GitHub-Mirror/riotX-android
Add to backstack when navigating from permalink in room details
This commit is contained in:
parent
84645c17c8
commit
14fc75a5f3
@ -35,5 +35,9 @@ class HomeModule(private val homeActivity: HomeActivity) {
|
|||||||
SelectedGroupHolder()
|
SelectedGroupHolder()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
single {
|
||||||
|
HomePermalinkHandler(get())
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,9 @@
|
|||||||
package im.vector.riotredesign.features.home
|
package im.vector.riotredesign.features.home
|
||||||
|
|
||||||
|
import android.support.v4.app.FragmentManager
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
|
import im.vector.riotredesign.core.extensions.addFragmentToBackstack
|
||||||
import im.vector.riotredesign.core.extensions.replaceFragment
|
import im.vector.riotredesign.core.extensions.replaceFragment
|
||||||
import im.vector.riotredesign.features.home.room.detail.RoomDetailArgs
|
import im.vector.riotredesign.features.home.room.detail.RoomDetailArgs
|
||||||
import im.vector.riotredesign.features.home.room.detail.RoomDetailFragment
|
import im.vector.riotredesign.features.home.room.detail.RoomDetailFragment
|
||||||
@ -14,8 +16,11 @@ class HomeNavigator {
|
|||||||
|
|
||||||
private var currentRoomId: String? = null
|
private var currentRoomId: String? = null
|
||||||
|
|
||||||
fun openRoomDetail(roomId: String, eventId: String?) {
|
fun openRoomDetail(roomId: String,
|
||||||
if (isRoomOpened(roomId)) {
|
eventId: String?,
|
||||||
|
addToBackstack: Boolean = false) {
|
||||||
|
Timber.v("Open room detail $roomId - $eventId - $addToBackstack")
|
||||||
|
if (!addToBackstack && isRoomOpened(roomId)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentRoomId = roomId
|
currentRoomId = roomId
|
||||||
@ -23,7 +28,12 @@ class HomeNavigator {
|
|||||||
val args = RoomDetailArgs(roomId, eventId)
|
val args = RoomDetailArgs(roomId, eventId)
|
||||||
val roomDetailFragment = RoomDetailFragment.newInstance(args)
|
val roomDetailFragment = RoomDetailFragment.newInstance(args)
|
||||||
it.drawerLayout?.closeDrawer(Gravity.LEFT)
|
it.drawerLayout?.closeDrawer(Gravity.LEFT)
|
||||||
it.replaceFragment(roomDetailFragment, R.id.homeDetailFragmentContainer)
|
if (addToBackstack) {
|
||||||
|
it.addFragmentToBackstack(roomDetailFragment, R.id.homeDetailFragmentContainer, roomId)
|
||||||
|
} else {
|
||||||
|
clearBackStack(it.supportFragmentManager)
|
||||||
|
it.replaceFragment(roomDetailFragment, R.id.homeDetailFragmentContainer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,4 +49,11 @@ class HomeNavigator {
|
|||||||
return currentRoomId == roomId
|
return currentRoomId == roomId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun clearBackStack(fragmentManager: FragmentManager) {
|
||||||
|
if (fragmentManager.backStackEntryCount > 0) {
|
||||||
|
val first = fragmentManager.getBackStackEntryAt(0)
|
||||||
|
fragmentManager.popBackStack(first.id, FragmentManager.POP_BACK_STACK_INCLUSIVE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,17 +8,18 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.airbnb.mvrx.args
|
import com.airbnb.mvrx.args
|
||||||
import com.airbnb.mvrx.fragmentViewModel
|
import com.airbnb.mvrx.fragmentViewModel
|
||||||
import im.vector.matrix.android.api.permalinks.PermalinkParser
|
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
import im.vector.riotredesign.core.platform.RiotFragment
|
import im.vector.riotredesign.core.platform.RiotFragment
|
||||||
import im.vector.riotredesign.core.platform.ToolbarConfigurable
|
import im.vector.riotredesign.core.platform.ToolbarConfigurable
|
||||||
import im.vector.riotredesign.features.home.AvatarRenderer
|
import im.vector.riotredesign.features.home.AvatarRenderer
|
||||||
|
import im.vector.riotredesign.features.home.HomePermalinkHandler
|
||||||
import im.vector.riotredesign.features.home.room.detail.timeline.TimelineEventController
|
import im.vector.riotredesign.features.home.room.detail.timeline.TimelineEventController
|
||||||
import kotlinx.android.parcel.Parcelize
|
import kotlinx.android.parcel.Parcelize
|
||||||
import kotlinx.android.synthetic.main.fragment_room_detail.*
|
import kotlinx.android.synthetic.main.fragment_room_detail.*
|
||||||
import org.koin.android.ext.android.inject
|
import org.koin.android.ext.android.inject
|
||||||
import org.koin.core.parameter.parametersOf
|
import org.koin.core.parameter.parametersOf
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class RoomDetailArgs(
|
data class RoomDetailArgs(
|
||||||
@ -41,6 +42,7 @@ class RoomDetailFragment : RiotFragment(), TimelineEventController.Callback {
|
|||||||
private val roomDetailArgs: RoomDetailArgs by args()
|
private val roomDetailArgs: RoomDetailArgs by args()
|
||||||
|
|
||||||
private val timelineEventController by inject<TimelineEventController> { parametersOf(roomDetailArgs.roomId) }
|
private val timelineEventController by inject<TimelineEventController> { parametersOf(roomDetailArgs.roomId) }
|
||||||
|
private val homePermalinkHandler by inject<HomePermalinkHandler>()
|
||||||
private lateinit var scrollOnNewMessageCallback: ScrollOnNewMessageCallback
|
private lateinit var scrollOnNewMessageCallback: ScrollOnNewMessageCallback
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
@ -70,16 +72,18 @@ class RoomDetailFragment : RiotFragment(), TimelineEventController.Callback {
|
|||||||
|
|
||||||
private fun setupRecyclerView() {
|
private fun setupRecyclerView() {
|
||||||
val layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
|
val layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
|
||||||
scrollOnNewMessageCallback = ScrollOnNewMessageCallback(layoutManager)
|
//scrollOnNewMessageCallback = ScrollOnNewMessageCallback(layoutManager)
|
||||||
recyclerView.layoutManager = layoutManager
|
recyclerView.layoutManager = layoutManager
|
||||||
timelineEventController.addModelBuildListener { it.dispatchTo(scrollOnNewMessageCallback) }
|
//timelineEventController.addModelBuildListener { it.dispatchTo(scrollOnNewMessageCallback) }
|
||||||
recyclerView.setController(timelineEventController)
|
recyclerView.setController(timelineEventController)
|
||||||
timelineEventController.callback = this
|
timelineEventController.callback = this
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderState(state: RoomDetailViewState) {
|
private fun renderState(state: RoomDetailViewState) {
|
||||||
if (state.asyncTimeline.complete) {
|
Timber.v("Render state")
|
||||||
renderTimeline(state.asyncTimeline())
|
val timeline = state.asyncTimeline()
|
||||||
|
if (timeline != null) {
|
||||||
|
renderTimeline(timeline)
|
||||||
}
|
}
|
||||||
renderRoomSummary(state.asyncRoomSummary())
|
renderRoomSummary(state.asyncRoomSummary())
|
||||||
}
|
}
|
||||||
@ -98,15 +102,14 @@ class RoomDetailFragment : RiotFragment(), TimelineEventController.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun renderTimeline(timeline: Timeline?) {
|
private fun renderTimeline(timeline: Timeline?) {
|
||||||
scrollOnNewMessageCallback.hasBeenUpdated.set(true)
|
//scrollOnNewMessageCallback.hasBeenUpdated.set(true)
|
||||||
timelineEventController.timeline = timeline
|
timelineEventController.timeline = timeline
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimelineEventController.Callback ************************************************************
|
// TimelineEventController.Callback ************************************************************
|
||||||
|
|
||||||
override fun onUrlClicked(url: String) {
|
override fun onUrlClicked(url: String) {
|
||||||
val permalinkData = PermalinkParser.parse(url)
|
homePermalinkHandler.launch(url)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package im.vector.riotredesign.features.home.room.detail.timeline
|
package im.vector.riotredesign.features.home.room.detail.timeline
|
||||||
|
|
||||||
|
import android.text.util.Linkify
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan
|
|
||||||
import im.vector.matrix.android.api.permalinks.MatrixLinkify
|
import im.vector.matrix.android.api.permalinks.MatrixLinkify
|
||||||
|
import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
import im.vector.riotredesign.core.epoxy.KotlinModel
|
import im.vector.riotredesign.core.epoxy.KotlinModel
|
||||||
import im.vector.riotredesign.features.home.AvatarRenderer
|
import im.vector.riotredesign.features.home.AvatarRenderer
|
||||||
@ -30,6 +31,7 @@ data class MessageItem(
|
|||||||
onUrlClickedListener?.invoke(url)
|
onUrlClickedListener?.invoke(url)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Linkify.addLinks(messageView, Linkify.ALL)
|
||||||
if (showInformation) {
|
if (showInformation) {
|
||||||
avatarImageView.visibility = View.VISIBLE
|
avatarImageView.visibility = View.VISIBLE
|
||||||
memberNameView.visibility = View.VISIBLE
|
memberNameView.visibility = View.VISIBLE
|
||||||
|
Loading…
Reference in New Issue
Block a user