From: Damyan Ivanov Date: Thu, 10 Jan 2019 17:38:04 +0000 (+0000) Subject: persistent profile list order X-Git-Tag: v0.3~83 X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=commitdiff_plain;h=ab390e82c5d6c9924d3fac5edbc808fb491fbc8d persistent profile list order --- diff --git a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java index 038515bf..96fa9b21 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -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 createInitialProfileList() { List result = new ArrayList<>(); MobileLedgerProfile first = diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileListActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileListActivity.java index b61f567a..3e4f14b2 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileListActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileListActivity.java @@ -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; diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java index b863cf6e..f4cfa619 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java @@ -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 index 00000000..235f6559 --- /dev/null +++ b/app/src/main/res/raw/sql_16.sql @@ -0,0 +1 @@ +alter table profiles add order_no integer; \ No newline at end of file