diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/BitsharesAccountNameCacheDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/BitsharesAccountNameCacheDao.java new file mode 100644 index 0000000..5d6e413 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/BitsharesAccountNameCacheDao.java @@ -0,0 +1,30 @@ +package cy.agorise.crystalwallet.dao; + +import android.arch.lifecycle.LiveData; +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Insert; +import android.arch.persistence.room.OnConflictStrategy; +import android.arch.persistence.room.Query; + +import java.util.List; + +import cy.agorise.crystalwallet.models.BitsharesAccountNameCache; +import cy.agorise.crystalwallet.models.GrapheneAccountInfo; + +/** + * Created by Henry Varona on 6/15/2018. + */ + +@Dao +public interface BitsharesAccountNameCacheDao { + + @Query("SELECT * FROM bitshares_account_name_cache WHERE account_id = :account_id") + LiveData getLDByAccountId(String account_id); + + @Query("SELECT * FROM bitshares_account_name_cache WHERE account_id = :account_id") + BitsharesAccountNameCache getByAccountId(String account_id); + + @Insert(onConflict = OnConflictStrategy.REPLACE) + public long[] insertBitsharesAccountNameCache(BitsharesAccountNameCache... accountsNames); + +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java index c6ef388..81570ea 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java @@ -10,6 +10,7 @@ import android.content.Context; import cy.agorise.crystalwallet.dao.converters.Converters; import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.BitsharesAccountNameCache; import cy.agorise.crystalwallet.models.BitsharesAssetInfo; import cy.agorise.crystalwallet.models.Contact; import cy.agorise.crystalwallet.models.ContactAddress; @@ -36,9 +37,10 @@ import cy.agorise.crystalwallet.models.GrapheneAccountInfo; CryptoCoinBalance.class, GrapheneAccountInfo.class, BitsharesAssetInfo.class, + BitsharesAccountNameCache.class, CryptoCurrencyEquivalence.class, GeneralSetting.class -}, version = 3) +}, version = 4) @TypeConverters({Converters.class}) public abstract class CrystalDatabase extends RoomDatabase { @@ -62,6 +64,7 @@ public abstract class CrystalDatabase extends RoomDatabase { CrystalDatabase.class, "CrystalWallet.db") .allowMainThreadQueries() .addMigrations(MIGRATION_2_3) + .addMigrations(MIGRATION_3_4) .build(); } return instance; @@ -73,4 +76,18 @@ public abstract class CrystalDatabase extends RoomDatabase { database.execSQL("ALTER TABLE graphene_account ADD COLUMN upgraded_to_ltm INTEGER NOT NULL DEFAULT 0"); } }; + + static final Migration MIGRATION_3_4 = new Migration(3, 4) { + @Override + public void migrate(SupportSQLiteDatabase database) { + database.execSQL("CREATE TABLE bitshares_account_name_cache (" + +"id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + +"account_id TEXT UNIQUE NOT NULL," + +"name TEXT)"); + + database.execSQL("CREATE UNIQUE INDEX index_bitshares_account_name_cache_account_id ON bitshares_account_name_cache (account_id)"); + + + } + }; } diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/BitsharesAccountNameCache.java b/app/src/main/java/cy/agorise/crystalwallet/models/BitsharesAccountNameCache.java new file mode 100644 index 0000000..c6fdb73 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/models/BitsharesAccountNameCache.java @@ -0,0 +1,75 @@ +package cy.agorise.crystalwallet.models; + + +import android.arch.persistence.room.ColumnInfo; +import android.arch.persistence.room.Entity; +import android.arch.persistence.room.Ignore; +import android.arch.persistence.room.Index; +import android.arch.persistence.room.PrimaryKey; +import android.support.annotation.NonNull; + +/** + * Represents a cache of a Bitshares Account name + * + * Created by Henry Varona on 6/13/2018. + */ + +@Entity(tableName = "bitshares_account_name_cache", + indices = {@Index("id"), + @Index(value = {"account_id"},unique = true)}) +public class BitsharesAccountNameCache { + + /** + * The id on the database + */ + @PrimaryKey(autoGenerate = true) + @ColumnInfo(name = "id") + private long mId; + + /** + * The id of the account + */ + @ColumnInfo(name = "account_id") + @NonNull + private String mAccountId; + + /* + * The name of the account + */ + @ColumnInfo(name = "name") + private String mName; + + public BitsharesAccountNameCache() { + } + + @Ignore + public BitsharesAccountNameCache(long id, String accountId, String name) { + this.mId = id; + this.mAccountId = accountId; + this.mName = name; + } + + public long getId() { + return mId; + } + + public void setId(long id){ + this.mId = id; + } + + public String getAccountId() { + return mAccountId; + } + + public void setAccountId(String accountId) { + this.mAccountId = accountId; + } + + public String getName() { + return mName; + } + + public void setName(String name) { + this.mName = name; + } +}