diff --git a/app/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt b/app/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt index 07f3be3e5f..4b5413f493 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt @@ -1,13 +1,13 @@ package im.vector.riotredesign.features.home +import android.arch.lifecycle.Observer import android.content.Context import android.content.Intent import android.os.Bundle 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.core.platform.RiotActivity -import kotlinx.android.synthetic.main.activity_home.* import org.koin.android.ext.android.inject import timber.log.Timber @@ -16,18 +16,16 @@ class HomeActivity : RiotActivity() { private val matrix by inject() private val currentSession = matrix.currentSession!! - private val realmHolder = currentSession.realmHolder() - private val syncThread = currentSession.syncThread() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_home) - val results = realmHolder.instance.where(RoomSummaryEntity::class.java).findAll() - results.addChangeListener { summaries -> - Timber.v("Summaries updated") - } - startSyncButton.setOnClickListener { syncThread.restart() } - stopSyncButton.setOnClickListener { syncThread.pause() } + currentSession.rooms().observe(this, Observer> { roomList -> + if (roomList == null) { + return@Observer + } + Timber.v("Observe rooms: %d", roomList.size) + }) } companion object { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt index 6b72884c0d..46a5d50ab5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt @@ -13,9 +13,4 @@ interface Session : RoomService { @MainThread fun close() - fun syncThread(): SyncThread - - // Visible for testing request directly. Will be deleted - fun realmHolder(): SessionRealmHolder - } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/Room.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/Room.kt index 4c41bfb808..898de8f878 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/Room.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/Room.kt @@ -4,4 +4,6 @@ interface Room { val roomId: String + + } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomService.kt index fa343f2882..9853278789 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomService.kt @@ -8,6 +8,6 @@ interface RoomService { fun getAllRooms(): List - fun observeAllRooms(): LiveData> + fun rooms(): LiveData> } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt index 5944f8a099..43cee60d16 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt @@ -47,15 +47,6 @@ class DefaultSession(private val sessionParams: SessionParams syncThread.start() } - override fun realmHolder(): SessionRealmHolder { - assert(isOpen) - return realmInstanceHolder - } - - override fun syncThread(): SyncThread { - assert(isOpen) - return syncThread - } @MainThread override fun close() { @@ -78,8 +69,8 @@ class DefaultSession(private val sessionParams: SessionParams return roomService.getAllRooms() } - override fun observeAllRooms(): LiveData> { - return roomService.observeAllRooms() + override fun rooms(): LiveData> { + return roomService.rooms() } // Private methods ***************************************************************************** diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt index d533eae245..3fe38f767f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt @@ -29,7 +29,7 @@ class DefaultRoomService(private val realmConfiguration: RealmConfiguration, return room } - override fun observeAllRooms(): LiveData> { + override fun rooms(): LiveData> { val roomResults = RoomEntity.getAll(mainThreadRealm.instance).findAllAsync() return RealmLiveData(roomResults) { DefaultRoom(it.roomId) } }