Skip to content

Commit

Permalink
QTUM_1449
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Romanovsky committed Feb 13, 2018
1 parent 888600b commit 85b3109
Show file tree
Hide file tree
Showing 31 changed files with 440 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ public void setContractType(boolean contractType) {
isContractType = contractType;
}

public void setHistoryType(HistoryType historyType) {
public void setHistoryType(HistoryPayType historyType) {
this.historyType = historyType.name();
}

public HistoryType getHistoryType() {
return HistoryType.valueOf(historyType);
public HistoryPayType getHistoryType() {
return HistoryPayType.valueOf(historyType);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.qtum.wallet.model.gson.history;


public enum HistoryType {
public enum HistoryPayType {

Received("Received"), Sent("Sent"), Internal_Transaction("Internal Transaction");

private String name;

HistoryType(String name){
HistoryPayType(String name){
this.name = name;
}

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/qtum/wallet/model/gson/history/Vin.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public Vin(String address) {
this.address = address;
}

public Vin(String address, String valueString) {
this.address = address;
this.valueString = valueString;
}

public boolean isOwnAddress() {
return isOwnAddress;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public Vout(String address) {
this.address = address;
}

public Vout(String address, String valueString) {
this.address = address;
this.valueString = valueString;
}

public boolean isOwnAddress() {
return isOwnAddress;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import org.qtum.wallet.model.gson.history.HistoryType;
import org.qtum.wallet.model.gson.history.HistoryPayType;

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
Expand All @@ -29,9 +29,10 @@ public class TokenHistory extends RealmObject{
private String txHash;
@SerializedName("tx_time")
@Expose
private Integer txTime;
private Long txTime;

private String historyType;
private boolean isReceiptUpdated = false;

public String getContractAddress() {
return contractAddress;
Expand Down Expand Up @@ -73,28 +74,36 @@ public void setTxHash(String txHash) {
this.txHash = txHash;
}

public Integer getTxTime() {
public Long getTxTime() {
return txTime;
}

public void setTxTime(Integer txTime) {
public void setTxTime(Long txTime) {
this.txTime = txTime;
}

public void setHistoryType(HistoryType historyType) {
public void setHistoryType(HistoryPayType historyType) {
this.historyType = historyType.name();
}

public HistoryType getHistoryType() {
return HistoryType.valueOf(historyType);
public HistoryPayType getHistoryType() {
return HistoryPayType.valueOf(historyType);
}

public TokenHistory(){

}

public void setReceiptUpdated(boolean receiptUpdated) {
isReceiptUpdated = receiptUpdated;
}

public boolean isReceiptUpdated() {
return isReceiptUpdated;
}

//for unit_test
public TokenHistory(String contractAddress, String from, String to, String amount, String txHash, Integer txTime) {
public TokenHistory(String contractAddress, String from, String to, String amount, String txHash, Long txTime) {
this.contractAddress = contractAddress;
this.from = from;
this.to = to;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.qtum.wallet.R;
import org.qtum.wallet.ui.base.base_fragment.BaseFragment;
import org.qtum.wallet.ui.fragment.transaction_fragment.HistoryType;
import org.qtum.wallet.ui.fragment_factory.Factory;

import butterknife.BindView;
Expand All @@ -16,6 +17,7 @@ public abstract class AddressesDetailFragment extends BaseFragment implements Ad


public static String TX_HASH = "tx_hash";
public static String HISTORY_TYPE = "history_type";
private AddressesDetailPresenter mAddressesDetailPresenter;

protected AddressesDetailAdapter mAddressesDetailAdapterFrom;
Expand All @@ -28,9 +30,10 @@ public abstract class AddressesDetailFragment extends BaseFragment implements Ad
protected
RecyclerView mRecyclerViewTo;

public static Fragment newInstance(Context context, String txHash) {
public static Fragment newInstance(Context context, String txHash, HistoryType historyType) {
Bundle args = new Bundle();
args.putString(TX_HASH, txHash);
args.putSerializable(HISTORY_TYPE, historyType);
Fragment fragment = Factory.instantiateDefaultFragment(context, AddressesDetailFragment.class);
fragment.setArguments(args);
return fragment;
Expand All @@ -57,4 +60,8 @@ public AddressesDetailPresenter getPresenter() {
public String getTxHash() {
return getArguments().getString(TX_HASH);
}

public HistoryType getHistoryType(){
return (HistoryType) getArguments().getSerializable(HISTORY_TYPE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@


import org.qtum.wallet.model.gson.history.History;
import org.qtum.wallet.model.gson.token_history.TokenHistory;


public interface AddressesDetailInteractor {
History getHistory(String txHash);
TokenHistory getTokenHistory(String txHash);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;

import org.qtum.wallet.model.gson.history.History;
import org.qtum.wallet.model.gson.token_history.TokenHistory;

import java.lang.ref.WeakReference;
import java.util.List;
Expand All @@ -24,4 +25,12 @@ public History getHistory(String txHash) {
.equalTo("txHash", txHash)
.findFirst();
}

@Override
public TokenHistory getTokenHistory(String txHash) {
Realm realm = Realm.getDefaultInstance();
return realm.where(TokenHistory.class)
.equalTo("txHash", txHash)
.findFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

import org.qtum.wallet.model.gson.history.History;
import org.qtum.wallet.model.gson.history.TransactionInfo;
import org.qtum.wallet.model.gson.history.Vin;
import org.qtum.wallet.model.gson.history.Vout;
import org.qtum.wallet.model.gson.token_history.TokenHistory;
import org.qtum.wallet.ui.base.base_fragment.BaseFragmentPresenterImpl;

import java.util.ArrayList;
Expand All @@ -12,7 +15,6 @@ class AddressesDetailPresenterImpl extends BaseFragmentPresenterImpl implements

private AddressesDetailInteractor mAddressesDetailInteractor;
private AddressesDetailView mAddressesDetailView;
private History mHistory;

AddressesDetailPresenterImpl(AddressesDetailView transactionDetailFragmentView, AddressesDetailInteractor addressesDetailInteractor) {
mAddressesDetailInteractor = addressesDetailInteractor;
Expand All @@ -31,9 +33,25 @@ private AddressesDetailInteractor getInteractor() {
@Override
public void initializeViews() {
super.initializeViews();
mHistory = getInteractor().getHistory(getView().getTxHash());
if (mHistory != null) {
getView().setUpRecyclerView(mHistory.getVin(), mHistory.getVout());
switch (getView().getHistoryType()){
case History:
History history = getInteractor().getHistory(getView().getTxHash());
if (history != null) {
getView().setUpRecyclerView(history.getVin(), history.getVout());
}
break;
case Token_History:
TokenHistory tokenHistory = getInteractor().getTokenHistory(getView().getTxHash());
if(tokenHistory!=null){
List<Vin> vinList = new ArrayList<>();
List<Vout> voutList = new ArrayList<>();
vinList.add(new Vin(tokenHistory.getFrom(), tokenHistory.getAmount()));
voutList.add(new Vout(tokenHistory.getTo(), tokenHistory.getAmount()));
getView().setUpRecyclerView(vinList, voutList);
}
break;
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import org.qtum.wallet.model.gson.history.Vin;
import org.qtum.wallet.model.gson.history.Vout;
import org.qtum.wallet.ui.base.base_fragment.BaseFragmentView;
import org.qtum.wallet.ui.fragment.transaction_fragment.HistoryType;

import java.util.List;

interface AddressesDetailView extends BaseFragmentView{
void setUpRecyclerView(List<Vin> transactionFrom, List<Vout> transactionTo);
String getTxHash();
HistoryType getHistoryType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void onNext(String string) {
}
}

@SuppressLint("DefaultLocale")

@Override
public void onBalanceChange(final TokenBalance tokenBalance) {
if (token.getContractAddress().equals(tokenBalance.getContractAddress())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.qtum.wallet.R;
import org.qtum.wallet.ui.base.base_fragment.BaseFragment;
import org.qtum.wallet.ui.fragment.addresses_detail_fragment.AddressesDetailFragment;
import org.qtum.wallet.ui.fragment.transaction_fragment.HistoryType;
import org.qtum.wallet.ui.fragment_factory.Factory;
import org.qtum.wallet.utils.ClipboardUtils;

Expand All @@ -31,23 +32,25 @@ public abstract class OverviewFragment extends BaseFragment implements OverviewV

OverviewPresenter mOverviewPresenter;
public static String TX_HASH = "tx_hash";
public static String HISTORY_TYPE = "history_type";

@BindView(R.id.recycler_view_overview)
protected
RecyclerView mRecyclerViewOverview;
protected OverviewAdapter mOverviewAdapter;

public static Fragment newInstance(Context context, String txHash) {
public static Fragment newInstance(Context context, String txHash, HistoryType historyType) {
Bundle args = new Bundle();
args.putString(TX_HASH, txHash);
args.putSerializable(HISTORY_TYPE, historyType);
Fragment fragment = Factory.instantiateDefaultFragment(context, OverviewFragment.class);
fragment.setArguments(args);
return fragment;
}

@Override
protected void createPresenter() {
mOverviewPresenter = new OverviewPresenterImpl(this, new OverviewIteractorImpl(getContext()));
mOverviewPresenter = new OverviewPresenterImpl(this, new OverviewIteractorImpl(getContext(),getMainActivity().getRealm()));
}

@Override
Expand All @@ -60,6 +63,8 @@ public String getTxHash() {
return getArguments().getString(TX_HASH);
}



@Override
public void initializeViews() {
super.initializeViews();
Expand Down Expand Up @@ -128,4 +133,8 @@ public int getItemCount() {
return mOverview.size();
}
}

public HistoryType getHistoryType(){
return (HistoryType) getArguments().getSerializable(HISTORY_TYPE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@


import org.qtum.wallet.model.gson.history.History;
import org.qtum.wallet.model.gson.history.TransactionReceipt;
import org.qtum.wallet.model.gson.token_history.TokenHistory;

public interface OverviewIteractor {
History getHistory(String txHash);
TokenHistory getTokenHistory(String txHash);
TransactionReceipt getReceiptByRxhHashFromRealm(String txHash);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.Context;

import org.qtum.wallet.model.gson.history.History;
import org.qtum.wallet.model.gson.history.TransactionReceipt;
import org.qtum.wallet.model.gson.token_history.TokenHistory;

import java.lang.ref.WeakReference;
import java.util.List;
Expand All @@ -13,16 +15,29 @@
public class OverviewIteractorImpl implements OverviewIteractor{

WeakReference<Context> mContext;
private Realm mRealm;

OverviewIteractorImpl(Context context){
OverviewIteractorImpl(Context context, Realm realm){
mContext = new WeakReference<Context>(context);
mRealm = realm;
}

public History getHistory(String txHash) {
Realm realm = Realm.getDefaultInstance();
return realm.where(History.class)
return mRealm.where(History.class)
.equalTo("txHash", txHash)
.findFirst();
}

@Override
public TokenHistory getTokenHistory(String txHash) {
return mRealm.where(TokenHistory.class)
.equalTo("txHash", txHash)
.findFirst();
}

@Override
public TransactionReceipt getReceiptByRxhHashFromRealm(String txHash) {
return mRealm.where(TransactionReceipt.class).equalTo("transactionHash", txHash).findFirst();
}

}
Loading

0 comments on commit 85b3109

Please sign in to comment.