Merge remote-tracking branch 'origin/master'

This commit is contained in:
henry 2017-09-26 22:48:52 -04:00
commit 42fce2a1f0
15 changed files with 164 additions and 35 deletions

View file

@ -15,7 +15,11 @@ import android.widget.Button;
import java.util.List;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.crystalwallet.randomdatagenerators.RandomCryptoNetAccountGenerator;
import cy.agorise.crystalwallet.randomdatagenerators.RandomSeedGenerator;
import cy.agorise.crystalwallet.randomdatagenerators.RandomTransactionsGenerator;
import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel;
import cy.agorise.crystalwallet.views.TransactionListView;
@ -33,10 +37,20 @@ public class IntroActivity extends LifecycleActivity {
setContentView(R.layout.activity_intro);
/*CrystalDatabase db = CrystalDatabase.getAppDatabase(getApplicationContext());
List<CryptoCoinTransaction> transactions = RandomTransactionsGenerator.generateTransactions(100,1262304001,1496275201,1,999999999);
List<AccountSeed> seeds = RandomSeedGenerator.generateSeeds(2);
for(int i=0;i<seeds.size();i++) {
long newId = db.accountSeedDao().insertAccountSeed(seeds.get(i))[0];
seeds.get(i).setId(newId);
}
List<CryptoNetAccount> accounts = RandomCryptoNetAccountGenerator.generateAccounts(5,seeds);
for(int i=0;i<accounts.size();i++) {
long newId = db.cryptoNetAccountDao().insertCryptoNetAccount(accounts.get(i))[0];
accounts.get(i).setId(newId);
}
List<CryptoCoinTransaction> transactions = RandomTransactionsGenerator.generateTransactions(accounts,100,1262304001,1496275201,1,999999999);
for(int i=0;i<transactions.size();i++) {
db.transactionDao().insertTransaction(transactions.get(i));
long newId = db.transactionDao().insertTransaction(transactions.get(i))[0];
transactions.get(i).setId(newId);
}*/
transactionListView = this.findViewById(R.id.transaction_list);

View file

@ -1,6 +1,8 @@
package cy.agorise.crystalwallet.dao;
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;
@ -16,4 +18,8 @@ public interface AccountSeedDao {
@Query("SELECT * FROM account_seed")
List<AccountSeed> getAll();
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long[] insertAccountSeed(AccountSeed... seeds);
}

View file

@ -1,6 +1,8 @@
package cy.agorise.crystalwallet.dao;
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;
@ -17,4 +19,8 @@ public interface CryptoNetAccountDao {
@Query("SELECT * FROM crypto_net_account")
List<CryptoNetAccount> getAll();
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long[] insertCryptoNetAccount(CryptoNetAccount... accounts);
}

View file

@ -35,13 +35,13 @@ public abstract class CrystalDatabase extends RoomDatabase {
Room.databaseBuilder(context,
CrystalDatabase.class, "CrystalWallet.db")
.allowMainThreadQueries()
.addMigrations(MIGRATION_1_2)
//.addMigrations(MIGRATION_1_2)
.build();
}
return instance;
}
static final Migration MIGRATION_1_2 = new Migration(1, 2) {
/*static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE 'account_seed' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, "
@ -55,5 +55,5 @@ public abstract class CrystalDatabase extends RoomDatabase {
+ "'date' INT, 'is_input' INT, amount INT, crypto_coin TEXT, is_confirmed INT, "
+ "FOREIGN_KEY(account_id) REFERENCES crypto_net_account(id))");
}
};
};*/
}

View file

@ -24,7 +24,7 @@ public interface TransactionDao {
LivePagedListProvider<Integer, CryptoCoinTransaction> transactionsByDate();
@Insert(onConflict = OnConflictStrategy.REPLACE)
public void insertTransaction(CryptoCoinTransaction... transactions);
public long[] insertTransaction(CryptoCoinTransaction... transactions);
@Query("DELETE FROM crypto_coin_transaction")
public void deleteAllTransactions();

View file

@ -30,7 +30,7 @@ public class Converters {
}
@TypeConverter
public int cryptoNetAccountToId(CryptoNetAccount account) {
public long cryptoNetAccountToId(CryptoNetAccount account) {
if (account == null) {
return -1;
} else {
@ -39,7 +39,7 @@ public class Converters {
}
@TypeConverter
public CryptoNetAccount fromCryptoNetAccountId(int value) {
public CryptoNetAccount fromCryptoNetAccountId(long value) {
if (value == -1){
return null;
} else {

View file

@ -18,7 +18,7 @@ public class AccountSeed {
*/
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
private int mId;
private long mId;
/**
* The name or tag of this seed
@ -32,11 +32,11 @@ public class AccountSeed {
@ColumnInfo(name = "master_seed")
private String mMasterSeed;
public int getId() {
public long getId() {
return mId;
}
public void setId(int id){
public void setId(long id){
this.mId = id;
}

View file

@ -39,7 +39,7 @@ public class CryptoCoinTransaction {
*/
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name="id")
protected int id;
protected long id;
/**
* The full date of this transaction
*/
@ -54,7 +54,7 @@ public class CryptoCoinTransaction {
* The id of the account assoiciated, this is used for the foreign key definition
*/
@ColumnInfo(name="account_id")
protected int accountId;
protected long accountId;
/**
* The amount of asset is moved in this transaction
*/
@ -92,11 +92,11 @@ public class CryptoCoinTransaction {
public void setTo(String to) { this.to = to; }
public int getAccountId() {
public long getAccountId() {
return accountId;
}
public void setAccountId(int accountId) {
public void setAccountId(long accountId) {
this.accountId = accountId;
}
@ -108,11 +108,11 @@ public class CryptoCoinTransaction {
this.account = account;
}
public int getId() {
public long getId() {
return id;
}
public void setId(int id) {
public void setId(long id) {
this.id = id;
}

View file

@ -25,13 +25,13 @@ public class CryptoNetAccount {
*/
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
private int mId;
private long mId;
/**
* The id of the seed used by this account
*/
@ColumnInfo(name = "seed_id")
private int mSeedId;
private long mSeedId;
/**
* The account number on the bip44 or slip44
@ -45,19 +45,19 @@ public class CryptoNetAccount {
@ColumnInfo(name = "account_index")
private int mAccountIndex;
public int getId() {
public long getId() {
return mId;
}
public void setId(int id){
public void setId(long id){
this.mId = id;
}
public int getSeedId() {
public long getSeedId() {
return mSeedId;
}
public void setSeedId(int mSeedId) {
public void setSeedId(long mSeedId) {
this.mSeedId = mSeedId;
}

View file

@ -0,0 +1,36 @@
package cy.agorise.crystalwallet.randomdatagenerators;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
/**
* Created by Henry Varona on 20/9/2017.
*/
public class RandomCryptoNetAccountGenerator {
static public List<CryptoNetAccount> generateAccounts(int numberOfAccounts,List<AccountSeed> seeds){
ArrayList<CryptoNetAccount> result = new ArrayList<CryptoNetAccount>();
Random randomGenerator = new Random();
CryptoNetAccount randomAccount;
for (int i=0;i<numberOfAccounts;i++){
int randomSeedIndex = randomGenerator.nextInt(seeds.size());
AccountSeed randomSelectedSeed = seeds.get(randomSeedIndex);
int randomAccountIndex = randomGenerator.nextInt(1000);
int randomAccountNumber = randomGenerator.nextInt(1000);
randomAccount = new CryptoNetAccount();
randomAccount.setSeedId(randomSelectedSeed.getId());
randomAccount.setAccountIndex(randomAccountIndex);
randomAccount.setAccountNumber(randomAccountNumber);
result.add(randomAccount);
}
return result;
}
}

View file

@ -0,0 +1,33 @@
package cy.agorise.crystalwallet.randomdatagenerators;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Random;
import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
/**
* Created by Henry Varona on 20/9/2017.
*/
public class RandomSeedGenerator {
static public List<AccountSeed> generateSeeds(int numberOfSeeds){
ArrayList<AccountSeed> result = new ArrayList<AccountSeed>();
Random randomGenerator = new Random();
AccountSeed randomSeed;
for (int i=0;i<numberOfSeeds;i++){
int randomInt = randomGenerator.nextInt(999999999);
randomSeed = new AccountSeed();
randomSeed.setMasterSeed(""+randomInt);
randomSeed.setName("seed"+randomInt);
result.add(randomSeed);
}
return result;
}
}

View file

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Random;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
/**
* Created by Henry Varona on 20/9/2017.
@ -13,7 +14,7 @@ import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
public class RandomTransactionsGenerator {
static public List<CryptoCoinTransaction> generateTransactions(int numberOfTransactions, int minTimestamp, int maxTimestamp, int minAmount, int maxAmount){
static public List<CryptoCoinTransaction> generateTransactions(List<CryptoNetAccount> accounts, int numberOfTransactions, int minTimestamp, int maxTimestamp, int minAmount, int maxAmount){
ArrayList<CryptoCoinTransaction> result = new ArrayList<CryptoCoinTransaction>();
Random randomGenerator = new Random();
Calendar cal = Calendar.getInstance();
@ -22,11 +23,14 @@ public class RandomTransactionsGenerator {
CryptoCoinTransaction randomTransaction;
for (int i=0;i<numberOfTransactions;i++){
int randomAccountIndex = randomGenerator.nextInt(accounts.size());
CryptoNetAccount randomSelectedAccount = accounts.get(randomAccountIndex);
randomAmount = randomGenerator.nextInt((maxAmount - minAmount) + 1) + minAmount;
randomTimeStamp = randomGenerator.nextInt((maxTimestamp - minTimestamp) + 1) + minTimestamp;
cal.setTimeInMillis(randomTimeStamp*1000);
randomTransaction = new CryptoCoinTransaction();
randomTransaction.setAccountId(randomSelectedAccount.getId());
randomTransaction.setAmount(randomAmount);
randomTransaction.setFrom("friend"+i);
randomTransaction.setTo("me"+i);

View file

@ -27,6 +27,7 @@ public class TransactionListViewModel extends AndroidViewModel {
this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext());
transactionList = this.db.transactionDao().transactionsByDate().create(0,
new PagedList.Config.Builder()
.setEnablePlaceholders(true)
.setPageSize(10)
.setPrefetchDistance(10)
.build()

View file

@ -31,6 +31,9 @@ public class TransactionListView extends RelativeLayout {
TransactionListViewModel transactionListViewModel;
private int visibleThreshold = 5;
private boolean loading = true;
public TransactionListView(Context context){
super(context);
this.mInflater = LayoutInflater.from(context);
@ -52,9 +55,28 @@ public class TransactionListView extends RelativeLayout {
public void init(){
rootView = mInflater.inflate(R.layout.transaction_list, this, true);
this.listView = rootView.findViewById(R.id.transactionListView);
this.listView.setLayoutManager(new LinearLayoutManager(this.getContext()));
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext());
this.listView.setLayoutManager(linearLayoutManager);
this.listView.setNestedScrollingEnabled(false);
/*this.listView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(!loading && linearLayoutManager.getItemCount() <= (linearLayoutManager.findLastVisibleItemPosition() + visibleThreshold)){
onLoadMore();
loading = true;
}
}
});*/
}
//public void onLoadMore(){
// listAdapter.add();
//}
public void setData(PagedList<CryptoCoinTransaction> data){
if (this.listAdapter == null) {

View file

@ -22,6 +22,7 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
transactionFrom = (TextView) itemView.findViewById(R.id.fromText);
transactionTo = (TextView) itemView.findViewById(R.id.toText);
transactionAmount = (TextView) itemView.findViewById(R.id.amountText);
}
public void clear(){
@ -31,6 +32,11 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
}
public void bindTo(final CryptoCoinTransaction transaction/*, final OnTransactionClickListener listener*/) {
if (transaction == null){
transactionFrom.setText("loading...");
transactionTo.setText("");
transactionAmount.setText("");
} else {
transactionFrom.setText(transaction.getFrom());
transactionTo.setText(transaction.getTo());
transactionAmount.setText("" + transaction.getAmount());
@ -42,3 +48,4 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
});*/
}
}
}