Post review fixes
This commit is contained in:
parent
1c97f8a720
commit
f532341ccc
3 changed files with 17 additions and 24 deletions
|
@ -82,7 +82,7 @@ class ImportExportPrefs @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun exportSharedPreferences(f: Fragment) {
|
fun exportSharedPreferences(f: Fragment) {
|
||||||
exportSharedPreferences(f.activity)
|
f.activity?.let { exportSharedPreferences(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun verifyStoragePermissions(fragment: Fragment) {
|
fun verifyStoragePermissions(fragment: Fragment) {
|
||||||
|
@ -94,14 +94,11 @@ class ImportExportPrefs @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun prepareMetadata(context: Context?): Map<PrefsMetadataKey, PrefMetadata> {
|
private fun prepareMetadata(context: Context): Map<PrefsMetadataKey, PrefMetadata> {
|
||||||
|
|
||||||
val metadata: MutableMap<PrefsMetadataKey, PrefMetadata> = mutableMapOf()
|
val metadata: MutableMap<PrefsMetadataKey, PrefMetadata> = mutableMapOf()
|
||||||
|
|
||||||
if (context != null) {
|
|
||||||
metadata[PrefsMetadataKey.DEVICE_NAME] = PrefMetadata(detectUserName(context), PrefsStatus.OK)
|
metadata[PrefsMetadataKey.DEVICE_NAME] = PrefMetadata(detectUserName(context), PrefsStatus.OK)
|
||||||
}
|
|
||||||
|
|
||||||
metadata[PrefsMetadataKey.CREATED_AT] = PrefMetadata(DateUtil.toISOString(Date()), PrefsStatus.OK)
|
metadata[PrefsMetadataKey.CREATED_AT] = PrefMetadata(DateUtil.toISOString(Date()), PrefsStatus.OK)
|
||||||
metadata[PrefsMetadataKey.AAPS_VERSION] = PrefMetadata(BuildConfig.VERSION_NAME, PrefsStatus.OK)
|
metadata[PrefsMetadataKey.AAPS_VERSION] = PrefMetadata(BuildConfig.VERSION_NAME, PrefsStatus.OK)
|
||||||
metadata[PrefsMetadataKey.AAPS_FLAVOUR] = PrefMetadata(BuildConfig.FLAVOR, PrefsStatus.OK)
|
metadata[PrefsMetadataKey.AAPS_FLAVOUR] = PrefMetadata(BuildConfig.FLAVOR, PrefsStatus.OK)
|
||||||
|
@ -141,15 +138,15 @@ class ImportExportPrefs @Inject constructor(
|
||||||
private fun prefsEncryptionIsDisabled() =
|
private fun prefsEncryptionIsDisabled() =
|
||||||
buildHelper.isEngineeringMode() && !sp.getBoolean(resourceHelper.gs(R.string.key_maintenance_encrypt_exported_prefs), true)
|
buildHelper.isEngineeringMode() && !sp.getBoolean(resourceHelper.gs(R.string.key_maintenance_encrypt_exported_prefs), true)
|
||||||
|
|
||||||
private fun askForMasterPass(activity: Activity?, @StringRes canceledMsg: Int, then: ((password: String) -> Unit)) {
|
private fun askForMasterPass(activity: Activity, @StringRes canceledMsg: Int, then: ((password: String) -> Unit)) {
|
||||||
passwordCheck.queryPassword(activity!!, R.string.master_password, R.string.key_master_password, { password ->
|
passwordCheck.queryPassword(activity, R.string.master_password, R.string.key_master_password, { password ->
|
||||||
then(password)
|
then(password)
|
||||||
}, {
|
}, {
|
||||||
ToastUtils.warnToast(activity, resourceHelper.gs(canceledMsg))
|
ToastUtils.warnToast(activity, resourceHelper.gs(canceledMsg))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun askForMasterPassIfNeeded(activity: Activity?, @StringRes canceledMsg: Int, then: ((password: String) -> Unit)) {
|
private fun askForMasterPassIfNeeded(activity: Activity, @StringRes canceledMsg: Int, then: ((password: String) -> Unit)) {
|
||||||
if (prefsEncryptionIsDisabled()) {
|
if (prefsEncryptionIsDisabled()) {
|
||||||
then("")
|
then("")
|
||||||
} else {
|
} else {
|
||||||
|
@ -157,9 +154,9 @@ class ImportExportPrefs @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun assureMasterPasswordSet(activity: Activity?, @StringRes wrongPwdTitle: Int): Boolean {
|
private fun assureMasterPasswordSet(activity: Activity, @StringRes wrongPwdTitle: Int): Boolean {
|
||||||
if (!sp.contains(R.string.key_master_password) || (sp.getString(R.string.key_master_password, "") == "")) {
|
if (!sp.contains(R.string.key_master_password) || (sp.getString(R.string.key_master_password, "") == "")) {
|
||||||
WarningDialog.showWarning(activity!!,
|
WarningDialog.showWarning(activity,
|
||||||
resourceHelper.gs(wrongPwdTitle),
|
resourceHelper.gs(wrongPwdTitle),
|
||||||
resourceHelper.gs(R.string.master_password_missing, resourceHelper.gs(R.string.configbuilder_general), resourceHelper.gs(R.string.protection)),
|
resourceHelper.gs(R.string.master_password_missing, resourceHelper.gs(R.string.configbuilder_general), resourceHelper.gs(R.string.protection)),
|
||||||
R.string.nav_preferences, {
|
R.string.nav_preferences, {
|
||||||
|
@ -173,35 +170,35 @@ class ImportExportPrefs @Inject constructor(
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun askToConfirmExport(activity: Activity?, then: ((password: String) -> Unit)) {
|
private fun askToConfirmExport(activity: Activity, then: ((password: String) -> Unit)) {
|
||||||
if (!prefsEncryptionIsDisabled() && !assureMasterPasswordSet(activity, R.string.nav_export)) return
|
if (!prefsEncryptionIsDisabled() && !assureMasterPasswordSet(activity, R.string.nav_export)) return
|
||||||
|
|
||||||
TwoMessagesAlertDialog.showAlert(activity!!, resourceHelper.gs(R.string.nav_export),
|
TwoMessagesAlertDialog.showAlert(activity, resourceHelper.gs(R.string.nav_export),
|
||||||
resourceHelper.gs(R.string.export_to) + " " + encFile + " ?",
|
resourceHelper.gs(R.string.export_to) + " " + encFile + " ?",
|
||||||
resourceHelper.gs(R.string.password_preferences_encrypt_prompt), {
|
resourceHelper.gs(R.string.password_preferences_encrypt_prompt), {
|
||||||
askForMasterPassIfNeeded(activity, R.string.preferences_export_canceled, then)
|
askForMasterPassIfNeeded(activity, R.string.preferences_export_canceled, then)
|
||||||
}, null, R.drawable.ic_header_export)
|
}, null, R.drawable.ic_header_export)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun askToConfirmImport(activity: Activity?, fileToImport: File, then: ((password: String) -> Unit)) {
|
private fun askToConfirmImport(activity: Activity, fileToImport: File, then: ((password: String) -> Unit)) {
|
||||||
|
|
||||||
if (encFile.exists()) {
|
if (encFile.exists()) {
|
||||||
if (!assureMasterPasswordSet(activity, R.string.nav_import)) return
|
if (!assureMasterPasswordSet(activity, R.string.nav_import)) return
|
||||||
|
|
||||||
TwoMessagesAlertDialog.showAlert(activity!!, resourceHelper.gs(R.string.nav_import),
|
TwoMessagesAlertDialog.showAlert(activity, resourceHelper.gs(R.string.nav_import),
|
||||||
resourceHelper.gs(R.string.import_from) + " " + fileToImport + " ?",
|
resourceHelper.gs(R.string.import_from) + " " + fileToImport + " ?",
|
||||||
resourceHelper.gs(R.string.password_preferences_decrypt_prompt), {
|
resourceHelper.gs(R.string.password_preferences_decrypt_prompt), {
|
||||||
askForMasterPass(activity, R.string.preferences_import_canceled, then)
|
askForMasterPass(activity, R.string.preferences_import_canceled, then)
|
||||||
}, null, R.drawable.ic_header_import)
|
}, null, R.drawable.ic_header_import)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
OKDialog.showConfirmation(activity!!, resourceHelper.gs(R.string.nav_import),
|
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.nav_import),
|
||||||
resourceHelper.gs(R.string.import_from) + " " + fileToImport + " ?",
|
resourceHelper.gs(R.string.import_from) + " " + fileToImport + " ?",
|
||||||
Runnable { then("") })
|
Runnable { then("") })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun exportSharedPreferences(activity: Activity?) {
|
private fun exportSharedPreferences(activity: Activity) {
|
||||||
askToConfirmExport(activity) { password ->
|
askToConfirmExport(activity) { password ->
|
||||||
try {
|
try {
|
||||||
val entries: MutableMap<String, String> = mutableMapOf()
|
val entries: MutableMap<String, String> = mutableMapOf()
|
||||||
|
@ -226,10 +223,10 @@ class ImportExportPrefs @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun importSharedPreferences(fragment: Fragment) {
|
fun importSharedPreferences(fragment: Fragment) {
|
||||||
importSharedPreferences(fragment.activity)
|
fragment.activity?.let { importSharedPreferences(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun importSharedPreferences(activity: Activity?) {
|
fun importSharedPreferences(activity: Activity) {
|
||||||
|
|
||||||
val importFile = prefsImportFile()
|
val importFile = prefsImportFile()
|
||||||
|
|
||||||
|
@ -325,7 +322,7 @@ class ImportExportPrefs @Inject constructor(
|
||||||
return importOk
|
return importOk
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun restartAppAfterImport(context: Context?) {
|
private fun restartAppAfterImport(context: Context) {
|
||||||
sp.putBoolean(R.string.key_setupwizard_processed, true)
|
sp.putBoolean(R.string.key_setupwizard_processed, true)
|
||||||
show(context!!, resourceHelper.gs(R.string.setting_imported), resourceHelper.gs(R.string.restartingapp), Runnable {
|
show(context!!, resourceHelper.gs(R.string.setting_imported), resourceHelper.gs(R.string.restartingapp), Runnable {
|
||||||
log.debug(TAG, "Exiting")
|
log.debug(TAG, "Exiting")
|
||||||
|
|
|
@ -26,8 +26,6 @@ import java.util.*
|
||||||
object PrefImportSummaryDialog {
|
object PrefImportSummaryDialog {
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
@JvmStatic
|
|
||||||
@JvmOverloads
|
|
||||||
fun showSummary(context: Context, importOk: Boolean, importPossible: Boolean, prefs: Prefs, ok: (() -> Unit)?, cancel: (() -> Unit)? = null) {
|
fun showSummary(context: Context, importOk: Boolean, importPossible: Boolean, prefs: Prefs, ok: (() -> Unit)?, cancel: (() -> Unit)? = null) {
|
||||||
|
|
||||||
@StyleRes val theme: Int = if (importOk) R.style.AppTheme else {
|
@StyleRes val theme: Int = if (importOk) R.style.AppTheme else {
|
||||||
|
|
|
@ -14,8 +14,6 @@ import info.nightscout.androidaps.utils.runOnUiThread
|
||||||
object TwoMessagesAlertDialog {
|
object TwoMessagesAlertDialog {
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
@JvmStatic
|
|
||||||
@JvmOverloads
|
|
||||||
fun showAlert(context: Context, title: String, message: String, secondMessage: String, ok: (() -> Unit)?, cancel: (() -> Unit)? = null, @DrawableRes icon: Int? = null) {
|
fun showAlert(context: Context, title: String, message: String, secondMessage: String, ok: (() -> Unit)?, cancel: (() -> Unit)? = null, @DrawableRes icon: Int? = null) {
|
||||||
|
|
||||||
val secondMessageLayout = LayoutInflater.from(context).inflate(R.layout.dialog_alert_two_messages, null)
|
val secondMessageLayout = LayoutInflater.from(context).inflate(R.layout.dialog_alert_two_messages, null)
|
||||||
|
|
Loading…
Reference in a new issue