This commit is contained in:
Benoit Marty 2019-06-13 10:33:04 +02:00
parent 480d197ffa
commit 6cd3b4dd95
8 changed files with 83 additions and 26 deletions

View File

@ -16,11 +16,25 @@

package im.vector.riotredesign.core.epoxy

import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.riotredesign.R
import im.vector.riotredesign.core.extensions.setTextOrHide

@EpoxyModelClass(layout = R.layout.item_loading)
abstract class LoadingItem : VectorEpoxyModel<LoadingItem.Holder>() {

class Holder : VectorEpoxyHolder()
@EpoxyAttribute var loadingText: String? = null

override fun bind(holder: Holder) {
super.bind(holder)

holder.textView.setTextOrHide(loadingText)
}


class Holder : VectorEpoxyHolder() {
val textView by bind<TextView>(R.id.loadingText)
}
}

View File

@ -77,4 +77,14 @@ class KeysBackupManageActivity : SimpleFragmentActivity() {
}
}
}

override fun onBackPressed() {
// When there is no network we could get stuck in infinite loading
// because backup state will stay in CheckingBackUpOnHomeserver
if (viewModel.canExit()) {
finish()
return
}
super.onBackPressed()
}
}

View File

@ -80,7 +80,7 @@ class KeysBackupSettingsFragment : VectorBaseFragment(),
.setMessage(R.string.keys_backup_settings_delete_confirm_message)
.setCancelable(false)
.setPositiveButton(R.string.keys_backup_settings_delete_confirm_title) { _, _ ->
viewModel.deleteCurrentBackup(it)
viewModel.deleteCurrentBackup()
}
.setNegativeButton(R.string.cancel, null)
.setCancelable(true)

View File

@ -59,6 +59,7 @@ class KeysBackupSettingsRecyclerViewController(val stringProvider: StringProvide
KeysBackupState.CheckingBackUpOnHomeserver -> {
loadingItem {
id("summary")
loadingText(stringProvider.getString(R.string.keys_backup_settings_checking_backup_state))
}
}
KeysBackupState.Disabled -> {

View File

@ -15,7 +15,6 @@
*/
package im.vector.riotredesign.features.crypto.keysbackup.settings

import android.content.Context
import com.airbnb.mvrx.*
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.Session
@ -105,7 +104,7 @@ class KeysBackupSettingsViewModel(initialState: KeysBackupSettingViewState,
getKeysBackupTrust()
}

fun deleteCurrentBackup(context: Context) {
fun deleteCurrentBackup() {
val keysBackupService = keysBackupService

if (keysBackupService.currentBackupVersion != null) {
@ -137,4 +136,11 @@ class KeysBackupSettingsViewModel(initialState: KeysBackupSettingViewState,
})
}
}

fun canExit(): Boolean {
val currentBackupState = keysBackupService.state

return currentBackupState == KeysBackupState.Unknown
|| currentBackupState == KeysBackupState.CheckingBackUpOnHomeserver
}
}

View File

@ -568,6 +568,9 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref
// Device list
refreshDevicesList()

//Refresh Key Management section
refreshKeysManagementSection()

// Advanced settings

// user account
@ -2192,24 +2195,6 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref
activity?.let { copyToClipboard(it, deviceId!!) }
true
}


manageBackupPref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
context?.let {
startActivity(KeysBackupManageActivity.intent(it))
}
false
}

exportPref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
exportKeys()
true
}

importPref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
importKeys()
true
}
}

// crypto section: device key (fingerprint)
@ -2239,6 +2224,27 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref
}
}

private fun refreshKeysManagementSection() {
//If crypto is not enabled parent section will be removed
//TODO notice that this will not work when no network
manageBackupPref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
context?.let {
startActivity(KeysBackupManageActivity.intent(it))
}
false
}

exportPref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
exportKeys()
true
}

importPref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
importKeys()
true
}
}

//==============================================================================================================
// devices list
//==============================================================================================================

View File

@ -1,7 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/progressBar"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_height="wrap_content"
android:background="?riotx_background"
android:padding="16dp" />
android:orientation="vertical">

<TextView
android:id="@+id/loadingText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/layout_vertical_margin"
android:gravity="center"
android:textColor="?riotx_text_primary"
android:textSize="16sp"
tools:text="Waiting message" />

<ProgressBar
android:id="@+id/loadingProgress"
android:layout_width="match_parent"
android:layout_height="80dp"
android:padding="16dp" />

</LinearLayout>

View File

@ -1379,6 +1379,7 @@ Why choose Riot.im?
<string name="keys_backup_settings_untrusted_backup">To use Key Backup on this device, restore with your passphrase or recovery key now.</string>
<string name="keys_backup_settings_deleting_backup">Deleting backup…</string>
<string name="keys_backup_settings_delete_backup_error">Failed to delete backup (%s)</string>
<string name="keys_backup_settings_checking_backup_state">Checking backup state</string>

<string name="keys_backup_settings_delete_confirm_title">Delete Backup</string>
<string name="keys_backup_settings_delete_confirm_message">Delete your backed up encryption keys from the server? You will no longer be able to use your recovery key to read encrypted message history.</string>