forked from GitHub-Mirror/riotX-android
Continue to work on timeline/pagination. WIP
This commit is contained in:
@ -9,4 +9,8 @@ fun AppCompatActivity.addFragment(fragment: Fragment, frameId: Int) {
|
||||
|
||||
fun AppCompatActivity.replaceFragment(fragment: Fragment, frameId: Int) {
|
||||
supportFragmentManager.inTransaction { replace(frameId, fragment) }
|
||||
}
|
||||
|
||||
fun AppCompatActivity.addFragmentToBackstack(fragment: Fragment, frameId: Int, tag: String? = null) {
|
||||
supportFragmentManager.inTransaction { replace(frameId, fragment).addToBackStack(tag) }
|
||||
}
|
@ -16,4 +16,12 @@ fun Fragment.addChildFragment(fragment: Fragment, frameId: Int) {
|
||||
|
||||
fun Fragment.replaceChildFragment(fragment: Fragment, frameId: Int) {
|
||||
childFragmentManager.inTransaction { replace(frameId, fragment) }
|
||||
}
|
||||
|
||||
fun Fragment.addFragmentToBackstack(fragment: Fragment, frameId: Int, tag: String? = null) {
|
||||
fragmentManager?.inTransaction { replace(frameId, fragment).addToBackStack(tag) }
|
||||
}
|
||||
|
||||
fun Fragment.addChildFragmentToBackstack(fragment: Fragment, frameId: Int, tag: String? = null) {
|
||||
childFragmentManager.inTransaction { replace(frameId, fragment).addToBackStack(tag) }
|
||||
}
|
@ -3,19 +3,21 @@ package im.vector.riotredesign.features.home
|
||||
import android.arch.lifecycle.Observer
|
||||
import android.arch.paging.PagedList
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import im.vector.matrix.android.api.Matrix
|
||||
import im.vector.matrix.android.api.session.events.model.Event
|
||||
import im.vector.matrix.android.api.session.room.Room
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.platform.RiotFragment
|
||||
import im.vector.riotredesign.core.utils.FragmentArgumentDelegate
|
||||
import kotlinx.android.synthetic.main.fragment_room_list.*
|
||||
import org.koin.android.ext.android.inject
|
||||
|
||||
class RoomDetailFragment : RiotFragment(), RoomController.Callback {
|
||||
class RoomDetailFragment : RiotFragment() {
|
||||
|
||||
companion object {
|
||||
|
||||
@ -29,11 +31,8 @@ class RoomDetailFragment : RiotFragment(), RoomController.Callback {
|
||||
private val matrix by inject<Matrix>()
|
||||
private val currentSession = matrix.currentSession!!
|
||||
private var roomId by FragmentArgumentDelegate<String>()
|
||||
|
||||
private val timelineController = TimelineEventController()
|
||||
private val room: Room? by lazy {
|
||||
currentSession.getRoom(roomId)
|
||||
}
|
||||
private lateinit var room: Room
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_room_detail, container, false)
|
||||
@ -41,19 +40,20 @@ class RoomDetailFragment : RiotFragment(), RoomController.Callback {
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
if (room == null) {
|
||||
activity?.onBackPressed()
|
||||
return
|
||||
}
|
||||
room?.liveTimeline()?.observe(this, Observer { renderEvents(it) })
|
||||
setupRecyclerView()
|
||||
room = currentSession.getRoom(roomId)!!
|
||||
room.liveTimeline().observe(this, Observer { renderEvents(it) })
|
||||
}
|
||||
|
||||
private fun renderEvents(events: PagedList<Event>?) {
|
||||
timelineController.submitList(events)
|
||||
}
|
||||
|
||||
override fun onRoomSelected(room: Room) {
|
||||
Toast.makeText(context, "Room ${room.roomId} clicked", Toast.LENGTH_SHORT).show()
|
||||
private fun setupRecyclerView() {
|
||||
val linearLayoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false)
|
||||
linearLayoutManager.stackFromEnd = true
|
||||
epoxyRecyclerView.layoutManager = linearLayoutManager
|
||||
epoxyRecyclerView.setController(timelineController)
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,13 +2,14 @@ package im.vector.riotredesign.features.home
|
||||
|
||||
import android.arch.lifecycle.Observer
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import im.vector.matrix.android.api.Matrix
|
||||
import im.vector.matrix.android.api.session.room.Room
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.extensions.replaceFragment
|
||||
import im.vector.riotredesign.core.extensions.addFragmentToBackstack
|
||||
import im.vector.riotredesign.core.platform.RiotFragment
|
||||
import kotlinx.android.synthetic.main.fragment_room_list.*
|
||||
import org.koin.android.ext.android.inject
|
||||
@ -43,7 +44,7 @@ class RoomListFragment : RiotFragment(), RoomController.Callback {
|
||||
|
||||
override fun onRoomSelected(room: Room) {
|
||||
val detailFragment = RoomDetailFragment.newInstance(room.roomId)
|
||||
replaceFragment(detailFragment, R.id.homeFragmentContainer)
|
||||
addFragmentToBackstack(detailFragment, R.id.homeFragmentContainer)
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,14 +6,15 @@ import com.airbnb.epoxy.paging.PagedListEpoxyController
|
||||
import im.vector.matrix.android.api.session.events.model.Event
|
||||
|
||||
class TimelineEventController : PagedListEpoxyController<Event>(
|
||||
modelBuildingHandler = EpoxyAsyncUtil.getAsyncBackgroundHandler()
|
||||
modelBuildingHandler = EpoxyAsyncUtil.getAsyncBackgroundHandler(),
|
||||
diffingHandler = EpoxyAsyncUtil.getAsyncBackgroundHandler()
|
||||
) {
|
||||
|
||||
override fun buildItemModel(currentPosition: Int, item: Event?): EpoxyModel<*> {
|
||||
return if (item == null) {
|
||||
LoadingItemModel_().id(-currentPosition)
|
||||
} else {
|
||||
TimelineEventItem(item.eventId ?: "$currentPosition").id(currentPosition)
|
||||
TimelineEventItem(item.toString()).id(currentPosition)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/titleView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="80dp"
|
||||
android:padding="16dp"
|
||||
android:textSize="14sp"
|
||||
tools:text="Room name" />
|
||||
android:textSize="14sp" />
|
Reference in New Issue
Block a user