PIN: move setting to a dedicated screen (no other change)

This commit is contained in:
Benoit Marty 2020-09-23 11:17:16 +02:00 committed by Benoit Marty
parent 9ab053d702
commit b8cbafa75d
7 changed files with 98 additions and 42 deletions

View file

@ -89,6 +89,7 @@ import im.vector.app.features.settings.VectorSettingsHelpAboutFragment
import im.vector.app.features.settings.VectorSettingsLabsFragment
import im.vector.app.features.settings.VectorSettingsNotificationPreferenceFragment
import im.vector.app.features.settings.VectorSettingsNotificationsTroubleshootFragment
import im.vector.app.features.settings.VectorSettingsPinFragment
import im.vector.app.features.settings.VectorSettingsPreferencesFragment
import im.vector.app.features.settings.VectorSettingsSecurityPrivacyFragment
import im.vector.app.features.settings.account.deactivation.DeactivateAccountFragment
@ -284,6 +285,11 @@ interface FragmentModule {
@FragmentKey(VectorSettingsLabsFragment::class)
fun bindVectorSettingsLabsFragment(fragment: VectorSettingsLabsFragment): Fragment
@Binds
@IntoMap
@FragmentKey(VectorSettingsPinFragment::class)
fun bindVectorSettingsPinFragment(fragment: VectorSettingsPinFragment): Fragment
@Binds
@IntoMap
@FragmentKey(PushRulesFragment::class)

View file

@ -28,7 +28,6 @@ import im.vector.app.core.platform.VectorBaseActivity
class PinActivity : VectorBaseActivity(), ToolbarConfigurable, UnlockedActivity {
companion object {
const val PIN_REQUEST_CODE = 17890
fun newIntent(context: Context, args: PinArgs): Intent {

View file

@ -0,0 +1,71 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.settings
import android.content.Intent
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import androidx.preference.SwitchPreference
import im.vector.app.R
import im.vector.app.features.navigation.Navigator
import im.vector.app.features.pin.PinActivity
import im.vector.app.features.pin.PinCodeStore
import im.vector.app.features.pin.PinLocker
import im.vector.app.features.pin.PinMode
import javax.inject.Inject
class VectorSettingsPinFragment @Inject constructor(
private val pinLocker: PinLocker,
private val pinCodeStore: PinCodeStore,
private val navigator: Navigator
) : VectorSettingsBaseFragment() {
override var titleRes = R.string.settings_security_application_protection_screen_title
override val preferenceXmlRes = R.xml.vector_settings_pin
private val usePinCodePref by lazy {
findPreference<SwitchPreference>(VectorPreferences.SETTINGS_SECURITY_USE_PIN_CODE_FLAG)!!
}
override fun bindPref() {
refreshPinCodeStatus()
}
private fun refreshPinCodeStatus() {
lifecycleScope.launchWhenResumed {
val hasPinCode = pinCodeStore.hasEncodedPin()
usePinCodePref.isChecked = hasPinCode
usePinCodePref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
val pinMode = if (hasPinCode) {
PinMode.DELETE
} else {
PinMode.CREATE
}
navigator.openPinCode(this@VectorSettingsPinFragment, pinMode)
true
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == PinActivity.PIN_REQUEST_CODE) {
pinLocker.unlock()
refreshPinCodeStatus()
}
}
}

View file

@ -29,7 +29,6 @@ import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.SwitchPreference
@ -53,11 +52,6 @@ import im.vector.app.features.crypto.keys.KeysExporter
import im.vector.app.features.crypto.keys.KeysImporter
import im.vector.app.features.crypto.keysbackup.settings.KeysBackupManageActivity
import im.vector.app.features.crypto.recover.BootstrapBottomSheet
import im.vector.app.features.navigation.Navigator
import im.vector.app.features.pin.PinActivity
import im.vector.app.features.pin.PinCodeStore
import im.vector.app.features.pin.PinLocker
import im.vector.app.features.pin.PinMode
import im.vector.app.features.raw.wellknown.ElementWellKnownMapper
import im.vector.app.features.raw.wellknown.isE2EByDefault
import im.vector.app.features.themes.ThemeUtils
@ -76,10 +70,7 @@ import javax.inject.Inject
class VectorSettingsSecurityPrivacyFragment @Inject constructor(
private val vectorPreferences: VectorPreferences,
private val pinLocker: PinLocker,
private val activeSessionHolder: ActiveSessionHolder,
private val pinCodeStore: PinCodeStore,
private val navigator: Navigator
private val activeSessionHolder: ActiveSessionHolder
) : VectorSettingsBaseFragment() {
override var titleRes = R.string.settings_security_and_privacy
@ -128,10 +119,6 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
findPreference<SwitchPreference>(VectorPreferences.SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY)!!
}
private val usePinCodePref by lazy {
findPreference<SwitchPreference>(VectorPreferences.SETTINGS_SECURITY_USE_PIN_CODE_FLAG)!!
}
override fun onCreateRecyclerView(inflater: LayoutInflater?, parent: ViewGroup?, savedInstanceState: Bundle?): RecyclerView {
return super.onCreateRecyclerView(inflater, parent, savedInstanceState).also {
// Insert animation are really annoying the first time the list is shown
@ -265,8 +252,6 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
}
}
refreshPinCodeStatus()
refreshXSigningStatus()
secureBackupPreference.icon = activity?.let {
@ -351,9 +336,6 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
})
}
}
} else if (requestCode == PinActivity.PIN_REQUEST_CODE) {
pinLocker.unlock()
refreshPinCodeStatus()
} else if (requestCode == REQUEST_E2E_FILE_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
importKeys(data)
@ -361,22 +343,6 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
}
}
private fun refreshPinCodeStatus() {
lifecycleScope.launchWhenResumed {
val hasPinCode = pinCodeStore.hasEncodedPin()
usePinCodePref.isChecked = hasPinCode
usePinCodePref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
val pinMode = if (hasPinCode) {
PinMode.DELETE
} else {
PinMode.CREATE
}
navigator.openPinCode(this@VectorSettingsSecurityPrivacyFragment, pinMode)
true
}
}
}
private fun refreshKeysManagementSection() {
// If crypto is not enabled parent section will be removed
// TODO notice that this will not work when no network

View file

@ -2566,6 +2566,9 @@
<string name="auth_pin_reset_title">Reset pin</string>
<string name="auth_pin_new_pin_action">New pin</string>
<string name="auth_pin_reset_content">To reset your PIN, you\'ll need to re-login and create a new one.</string>
<string name="settings_security_application_protection_title">Protect access to the application.</string>
<string name="settings_security_application_protection_summary">Protect access to the application using pin code and biometrics.</string>
<string name="settings_security_application_protection_screen_title">Configure protection</string>
<string name="settings_security_pin_code_title">Enable PIN</string>
<string name="settings_security_pin_code_summary">If you want to reset your PIN, tap Forgot PIN to logout and reset.</string>
<string name="auth_pin_confirm_to_disable_title">Confirm PIN to disable PIN</string>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="false"
android:key="SETTINGS_SECURITY_USE_PIN_CODE_FLAG"
android:summary="@string/settings_security_pin_code_summary"
android:title="@string/settings_security_pin_code_title" />
</androidx.preference.PreferenceScreen>

View file

@ -117,18 +117,19 @@
<im.vector.app.core.preference.VectorPreferenceCategory android:title="@string/settings_other">
<im.vector.app.core.preference.VectorPreference
android:key="SETTINGS_SECURITY_PIN"
android:persistent="false"
android:title="@string/settings_security_application_protection_title"
android:summary="@string/settings_security_application_protection_summary"
app:fragment="im.vector.app.features.settings.VectorSettingsPinFragment" />
<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="false"
android:key="SETTINGS_SECURITY_USE_FLAG_SECURE"
android:summary="@string/settings_security_prevent_screenshots_summary"
android:title="@string/settings_security_prevent_screenshots_title" />
<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="false"
android:key="SETTINGS_SECURITY_USE_PIN_CODE_FLAG"
android:summary="@string/settings_security_pin_code_summary"
android:title="@string/settings_security_pin_code_title" />
</im.vector.app.core.preference.VectorPreferenceCategory>
</androidx.preference.PreferenceScreen>