diff --git a/app/src/main/java/im/vector/riotredesign/features/home/HomeModule.kt b/app/src/main/java/im/vector/riotredesign/features/home/HomeModule.kt index f9a6a2634d..86a414f1cd 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/HomeModule.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/HomeModule.kt @@ -35,5 +35,9 @@ class HomeModule(private val homeActivity: HomeActivity) { SelectedGroupHolder() } + single { + HomePermalinkHandler(get()) + } + } } \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/home/HomeNavigator.kt b/app/src/main/java/im/vector/riotredesign/features/home/HomeNavigator.kt index 91a64011ad..41f61688d5 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/HomeNavigator.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/HomeNavigator.kt @@ -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,7 +28,12 @@ class HomeNavigator { val args = RoomDetailArgs(roomId, eventId) val roomDetailFragment = RoomDetailFragment.newInstance(args) 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 } + private fun clearBackStack(fragmentManager: FragmentManager) { + if (fragmentManager.backStackEntryCount > 0) { + val first = fragmentManager.getBackStackEntryAt(0) + fragmentManager.popBackStack(first.id, FragmentManager.POP_BACK_STACK_INCLUSIVE) + } + } + } \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt index 6d7c057170..3eb67ccf50 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt @@ -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 { parametersOf(roomDetailArgs.roomId) } + private val homePermalinkHandler by inject() 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) } } diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItem.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItem.kt index 44a9b2f655..4fe08c1891 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItem.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItem.kt @@ -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