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()
|
||||
}
|
||||
|
||||
single {
|
||||
HomePermalinkHandler(get())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package im.vector.riotredesign.features.home
|
||||
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.view.Gravity
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.extensions.addFragmentToBackstack
|
||||
import im.vector.riotredesign.core.extensions.replaceFragment
|
||||
import im.vector.riotredesign.features.home.room.detail.RoomDetailArgs
|
||||
import im.vector.riotredesign.features.home.room.detail.RoomDetailFragment
|
||||
@ -14,8 +16,11 @@ class HomeNavigator {
|
||||
|
||||
private var currentRoomId: String? = null
|
||||
|
||||
fun openRoomDetail(roomId: String, eventId: String?) {
|
||||
if (isRoomOpened(roomId)) {
|
||||
fun openRoomDetail(roomId: String,
|
||||
eventId: String?,
|
||||
addToBackstack: Boolean = false) {
|
||||
Timber.v("Open room detail $roomId - $eventId - $addToBackstack")
|
||||
if (!addToBackstack && isRoomOpened(roomId)) {
|
||||
return
|
||||
}
|
||||
currentRoomId = roomId
|
||||
@ -23,9 +28,14 @@ class HomeNavigator {
|
||||
val args = RoomDetailArgs(roomId, eventId)
|
||||
val roomDetailFragment = RoomDetailFragment.newInstance(args)
|
||||
it.drawerLayout?.closeDrawer(Gravity.LEFT)
|
||||
if (addToBackstack) {
|
||||
it.addFragmentToBackstack(roomDetailFragment, R.id.homeDetailFragmentContainer, roomId)
|
||||
} else {
|
||||
clearBackStack(it.supportFragmentManager)
|
||||
it.replaceFragment(roomDetailFragment, R.id.homeDetailFragmentContainer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun openGroupDetail(groupId: String) {
|
||||
Timber.v("Open group detail $groupId")
|
||||
@ -39,4 +49,11 @@ class HomeNavigator {
|
||||
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 com.airbnb.mvrx.args
|
||||
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.riotredesign.R
|
||||
import im.vector.riotredesign.core.platform.RiotFragment
|
||||
import im.vector.riotredesign.core.platform.ToolbarConfigurable
|
||||
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 kotlinx.android.parcel.Parcelize
|
||||
import kotlinx.android.synthetic.main.fragment_room_detail.*
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.core.parameter.parametersOf
|
||||
import timber.log.Timber
|
||||
|
||||
@Parcelize
|
||||
data class RoomDetailArgs(
|
||||
@ -41,6 +42,7 @@ class RoomDetailFragment : RiotFragment(), TimelineEventController.Callback {
|
||||
private val roomDetailArgs: RoomDetailArgs by args()
|
||||
|
||||
private val timelineEventController by inject<TimelineEventController> { parametersOf(roomDetailArgs.roomId) }
|
||||
private val homePermalinkHandler by inject<HomePermalinkHandler>()
|
||||
private lateinit var scrollOnNewMessageCallback: ScrollOnNewMessageCallback
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
@ -70,16 +72,18 @@ class RoomDetailFragment : RiotFragment(), TimelineEventController.Callback {
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
val layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
|
||||
scrollOnNewMessageCallback = ScrollOnNewMessageCallback(layoutManager)
|
||||
//scrollOnNewMessageCallback = ScrollOnNewMessageCallback(layoutManager)
|
||||
recyclerView.layoutManager = layoutManager
|
||||
timelineEventController.addModelBuildListener { it.dispatchTo(scrollOnNewMessageCallback) }
|
||||
//timelineEventController.addModelBuildListener { it.dispatchTo(scrollOnNewMessageCallback) }
|
||||
recyclerView.setController(timelineEventController)
|
||||
timelineEventController.callback = this
|
||||
}
|
||||
|
||||
private fun renderState(state: RoomDetailViewState) {
|
||||
if (state.asyncTimeline.complete) {
|
||||
renderTimeline(state.asyncTimeline())
|
||||
Timber.v("Render state")
|
||||
val timeline = state.asyncTimeline()
|
||||
if (timeline != null) {
|
||||
renderTimeline(timeline)
|
||||
}
|
||||
renderRoomSummary(state.asyncRoomSummary())
|
||||
}
|
||||
@ -98,15 +102,14 @@ class RoomDetailFragment : RiotFragment(), TimelineEventController.Callback {
|
||||
}
|
||||
|
||||
private fun renderTimeline(timeline: Timeline?) {
|
||||
scrollOnNewMessageCallback.hasBeenUpdated.set(true)
|
||||
//scrollOnNewMessageCallback.hasBeenUpdated.set(true)
|
||||
timelineEventController.timeline = timeline
|
||||
}
|
||||
|
||||
// TimelineEventController.Callback ************************************************************
|
||||
|
||||
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
|
||||
|
||||
import android.text.util.Linkify
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
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.MatrixPermalinkSpan
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.epoxy.KotlinModel
|
||||
import im.vector.riotredesign.features.home.AvatarRenderer
|
||||
@ -30,6 +31,7 @@ data class MessageItem(
|
||||
onUrlClickedListener?.invoke(url)
|
||||
}
|
||||
})
|
||||
Linkify.addLinks(messageView, Linkify.ALL)
|
||||
if (showInformation) {
|
||||
avatarImageView.visibility = View.VISIBLE
|
||||
memberNameView.visibility = View.VISIBLE
|
||||
|
Loading…
Reference in New Issue
Block a user