From 3d6ddb8d5edecb8931a352547d88bef1ad032b5e Mon Sep 17 00:00:00 2001 From: vanous Date: Sat, 7 Sep 2019 11:07:40 +0200 Subject: [PATCH] make look nicer - font, uri string, buttons positions --- .../activities/DbManagementActivity.java | 49 +++++++++++++++++-- .../res/layout/activity_db_management.xml | 32 ++++++------ app/src/main/res/values/strings.xml | 3 +- 3 files changed, 63 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DbManagementActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DbManagementActivity.java index 3a0765db2..b92e2bff8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DbManagementActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DbManagementActivity.java @@ -17,13 +17,18 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.activities; +import android.app.Activity; import android.app.AlertDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.database.Cursor; import android.database.sqlite.SQLiteOpenHelper; +import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; +import android.provider.DocumentsContract; import android.view.MenuItem; import android.view.View; import android.widget.Button; @@ -45,6 +50,7 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; import nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter; import nodomain.freeyourgadget.gadgetbridge.entities.Device; +import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils; import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; @@ -104,7 +110,8 @@ public class DbManagementActivity extends AbstractGBActivity { Prefs prefs = GBApplication.getPrefs(); boolean autoExportEnabled = prefs.getBoolean(GBPrefs.AUTO_EXPORT_ENABLED, false); Integer autoExportInterval = prefs.getInt(GBPrefs.AUTO_EXPORT_INTERVAL, 0); - String autoExportLocation = prefs.getString(GBPrefs.AUTO_EXPORT_LOCATION, ""); + //returns an ugly content://... + //String autoExportLocation = prefs.getString(GBPrefs.AUTO_EXPORT_LOCATION, ""); int testExportVisibility = (autoExportInterval > 0 && autoExportEnabled) ? View.VISIBLE : View.GONE; @@ -114,22 +121,54 @@ public class DbManagementActivity extends AbstractGBActivity { TextView autoExportLocation_intro = findViewById(R.id.autoExportLocation_intro); autoExportLocation_intro.setVisibility(testExportVisibility); - TextView autoExportLocationview = findViewById(R.id.autoExportLocationview); - autoExportLocationview.setVisibility(testExportVisibility); - autoExportLocationview.setText(autoExportLocation); + TextView autoExportLocation_path = findViewById(R.id.autoExportLocation_path); + autoExportLocation_path.setVisibility(testExportVisibility); + autoExportLocation_path.setText(getAutoExportLocationSummary()); + final Context context = getApplicationContext(); Button testExportDBButton = findViewById(R.id.testExportDBButton); testExportDBButton.setVisibility(testExportVisibility); testExportDBButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - sendBroadcast(new Intent(getApplicationContext(), PeriodicExporter.class)); + sendBroadcast(new Intent(context, PeriodicExporter.class)); + GB.toast(context, + context.getString(R.string.activity_DB_test_export_message), + Toast.LENGTH_SHORT, GB.INFO); } }); sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); } + //would rather re-use method of SettingsActivity... but lifecycle... + private String getAutoExportLocationSummary() { + String autoExportLocation = GBApplication.getPrefs().getString(GBPrefs.AUTO_EXPORT_LOCATION, null); + if (autoExportLocation == null) { + return ""; + } + Uri uri = Uri.parse(autoExportLocation); + try { + return AndroidUtils.getFilePath(getApplicationContext(), uri); + } catch (IllegalArgumentException e) { + try { + Cursor cursor = getContentResolver().query( + uri, + new String[]{DocumentsContract.Document.COLUMN_DISPLAY_NAME}, + null, null, null, null + ); + if (cursor != null && cursor.moveToFirst()) { + return cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME)); + } + } + catch (Exception fdfsdfds) { + LOG.warn("fuck"); + } + } + return ""; + } + + private boolean hasOldActivityDatabase() { return new DBHelper(this).existsDB("ActivityDatabase"); } diff --git a/app/src/main/res/layout/activity_db_management.xml b/app/src/main/res/layout/activity_db_management.xml index 912a642c9..8d57a6404 100644 --- a/app/src/main/res/layout/activity_db_management.xml +++ b/app/src/main/res/layout/activity_db_management.xml @@ -30,18 +30,6 @@ grid:layout_columnSpan="2" grid:layout_columnWeight="1" /> -