Code cleanup
This commit is contained in:
parent
f532341ccc
commit
3565ef9fbc
2 changed files with 29 additions and 26 deletions
|
@ -81,16 +81,19 @@ class ImportExportPrefs @Inject constructor(
|
||||||
return encFile.exists() || file.exists()
|
return encFile.exists() || file.exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun exportSharedPreferences(f: Fragment) {
|
fun exportSharedPreferences(f: Fragment) {
|
||||||
f.activity?.let { exportSharedPreferences(it) }
|
f.activity?.let { exportSharedPreferences(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun verifyStoragePermissions(fragment: Fragment) {
|
fun verifyStoragePermissions(fragment: Fragment) {
|
||||||
val permission = ContextCompat.checkSelfPermission(fragment.context!!,
|
fragment.context?.let {
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
val permission = ContextCompat.checkSelfPermission(it,
|
||||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
// We don't have permission so prompt the user
|
if (permission != PackageManager.PERMISSION_GRANTED) {
|
||||||
fragment.requestPermissions(PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE)
|
// We don't have permission so prompt the user
|
||||||
|
fragment.requestPermissions(PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +248,7 @@ class ImportExportPrefs @Inject constructor(
|
||||||
// if at end we allow to import preferences
|
// if at end we allow to import preferences
|
||||||
val importPossible = (importOk || buildHelper.isEngineeringMode()) && (prefs.values.size > 0)
|
val importPossible = (importOk || buildHelper.isEngineeringMode()) && (prefs.values.size > 0)
|
||||||
|
|
||||||
PrefImportSummaryDialog.showSummary(activity!!, importOk, importPossible, prefs, {
|
PrefImportSummaryDialog.showSummary(activity, importOk, importPossible, prefs, {
|
||||||
if (importPossible) {
|
if (importPossible) {
|
||||||
sp.clear()
|
sp.clear()
|
||||||
for ((key, value) in prefs.values) {
|
for ((key, value) in prefs.values) {
|
||||||
|
@ -277,35 +280,35 @@ class ImportExportPrefs @Inject constructor(
|
||||||
private fun checkMetadata(metadata: Map<PrefsMetadataKey, PrefMetadata>): Map<PrefsMetadataKey, PrefMetadata> {
|
private fun checkMetadata(metadata: Map<PrefsMetadataKey, PrefMetadata>): Map<PrefsMetadataKey, PrefMetadata> {
|
||||||
val meta = metadata.toMutableMap()
|
val meta = metadata.toMutableMap()
|
||||||
|
|
||||||
if (meta.containsKey(PrefsMetadataKey.AAPS_FLAVOUR)) {
|
meta[PrefsMetadataKey.AAPS_FLAVOUR]?.let { flavour ->
|
||||||
val flavourOfPrefs = meta[PrefsMetadataKey.AAPS_FLAVOUR]!!.value
|
val flavourOfPrefs = flavour.value
|
||||||
if (meta[PrefsMetadataKey.AAPS_FLAVOUR]!!.value != BuildConfig.FLAVOR) {
|
if (flavour.value != BuildConfig.FLAVOR) {
|
||||||
meta[PrefsMetadataKey.AAPS_FLAVOUR]!!.status = PrefsStatus.WARN
|
flavour.status = PrefsStatus.WARN
|
||||||
meta[PrefsMetadataKey.AAPS_FLAVOUR]!!.info = resourceHelper.gs(R.string.metadata_warning_different_flavour, flavourOfPrefs, BuildConfig.FLAVOR)
|
flavour.info = resourceHelper.gs(R.string.metadata_warning_different_flavour, flavourOfPrefs, BuildConfig.FLAVOR)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
meta[PrefsMetadataKey.DEVICE_MODEL]?.let { model ->
|
||||||
|
if (model.value != getCurrentDeviceModelString()) {
|
||||||
|
model.status = PrefsStatus.WARN
|
||||||
|
model.info = resourceHelper.gs(R.string.metadata_warning_different_device)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta.containsKey(PrefsMetadataKey.DEVICE_MODEL)) {
|
meta[PrefsMetadataKey.CREATED_AT]?.let { createdAt ->
|
||||||
if (meta[PrefsMetadataKey.DEVICE_MODEL]!!.value != getCurrentDeviceModelString()) {
|
|
||||||
meta[PrefsMetadataKey.DEVICE_MODEL]!!.status = PrefsStatus.WARN
|
|
||||||
meta[PrefsMetadataKey.DEVICE_MODEL]!!.info = resourceHelper.gs(R.string.metadata_warning_different_device)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (meta.containsKey(PrefsMetadataKey.CREATED_AT)) {
|
|
||||||
try {
|
try {
|
||||||
val date1 = DateTime.parse(meta[PrefsMetadataKey.CREATED_AT]!!.value);
|
val date1 = DateTime.parse(createdAt.value);
|
||||||
val date2 = DateTime.now()
|
val date2 = DateTime.now()
|
||||||
|
|
||||||
val daysOld = Days.daysBetween(date1.toLocalDate(), date2.toLocalDate()).getDays()
|
val daysOld = Days.daysBetween(date1.toLocalDate(), date2.toLocalDate()).getDays()
|
||||||
|
|
||||||
if (daysOld > IMPORT_AGE_NOT_YET_OLD_DAYS) {
|
if (daysOld > IMPORT_AGE_NOT_YET_OLD_DAYS) {
|
||||||
meta[PrefsMetadataKey.CREATED_AT]!!.status = PrefsStatus.WARN
|
createdAt.status = PrefsStatus.WARN
|
||||||
meta[PrefsMetadataKey.CREATED_AT]!!.info = resourceHelper.gs(R.string.metadata_warning_old_export, daysOld.toString())
|
createdAt.info = resourceHelper.gs(R.string.metadata_warning_old_export, daysOld.toString())
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
meta[PrefsMetadataKey.CREATED_AT]!!.status = PrefsStatus.WARN
|
createdAt.status = PrefsStatus.WARN
|
||||||
meta[PrefsMetadataKey.CREATED_AT]!!.info = resourceHelper.gs(R.string.metadata_warning_date_format)
|
createdAt.info = resourceHelper.gs(R.string.metadata_warning_date_format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +327,7 @@ class ImportExportPrefs @Inject constructor(
|
||||||
|
|
||||||
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")
|
||||||
rxBus.send(EventAppExit())
|
rxBus.send(EventAppExit())
|
||||||
if (context is Activity) {
|
if (context is Activity) {
|
||||||
|
|
|
@ -109,7 +109,7 @@ class EncryptedPrefsFormat @Inject constructor(
|
||||||
val fileFormat = container.getString(PrefsMetadataKey.FILE_FORMAT.key)
|
val fileFormat = container.getString(PrefsMetadataKey.FILE_FORMAT.key)
|
||||||
|
|
||||||
if ((fileFormat != FORMAT_KEY_ENC) && (fileFormat != FORMAT_KEY_NOENC)) {
|
if ((fileFormat != FORMAT_KEY_ENC) && (fileFormat != FORMAT_KEY_NOENC)) {
|
||||||
throw PrefFormatError("Unsupported file format: "+fileFormat)
|
throw PrefFormatError("Unsupported file format: " + fileFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
val meta = container.getJSONObject("metadata")
|
val meta = container.getJSONObject("metadata")
|
||||||
|
|
Loading…
Reference in a new issue