From 76409f197780a5b0168ebf05b5204590d2dbc459 Mon Sep 17 00:00:00 2001 From: Jacques Date: Sat, 14 Sep 2024 10:14:29 +0200 Subject: [PATCH] [WIP] Add folder picker code --- .../foucry/pilldroid/DrugListActivity.java | 54 +++++-------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index ff89bc9..0065261 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -322,7 +322,8 @@ public class DrugListActivity extends AppCompatActivity { startActivity(new Intent(this, WelcomeActivity.class)); return true; } else if (id == R.id.ImportExport) { - backupprefs(); + //backupprefs(); + choseDir(); } return super.onOptionsItemSelected(item); } @@ -331,6 +332,11 @@ public class DrugListActivity extends AppCompatActivity { protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); constructDrugsList(); + if(requestCode == PICK_DIRECTORY && resultCode == RESULT_OK) { + Bundle extras = data.getExtras(); + String path = (String) extras.get("chosenDir"); + println("Path ==" path); + } } public void onResume() { @@ -722,6 +728,12 @@ public class DrugListActivity extends AppCompatActivity { } } + void choseDir() { + Intent result = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); + result.putExtra("chosenDir", path); + setResult(RESULT_OK, result); + } + void backupprefs() { Log.i(TAG, "backupprefs"); @@ -910,43 +922,3 @@ public class DrugListActivity extends AppCompatActivity { } } } - - -/* -final RoomBackup roomBackup = new RoomBackup(MainActivityJava.this); - */ -/*---------------------Backup and Restore Database--------------------------*//* - - btn_backup.setOnClickListener(v -> { - roomBackup.backupLocation(storageLocation); - roomBackup.backupLocationCustomFile(new File(this.getFilesDir() + "/databasebackup/geilesBackup.sqlite3")); - roomBackup.database(FruitDatabase.Companion.getInstance(getApplicationContext())); - roomBackup.enableLogDebug(enableLog); - roomBackup.backupIsEncrypted(encryptBackup); - roomBackup.customEncryptPassword(MainActivity.SECRET_PASSWORD); - if (useMaxFileCount) - roomBackup.maxFileCount(5); - roomBackup.onCompleteListener((success, message, exitCode) -> { - Log.d(TAG, "oncomplete: " + success + ", message: " + message + ", exitCode: " + exitCode); - if (success) - roomBackup.restartApp(new Intent(getApplicationContext(), MainActivityJava.class)); - }); - roomBackup.backup(); - - }); - - btn_restore.setOnClickListener(v -> { - roomBackup.backupLocation(storageLocation); - roomBackup.backupLocationCustomFile(new File(this.getFilesDir() + "/databasebackup/geilesBackup.sqlite3")); - roomBackup.database(FruitDatabase.Companion.getInstance(getApplicationContext())); - roomBackup.enableLogDebug(enableLog); - roomBackup.backupIsEncrypted(encryptBackup); - roomBackup.customEncryptPassword(MainActivity.SECRET_PASSWORD); - roomBackup.onCompleteListener((success, message, exitCode) -> { - Log.d(TAG, "oncomplete: " + success + ", message: " + message + ", exitCode: " + exitCode); - if (success) - roomBackup.restartApp(new Intent(getApplicationContext(), MainActivityJava.class)); - }); - roomBackup.restore(); - - });*/