2018-10-03 15:56:33 +00:00
|
|
|
package im.vector.riotredesign.features.home
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
|
|
|
import android.os.Bundle
|
2018-10-08 15:52:45 +00:00
|
|
|
import android.view.View
|
|
|
|
import im.vector.matrix.android.api.Matrix
|
|
|
|
import im.vector.matrix.android.api.MatrixCallback
|
|
|
|
import im.vector.matrix.android.api.failure.Failure
|
2018-10-16 13:52:30 +00:00
|
|
|
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
2018-10-08 15:52:45 +00:00
|
|
|
import im.vector.matrix.android.internal.events.sync.data.SyncResponse
|
2018-10-03 15:56:33 +00:00
|
|
|
import im.vector.riotredesign.R
|
|
|
|
import im.vector.riotredesign.core.platform.RiotActivity
|
2018-10-08 15:52:45 +00:00
|
|
|
import kotlinx.android.synthetic.main.activity_home.*
|
|
|
|
import org.koin.android.ext.android.inject
|
2018-10-16 13:52:30 +00:00
|
|
|
import timber.log.Timber
|
2018-10-03 15:56:33 +00:00
|
|
|
|
|
|
|
class HomeActivity : RiotActivity() {
|
|
|
|
|
2018-10-08 15:52:45 +00:00
|
|
|
private val matrix by inject<Matrix>()
|
|
|
|
private val synchronizer = matrix.currentSession?.synchronizer()
|
2018-10-16 13:52:30 +00:00
|
|
|
private val realmHolder = matrix.currentSession?.realmHolder()
|
2018-10-08 15:52:45 +00:00
|
|
|
|
2018-10-03 15:56:33 +00:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.activity_home)
|
2018-10-08 15:52:45 +00:00
|
|
|
synchronizeButton.setOnClickListener { synchronize() }
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun synchronize() {
|
|
|
|
synchronizeButton.visibility = View.GONE
|
|
|
|
loadingView.visibility = View.VISIBLE
|
|
|
|
synchronizer?.synchronize(object : MatrixCallback<SyncResponse> {
|
2018-10-16 13:52:30 +00:00
|
|
|
override fun onSuccess(data: SyncResponse) {
|
2018-10-08 15:52:45 +00:00
|
|
|
synchronizeButton.visibility = View.VISIBLE
|
|
|
|
loadingView.visibility = View.GONE
|
2018-10-16 13:52:30 +00:00
|
|
|
Timber.v("Sync successful")
|
2018-10-08 15:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onFailure(failure: Failure) {
|
|
|
|
synchronizeButton.visibility = View.VISIBLE
|
|
|
|
loadingView.visibility = View.GONE
|
2018-10-16 13:52:30 +00:00
|
|
|
Timber.e("Sync has failed : %s", failure.toString())
|
2018-10-08 15:52:45 +00:00
|
|
|
}
|
|
|
|
})
|
2018-10-15 17:42:13 +00:00
|
|
|
if (realmHolder != null) {
|
2018-10-16 13:52:30 +00:00
|
|
|
val results = realmHolder.instance.where(RoomSummaryEntity::class.java).findAll()
|
|
|
|
results.addChangeListener { summaries ->
|
|
|
|
Timber.v("Summaries updated")
|
|
|
|
}
|
2018-10-15 17:42:13 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 15:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
fun newIntent(context: Context): Intent {
|
|
|
|
return Intent(context, HomeActivity::class.java)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|