import android.content.res.Resources;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
+import android.text.TextUtils;
import android.util.SparseArray;
import androidx.annotation.Nullable;
result = item;
}
}
- Data.profiles.setValue(list);
+ Data.profiles.postValue(list);
return result;
}
public static void storeProfilesOrder() {
}
public void storeAccountValue(SQLiteDatabase db, int generation, String name, String currency,
Float amount) {
+ if (!TextUtils.isEmpty(currency)) {
+ boolean exists;
+ try (Cursor c = db.rawQuery("select 1 from currencies where name=?",
+ new String[]{currency}))
+ {
+ exists = c.moveToFirst();
+ }
+ if (!exists) {
+ db.execSQL(
+ "insert into currencies(id, name, position, has_gap) values((select max" +
+ "(id) from currencies)+1, ?, ?, ?)", new Object[]{currency,
+ Objects.requireNonNull(
+ Data.currencySymbolPosition.getValue()).toString(),
+ Data.currencyGap.getValue()
+ });
+ }
+ }
+
db.execSQL("replace into account_values(profile, account, " +
"currency, value, generation) values(?, ?, ?, ?, ?);",
new Object[]{uuid, name, Misc.emptyIsNull(currency), amount, generation});
db.beginTransactionNonExclusive();
try {
Object[] uuid_param = new Object[]{uuid};
- db.execSQL("delete from profiles where uuid=?", uuid_param);
- db.execSQL("delete from accounts where profile=?", uuid_param);
- db.execSQL("delete from account_values where profile=?", uuid_param);
- db.execSQL("delete from transactions where profile=?", uuid_param);
db.execSQL("delete from transaction_accounts where profile=?", uuid_param);
+ db.execSQL("delete from transactions where profile=?", uuid_param);
+ db.execSQL("delete from account_values where profile=?", uuid_param);
+ db.execSQL("delete from accounts where profile=?", uuid_param);
db.execSQL("delete from options where profile=?", uuid_param);
+ db.execSQL("delete from profiles where uuid=?", uuid_param);
db.setTransactionSuccessful();
}
finally {