Fix crash when preferences import list is opened for the second time (due to buggy implementation of ActivityResult and Contracts in early androidx)
* updated to newest version of fragments where bug is fixed * catched exception and inform user with Toast * refactor duplicated code in ImportExportPrefs
This commit is contained in:
parent
4ef40c70c5
commit
4068cd72ca
3 changed files with 12 additions and 7 deletions
|
@ -257,6 +257,7 @@ dependencies {
|
|||
implementation 'androidx.percentlayout:percentlayout:1.0.0'
|
||||
implementation "androidx.preference:preference-ktx:1.1.1"
|
||||
implementation "androidx.activity:activity-ktx:${activityVersion}"
|
||||
implementation "androidx.fragment:fragment:${fragmentVersion}"
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'com.google.android.material:material:1.1.0'
|
||||
|
||||
|
|
|
@ -215,12 +215,7 @@ class ImportExportPrefs @Inject constructor(
|
|||
|
||||
fun importSharedPreferences(fragment: Fragment) {
|
||||
fragment.activity?.let { fragmentAct ->
|
||||
val callForPrefFile = fragmentAct.registerForActivityResult(PrefsFileContract()) {
|
||||
it?.let {
|
||||
importSharedPreferences(fragmentAct, it)
|
||||
}
|
||||
}
|
||||
callForPrefFile.launch(null)
|
||||
importSharedPreferences(fragmentAct)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,7 +225,15 @@ class ImportExportPrefs @Inject constructor(
|
|||
importSharedPreferences(activity, it)
|
||||
}
|
||||
}
|
||||
callForPrefFile.launch(null)
|
||||
|
||||
try {
|
||||
callForPrefFile.launch(null)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
// this exception happens on some early implementations of ActivityResult contracts
|
||||
// when registered and called for the second time
|
||||
ToastUtils.errorToast(activity, "Please go back to main screen and try again.")
|
||||
log.error(TAG, "Internal android framework exception", e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun importSharedPreferences(activity: Activity, importFile: PrefsFile) {
|
||||
|
|
|
@ -12,6 +12,7 @@ buildscript {
|
|||
dagger_version = '2.28.1'
|
||||
coroutinesVersion = '1.3.7'
|
||||
activityVersion = '1.2.0-alpha06'
|
||||
fragmentVersion = '1.3.0-alpha07'
|
||||
ormLiteVersion = "4.46"
|
||||
}
|
||||
repositories {
|
||||
|
|
Loading…
Reference in a new issue