From 9212af814138cc66b5853946049060fc9ee10383 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 9 Jan 2018 22:33:23 -0400 Subject: [PATCH] Account seed find by id with livedata --- .../java/cy/agorise/crystalwallet/dao/AccountSeedDao.java | 5 ++++- .../cy/agorise/crystalwallet/models/GrapheneAccount.java | 6 +++--- .../crystalwallet/viewmodels/AccountSeedViewModel.java | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/AccountSeedDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/AccountSeedDao.java index 40cacbf..16790d1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/AccountSeedDao.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/AccountSeedDao.java @@ -23,7 +23,10 @@ public interface AccountSeedDao { LiveData> getAll(); @Query("SELECT * FROM account_seed WHERE id = :id") - LiveData findById(long id); + LiveData findByIdLiveData(long id); + + @Query("SELECT * FROM account_seed WHERE id = :id") + AccountSeed findById(long id); @Query("SELECT COUNT(*) from account_seed") int countAccountSeeds(); diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java index 7cf11be..c89f639 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java @@ -54,7 +54,7 @@ public class GrapheneAccount extends CryptoNetAccount { * Return the owner key, generates from the seed if it has not been generated. null if it can't be generated */ public ECKey getOwnerKey(Context context){ - AccountSeed seed = CrystalDatabase.getAppDatabase(context).accountSeedDao().findById(this.getSeedId()).getValue(); + AccountSeed seed = CrystalDatabase.getAppDatabase(context).accountSeedDao().findById(this.getSeedId()); if(seed == null){ System.out.println("Error: Seed null " + this.getSeedId()); return null; @@ -83,7 +83,7 @@ public class GrapheneAccount extends CryptoNetAccount { * Return the active key, generates from the seed if it has not been generated. null if it can't be generated */ public ECKey getActiveKey(Context context){ - AccountSeed seed = CrystalDatabase.getAppDatabase(context).accountSeedDao().findById(this.getSeedId()).getValue(); + AccountSeed seed = CrystalDatabase.getAppDatabase(context).accountSeedDao().findById(this.getSeedId()); if(seed == null) return null; if(seed.getType().equals(SeedType.BRAINKEY)){ @@ -107,7 +107,7 @@ public class GrapheneAccount extends CryptoNetAccount { * Return the memo key, generates from the seed if it has not been generated. null if it can't be generated */ public ECKey getMemoKey(Context context){ - AccountSeed seed = CrystalDatabase.getAppDatabase(context).accountSeedDao().findById(this.getSeedId()).getValue(); + AccountSeed seed = CrystalDatabase.getAppDatabase(context).accountSeedDao().findById(this.getSeedId()); if(seed == null) return null; if(seed.getType().equals(SeedType.BRAINKEY)){ diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/AccountSeedViewModel.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/AccountSeedViewModel.java index e068905..af9e253 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/AccountSeedViewModel.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/AccountSeedViewModel.java @@ -30,7 +30,7 @@ public class AccountSeedViewModel extends AndroidViewModel { } public void loadSeed(int seedId){ - this.accountSeed = this.db.accountSeedDao().findById(seedId); + this.accountSeed = this.db.accountSeedDao().findByIdLiveData(seedId); } public void addSeed(AccountSeed seed){