Skip to content

Commit

Permalink
Merge pull request #276 from hapramp/improve/voters-list-display
Browse files Browse the repository at this point in the history
Improve/voters list display
  • Loading branch information
singhpratyush authored Feb 5, 2019
2 parents 153d9d0 + f3ce9f5 commit 5529f73
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 68 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ android {
applicationId "com.hapramp"
minSdkVersion 16
targetSdkVersion 27
versionCode 120
versionName "1.2"
versionCode 123
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
setProperty("archivesBaseName", "1ramp_" + versionCode + "_" + versionName)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/hapramp/datastore/JSONParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private ArrayList<Voter> readVoters(JSONObject rootObject) throws JSONException
voters.add(new Voter(
__voter.optString("voter",""),
__voter.optInt("percent",0),
__voter.optString("reputation",""),
__voter.optLong("rshares",0),
__voter.optString("time","")
));
}
Expand Down
34 changes: 27 additions & 7 deletions app/src/main/java/com/hapramp/models/VoterData.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
public class VoterData {
private String username;
private String perecent;
private String reputation;
private long rshare;
private String voteValue;

public VoterData(String username, String perecent, String reputation) {
public VoterData(String username, String perecent,long rshare, String voteValue) {
this.username = username;
this.perecent = perecent;
this.reputation = reputation;
this.rshare = rshare;
this.voteValue = voteValue;
}

public String getUsername() {
Expand All @@ -27,11 +29,29 @@ public void setPerecent(String perecent) {
this.perecent = perecent;
}

public String getReputation() {
return reputation;
public long getRshare() {
return rshare;
}

public void setReputation(String reputation) {
this.reputation = reputation;
public void setRshare(long rshare) {
this.rshare = rshare;
}

public String getVoteValue() {
return voteValue;
}

public void setVoteValue(String reputation) {
this.voteValue = reputation;
}

@Override
public String toString() {
return "VoterData{" +
"username='" + username + '\'' +
", perecent='" + perecent + '\'' +
", rshare=" + rshare +
", voteValue='" + voteValue + '\'' +
'}';
}
}
81 changes: 49 additions & 32 deletions app/src/main/java/com/hapramp/steem/models/Feed.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,55 @@ protected Feed(Parcel in) {
public Feed() {
}

public double getManagedPayout() {
try {
double pendingPayoutValue = Double.parseDouble(getPendingPayoutValue().split(" ")[0]);
double totalPayoutValue = Double.parseDouble(getTotalPayoutValue().split(" ")[0]);
double curatorPayoutValue = Double.parseDouble(getCuratorPayoutValue().split(" ")[0]);
if (pendingPayoutValue > 0) {
return pendingPayoutValue;
} else if ((totalPayoutValue + curatorPayoutValue) > 0) {
return (totalPayoutValue + curatorPayoutValue);
}
}
catch (Exception e) {
e.printStackTrace();
}
return 0;
}

public String getPendingPayoutValue() {
return pendingPayoutValue;
}

public String getTotalPayoutValue() {
return totalPayoutValue;
}

public void setTotalPayoutValue(String totalPayoutValue) {
this.totalPayoutValue = totalPayoutValue;
}

public String getCuratorPayoutValue() {
return curatorPayoutValue;
}

public void setCuratorPayoutValue(String curatorPayoutValue) {
this.curatorPayoutValue = curatorPayoutValue;
}

public void setPendingPayoutValue(String pendingPayoutValue) {
this.pendingPayoutValue = pendingPayoutValue;
}

public String getMaxAcceptedPayoutValue() {
return maxAcceptedPayoutValue;
}

public void setMaxAcceptedPayoutValue(String maxAcceptedPayoutValue) {
this.maxAcceptedPayoutValue = maxAcceptedPayoutValue;
}

@Override
public int describeContents() {
return 0;
Expand Down Expand Up @@ -171,14 +220,6 @@ public void setCashOutTime(String cashOutTime) {
this.cashOutTime = cashOutTime;
}

public String getMaxAcceptedPayoutValue() {
return maxAcceptedPayoutValue;
}

public void setMaxAcceptedPayoutValue(String maxAcceptedPayoutValue) {
this.maxAcceptedPayoutValue = maxAcceptedPayoutValue;
}

public boolean isResteemed() {
return isResteemed;
}
Expand Down Expand Up @@ -299,22 +340,6 @@ public void setChildren(int children) {
this.children = children;
}

public String getTotalPayoutValue() {
return totalPayoutValue;
}

public void setTotalPayoutValue(String totalPayoutValue) {
this.totalPayoutValue = totalPayoutValue;
}

public String getCuratorPayoutValue() {
return curatorPayoutValue;
}

public void setCuratorPayoutValue(String curatorPayoutValue) {
this.curatorPayoutValue = curatorPayoutValue;
}

public String getRootAuthor() {
return rootAuthor;
}
Expand All @@ -339,14 +364,6 @@ public void setUrl(String url) {
this.url = url;
}

public String getPendingPayoutValue() {
return pendingPayoutValue;
}

public void setPendingPayoutValue(String pendingPayoutValue) {
this.pendingPayoutValue = pendingPayoutValue;
}

public String getTotalPendingPayoutValue() {
return totalPendingPayoutValue;
}
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/com/hapramp/steem/models/Voter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ public Voter[] newArray(int size) {
};
private String voter;
private int percent;
private String reputation;
private long rshare;
private String voteTime;

protected Voter(Parcel in) {
voter = in.readString();
percent = in.readInt();
reputation = in.readString();
rshare = in.readLong();
voteTime = in.readString();
}

public Voter() {
}

public Voter(String voter, int percent, String reputation, String voteTime) {
public Voter(String voter, int percent, long rshare, String voteTime) {
this.voter = voter;
this.percent = percent;
this.reputation = reputation;
this.rshare = rshare;
this.voteTime = voteTime;
}

Expand All @@ -48,7 +48,7 @@ public int describeContents() {
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(voter);
dest.writeInt(percent);
dest.writeString(reputation);
dest.writeLong(rshare);
dest.writeString(voteTime);
}

Expand All @@ -68,12 +68,12 @@ public void setPercent(int percent) {
this.percent = percent;
}

public void setReputation(String reputation) {
this.reputation = reputation;
public long getRshare() {
return rshare;
}

public String getReputation() {
return reputation;
public void setRshare(long rshare) {
this.rshare = rshare;
}

public void setVoteTime(String voteTime) {
Expand All @@ -85,7 +85,7 @@ public String toString() {
return "Voter{" +
"voter='" + voter + '\'' +
", percent=" + percent +
", reputation='" + reputation + '\'' +
", reputation='" + rshare + '\'' +
", voteTime='" + voteTime + '\'' +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@
import com.hapramp.utils.ImageHandler;
import com.hapramp.utils.MomentsUtils;
import com.hapramp.utils.PostMenu;
import com.hapramp.utils.RegexUtils;
import com.hapramp.utils.ShareUtils;
import com.hapramp.utils.VoteUtils;
import com.hapramp.views.CommunityStripView;
import com.hapramp.views.VoterPeekView;
import com.hapramp.views.comments.CommentsItemView;
Expand Down Expand Up @@ -680,6 +678,7 @@ public void afterTextChanged(Editable editable) {

private void openVotersList() {
Intent intent = new Intent(this, VotersListActivity.class);
intent.putExtra(VotersListActivity.EXTRA_TOTAL_EARNING, post.getManagedPayout());
intent.putParcelableArrayListExtra(VotersListActivity.EXTRA_USER_LIST, post.getVoters());
startActivity(intent);
}
Expand Down
42 changes: 36 additions & 6 deletions app/src/main/java/com/hapramp/ui/activity/VotersListActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.hapramp.ui.activity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand All @@ -13,19 +15,19 @@
import com.hapramp.models.VoterData;
import com.hapramp.steem.models.Voter;
import com.hapramp.ui.adapters.VoterListAdapter;
import com.hapramp.utils.ReputationCalc;
import com.hapramp.utils.ViewItemDecoration;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;

public class VotersListActivity extends AppCompatActivity {

public static final String EXTRA_USER_LIST = "extra_user_list";
public String quote;
public String base;
public static final String EXTRA_TOTAL_EARNING = "total_earning";
@BindView(R.id.backBtn)
ImageView backBtn;
@BindView(R.id.action_bar_title)
Expand All @@ -35,6 +37,14 @@ public class VotersListActivity extends AppCompatActivity {
@BindView(R.id.voters_recyclerview)
RecyclerView userListRecyclerView;
private ArrayList<Voter> voters;
private double totalEarning = 0;
private Comparator<? super VoterData> votersComparator = new Comparator<VoterData>() {
@Override
public int compare(VoterData voter1, VoterData voter2) {
int comp = voter1.getRshare() > voter2.getRshare() ? -1 : 1;
return comp;
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -55,7 +65,11 @@ public void onClick(View view) {
}

private void initList() {
totalEarning = getIntent().getDoubleExtra(EXTRA_TOTAL_EARNING, 0);
voters = getIntent().getParcelableArrayListExtra(EXTRA_USER_LIST);
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.leaderboard_item_divider);
ViewItemDecoration viewItemDecoration = new ViewItemDecoration(drawable);
userListRecyclerView.addItemDecoration(viewItemDecoration);
userListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
VoterListAdapter voterListAdapter = new VoterListAdapter();
userListRecyclerView.setAdapter(voterListAdapter);
Expand All @@ -64,11 +78,27 @@ private void initList() {

private ArrayList<VoterData> processVoterData(ArrayList<Voter> voters) {
ArrayList<VoterData> processedData = new ArrayList<>();
long totalRshares = 0;
for (int i = 0; i < voters.size(); i++) {
totalRshares += voters.get(i).getRshare();
}

for (int i = 0; i < voters.size(); i++) {
double percent = voters.get(i).getPercent();
long rshare = voters.get(i).getRshare();
double voteValue = calculateVoteValueFrom(rshare, totalRshares, totalEarning);
voteValue = Double.parseDouble(String.format("%.3f", voteValue));
String voteValueString = voteValue > 0 ? String.format(Locale.US, "$%.3f", voteValue) : "";

processedData.add(new VoterData(voters.get(i).getVoter(),
String.format(Locale.US, "%d%%", voters.get(i).getPercent() / 100),
String.format(Locale.US, "(%.2f)", ReputationCalc.calculateReputation(Long.valueOf(voters.get(i).getReputation())))));
String.format(Locale.US, String.format(Locale.US, "%.2f", percent / 100)) + "%",
rshare, voteValueString));
}
Collections.sort(processedData, votersComparator);
return processedData;
}

private double calculateVoteValueFrom(double rshare, long totalRshares, double totalEarning) {
return (totalEarning * rshare) / totalRshares;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class VoterItemViewHolder extends RecyclerView.ViewHolder {
TextView voterName;
@BindView(R.id.vote_percent)
TextView votePercent;
@BindView(R.id.reputation)
TextView reputation;
@BindView(R.id.vote_value)
TextView voteValue;

public VoterItemViewHolder(View itemView) {
super(itemView);
Expand All @@ -73,7 +73,7 @@ public void bind(final VoterData voterData) {
voterData.getUsername()));
voterName.setText(voterData.getUsername());
votePercent.setText(voterData.getPerecent());
reputation.setText(voterData.getReputation());
voteValue.setText(voterData.getVoteValue());
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hapramp/utils/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private ArrayList<Voter> readVoters(JSONObject rootObject) throws JSONException
voters.add(new Voter(
__voter.getString("voter"),
__voter.getInt("percent"),
__voter.getString("reputation"),
__voter.getLong("rshares"),
__voter.getString("time")
));
}
Expand Down Expand Up @@ -342,7 +342,7 @@ public ArrayList<Voter> parseVoters(String response) {
voters.add(new Voter(
__voter.getString("voter"),
__voter.getInt("percent"),
__voter.getString("reputation"),
__voter.getLong("rshares"),
__voter.getString("time")
));
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/hapramp/views/post/PostItemView.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ private void navigateToCommentsPage() {

private void openVotersList() {
Intent intent = new Intent(mContext, VotersListActivity.class);
intent.putExtra(VotersListActivity.EXTRA_TOTAL_EARNING,mFeed.getManagedPayout());
intent.putParcelableArrayListExtra(VotersListActivity.EXTRA_USER_LIST, mFeed.getVoters());
mContext.startActivity(intent);
}
Expand Down
Loading

0 comments on commit 5529f73

Please sign in to comment.