- Fixing code that ask for a livedata but doesn't listen to it

master
Javier Varona 2017-10-22 20:53:33 -04:00
parent 7f96370568
commit b4b7ba7743
5 changed files with 28 additions and 9 deletions

View File

@ -24,7 +24,10 @@ public interface CryptoNetAccountDao {
LiveData<List<CryptoNetAccount>> getAll();
@Query("SELECT * FROM crypto_net_account WHERE id = :accountId")
LiveData<CryptoNetAccount> getById( long accountId);
LiveData<CryptoNetAccount> getByIdLiveData( long accountId);
@Query("SELECT * FROM crypto_net_account WHERE id = :accountId")
CryptoNetAccount getById( long accountId);
@Query("SELECT * FROM crypto_net_account WHERE crypto_net = 'BITSHARES'")
LiveData<List<CryptoNetAccount>> getBitsharesAccounts();

View File

@ -25,6 +25,9 @@ public interface GrapheneAccountInfoDao {
@Query("SELECT * FROM graphene_account WHERE crypto_net_account_id = :cryptoNetAccountId")
LiveData<GrapheneAccountInfo> getGrapheneAccountInfo(long cryptoNetAccountId);
@Query("SELECT * FROM graphene_account WHERE crypto_net_account_id = :cryptoNetAccountId")
GrapheneAccountInfo getByAccountId(long cryptoNetAccountId);
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long[] insertGrapheneAccountInfo(GrapheneAccountInfo... accounts);

View File

@ -103,7 +103,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
if(account instanceof GrapheneAccount){
GrapheneAccount grapheneAccount = (GrapheneAccount) account;
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
grapheneAccount.loadInfo(db.grapheneAccountInfoDao().getGrapheneAccountInfo(account.getId()).getValue());
grapheneAccount.loadInfo(db.grapheneAccountInfoDao().getByAccountId(account.getId()));
if(grapheneAccount.getAccountId() == null){
grapheneAccount = this.getAccountInfoByName(grapheneAccount.getName());
}else if(grapheneAccount.getName() == null){
@ -270,12 +270,12 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
public static void refreshAccountTransactions(long idAccount, Context context){
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
LiveData<List<CryptoCoinTransaction>> transactions = db.transactionDao().getByIdAccount(idAccount);
LiveData<CryptoNetAccount> account = db.cryptoNetAccountDao().getById(idAccount);
if(account.getValue().getCryptoNet() == CryptoNet.BITSHARES) {
CryptoNetAccount account = db.cryptoNetAccountDao().getById(idAccount);
if(account.getCryptoNet() == CryptoNet.BITSHARES) {
GrapheneAccount grapheneAccount = new GrapheneAccount(account.getValue());
GrapheneAccount grapheneAccount = new GrapheneAccount(account);
grapheneAccount.loadInfo(db.grapheneAccountInfoDao().getGrapheneAccountInfo(idAccount).getValue());
grapheneAccount.loadInfo(db.grapheneAccountInfoDao().getByAccountId(idAccount));
int start = transactions.getValue().size();

View File

@ -19,6 +19,8 @@ import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.manager.BitsharesAccountManager;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.crystalwallet.models.GrapheneAccount;
import cy.agorise.crystalwallet.models.GrapheneAccountInfo;
/**
* Created by Henry Varona on 3/10/2017.
@ -54,13 +56,19 @@ public class CrystalWalletService extends LifecycleService {
this.keepLoadingAccountTransactions = true;
final CrystalWalletService thisService = this;
CrystalDatabase db = CrystalDatabase.getAppDatabase(this);
final CrystalDatabase db = CrystalDatabase.getAppDatabase(this);
final LiveData<List<CryptoNetAccount>> cryptoNetAccountList = db.cryptoNetAccountDao().getAll();
cryptoNetAccountList.observe(this, new Observer<List<CryptoNetAccount>>() {
@Override
public void onChanged(@Nullable List<CryptoNetAccount> cryptoNetAccounts) {
GrapheneAccount nextGrapheneAccount;
for(CryptoNetAccount nextAccount : cryptoNetAccountList.getValue()) {
bitsharesAccountManager.loadAccountFromDB(nextAccount,thisService);
GrapheneAccountInfo grapheneAccountInfo = db.grapheneAccountInfoDao().getByAccountId(nextAccount.getId());
nextGrapheneAccount = new GrapheneAccount(nextAccount);
nextGrapheneAccount.loadInfo(grapheneAccountInfo);
bitsharesAccountManager.loadAccountFromDB(nextGrapheneAccount,thisService);
}
}
});
@ -81,6 +89,7 @@ public class CrystalWalletService extends LifecycleService {
@Override
public void onCreate() {
super.onCreate();
//Creates a instance for the cryptoNetInfoRequest and the managers
this.cryptoNetInfoRequests = CryptoNetInfoRequests.getInstance();
this.bitsharesAccountManager = new BitsharesAccountManager();
@ -92,6 +101,8 @@ public class CrystalWalletService extends LifecycleService {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent,flags,startId);
if (LoadAccountTransactionsThread == null) {
LoadAccountTransactionsThread = new Thread() {
public void run() {
@ -107,11 +118,13 @@ public class CrystalWalletService extends LifecycleService {
@Override
public IBinder onBind(Intent intent) {
super.onBind(intent);
return null;
}
@Override
public void onDestroy() {
super.onDestroy();
Log.i("Crystal Service", "Destroying service");
}
}

View File

@ -25,7 +25,7 @@ public class CryptoNetAccountViewModel extends AndroidViewModel {
}
public void loadCryptoNetAccount(int accountId){
this.cryptoNetAccount = this.db.cryptoNetAccountDao().getById(accountId);
this.cryptoNetAccount = this.db.cryptoNetAccountDao().getByIdLiveData(accountId);
}
public void addCryptoNetAccount(CryptoNetAccount account){