From 515d09c0c22f62a92b420eeea8e50c1ece28fc2e Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Sun, 24 Sep 2017 17:52:32 -0400 Subject: [PATCH] - Now the Transaction History is working and is Paged - New class to test the app: a Random Transaction Generator --- .../com/carbon/TransactionListTest.java | 42 +++++++------------ .../agorise/crystalwallet/IntroActivity.java | 11 +++++ .../RandomTransactionsGenerator.java | 39 +++++++++++++++++ .../views/TransactionListAdapter.java | 5 ++- .../views/TransactionListView.java | 7 +++- app/src/main/res/layout/activity_intro.xml | 2 +- app/src/main/res/layout/transaction_list.xml | 9 ++-- .../main/res/layout/transaction_list_item.xml | 2 +- 8 files changed, 84 insertions(+), 33 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/randomdatagenerators/RandomTransactionsGenerator.java diff --git a/app/src/androidTest/java/carbon/crypto/com/carbon/TransactionListTest.java b/app/src/androidTest/java/carbon/crypto/com/carbon/TransactionListTest.java index 2884cbc..60f8a33 100644 --- a/app/src/androidTest/java/carbon/crypto/com/carbon/TransactionListTest.java +++ b/app/src/androidTest/java/carbon/crypto/com/carbon/TransactionListTest.java @@ -10,18 +10,25 @@ import android.support.test.InstrumentationRegistry; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.List; import carbon.crypto.com.carbon.Assertions.RecyclerViewItemsCountAssertion; import cy.agorise.crystalwallet.IntroActivity; import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; +import cy.agorise.crystalwallet.randomdatagenerators.RandomTransactionsGenerator; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.matcher.ViewMatchers.withId; +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + + /** * Created by Henry Varona on 19/9/2017. */ @@ -29,34 +36,17 @@ import static android.support.test.espresso.matcher.ViewMatchers.withId; public class TransactionListTest { CrystalDatabase db; + List transactions; + int numberOfTransactions = 100; + @Before public void addingTransactions(){ - Calendar cal = Calendar.getInstance(); + db = CrystalDatabase.getAppDatabase(InstrumentationRegistry.getTargetContext()); + transactions = RandomTransactionsGenerator.generateTransactions(numberOfTransactions,1262304001,1496275201,1,999999999); - this.db = CrystalDatabase.getAppDatabase(InstrumentationRegistry.getTargetContext()); - cal.set(2017,01,01,01,01,01); - CryptoCoinTransaction newTransaction = new CryptoCoinTransaction(); - newTransaction.setAmount(1); - newTransaction.setFrom("friend1"); - newTransaction.setTo("me1"); - newTransaction.setDate(cal.getTime()); - db.transactionDao().insertTransaction(newTransaction); - - cal.set(2017,02,02,02,02,02); - newTransaction = new CryptoCoinTransaction(); - newTransaction.setAmount(2); - newTransaction.setFrom("friend2"); - newTransaction.setTo("me2"); - newTransaction.setDate(cal.getTime()); - db.transactionDao().insertTransaction(newTransaction); - - cal.set(2017,03,03,03,03,03); - newTransaction = new CryptoCoinTransaction(); - newTransaction.setAmount(3); - newTransaction.setFrom("friend3"); - newTransaction.setTo("me3"); - newTransaction.setDate(cal.getTime()); - db.transactionDao().insertTransaction(newTransaction); + for(int i=0;i transactions = RandomTransactionsGenerator.generateTransactions(100,1262304001,1496275201,1,999999999); + + for(int i=0;i> transactionData = transactionListViewModel.getTransactionList(); + transactionListView.setData(null); transactionData.observe(this, new Observer>() { @Override diff --git a/app/src/main/java/cy/agorise/crystalwallet/randomdatagenerators/RandomTransactionsGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/randomdatagenerators/RandomTransactionsGenerator.java new file mode 100644 index 0000000..dbe7809 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/randomdatagenerators/RandomTransactionsGenerator.java @@ -0,0 +1,39 @@ +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.CryptoCoinTransaction; + +/** + * Created by Henry Varona on 20/9/2017. + */ + +public class RandomTransactionsGenerator { + + static public List generateTransactions(int numberOfTransactions, int minTimestamp, int maxTimestamp, int minAmount, int maxAmount){ + ArrayList result = new ArrayList(); + Random randomGenerator = new Random(); + Calendar cal = Calendar.getInstance(); + int randomTimeStamp; + int randomAmount; + CryptoCoinTransaction randomTransaction; + + for (int i=0;i data){ if (this.listAdapter == null) { this.listAdapter = new TransactionListAdapter(); this.listView.setAdapter(this.listAdapter); - } else { + } + + if (data != null) { this.listAdapter.setList(data); } } diff --git a/app/src/main/res/layout/activity_intro.xml b/app/src/main/res/layout/activity_intro.xml index f452a80..83a0215 100644 --- a/app/src/main/res/layout/activity_intro.xml +++ b/app/src/main/res/layout/activity_intro.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_intro" android:layout_width="match_parent" - android:layout_height="match_parent" + android:layout_height="wrap_content" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" diff --git a/app/src/main/res/layout/transaction_list.xml b/app/src/main/res/layout/transaction_list.xml index 6f02e45..27063ea 100644 --- a/app/src/main/res/layout/transaction_list.xml +++ b/app/src/main/res/layout/transaction_list.xml @@ -1,10 +1,13 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + android:layout_height="wrap_content" + /> \ No newline at end of file diff --git a/app/src/main/res/layout/transaction_list_item.xml b/app/src/main/res/layout/transaction_list_item.xml index 7483951..68a4cde 100644 --- a/app/src/main/res/layout/transaction_list_item.xml +++ b/app/src/main/res/layout/transaction_list_item.xml @@ -1,7 +1,7 @@