]> git.ktnx.net Git - mobile-ledger.git/commitdiff
persistent profile list order
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 10 Jan 2019 17:38:04 +0000 (17:38 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 10 Jan 2019 17:38:04 +0000 (17:38 +0000)
app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileListActivity.java
app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java
app/src/main/res/raw/sql_16.sql [new file with mode: 0644]

index 038515bfb02e4ec32e01293476c179c878276f22..96fa9b215e88fc1727c2437fe0a213bf77ebf141 100644 (file)
@@ -65,6 +65,22 @@ public final class MobileLedgerProfile {
         }
         return result;
     }
+    public static void storeProfilesOrder() {
+        SQLiteDatabase db = MLDB.getWritableDatabase();
+        db.beginTransaction();
+        try {
+            int orderNo = 0;
+            for (MobileLedgerProfile p : Data.profiles.getList()) {
+                db.execSQL("update profiles set order_no=? where uuid=?",
+                        new Object[]{orderNo, p.getUuid()});
+                orderNo++;
+            }
+            db.setTransactionSuccessful();
+        }
+        finally {
+            db.endTransaction();
+        }
+    }
     public static List<MobileLedgerProfile> createInitialProfileList() {
         List<MobileLedgerProfile> result = new ArrayList<>();
         MobileLedgerProfile first =
index b61f567a6dbc0cbb13960ea962060e6d04594b09..3e4f14b2d37fd3f7cc76a8ab58bb542eefa23a72 100644 (file)
@@ -127,6 +127,7 @@ public class ProfileListActivity extends AppCompatActivity {
                                   @NonNull RecyclerView.ViewHolder target) {
                 Collections.swap(Data.profiles.getList(), viewHolder.getAdapterPosition(),
                         target.getAdapterPosition());
+                MobileLedgerProfile.storeProfilesOrder();
                 adapter.notifyItemMoved(viewHolder.getAdapterPosition(),
                         target.getAdapterPosition());
                 return true;
index b863cf6eab542942cbfefbe59c5322ad99903a1c..f4cfa619fc5aafc66015db2f58f2d1c176af54d6 100644 (file)
@@ -200,12 +200,13 @@ public final class MLDB {
         if ((helperForWriting != helperForReading) && (helperForWriting != null))
             helperForWriting.close();
     }
+
     public enum DatabaseMode {READ, WRITE}
 }
 
 class MobileLedgerDatabase extends SQLiteOpenHelper implements AutoCloseable {
     public static final String DB_NAME = "mobile-ledger.db";
-    public static final int LATEST_REVISION = 15;
+    public static final int LATEST_REVISION = 16;
 
     private final Application mContext;
 
diff --git a/app/src/main/res/raw/sql_16.sql b/app/src/main/res/raw/sql_16.sql
new file mode 100644 (file)
index 0000000..235f655
--- /dev/null
@@ -0,0 +1 @@
+alter table profiles add order_no integer;
\ No newline at end of file