fix importing settings
This commit is contained in:
parent
79d24dfeca
commit
13a55eeb42
3 changed files with 26 additions and 8 deletions
|
@ -45,6 +45,8 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin
|
import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin
|
||||||
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils
|
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils
|
||||||
|
import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefs
|
||||||
|
import info.nightscout.androidaps.plugins.general.maintenance.PrefsFileContract
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus
|
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus
|
||||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
||||||
import info.nightscout.androidaps.setupwizard.SetupWizardActivity
|
import info.nightscout.androidaps.setupwizard.SetupWizardActivity
|
||||||
|
@ -87,10 +89,17 @@ class MainActivity : NoSplashAppCompatActivity() {
|
||||||
@Inject lateinit var constraintChecker: ConstraintChecker
|
@Inject lateinit var constraintChecker: ConstraintChecker
|
||||||
@Inject lateinit var signatureVerifierPlugin: SignatureVerifierPlugin
|
@Inject lateinit var signatureVerifierPlugin: SignatureVerifierPlugin
|
||||||
@Inject lateinit var config: Config
|
@Inject lateinit var config: Config
|
||||||
|
@Inject lateinit var importExportPrefs: ImportExportPrefs
|
||||||
|
|
||||||
private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle
|
private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle
|
||||||
private var pluginPreferencesMenuItem: MenuItem? = null
|
private var pluginPreferencesMenuItem: MenuItem? = null
|
||||||
|
|
||||||
|
val callForPrefFile = registerForActivityResult(PrefsFileContract()) {
|
||||||
|
it?.let {
|
||||||
|
importExportPrefs.importSharedPreferences(this, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
Iconify.with(FontAwesomeModule())
|
Iconify.with(FontAwesomeModule())
|
||||||
|
|
|
@ -9,6 +9,8 @@ import dagger.android.support.DaggerAppCompatActivity
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase
|
import info.nightscout.androidaps.interfaces.PluginBase
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
|
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
|
||||||
|
import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefs
|
||||||
|
import info.nightscout.androidaps.plugins.general.maintenance.PrefsFileContract
|
||||||
import info.nightscout.androidaps.utils.locale.LocaleHelper
|
import info.nightscout.androidaps.utils.locale.LocaleHelper
|
||||||
import info.nightscout.androidaps.utils.protection.ProtectionCheck
|
import info.nightscout.androidaps.utils.protection.ProtectionCheck
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -16,9 +18,16 @@ import javax.inject.Inject
|
||||||
class SingleFragmentActivity : DaggerAppCompatActivity() {
|
class SingleFragmentActivity : DaggerAppCompatActivity() {
|
||||||
@Inject lateinit var pluginStore: PluginStore
|
@Inject lateinit var pluginStore: PluginStore
|
||||||
@Inject lateinit var protectionCheck: ProtectionCheck
|
@Inject lateinit var protectionCheck: ProtectionCheck
|
||||||
|
@Inject lateinit var importExportPrefs: ImportExportPrefs
|
||||||
|
|
||||||
private var plugin: PluginBase? = null
|
private var plugin: PluginBase? = null
|
||||||
|
|
||||||
|
val callForPrefFile = registerForActivityResult(PrefsFileContract()) {
|
||||||
|
it?.let {
|
||||||
|
importExportPrefs.importSharedPreferences(this, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_single_fragment)
|
setContentView(R.layout.activity_single_fragment)
|
||||||
|
|
|
@ -12,8 +12,10 @@ import androidx.core.content.ContextCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import info.nightscout.androidaps.BuildConfig
|
import info.nightscout.androidaps.BuildConfig
|
||||||
|
import info.nightscout.androidaps.MainActivity
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.activities.PreferencesActivity
|
import info.nightscout.androidaps.activities.PreferencesActivity
|
||||||
|
import info.nightscout.androidaps.activities.SingleFragmentActivity
|
||||||
import info.nightscout.androidaps.events.EventAppExit
|
import info.nightscout.androidaps.events.EventAppExit
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
|
@ -261,14 +263,12 @@ class ImportExportPrefs @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun importSharedPreferences(activity: FragmentActivity) {
|
fun importSharedPreferences(activity: FragmentActivity) {
|
||||||
val callForPrefFile = activity.registerForActivityResult(PrefsFileContract()) {
|
|
||||||
it?.let {
|
|
||||||
importSharedPreferences(activity, it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
callForPrefFile.launch(null)
|
if (activity is SingleFragmentActivity)
|
||||||
|
activity.callForPrefFile.launch(null)
|
||||||
|
if (activity is MainActivity)
|
||||||
|
activity.callForPrefFile.launch(null)
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
// this exception happens on some early implementations of ActivityResult contracts
|
// this exception happens on some early implementations of ActivityResult contracts
|
||||||
// when registered and called for the second time
|
// when registered and called for the second time
|
||||||
|
@ -277,12 +277,12 @@ class ImportExportPrefs @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun importSharedPreferences(activity: FragmentActivity, importFile: PrefsFile) {
|
public fun importSharedPreferences(activity: FragmentActivity, importFile: PrefsFile) {
|
||||||
|
|
||||||
askToConfirmImport(activity, importFile) { password ->
|
askToConfirmImport(activity, importFile) { password ->
|
||||||
|
|
||||||
val format: PrefsFormat = when (importFile.handler) {
|
val format: PrefsFormat = when (importFile.handler) {
|
||||||
PrefsFormatsHandler.CLASSIC -> classicPrefsFormat
|
PrefsFormatsHandler.CLASSIC -> classicPrefsFormat
|
||||||
PrefsFormatsHandler.ENCRYPTED -> encryptedPrefsFormat
|
PrefsFormatsHandler.ENCRYPTED -> encryptedPrefsFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue