Integrate keysbackup banner

This commit is contained in:
Benoit Marty 2019-06-11 15:45:40 +02:00
parent 5621f0661e
commit 4827b76b80
5 changed files with 84 additions and 5 deletions

View File

@ -20,20 +20,26 @@ import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
import androidx.core.view.forEachIndexed
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.bottomnavigation.BottomNavigationItemView
import com.google.android.material.bottomnavigation.BottomNavigationMenuView
import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupState
import im.vector.riotredesign.R
import im.vector.riotredesign.core.platform.ToolbarConfigurable
import im.vector.riotredesign.core.platform.VectorBaseFragment
import im.vector.riotredesign.core.ui.views.KeysBackupBanner
import im.vector.riotredesign.features.home.room.list.RoomListFragment
import im.vector.riotredesign.features.home.room.list.RoomListParams
import im.vector.riotredesign.features.home.room.list.UnreadCounterBadgeView
import im.vector.riotredesign.features.workers.signout.SignOutViewModel
import kotlinx.android.parcel.Parcelize
import kotlinx.android.synthetic.main.fragment_home_detail.*
import org.koin.android.ext.android.inject
@Parcelize
@ -50,7 +56,7 @@ private const val INDEX_CATCHUP = 0
private const val INDEX_PEOPLE = 1
private const val INDEX_ROOMS = 2
class HomeDetailFragment : VectorBaseFragment() {
class HomeDetailFragment : VectorBaseFragment(), KeysBackupBanner.Delegate {
private val params: HomeDetailParams by args()
private val unreadCounterBadgeViews = arrayListOf<UnreadCounterBadgeView>()
@ -59,6 +65,8 @@ class HomeDetailFragment : VectorBaseFragment() {
private val viewModel: HomeDetailViewModel by fragmentViewModel()
private lateinit var navigationViewModel: HomeNavigationViewModel
private val session by inject<Session>()
override fun getLayoutResId(): Int {
return R.layout.fragment_home_detail
}
@ -73,6 +81,41 @@ class HomeDetailFragment : VectorBaseFragment() {
switchDisplayMode(currentDisplayMode)
setupBottomNavigationView()
setupToolbar()
setupKeysBackupBanner()
}
private fun setupKeysBackupBanner() {
// Keys backup banner
// Use the SignOutViewModel, it observe the keys backup state and this is what we need here
val model = ViewModelProviders.of(this).get(SignOutViewModel::class.java)
model.init(session)
model.keysBackupState.observe(this, Observer { keysBackupState ->
when (keysBackupState) {
null ->
homeKeysBackupBanner.render(KeysBackupBanner.State.Hidden, false)
KeysBackupState.Disabled ->
homeKeysBackupBanner.render(KeysBackupBanner.State.Setup(model.getNumberOfKeysToBackup()), false)
KeysBackupState.NotTrusted,
KeysBackupState.WrongBackUpVersion ->
// In this case, getCurrentBackupVersion() should not return ""
homeKeysBackupBanner.render(KeysBackupBanner.State.Recover(model.getCurrentBackupVersion()), false)
KeysBackupState.WillBackUp,
KeysBackupState.BackingUp ->
homeKeysBackupBanner.render(KeysBackupBanner.State.BackingUp, false)
KeysBackupState.ReadyToBackUp ->
if (model.canRestoreKeys()) {
homeKeysBackupBanner.render(KeysBackupBanner.State.Update(model.getCurrentBackupVersion()), false)
} else {
homeKeysBackupBanner.render(KeysBackupBanner.State.Hidden, false)
}
else ->
homeKeysBackupBanner.render(KeysBackupBanner.State.Hidden, false)
}
})
homeKeysBackupBanner.delegate = this
}
@ -140,6 +183,17 @@ class HomeDetailFragment : VectorBaseFragment() {
.commit()
}
/* ==========================================================================================
* KeysBackupBanner Listener
* ========================================================================================== */
override fun setupKeysBackup() {
navigator.openKeysBackupSetup(requireActivity(), false)
}
override fun recoverKeysBackup() {
navigator.openKeysBackupManager(requireActivity())
}
override fun invalidate() = withState(viewModel) {
unreadCounterBadgeViews[INDEX_CATCHUP].render(UnreadCounterBadgeView.State(it.notificationCountCatchup, it.notificationHighlightCatchup))

View File

@ -19,6 +19,8 @@ package im.vector.riotredesign.features.navigation
import android.content.Context
import android.content.Intent
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
import im.vector.riotredesign.features.crypto.keysbackup.settings.KeysBackupManageActivity
import im.vector.riotredesign.features.crypto.keysbackup.setup.KeysBackupSetupActivity
import im.vector.riotredesign.features.debug.DebugMenuActivity
import im.vector.riotredesign.features.home.room.detail.RoomDetailActivity
import im.vector.riotredesign.features.home.room.detail.RoomDetailArgs
@ -53,4 +55,12 @@ class DefaultNavigator : Navigator {
override fun openDebug(context: Context) {
context.startActivity(Intent(context, DebugMenuActivity::class.java))
}
override fun openKeysBackupSetup(context: Context, showManualExport: Boolean) {
context.startActivity(KeysBackupSetupActivity.intent(context, showManualExport))
}
override fun openKeysBackupManager(context: Context) {
context.startActivity(KeysBackupManageActivity.intent(context))
}
}

View File

@ -31,4 +31,7 @@ interface Navigator {
fun openDebug(context: Context)
fun openKeysBackupSetup(context: Context, showManualExport: Boolean)
fun openKeysBackupManager(context: Context)
}

View File

@ -44,13 +44,24 @@
</androidx.appcompat.widget.Toolbar>
<im.vector.riotredesign.core.ui.views.KeysBackupBanner
android:id="@+id/homeKeysBackupBanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?vctr_list_header_background_color"
android:minHeight="67dp"
app:layout_constraintBottom_toTopOf="@+id/roomListContainer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/groupToolbar" />
<FrameLayout
android:id="@+id/roomListContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?riotx_header_panel_background"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintTop_toBottomOf="@+id/groupToolbar" />
app:layout_constraintTop_toBottomOf="@+id/homeKeysBackupBanner" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"

View File

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?vctr_list_header_background_color"
android:minHeight="67dp">
android:minHeight="67dp"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<ImageView
android:id="@+id/view_keys_backup_banner_picto"
@ -101,4 +102,4 @@
android:background="?vctr_line_divider"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</merge>