Clean some files
This commit is contained in:
parent
00188fde29
commit
1646687e6d
@ -1,13 +1,13 @@
|
|||||||
package im.vector.riotredesign.features.home
|
package im.vector.riotredesign.features.home
|
||||||
|
|
||||||
|
import android.arch.lifecycle.Observer
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import im.vector.matrix.android.api.Matrix
|
import im.vector.matrix.android.api.Matrix
|
||||||
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
import im.vector.matrix.android.api.session.room.Room
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
import im.vector.riotredesign.core.platform.RiotActivity
|
import im.vector.riotredesign.core.platform.RiotActivity
|
||||||
import kotlinx.android.synthetic.main.activity_home.*
|
|
||||||
import org.koin.android.ext.android.inject
|
import org.koin.android.ext.android.inject
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@ -16,18 +16,16 @@ class HomeActivity : RiotActivity() {
|
|||||||
|
|
||||||
private val matrix by inject<Matrix>()
|
private val matrix by inject<Matrix>()
|
||||||
private val currentSession = matrix.currentSession!!
|
private val currentSession = matrix.currentSession!!
|
||||||
private val realmHolder = currentSession.realmHolder()
|
|
||||||
private val syncThread = currentSession.syncThread()
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_home)
|
setContentView(R.layout.activity_home)
|
||||||
val results = realmHolder.instance.where(RoomSummaryEntity::class.java).findAll()
|
currentSession.rooms().observe(this, Observer<List<Room>> { roomList ->
|
||||||
results.addChangeListener { summaries ->
|
if (roomList == null) {
|
||||||
Timber.v("Summaries updated")
|
return@Observer
|
||||||
}
|
}
|
||||||
startSyncButton.setOnClickListener { syncThread.restart() }
|
Timber.v("Observe rooms: %d", roomList.size)
|
||||||
stopSyncButton.setOnClickListener { syncThread.pause() }
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -13,9 +13,4 @@ interface Session : RoomService {
|
|||||||
@MainThread
|
@MainThread
|
||||||
fun close()
|
fun close()
|
||||||
|
|
||||||
fun syncThread(): SyncThread
|
|
||||||
|
|
||||||
// Visible for testing request directly. Will be deleted
|
|
||||||
fun realmHolder(): SessionRealmHolder
|
|
||||||
|
|
||||||
}
|
}
|
@ -4,4 +4,6 @@ interface Room {
|
|||||||
|
|
||||||
val roomId: String
|
val roomId: String
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -8,6 +8,6 @@ interface RoomService {
|
|||||||
|
|
||||||
fun getAllRooms(): List<Room>
|
fun getAllRooms(): List<Room>
|
||||||
|
|
||||||
fun observeAllRooms(): LiveData<List<Room>>
|
fun rooms(): LiveData<List<Room>>
|
||||||
|
|
||||||
}
|
}
|
@ -47,15 +47,6 @@ class DefaultSession(private val sessionParams: SessionParams
|
|||||||
syncThread.start()
|
syncThread.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun realmHolder(): SessionRealmHolder {
|
|
||||||
assert(isOpen)
|
|
||||||
return realmInstanceHolder
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun syncThread(): SyncThread {
|
|
||||||
assert(isOpen)
|
|
||||||
return syncThread
|
|
||||||
}
|
|
||||||
|
|
||||||
@MainThread
|
@MainThread
|
||||||
override fun close() {
|
override fun close() {
|
||||||
@ -78,8 +69,8 @@ class DefaultSession(private val sessionParams: SessionParams
|
|||||||
return roomService.getAllRooms()
|
return roomService.getAllRooms()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun observeAllRooms(): LiveData<List<Room>> {
|
override fun rooms(): LiveData<List<Room>> {
|
||||||
return roomService.observeAllRooms()
|
return roomService.rooms()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private methods *****************************************************************************
|
// Private methods *****************************************************************************
|
||||||
|
@ -29,7 +29,7 @@ class DefaultRoomService(private val realmConfiguration: RealmConfiguration,
|
|||||||
return room
|
return room
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun observeAllRooms(): LiveData<List<Room>> {
|
override fun rooms(): LiveData<List<Room>> {
|
||||||
val roomResults = RoomEntity.getAll(mainThreadRealm.instance).findAllAsync()
|
val roomResults = RoomEntity.getAll(mainThreadRealm.instance).findAllAsync()
|
||||||
return RealmLiveData(roomResults) { DefaultRoom(it.roomId) }
|
return RealmLiveData(roomResults) { DefaultRoom(it.roomId) }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user