forked from GitHub-Mirror/riotX-android
First attempt to handle room name + make app listen to room summaries instead of rooms
This commit is contained in:
@ -3,6 +3,7 @@ package im.vector.riotredesign
|
||||
import android.app.Application
|
||||
import im.vector.matrix.android.BuildConfig
|
||||
import im.vector.riotredesign.core.di.AppModule
|
||||
import org.koin.log.EmptyLogger
|
||||
import org.koin.standalone.StandAloneContext.startKoin
|
||||
import timber.log.Timber
|
||||
|
||||
@ -13,7 +14,7 @@ class Riot : Application() {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Timber.plant(Timber.DebugTree())
|
||||
}
|
||||
startKoin(listOf(AppModule(this)))
|
||||
startKoin(listOf(AppModule(this)), logger = EmptyLogger())
|
||||
}
|
||||
|
||||
}
|
@ -5,11 +5,11 @@ import im.vector.matrix.android.api.session.events.model.EnrichedEvent
|
||||
|
||||
class EventDiffUtilCallback : DiffUtil.ItemCallback<EnrichedEvent>() {
|
||||
override fun areItemsTheSame(p0: EnrichedEvent, p1: EnrichedEvent): Boolean {
|
||||
return p0.core.eventId == p1.core.eventId
|
||||
return p0.root.eventId == p1.root.eventId
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(p0: EnrichedEvent, p1: EnrichedEvent): Boolean {
|
||||
return p0.core == p1.core
|
||||
return p0.root == p1.root
|
||||
&& p0.getMetaEvents()
|
||||
.zip(p1.getMetaEvents()) { a, b ->
|
||||
a.eventId == b.eventId
|
||||
|
@ -1,20 +0,0 @@
|
||||
package im.vector.riotredesign.features.home
|
||||
|
||||
import com.airbnb.epoxy.TypedEpoxyController
|
||||
import im.vector.matrix.android.api.session.room.Room
|
||||
|
||||
class RoomController(private val callback: Callback? = null) : TypedEpoxyController<List<Room>>() {
|
||||
|
||||
override fun buildModels(data: List<Room>?) {
|
||||
data?.forEach {
|
||||
RoomItem(it.roomId, listener = { callback?.onRoomSelected(it) })
|
||||
.id(it.roomId)
|
||||
.addTo(this)
|
||||
}
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
fun onRoomSelected(room: Room)
|
||||
}
|
||||
|
||||
}
|
@ -55,9 +55,10 @@ class RoomDetailFragment : RiotFragment(), TimelineEventAdapter.Callback {
|
||||
layoutManager.stackFromEnd = true
|
||||
timelineAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||
if (layoutManager.findFirstVisibleItemPosition() == 0) {
|
||||
/*if (layoutManager.findFirstVisibleItemPosition() == 0) {
|
||||
layoutManager.scrollToPosition(0)
|
||||
}
|
||||
*/
|
||||
}
|
||||
})
|
||||
recyclerView.layoutManager = layoutManager
|
||||
|
@ -5,7 +5,7 @@ import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.epoxy.KotlinModel
|
||||
|
||||
data class RoomItem(
|
||||
val title: String,
|
||||
val title: CharSequence,
|
||||
val listener: (() -> Unit)? = null
|
||||
) : KotlinModel(R.layout.item_room) {
|
||||
|
||||
|
@ -2,19 +2,18 @@ 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.matrix.android.api.session.room.model.RoomSummary
|
||||
import im.vector.riotredesign.R
|
||||
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
|
||||
|
||||
class RoomListFragment : RiotFragment(), RoomController.Callback {
|
||||
class RoomListFragment : RiotFragment(), RoomSummaryController.Callback {
|
||||
|
||||
companion object {
|
||||
|
||||
@ -26,7 +25,7 @@ class RoomListFragment : RiotFragment(), RoomController.Callback {
|
||||
|
||||
private val matrix by inject<Matrix>()
|
||||
private val currentSession = matrix.currentSession!!
|
||||
private val roomController = RoomController(this)
|
||||
private lateinit var roomController: RoomSummaryController
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_room_list, container, false)
|
||||
@ -34,15 +33,16 @@ class RoomListFragment : RiotFragment(), RoomController.Callback {
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
roomController = RoomSummaryController(this)
|
||||
epoxyRecyclerView.setController(roomController)
|
||||
currentSession.liveRooms().observe(this, Observer<List<Room>> { renderRooms(it) })
|
||||
currentSession.liveRoomSummaries().observe(this, Observer<List<RoomSummary>> { renderRooms(it) })
|
||||
}
|
||||
|
||||
private fun renderRooms(rooms: List<Room>?) {
|
||||
private fun renderRooms(rooms: List<RoomSummary>?) {
|
||||
roomController.setData(rooms)
|
||||
}
|
||||
|
||||
override fun onRoomSelected(room: Room) {
|
||||
override fun onRoomSelected(room: RoomSummary) {
|
||||
val detailFragment = RoomDetailFragment.newInstance(room.roomId)
|
||||
addFragmentToBackstack(detailFragment, R.id.homeFragmentContainer)
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package im.vector.riotredesign.features.home
|
||||
|
||||
import com.airbnb.epoxy.TypedEpoxyController
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
|
||||
class RoomSummaryController(private val callback: Callback? = null
|
||||
) : TypedEpoxyController<List<RoomSummary>>() {
|
||||
|
||||
override fun buildModels(data: List<RoomSummary>?) {
|
||||
data?.forEach {
|
||||
RoomItem(it.displayName, listener = { callback?.onRoomSelected(it) })
|
||||
.id(it.roomId)
|
||||
.addTo(this)
|
||||
}
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
fun onRoomSelected(room: RoomSummary)
|
||||
}
|
||||
|
||||
}
|
@ -38,10 +38,10 @@ class TimelineEventAdapter(private val callback: Callback? = null)
|
||||
val titleView = view.findViewById<TextView>(R.id.titleView)!!
|
||||
|
||||
fun bind(event: EnrichedEvent?) {
|
||||
if (event == null || event.core.type != EventType.MESSAGE) {
|
||||
if (event == null) {
|
||||
titleView.text = null
|
||||
} else {
|
||||
val messageContent = event.core.content<MessageContent>()
|
||||
} else if (event.root.type == EventType.MESSAGE) {
|
||||
val messageContent = event.root.content<MessageContent>()
|
||||
val roomMember = event.getMetaEvents(EventType.STATE_ROOM_MEMBER).firstOrNull()?.content<RoomMember>()
|
||||
if (messageContent == null || roomMember == null) {
|
||||
titleView.text = null
|
||||
@ -49,6 +49,8 @@ class TimelineEventAdapter(private val callback: Callback? = null)
|
||||
val text = "${roomMember.displayName} : ${messageContent.body}"
|
||||
titleView.text = text
|
||||
}
|
||||
} else {
|
||||
titleView.text = event.root.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user