Skip to content

Commit

Permalink
Enhance transfer history view (#27)
Browse files Browse the repository at this point in the history
* enahced transfer operation, claim reward view

* enhance history item view

* change GOTO to GO TO
  • Loading branch information
bxute authored and singhpratyush committed Jul 12, 2018
1 parent 467ea4f commit 98530de
Show file tree
Hide file tree
Showing 25 changed files with 794 additions and 203 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
android:screenOrientation="portrait" />
<activity
android:name=".ui.activity.AccountHistoryActivity"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"/>
</application>

</manifest>
62 changes: 47 additions & 15 deletions app/src/main/java/com/hapramp/steem/TransferHistoryParser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hapramp.steem;

import android.util.Log;

import com.hapramp.search.TranserHistoryManager;
import com.hapramp.steem.models.TransferHistoryModel;

Expand All @@ -10,10 +12,20 @@
import java.util.ArrayList;

public class TransferHistoryParser {
private String total_vesting_fund_steem;
private String total_vesting_share;

public ArrayList<TransferHistoryModel> parseTransferHistory(String response, String user) {
ArrayList<TransferHistoryModel> transferHistoryList = new ArrayList<>();
try {
JSONObject root = new JSONObject(response);
JSONObject props = root
.getJSONObject(TranserHistoryManager.KEYS.KEY_RESULT)
.getJSONObject(TranserHistoryManager.KEYS.KEY_PROPS);

total_vesting_fund_steem = props.getString(TranserHistoryManager.KEYS.KEY_TOTAL_VESTING_FUND_STEEM);
total_vesting_share = props.getString(TranserHistoryManager.KEYS.KEY_TOTAL_VESTING_SHARE);

JSONArray transfer_history = root
.getJSONObject(TranserHistoryManager.KEYS.KEY_RESULT)
.getJSONObject(TranserHistoryManager.KEYS.KEY_ACCOUNTS)
Expand All @@ -24,10 +36,16 @@ public ArrayList<TransferHistoryModel> parseTransferHistory(String response, Str
JSONArray _history_item = transfer_history.getJSONArray(i);
JSONObject transfer_obj = _history_item.getJSONObject(1);
JSONArray operationArray = transfer_obj.getJSONArray(TranserHistoryManager.KEYS.KEY_OPERATION);
String timestamp = transfer_obj.getString("timestamp");
String timestamp = transfer_obj.getString(TranserHistoryManager.KEYS.KEY_TIMESTAMP);
JSONObject meta_data_obj = operationArray.getJSONObject(1);
String operation = operationArray.getString(0);
transferHistoryList.add(parse(operation, timestamp, meta_data_obj));
//skipping extra data
if (operation.equals(TranserHistoryManager.KEYS.OPERATION_CLAIM_REWARD_BALANCE) ||
operation.equals(TranserHistoryManager.KEYS.OPERATION_AUTHOR_REWARD) ||
operation.equals(TranserHistoryManager.KEYS.OPERATION_TRANSFER) ||
operation.equals(TranserHistoryManager.KEYS.OPERATION_CURATION_REWARD)) {
transferHistoryList.add(parse(user, operation, timestamp, meta_data_obj));
}
}
}
catch (JSONException e) {
Expand All @@ -36,29 +54,32 @@ public ArrayList<TransferHistoryModel> parseTransferHistory(String response, Str
return transferHistoryList;
}

private TransferHistoryModel parse(String operation, String timestamp, JSONObject meta_data_obj) {
private TransferHistoryModel parse(String user, String operation, String timestamp, JSONObject meta_data_obj) {
try {
switch (operation) {
case TranserHistoryManager.KEYS.OPERATION_TRANSFER:
return parseTransfer(operation, timestamp, meta_data_obj);
return parseTransfer(user, operation, timestamp, meta_data_obj);
case TranserHistoryManager.KEYS.OPERATION_AUTHOR_REWARD:
return parseAuthorReward(operation, timestamp, meta_data_obj);
return parseAuthorReward(user, operation, timestamp, meta_data_obj);
case TranserHistoryManager.KEYS.OPERATION_CLAIM_REWARD_BALANCE:
return parseClaimRewardBalance(operation, timestamp, meta_data_obj);
case TranserHistoryManager.KEYS.OPERATION_COMMENT_BENEFACTOR_REWARD:
return parseCommentBenefactor(operation, timestamp, meta_data_obj);
return parseClaimRewardBalance(user, operation, timestamp, meta_data_obj);
/* case TranserHistoryManager.KEYS.OPERATION_COMMENT_BENEFACTOR_REWARD:
return parseCommentBenefactor(user, operation, timestamp, meta_data_obj);*/
case TranserHistoryManager.KEYS.OPERATION_CURATION_REWARD:
return parseCurationReward(operation, timestamp, meta_data_obj);
return parseCurationReward(user, operation, timestamp, meta_data_obj);
}
}
catch (JSONException e) {
}
return null;
}

private TransferHistoryModel parseCurationReward(String op, String timestamp, JSONObject meta_data_obj) throws JSONException {
private TransferHistoryModel parseCurationReward(String user, String op, String timestamp, JSONObject meta_data_obj) throws JSONException {
TransferHistoryModel transferHistoryModel = new TransferHistoryModel();
transferHistoryModel.setOperation(op);
transferHistoryModel.setUserAccount(user);
transferHistoryModel.setTotal_vesting_fund_steem(total_vesting_fund_steem);
transferHistoryModel.setTotal_vesting_shares(total_vesting_share);
transferHistoryModel.setTimeStamp(timestamp);
transferHistoryModel.setCurationReward(new TransferHistoryModel.CurationReward(
meta_data_obj.getString(TranserHistoryManager.KEYS.KEY_CURATOR),
Expand All @@ -69,10 +90,13 @@ private TransferHistoryModel parseCurationReward(String op, String timestamp, JS
return transferHistoryModel;
}

private TransferHistoryModel parseCommentBenefactor(String op, String timestamp, JSONObject meta_data_obj) throws JSONException {
private TransferHistoryModel parseCommentBenefactor(String user, String op, String timestamp, JSONObject meta_data_obj) throws JSONException {
TransferHistoryModel transferHistoryModel = new TransferHistoryModel();
transferHistoryModel.setOperation(op);
transferHistoryModel.setUserAccount(user);
transferHistoryModel.setTimeStamp(timestamp);
transferHistoryModel.setTotal_vesting_fund_steem(total_vesting_fund_steem);
transferHistoryModel.setTotal_vesting_shares(total_vesting_share);
transferHistoryModel.setCommentBenefactor(new TransferHistoryModel.CommentBenefactor(
meta_data_obj.getString(TranserHistoryManager.KEYS.KEY_BENEFACTOR),
meta_data_obj.getString(TranserHistoryManager.KEYS.KEY_AUTHOR),
Expand All @@ -82,10 +106,13 @@ private TransferHistoryModel parseCommentBenefactor(String op, String timestamp,
return transferHistoryModel;
}

private TransferHistoryModel parseClaimRewardBalance(String op, String timestamp, JSONObject meta_data_obj) throws JSONException {
private TransferHistoryModel parseClaimRewardBalance(String user, String op, String timestamp, JSONObject meta_data_obj) throws JSONException {
TransferHistoryModel transferHistoryModel = new TransferHistoryModel();
transferHistoryModel.setOperation(op);
transferHistoryModel.setUserAccount(user);
transferHistoryModel.setTimeStamp(timestamp);
transferHistoryModel.setTotal_vesting_fund_steem(total_vesting_fund_steem);
transferHistoryModel.setTotal_vesting_shares(total_vesting_share);
transferHistoryModel.setClaimRewardBalance(new TransferHistoryModel.ClaimRewardBalance(
meta_data_obj.getString(TranserHistoryManager.KEYS.KEY_ACCOUNT),
meta_data_obj.getString(TranserHistoryManager.KEYS.KEY_REWARD_STEEM),
Expand All @@ -95,10 +122,13 @@ private TransferHistoryModel parseClaimRewardBalance(String op, String timestamp
return transferHistoryModel;
}

private TransferHistoryModel parseAuthorReward(String op, String timestamp, JSONObject meta_data_obj) throws JSONException {
private TransferHistoryModel parseAuthorReward(String user, String op, String timestamp, JSONObject meta_data_obj) throws JSONException {
TransferHistoryModel transferHistoryModel = new TransferHistoryModel();
transferHistoryModel.setOperation(op);
transferHistoryModel.setUserAccount(user);
transferHistoryModel.setTimeStamp(timestamp);
transferHistoryModel.setTotal_vesting_fund_steem(total_vesting_fund_steem);
transferHistoryModel.setTotal_vesting_shares(total_vesting_share);
transferHistoryModel.setAuthorReward(new TransferHistoryModel.AuthorReward(
meta_data_obj.getString(TranserHistoryManager.KEYS.KEY_AUTHOR),
meta_data_obj.getString(TranserHistoryManager.KEYS.KEY_PERMLINK),
Expand All @@ -109,10 +139,13 @@ private TransferHistoryModel parseAuthorReward(String op, String timestamp, JSON
return transferHistoryModel;
}

private TransferHistoryModel parseTransfer(String op, String timestamp, JSONObject meta_data_obj) throws JSONException {
private TransferHistoryModel parseTransfer(String user, String op, String timestamp, JSONObject meta_data_obj) throws JSONException {
TransferHistoryModel transferHistoryModel = new TransferHistoryModel();
transferHistoryModel.setOperation(op);
transferHistoryModel.setUserAccount(user);
transferHistoryModel.setTimeStamp(timestamp);
transferHistoryModel.setTotal_vesting_fund_steem(total_vesting_fund_steem);
transferHistoryModel.setTotal_vesting_shares(total_vesting_share);
transferHistoryModel.setTransfer(new TransferHistoryModel.Transfer(
meta_data_obj.getString(TranserHistoryManager.KEYS.KEY_FROM),
meta_data_obj.getString(TranserHistoryManager.KEYS.KEY_TO),
Expand All @@ -121,5 +154,4 @@ private TransferHistoryModel parseTransfer(String op, String timestamp, JSONObje
));
return transferHistoryModel;
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.hapramp.steem.models;

public class TransferHistoryModel {
private String userAccount;
private String operation;
private Transfer transfer;
private String total_vesting_fund_steem;
private String total_vesting_shares;
private AuthorReward authorReward;
private CommentBenefactor commentBenefactor;
private ClaimRewardBalance claimRewardBalance;
Expand All @@ -11,6 +14,30 @@ public class TransferHistoryModel {

public TransferHistoryModel() { }

public String getUserAccount() {
return userAccount;
}

public void setUserAccount(String userAccount) {
this.userAccount = userAccount;
}

public String getTotal_vesting_fund_steem() {
return total_vesting_fund_steem;
}

public void setTotal_vesting_fund_steem(String total_vesting_fund_steem) {
this.total_vesting_fund_steem = total_vesting_fund_steem;
}

public String getTotal_vesting_shares() {
return total_vesting_shares;
}

public void setTotal_vesting_shares(String total_vesting_shares) {
this.total_vesting_shares = total_vesting_shares;
}

public void setOperation(String operation) {
this.operation = operation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.hapramp.steem.TransferHistoryParser;
import com.hapramp.steem.models.TransferHistoryModel;
import com.hapramp.ui.adapters.AccountHistoryAdapter;
import com.hapramp.utils.AccountHistoryItemDecoration;
import com.hapramp.utils.FontManager;

import java.util.ArrayList;
Expand All @@ -37,6 +38,8 @@ public class AccountHistoryActivity extends AppCompatActivity {
ProgressBar loadingProgressBar;
@BindView(R.id.toolbar_title)
TextView toolbarTitle;
@BindView(R.id.empty_message)
TextView emptyMessage;

private AccountHistoryAdapter accountHistoryAdapter;
public static final String EXTRA_USERNAME = "username";
Expand All @@ -50,9 +53,9 @@ protected void onCreate(Bundle savedInstanceState) {
ButterKnife.bind(this);
init();
if (getIntent().getExtras() != null) {
mUsername = getIntent().getExtras().getString(EXTRA_USERNAME, HaprampPreferenceManager.getInstance().getCurrentSteemUsername());
toolbarTitle.setText(String.format("%s`s Account History", mUsername));
fetchHistory(mUsername);
mUsername = getIntent().getExtras().getString(EXTRA_USERNAME, HaprampPreferenceManager.getInstance().getCurrentSteemUsername());
toolbarTitle.setText(String.format("%s`s Account History", mUsername));
fetchHistory(mUsername);
}
}

Expand All @@ -61,8 +64,8 @@ private void init() {
closeBtn.setTypeface(FontManager.getInstance().getTypeFace(FontManager.FONT_MATERIAL));
accountHistoryAdapter = new AccountHistoryAdapter(this);
accountHistoryRv.setLayoutManager(new LinearLayoutManager(this));
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, LinearLayoutManager.VERTICAL);
accountHistoryRv.addItemDecoration(dividerItemDecoration);
AccountHistoryItemDecoration itemDecoration = new AccountHistoryItemDecoration();
accountHistoryRv.addItemDecoration(itemDecoration);
accountHistoryRv.setAdapter(accountHistoryAdapter);
closeBtn.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -98,7 +101,12 @@ private void bindData(ArrayList<TransferHistoryModel> transferHistory) {
if (loadingProgressBar != null) {
loadingProgressBar.setVisibility(View.GONE);
}
Collections.reverse(transferHistory);
accountHistoryAdapter.setTransferHistoryModels(transferHistory);
if(transferHistory.size() > 0) {
emptyMessage.setVisibility(View.GONE);
Collections.reverse(transferHistory);
accountHistoryAdapter.setTransferHistoryModels(transferHistory);
}else{
emptyMessage.setVisibility(View.VISIBLE);
}
}
}

0 comments on commit 98530de

Please sign in to comment.