From b0c738e0177eef08f9519b970eb28bd3c2784401 Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 2 Jun 2024 21:55:11 +0200 Subject: [PATCH] Remove unused code --- .../main/java/net/foucry/pilldroid/Utils.java | 77 ++----------------- 1 file changed, 6 insertions(+), 71 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java index ad179a8..81a12b1 100644 --- a/app/src/main/java/net/foucry/pilldroid/Utils.java +++ b/app/src/main/java/net/foucry/pilldroid/Utils.java @@ -3,7 +3,6 @@ package net.foucry.pilldroid; import net.foucry.pilldroid.models.Medicine; import net.foucry.pilldroid.models.Prescription; -import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Locale; @@ -49,75 +48,11 @@ public class Utils { } public static void sortPrescriptionList(List prescriptionList) { - prescriptionList.sort(new Comparator<>() { - @Override - public int compare(Prescription lhs, Prescription rhs) { - if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0) - return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); - else - return (int) (lhs.getStock() - rhs.getStock()); - } - if(id == R.id.action_save_db) { + prescriptionList.sort((lhs, rhs) -> { + if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0) + return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); + else + return (int) (lhs.getStock() - rhs.getStock()); }); } - - public void backupDB() { - int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE); - if(permission == PackageManager.PERMISSION_GRANTED) { - //AppDatabase.getInstance(this).getDatabase().close(); - PrescriptionDatabase.getInstanceDatabase(this).getDatabase().close(); - - File db = getDatabasePath("PrescriptionDatabase"); - File dbShm = new File(db.getParent(), "PrescriptionDatabase-shm"); - File dbWal = new File(db.getParent(), "PrescriptionDatabase-wal"); - - File db2 = new File("/sdcard/", "PrescriptionDatabase"); - File dbShm2 = new File(db2.getParent(), "PrescriptionDatabase-shm"); - File dbWal2 = new File(db2.getParent(), "PrescriptionDatabase-wal"); - - try { - FileUtils.copyFile(db, db2); - FileUtils.copyFile(dbShm, dbShm2); - FileUtils.copyFile(dbWal, dbWal2); - } catch (Exception e) { - Log.e("SAVEDB", e.toString()); - } - } else { - Snackbar.make(mDrawer, "Please allow access to your storage", Snackbar.LENGTH_LONG) - .setAction("Allow", view -> ActivityCompat.requestPermissions(this, new String[] { - Manifest.permission.WRITE_EXTERNAL_STORAGE - }, 0)).show(); - } - } - - public void restoreDB () - { - int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE); - if(permission == PackageManager.PERMISSION_GRANTED) { - //AppDatabase.getInstance(this).getDatabase().close(); - PrescriptionDatabase.getInstanceDatabase(this).getDatabase().close(); - - File db = new File("/sdcard/", "PrescriptionDatabaseb"); - File dbShm = new File(db.getParent(), "PrescriptionDatabase-shm"); - File dbWal = new File(db.getParent(), "PrescriptionDatabase-wal"); - - File db2 = getDatabasePath("PrescriptionDatabase"); - File dbShm2 = new File(db2.getParent(), "PrescriptionDatabase-shm"); - File dbWal2 = new File(db2.getParent(), "PrescriptionDatabase-wal"); - - try { - FileUtils.copyFile(db, db2); - FileUtils.copyFile(dbShm, dbShm2); - FileUtils.copyFile(dbWal, dbWal2); - } catch (Exception e) { - Loge("RESTOREDB", e.toString()); - } - } else { - Snackbar.make(mDrawer, "Please allow access to your storage", Snackbar.LENGTH_LONG) - .setAction("Allow", view -> ActivityCompat.requestPermissions(this, new String[] { - Manifest.permission.READ_EXTERNAL_STORAGE - }, 0)).show(); - } - } - -} +} \ No newline at end of file