Merge pull request #15 from osodebailar/import_export_fix_for_very_small_displays

fix for small displays that  cannot import settings due to scroll and…
This commit is contained in:
Milos Kozak 2020-10-01 18:03:54 +02:00 committed by GitHub
commit 04f2b0aa15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 60 additions and 36 deletions

View file

@ -167,7 +167,7 @@ class ImportExportPrefs @Inject constructor(
if (!prefsEncryptionIsDisabled() && !assureMasterPasswordSet(activity, R.string.nav_export)) return
TwoMessagesAlertDialog.showAlert(activity, resourceHelper.gs(R.string.nav_export),
resourceHelper.gs(R.string.export_to) + " " + fileToExport + " ?",
resourceHelper.gs(R.string.export_to) + " " + fileToExport.name + " ?",
resourceHelper.gs(R.string.password_preferences_encrypt_prompt), {
askForMasterPassIfNeeded(activity, R.string.preferences_export_canceled, then)
}, null, R.drawable.ic_header_export)
@ -177,9 +177,8 @@ class ImportExportPrefs @Inject constructor(
if (fileToImport.handler == PrefsFormatsHandler.ENCRYPTED) {
if (!assureMasterPasswordSet(activity, R.string.nav_import)) return
TwoMessagesAlertDialog.showAlert(activity, resourceHelper.gs(R.string.nav_import),
resourceHelper.gs(R.string.import_from) + " " + fileToImport.file + " ?",
resourceHelper.gs(R.string.import_from) + " " + fileToImport.name + " ?",
resourceHelper.gs(R.string.password_preferences_decrypt_prompt), {
askForMasterPass(activity, R.string.preferences_import_canceled, then)
}, null, R.drawable.ic_header_import)

View file

@ -34,6 +34,7 @@ enum class PrefsImportDir {
@Parcelize
data class PrefsFile(
val name: String,
val file: File,
val baseDir: File,
val dirKind: PrefsImportDir,
@ -46,6 +47,7 @@ data class PrefsFile(
class PrefsFileContract : ActivityResultContract<Void, PrefsFile>() {
companion object {
const val OUTPUT_PARAM = "prefs_file"
}
@ -74,6 +76,7 @@ class PrefFileListProvider @Inject constructor(
) {
companion object {
private val path = File(Environment.getExternalStorageDirectory().toString())
private val aapsPath = File(path, "AAPS" + File.separator + "preferences")
private const val IMPORT_AGE_NOT_YET_OLD_DAYS = 60
@ -96,7 +99,7 @@ class PrefFileListProvider @Inject constructor(
val detectedOld = !detectedNew && classicPrefsFormat.isPreferencesFile(it, contents)
if (detectedNew || detectedOld) {
val formatHandler = if (detectedNew) PrefsFormatsHandler.ENCRYPTED else PrefsFormatsHandler.CLASSIC
prefFiles.add(PrefsFile(it, path, PrefsImportDir.ROOT_DIR, formatHandler, metadataFor(loadMetadata, formatHandler, contents)))
prefFiles.add(PrefsFile(it.name, it, path, PrefsImportDir.ROOT_DIR, formatHandler, metadataFor(loadMetadata, formatHandler, contents)))
}
}
@ -104,7 +107,7 @@ class PrefFileListProvider @Inject constructor(
aapsPath.walk().filter { it.isFile && it.name.endsWith(".json") }.forEach {
val contents = storage.getFileContents(it)
if (encryptedPrefsFormat.isPreferencesFile(it, contents)) {
prefFiles.add(PrefsFile(it, aapsPath, PrefsImportDir.AAPS_DIR, PrefsFormatsHandler.ENCRYPTED, metadataFor(loadMetadata, PrefsFormatsHandler.ENCRYPTED, contents)))
prefFiles.add(PrefsFile(it.name, it, aapsPath, PrefsImportDir.AAPS_DIR, PrefsFormatsHandler.ENCRYPTED, metadataFor(loadMetadata, PrefsFormatsHandler.ENCRYPTED, contents)))
}
}

View file

@ -132,6 +132,9 @@ object PrefImportSummaryDialog {
}
val dialog = builder.show()
val textView = dialog.findViewById<View>(android.R.id.message) as TextView?
textView!!.textSize = 12f
textView!!.setPadding(10,0,0,0)
dialog.setCanceledOnTouchOutside(false)
}

View file

@ -1,5 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_content_frame"
android:layout_width="match_parent"
android:layout_height="210dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
@ -9,8 +17,8 @@
android:id="@+id/summary_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:stretchColumns="2" />
<Button
@ -19,12 +27,17 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:gravity="bottom"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="3dp"
android:text="@string/check_preferences_details_btn"
android:textColor="@color/colorTreatmentButton"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
android:padding="10dp">
<TextView
android:id="@+id/password_prompt_title"

View file

@ -25,6 +25,7 @@ object AlertDialogHelper {
val titleLayout = LayoutInflater.from(ContextThemeWrapper(context, themeResId)).inflate(layoutResource, null)
(titleLayout.findViewById<View>(R.id.alertdialog_title) as TextView).text = title
(titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(iconResource)
titleLayout.findViewById<View>(R.id.alertdialog_title).setSelected(true)
return titleLayout
}

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Loading this view directly, without proper Theme, will likely result in crash due to lack of ?dialog... attribute definitions
Please use AlertDialogHelper or wrap inflater context with ContextThemeWrapper(context, R.style.AppTheme)
-->
@ -29,8 +28,14 @@
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginStart="2dp"
android:layout_marginEnd="50dp"
android:layout_marginEnd="40dp"
android:layout_toEndOf="@id/alertdialog_icon"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="?dialogTitleColor" />