X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FCurrency.java;h=5f488e28634eb4ca72a156b05371be075747c0af;hb=HEAD;hp=28e6d03e9fe6c2007c1b4ece489472c027ab030b;hpb=7526e4b8588361e218b5215f77bc7445e02ba970;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/model/Currency.java b/app/src/main/java/net/ktnx/mobileledger/model/Currency.java index 28e6d03e..bfe84ea0 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Currency.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Currency.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Damyan Ivanov. + * Copyright © 2020 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -17,32 +17,10 @@ package net.ktnx.mobileledger.model; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DiffUtil; - -import net.ktnx.mobileledger.App; import net.ktnx.mobileledger.utils.Misc; public class Currency { - public static final DiffUtil.ItemCallback DIFF_CALLBACK = - new DiffUtil.ItemCallback() { - @Override - public boolean areItemsTheSame(@NonNull Currency oldItem, - @NonNull Currency newItem) { - return oldItem.id == newItem.id; - } - @Override - public boolean areContentsTheSame(@NonNull Currency oldItem, - @NonNull Currency newItem) { - return oldItem.name.equals(newItem.name) && - oldItem.position.equals(newItem.position) && - (oldItem.hasGap == newItem.hasGap); - } - }; - private int id; + private final int id; private String name; private Position position; private boolean hasGap; @@ -58,24 +36,6 @@ public class Currency { this.position = position; this.hasGap = hasGap; } - public Currency(MobileLedgerProfile profile, String name, Position position, boolean hasGap) { - SQLiteDatabase db = App.getDatabase(); - - try (Cursor c = db.rawQuery("select max(rowid) from currencies", null)) { - c.moveToNext(); - this.id = c.getInt(0) + 1; - } - db.execSQL("insert into currencies(id, name, position, has_gap) values(?, ?, ?, ?)", - new Object[]{this.id, name, position.toString(), hasGap}); - - this.name = name; - this.position = position; - this.hasGap = hasGap; - } - public static Currency loadByName(String name) { - MobileLedgerProfile profile = Data.getProfile(); - return profile.loadCurrencyByName(name); - } static public boolean equal(Currency left, Currency right) { if (left == null) { return right == null; @@ -119,24 +79,6 @@ public class Currency { this.hasGap = hasGap; } public enum Position { - before(-1), after(1), unknown(0), none(-2); - private int value; - Position(int value) { - this.value = value; - } - static Position valueOf(int value) { - switch (value) { - case -1: - return before; - case +1: - return after; - case 0: - return unknown; - case -2: - return none; - default: - throw new IllegalStateException(String.format("Unexpected value (%d)", value)); - } - } + before, after, unknown, none } }