xml export initialization
This commit is contained in:
parent
c065672179
commit
177bf214fd
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.BuildConfig
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.activities.DaggerAppCompatActivityWithResult
|
import info.nightscout.androidaps.activities.DaggerAppCompatActivityWithResult
|
||||||
import info.nightscout.androidaps.activities.PreferencesActivity
|
import info.nightscout.androidaps.activities.PreferencesActivity
|
||||||
|
import info.nightscout.androidaps.database.entities.UserEntry
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.*
|
import info.nightscout.androidaps.database.entities.UserEntry.*
|
||||||
import info.nightscout.androidaps.events.EventAppExit
|
import info.nightscout.androidaps.events.EventAppExit
|
||||||
import info.nightscout.androidaps.interfaces.ConfigInterface
|
import info.nightscout.androidaps.interfaces.ConfigInterface
|
||||||
|
@ -35,6 +36,7 @@ import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||||
import info.nightscout.androidaps.utils.protection.PasswordCheck
|
import info.nightscout.androidaps.utils.protection.PasswordCheck
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
import io.reactivex.Single
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileNotFoundException
|
import java.io.FileNotFoundException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
@ -355,4 +357,49 @@ class ImportExportPrefs @Inject constructor(
|
||||||
exitProcess(0)
|
exitProcess(0)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override fun exportUserEntriesXml(activity: FragmentActivity, listEntries: Single<List<UserEntry>>) {
|
||||||
|
val entries = listEntries.blockingGet()
|
||||||
|
prefFileList.ensureExportDirExists()
|
||||||
|
val legacyFile = prefFileList.legacyFile()
|
||||||
|
val newFile = prefFileList.newExportXmlFile()
|
||||||
|
/*
|
||||||
|
askToConfirmExport(activity, newFile) { password ->
|
||||||
|
try {
|
||||||
|
val entries: MutableMap<String, String> = mutableMapOf()
|
||||||
|
for ((key, value) in sp.getAll()) {
|
||||||
|
entries[key] = value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
val prefs = Prefs(entries, prepareMetadata(activity))
|
||||||
|
|
||||||
|
if (BuildConfig.DEBUG && buildHelper.isEngineeringMode()) {
|
||||||
|
classicPrefsFormat.savePreferences(legacyFile, prefs)
|
||||||
|
}
|
||||||
|
encryptedPrefsFormat.savePreferences(newFile, prefs, password)
|
||||||
|
|
||||||
|
ToastUtils.okToast(activity, resourceHelper.gs(R.string.exported))
|
||||||
|
} catch (e: FileNotFoundException) {
|
||||||
|
ToastUtils.errorToast(activity, resourceHelper.gs(R.string.filenotfound) + " " + newFile)
|
||||||
|
log.error(LTag.CORE, "Unhandled exception", e)
|
||||||
|
} catch (e: IOException) {
|
||||||
|
ToastUtils.errorToast(activity, e.message)
|
||||||
|
log.error(LTag.CORE, "Unhandled exception", e)
|
||||||
|
} catch (e: PrefFileNotFoundError) {
|
||||||
|
ToastUtils.Long.errorToast(activity, resourceHelper.gs(R.string.preferences_export_canceled)
|
||||||
|
+ "\n\n" + resourceHelper.gs(R.string.filenotfound)
|
||||||
|
+ ": " + e.message
|
||||||
|
+ "\n\n" + resourceHelper.gs(R.string.needstoragepermission))
|
||||||
|
log.error(LTag.CORE, "File system exception", e)
|
||||||
|
} catch (e: PrefIOError) {
|
||||||
|
ToastUtils.Long.errorToast(activity, resourceHelper.gs(R.string.preferences_export_canceled)
|
||||||
|
+ "\n\n" + resourceHelper.gs(R.string.needstoragepermission)
|
||||||
|
+ ": " + e.message)
|
||||||
|
log.error(LTag.CORE, "File system exception", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -14,12 +14,16 @@ import info.nightscout.androidaps.database.entities.UserEntry
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.*
|
import info.nightscout.androidaps.database.entities.UserEntry.*
|
||||||
import info.nightscout.androidaps.databinding.TreatmentsUserEntryFragmentBinding
|
import info.nightscout.androidaps.databinding.TreatmentsUserEntryFragmentBinding
|
||||||
import info.nightscout.androidaps.databinding.TreatmentsUserEntryItemBinding
|
import info.nightscout.androidaps.databinding.TreatmentsUserEntryItemBinding
|
||||||
|
import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.Translator
|
import info.nightscout.androidaps.utils.Translator
|
||||||
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||||
import info.nightscout.androidaps.utils.extensions.*
|
import info.nightscout.androidaps.utils.extensions.*
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
|
@ -37,6 +41,8 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
||||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||||
@Inject lateinit var rxBus: RxBusWrapper
|
@Inject lateinit var rxBus: RxBusWrapper
|
||||||
@Inject lateinit var translator: Translator
|
@Inject lateinit var translator: Translator
|
||||||
|
@Inject lateinit var importExportPrefs: ImportExportPrefsInterface
|
||||||
|
@Inject lateinit var uel: UserEntryLogger
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
|
@ -53,6 +59,14 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
binding.recyclerview.setHasFixedSize(true)
|
binding.recyclerview.setHasFixedSize(true)
|
||||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||||
|
binding.ueExportToXml.setOnClickListener {
|
||||||
|
activity?.let { activity ->
|
||||||
|
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.ue_export_to_xml) + "?") {
|
||||||
|
uel.log(Action.TREATMENTS_NS_REFRESH)
|
||||||
|
importExportPrefs.exportUserEntriesXml(activity, repository.getAllUserEntries())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
disposable += repository
|
disposable += repository
|
||||||
.getAllUserEntries()
|
.getAllUserEntries()
|
||||||
|
|
|
@ -5,6 +5,15 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context=".plugins.treatments.fragments.TreatmentsUserEntryFragment">
|
tools:context=".plugins.treatments.fragments.TreatmentsUserEntryFragment">
|
||||||
|
|
||||||
|
<info.nightscout.androidaps.utils.ui.SingleClickButton
|
||||||
|
android:id="@+id/ue_export_to_xml"
|
||||||
|
style="?android:attr/buttonStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:drawableStart="@drawable/ic_header_export"
|
||||||
|
android:text="@string/ue_export_to_xml" />
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recyclerview"
|
android:id="@+id/recyclerview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -2,7 +2,9 @@ package info.nightscout.androidaps.interfaces
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
|
import info.nightscout.androidaps.database.entities.UserEntry
|
||||||
import info.nightscout.androidaps.plugins.general.maintenance.PrefsFile
|
import info.nightscout.androidaps.plugins.general.maintenance.PrefsFile
|
||||||
|
import io.reactivex.Single
|
||||||
|
|
||||||
interface ImportExportPrefsInterface {
|
interface ImportExportPrefsInterface {
|
||||||
|
|
||||||
|
@ -12,4 +14,5 @@ interface ImportExportPrefsInterface {
|
||||||
fun prefsFileExists(): Boolean
|
fun prefsFileExists(): Boolean
|
||||||
fun verifyStoragePermissions(fragment: Fragment, onGranted: Runnable)
|
fun verifyStoragePermissions(fragment: Fragment, onGranted: Runnable)
|
||||||
fun exportSharedPreferences(f: Fragment)
|
fun exportSharedPreferences(f: Fragment)
|
||||||
|
fun exportUserEntriesXml(activity: FragmentActivity, entries: Single<List<UserEntry>>)
|
||||||
}
|
}
|
|
@ -100,6 +100,11 @@ class PrefFileListProvider @Inject constructor(
|
||||||
return File(aapsPath, timeLocal + "_" + config.FLAVOR + ".json")
|
return File(aapsPath, timeLocal + "_" + config.FLAVOR + ".json")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun newExportXmlFile(): File {
|
||||||
|
val timeLocal = LocalDateTime.now().toString(DateTimeFormat.forPattern("yyyy-MM-dd'_'HHmmss"))
|
||||||
|
return File(aapsPath, timeLocal + "_UserEntry.xml")
|
||||||
|
}
|
||||||
|
|
||||||
// check metadata for known issues, change their status and add info with explanations
|
// check metadata for known issues, change their status and add info with explanations
|
||||||
fun checkMetadata(metadata: Map<PrefsMetadataKey, PrefMetadata>): Map<PrefsMetadataKey, PrefMetadata> {
|
fun checkMetadata(metadata: Map<PrefsMetadataKey, PrefMetadata>): Map<PrefsMetadataKey, PrefMetadata> {
|
||||||
val meta = metadata.toMutableMap()
|
val meta = metadata.toMutableMap()
|
||||||
|
|
|
@ -102,6 +102,7 @@ fun UserEntry.Action.stringId(): Int {
|
||||||
UserEntry.Action.TT_DELETED_FROM_NS -> R.string.uel_tt_deleted_from_ns
|
UserEntry.Action.TT_DELETED_FROM_NS -> R.string.uel_tt_deleted_from_ns
|
||||||
UserEntry.Action.TT_FROM_NS -> R.string.uel_tt_from_ns
|
UserEntry.Action.TT_FROM_NS -> R.string.uel_tt_from_ns
|
||||||
UserEntry.Action.TT_CANCELED_FROM_NS -> R.string.uel_tt_canceleted_from_ns
|
UserEntry.Action.TT_CANCELED_FROM_NS -> R.string.uel_tt_canceleted_from_ns
|
||||||
|
UserEntry.Action.UE_EXPORT_TO_XML -> R.string.ue_export_to_xml
|
||||||
else -> R.string.uel_unknown
|
else -> R.string.uel_unknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -486,6 +486,7 @@
|
||||||
<string name="uel_tt_canceleted_from_ns">TT CANCELED FROM NS</string>
|
<string name="uel_tt_canceleted_from_ns">TT CANCELED FROM NS</string>
|
||||||
<string name="uel_unknown">UNKNOWN</string>
|
<string name="uel_unknown">UNKNOWN</string>
|
||||||
<string name="formated_string">Formated string</string>
|
<string name="formated_string">Formated string</string>
|
||||||
|
<string name="ue_export_to_xml">Export User Entries to xml</string>
|
||||||
|
|
||||||
<plurals name="days">
|
<plurals name="days">
|
||||||
<item quantity="one">%1$d day</item>
|
<item quantity="one">%1$d day</item>
|
||||||
|
|
|
@ -115,6 +115,7 @@ data class UserEntry(
|
||||||
@SerializedName("TT_DELETED_FROM_NS") TT_DELETED_FROM_NS,
|
@SerializedName("TT_DELETED_FROM_NS") TT_DELETED_FROM_NS,
|
||||||
@SerializedName("TT_FROM_NS") TT_FROM_NS,
|
@SerializedName("TT_FROM_NS") TT_FROM_NS,
|
||||||
@SerializedName("TT_CANCELED_FROM_NS") TT_CANCELED_FROM_NS,
|
@SerializedName("TT_CANCELED_FROM_NS") TT_CANCELED_FROM_NS,
|
||||||
|
@SerializedName("UE_EXPORT_TO_XML") UE_EXPORT_TO_XML,
|
||||||
@SerializedName("UNKNOWN") UNKNOWN
|
@SerializedName("UNKNOWN") UNKNOWN
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue