- Creating the view for Transaction History
This commit is contained in:
parent
65c362da8d
commit
81da660a2e
10 changed files with 150 additions and 8 deletions
|
@ -34,7 +34,9 @@ dependencies {
|
|||
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
testCompile 'junit:junit:4.12'
|
||||
|
||||
compile "android.arch.lifecycle:runtime:1.0.0-alpha9"
|
||||
compile "android.arch.lifecycle:extensions:1.0.0-alpha9"
|
||||
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha9"
|
||||
compile 'android.arch.persistence.room:runtime:1.0.0-alpha9';
|
||||
|
||||
apt "android.arch.persistence.room:compiler:1.0.0-alpha9";
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package cy.agorise.crystalwallet;
|
||||
|
||||
import android.arch.lifecycle.LifecycleActivity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
public class IntroActivity extends AppCompatActivity {
|
||||
public class IntroActivity extends LifecycleActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
|
@ -6,19 +6,21 @@ import android.arch.persistence.room.migration.Migration;
|
|||
import android.content.Context;
|
||||
|
||||
import cy.agorise.crystalwallet.models.AccountSeed;
|
||||
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
||||
import cy.agorise.crystalwallet.models.CryptoNetAccount;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 4/9/2017.
|
||||
*/
|
||||
|
||||
@Database(entities = {AccountSeed.class/*, CryptoNetAccount.class*/}, version = 2)
|
||||
@Database(entities = {AccountSeed.class, CryptoNetAccount.class, CryptoCoinTransaction.class}, version = 2)
|
||||
public abstract class CrystalDatabase extends RoomDatabase {
|
||||
|
||||
private static CrystalDatabase instance;
|
||||
|
||||
public abstract AccountSeedDao accountSeedDao();
|
||||
public abstract CryptoNetAccountDao cryptoNetAccountDao();
|
||||
public abstract TransactionDao transactionDao();
|
||||
|
||||
public static CrystalDatabase getAppDatabase(Context context) {
|
||||
if (instance == null) {
|
||||
|
@ -43,7 +45,7 @@ public abstract class CrystalDatabase extends RoomDatabase {
|
|||
+ "FOREIGN_KEY(seed_id) REFERENCES seed(id))");
|
||||
database.execSQL("CREATE TABLE 'crypto_coin_transaction' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ "'account_id' INTEGER, "
|
||||
+ "'date' INT, 'is_input' INT,"
|
||||
+ "'date' INT, 'is_input' INT, amount INT, crypto_coin TEXT, is_confirmed INT, "
|
||||
+ "FOREIGN_KEY(account_id) REFERENCES crypto_net_account(id))");
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package cy.agorise.crystalwallet.dao;
|
||||
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.arch.persistence.room.Dao;
|
||||
import android.arch.persistence.room.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 12/9/2017.
|
||||
*/
|
||||
@Dao
|
||||
public interface TransactionDao {
|
||||
|
||||
@Query("SELECT * FROM crypto_coin_transaction")
|
||||
LiveData<List<CryptoCoinTransaction>> getAll();
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package cy.agorise.crystalwallet.enums;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 12/9/2017.
|
||||
*/
|
||||
|
||||
public enum CryptoCoin implements Serializable {
|
||||
BITCOIN(CryptoNet.BITCOIN,"BTC",8,6),
|
||||
BITCOIN_TEST(CryptoNet.BITCOIN_TEST,"BTC",8,6),
|
||||
LITECOIN(CryptoNet.LITECOIN,"LTC",8,6),
|
||||
DASH(CryptoNet.DASH,"DASH",8,6),
|
||||
DOGECOIN(CryptoNet.DOGECOIN,"DOGE",8,6),
|
||||
BITSHARES(CryptoNet.BITSHARES,"BTS",8,6);
|
||||
|
||||
protected CryptoNet cryptoNet;
|
||||
protected String label;
|
||||
protected int precision;
|
||||
protected int confirmationsNeeded;
|
||||
|
||||
CryptoCoin(CryptoNet cryptoNet, String label, int precision, int confirmationsNeeded){
|
||||
this.cryptoNet = cryptoNet;
|
||||
this.label = label;
|
||||
this.precision = precision;
|
||||
this.confirmationsNeeded = confirmationsNeeded;
|
||||
}
|
||||
|
||||
public CryptoNet getCryptoNet(){
|
||||
return this.cryptoNet;
|
||||
}
|
||||
public String getLabel(){
|
||||
return this.label;
|
||||
}
|
||||
public int getPrecision(){
|
||||
return this.precision;
|
||||
}
|
||||
public int getConfirmationsNeeded(){
|
||||
return this.confirmationsNeeded;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package cy.agorise.crystalwallet.enums;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 12/9/2017.
|
||||
*/
|
||||
|
||||
public enum CryptoNet implements Serializable {
|
||||
BITCOIN("BITCOIN"), BITCOIN_TEST("BITCOIN(TEST)"), LITECOIN("LITECOIN"), DASH("DASH"), DOGECOIN("DOGECOIN"), BITSHARES("BITSHARES");
|
||||
|
||||
protected String label;
|
||||
|
||||
CryptoNet(String label){
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getLabel(){
|
||||
return this.label;
|
||||
}
|
||||
}
|
|
@ -6,6 +6,8 @@ import android.arch.persistence.room.PrimaryKey;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import cy.agorise.crystalwallet.enums.CryptoCoin;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 11/9/2017.
|
||||
*/
|
||||
|
@ -23,6 +25,12 @@ public class CryptoCoinTransaction {
|
|||
protected boolean isInput;
|
||||
@ColumnInfo(name="account_id")
|
||||
protected int accountId;
|
||||
@ColumnInfo(name="amount")
|
||||
protected int amount;
|
||||
@ColumnInfo(name="crypto_coin")
|
||||
protected CryptoCoin coin;
|
||||
@ColumnInfo(name="is_confirmed")
|
||||
protected boolean isConfirmed;
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package cy.agorise.crystalwallet.viewmodels;
|
||||
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.arch.lifecycle.ViewModel;
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
||||
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
||||
import cy.agorise.crystalwallet.views.TransactionListView;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 12/9/2017.
|
||||
*/
|
||||
|
||||
public class TransactionListViewModel extends ViewModel {
|
||||
|
||||
private LiveData<List<CryptoCoinTransaction>> transactionList;
|
||||
private CrystalDatabase db;
|
||||
|
||||
public TransactionListViewModel(Context context){
|
||||
this.db = CrystalDatabase.getAppDatabase(context);
|
||||
transactionList = this.db.transactionDao().getAll();
|
||||
}
|
||||
|
||||
public LiveData<List<CryptoCoinTransaction>> getTransactionList(){
|
||||
return this.transactionList;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package cy.agorise.crystalwallet.views;
|
||||
|
||||
import android.arch.lifecycle.ViewModelProviders;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
@ -8,6 +9,9 @@ import android.widget.ListView;
|
|||
import android.widget.RelativeLayout;
|
||||
|
||||
import cy.agorise.crystalwallet.R;
|
||||
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
||||
import cy.agorise.crystalwallet.dao.TransactionDao;
|
||||
import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 10/9/2017.
|
||||
|
@ -16,15 +20,23 @@ import cy.agorise.crystalwallet.R;
|
|||
public class TransactionListView extends RelativeLayout {
|
||||
|
||||
View rootView;
|
||||
ListView list;
|
||||
ListView listView;
|
||||
ListAdapter listAdapter;
|
||||
|
||||
|
||||
TransactionListViewModel transactionListViewModel;
|
||||
|
||||
public TransactionListView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
rootView = inflate(context, R.layout.transaction_list, this);
|
||||
list = rootView.findViewById(R.id.transactionListView);
|
||||
listAdapter = new TransactionListAdapter();
|
||||
list.setAdapter(listAdapter);
|
||||
listView = rootView.findViewById(R.id.transactionListView);
|
||||
|
||||
|
||||
|
||||
transactionListViewModel = ViewModelProviders.of(this).get(TransactionListViewModel.class);
|
||||
|
||||
listAdapter = new TransactionListAdapter(context, getResources(), transactionDao.getAll());
|
||||
listView.setAdapter(listAdapter);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -14,4 +14,9 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!" />
|
||||
<cy.agorise.crystalwallet.views.TransactionListView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
</cy.agorise.crystalwallet.views.TransactionListView>
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in a new issue