Skip to content

Commit 5529f73

Browse files
Merge pull request #276 from hapramp/improve/voters-list-display
Improve/voters list display
2 parents 153d9d0 + f3ce9f5 commit 5529f73

File tree

11 files changed

+135
-68
lines changed

11 files changed

+135
-68
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ android {
3737
applicationId "com.hapramp"
3838
minSdkVersion 16
3939
targetSdkVersion 27
40-
versionCode 120
41-
versionName "1.2"
40+
versionCode 123
41+
versionName "1.3"
4242
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
4343
multiDexEnabled true
4444
setProperty("archivesBaseName", "1ramp_" + versionCode + "_" + versionName)

app/src/main/java/com/hapramp/datastore/JSONParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ private ArrayList<Voter> readVoters(JSONObject rootObject) throws JSONException
339339
voters.add(new Voter(
340340
__voter.optString("voter",""),
341341
__voter.optInt("percent",0),
342-
__voter.optString("reputation",""),
342+
__voter.optLong("rshares",0),
343343
__voter.optString("time","")
344344
));
345345
}

app/src/main/java/com/hapramp/models/VoterData.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
public class VoterData {
44
private String username;
55
private String perecent;
6-
private String reputation;
6+
private long rshare;
7+
private String voteValue;
78

8-
public VoterData(String username, String perecent, String reputation) {
9+
public VoterData(String username, String perecent,long rshare, String voteValue) {
910
this.username = username;
1011
this.perecent = perecent;
11-
this.reputation = reputation;
12+
this.rshare = rshare;
13+
this.voteValue = voteValue;
1214
}
1315

1416
public String getUsername() {
@@ -27,11 +29,29 @@ public void setPerecent(String perecent) {
2729
this.perecent = perecent;
2830
}
2931

30-
public String getReputation() {
31-
return reputation;
32+
public long getRshare() {
33+
return rshare;
3234
}
3335

34-
public void setReputation(String reputation) {
35-
this.reputation = reputation;
36+
public void setRshare(long rshare) {
37+
this.rshare = rshare;
38+
}
39+
40+
public String getVoteValue() {
41+
return voteValue;
42+
}
43+
44+
public void setVoteValue(String reputation) {
45+
this.voteValue = reputation;
46+
}
47+
48+
@Override
49+
public String toString() {
50+
return "VoterData{" +
51+
"username='" + username + '\'' +
52+
", perecent='" + perecent + '\'' +
53+
", rshare=" + rshare +
54+
", voteValue='" + voteValue + '\'' +
55+
'}';
3656
}
3757
}

app/src/main/java/com/hapramp/steem/models/Feed.java

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,55 @@ protected Feed(Parcel in) {
102102
public Feed() {
103103
}
104104

105+
public double getManagedPayout() {
106+
try {
107+
double pendingPayoutValue = Double.parseDouble(getPendingPayoutValue().split(" ")[0]);
108+
double totalPayoutValue = Double.parseDouble(getTotalPayoutValue().split(" ")[0]);
109+
double curatorPayoutValue = Double.parseDouble(getCuratorPayoutValue().split(" ")[0]);
110+
if (pendingPayoutValue > 0) {
111+
return pendingPayoutValue;
112+
} else if ((totalPayoutValue + curatorPayoutValue) > 0) {
113+
return (totalPayoutValue + curatorPayoutValue);
114+
}
115+
}
116+
catch (Exception e) {
117+
e.printStackTrace();
118+
}
119+
return 0;
120+
}
121+
122+
public String getPendingPayoutValue() {
123+
return pendingPayoutValue;
124+
}
125+
126+
public String getTotalPayoutValue() {
127+
return totalPayoutValue;
128+
}
129+
130+
public void setTotalPayoutValue(String totalPayoutValue) {
131+
this.totalPayoutValue = totalPayoutValue;
132+
}
133+
134+
public String getCuratorPayoutValue() {
135+
return curatorPayoutValue;
136+
}
137+
138+
public void setCuratorPayoutValue(String curatorPayoutValue) {
139+
this.curatorPayoutValue = curatorPayoutValue;
140+
}
141+
142+
public void setPendingPayoutValue(String pendingPayoutValue) {
143+
this.pendingPayoutValue = pendingPayoutValue;
144+
}
145+
146+
public String getMaxAcceptedPayoutValue() {
147+
return maxAcceptedPayoutValue;
148+
}
149+
150+
public void setMaxAcceptedPayoutValue(String maxAcceptedPayoutValue) {
151+
this.maxAcceptedPayoutValue = maxAcceptedPayoutValue;
152+
}
153+
105154
@Override
106155
public int describeContents() {
107156
return 0;
@@ -171,14 +220,6 @@ public void setCashOutTime(String cashOutTime) {
171220
this.cashOutTime = cashOutTime;
172221
}
173222

174-
public String getMaxAcceptedPayoutValue() {
175-
return maxAcceptedPayoutValue;
176-
}
177-
178-
public void setMaxAcceptedPayoutValue(String maxAcceptedPayoutValue) {
179-
this.maxAcceptedPayoutValue = maxAcceptedPayoutValue;
180-
}
181-
182223
public boolean isResteemed() {
183224
return isResteemed;
184225
}
@@ -299,22 +340,6 @@ public void setChildren(int children) {
299340
this.children = children;
300341
}
301342

302-
public String getTotalPayoutValue() {
303-
return totalPayoutValue;
304-
}
305-
306-
public void setTotalPayoutValue(String totalPayoutValue) {
307-
this.totalPayoutValue = totalPayoutValue;
308-
}
309-
310-
public String getCuratorPayoutValue() {
311-
return curatorPayoutValue;
312-
}
313-
314-
public void setCuratorPayoutValue(String curatorPayoutValue) {
315-
this.curatorPayoutValue = curatorPayoutValue;
316-
}
317-
318343
public String getRootAuthor() {
319344
return rootAuthor;
320345
}
@@ -339,14 +364,6 @@ public void setUrl(String url) {
339364
this.url = url;
340365
}
341366

342-
public String getPendingPayoutValue() {
343-
return pendingPayoutValue;
344-
}
345-
346-
public void setPendingPayoutValue(String pendingPayoutValue) {
347-
this.pendingPayoutValue = pendingPayoutValue;
348-
}
349-
350367
public String getTotalPendingPayoutValue() {
351368
return totalPendingPayoutValue;
352369
}

app/src/main/java/com/hapramp/steem/models/Voter.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ public Voter[] newArray(int size) {
1919
};
2020
private String voter;
2121
private int percent;
22-
private String reputation;
22+
private long rshare;
2323
private String voteTime;
2424

2525
protected Voter(Parcel in) {
2626
voter = in.readString();
2727
percent = in.readInt();
28-
reputation = in.readString();
28+
rshare = in.readLong();
2929
voteTime = in.readString();
3030
}
3131

3232
public Voter() {
3333
}
3434

35-
public Voter(String voter, int percent, String reputation, String voteTime) {
35+
public Voter(String voter, int percent, long rshare, String voteTime) {
3636
this.voter = voter;
3737
this.percent = percent;
38-
this.reputation = reputation;
38+
this.rshare = rshare;
3939
this.voteTime = voteTime;
4040
}
4141

@@ -48,7 +48,7 @@ public int describeContents() {
4848
public void writeToParcel(Parcel dest, int flags) {
4949
dest.writeString(voter);
5050
dest.writeInt(percent);
51-
dest.writeString(reputation);
51+
dest.writeLong(rshare);
5252
dest.writeString(voteTime);
5353
}
5454

@@ -68,12 +68,12 @@ public void setPercent(int percent) {
6868
this.percent = percent;
6969
}
7070

71-
public void setReputation(String reputation) {
72-
this.reputation = reputation;
71+
public long getRshare() {
72+
return rshare;
7373
}
7474

75-
public String getReputation() {
76-
return reputation;
75+
public void setRshare(long rshare) {
76+
this.rshare = rshare;
7777
}
7878

7979
public void setVoteTime(String voteTime) {
@@ -85,7 +85,7 @@ public String toString() {
8585
return "Voter{" +
8686
"voter='" + voter + '\'' +
8787
", percent=" + percent +
88-
", reputation='" + reputation + '\'' +
88+
", reputation='" + rshare + '\'' +
8989
", voteTime='" + voteTime + '\'' +
9090
'}';
9191
}

app/src/main/java/com/hapramp/ui/activity/DetailedActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@
5959
import com.hapramp.utils.ImageHandler;
6060
import com.hapramp.utils.MomentsUtils;
6161
import com.hapramp.utils.PostMenu;
62-
import com.hapramp.utils.RegexUtils;
6362
import com.hapramp.utils.ShareUtils;
64-
import com.hapramp.utils.VoteUtils;
6563
import com.hapramp.views.CommunityStripView;
6664
import com.hapramp.views.VoterPeekView;
6765
import com.hapramp.views.comments.CommentsItemView;
@@ -680,6 +678,7 @@ public void afterTextChanged(Editable editable) {
680678

681679
private void openVotersList() {
682680
Intent intent = new Intent(this, VotersListActivity.class);
681+
intent.putExtra(VotersListActivity.EXTRA_TOTAL_EARNING, post.getManagedPayout());
683682
intent.putParcelableArrayListExtra(VotersListActivity.EXTRA_USER_LIST, post.getVoters());
684683
startActivity(intent);
685684
}

app/src/main/java/com/hapramp/ui/activity/VotersListActivity.java

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.hapramp.ui.activity;
22

3+
import android.graphics.drawable.Drawable;
34
import android.os.Bundle;
5+
import android.support.v4.content.ContextCompat;
46
import android.support.v7.app.AppCompatActivity;
57
import android.support.v7.widget.LinearLayoutManager;
68
import android.support.v7.widget.RecyclerView;
@@ -13,19 +15,19 @@
1315
import com.hapramp.models.VoterData;
1416
import com.hapramp.steem.models.Voter;
1517
import com.hapramp.ui.adapters.VoterListAdapter;
16-
import com.hapramp.utils.ReputationCalc;
18+
import com.hapramp.utils.ViewItemDecoration;
1719

1820
import java.util.ArrayList;
21+
import java.util.Collections;
22+
import java.util.Comparator;
1923
import java.util.Locale;
2024

2125
import butterknife.BindView;
2226
import butterknife.ButterKnife;
2327

2428
public class VotersListActivity extends AppCompatActivity {
25-
2629
public static final String EXTRA_USER_LIST = "extra_user_list";
27-
public String quote;
28-
public String base;
30+
public static final String EXTRA_TOTAL_EARNING = "total_earning";
2931
@BindView(R.id.backBtn)
3032
ImageView backBtn;
3133
@BindView(R.id.action_bar_title)
@@ -35,6 +37,14 @@ public class VotersListActivity extends AppCompatActivity {
3537
@BindView(R.id.voters_recyclerview)
3638
RecyclerView userListRecyclerView;
3739
private ArrayList<Voter> voters;
40+
private double totalEarning = 0;
41+
private Comparator<? super VoterData> votersComparator = new Comparator<VoterData>() {
42+
@Override
43+
public int compare(VoterData voter1, VoterData voter2) {
44+
int comp = voter1.getRshare() > voter2.getRshare() ? -1 : 1;
45+
return comp;
46+
}
47+
};
3848

3949
@Override
4050
protected void onCreate(Bundle savedInstanceState) {
@@ -55,7 +65,11 @@ public void onClick(View view) {
5565
}
5666

5767
private void initList() {
68+
totalEarning = getIntent().getDoubleExtra(EXTRA_TOTAL_EARNING, 0);
5869
voters = getIntent().getParcelableArrayListExtra(EXTRA_USER_LIST);
70+
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.leaderboard_item_divider);
71+
ViewItemDecoration viewItemDecoration = new ViewItemDecoration(drawable);
72+
userListRecyclerView.addItemDecoration(viewItemDecoration);
5973
userListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
6074
VoterListAdapter voterListAdapter = new VoterListAdapter();
6175
userListRecyclerView.setAdapter(voterListAdapter);
@@ -64,11 +78,27 @@ private void initList() {
6478

6579
private ArrayList<VoterData> processVoterData(ArrayList<Voter> voters) {
6680
ArrayList<VoterData> processedData = new ArrayList<>();
81+
long totalRshares = 0;
82+
for (int i = 0; i < voters.size(); i++) {
83+
totalRshares += voters.get(i).getRshare();
84+
}
85+
6786
for (int i = 0; i < voters.size(); i++) {
87+
double percent = voters.get(i).getPercent();
88+
long rshare = voters.get(i).getRshare();
89+
double voteValue = calculateVoteValueFrom(rshare, totalRshares, totalEarning);
90+
voteValue = Double.parseDouble(String.format("%.3f", voteValue));
91+
String voteValueString = voteValue > 0 ? String.format(Locale.US, "$%.3f", voteValue) : "";
92+
6893
processedData.add(new VoterData(voters.get(i).getVoter(),
69-
String.format(Locale.US, "%d%%", voters.get(i).getPercent() / 100),
70-
String.format(Locale.US, "(%.2f)", ReputationCalc.calculateReputation(Long.valueOf(voters.get(i).getReputation())))));
94+
String.format(Locale.US, String.format(Locale.US, "%.2f", percent / 100)) + "%",
95+
rshare, voteValueString));
7196
}
97+
Collections.sort(processedData, votersComparator);
7298
return processedData;
7399
}
100+
101+
private double calculateVoteValueFrom(double rshare, long totalRshares, double totalEarning) {
102+
return (totalEarning * rshare) / totalRshares;
103+
}
74104
}

app/src/main/java/com/hapramp/ui/adapters/VoterListAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class VoterItemViewHolder extends RecyclerView.ViewHolder {
5858
TextView voterName;
5959
@BindView(R.id.vote_percent)
6060
TextView votePercent;
61-
@BindView(R.id.reputation)
62-
TextView reputation;
61+
@BindView(R.id.vote_value)
62+
TextView voteValue;
6363

6464
public VoterItemViewHolder(View itemView) {
6565
super(itemView);
@@ -73,7 +73,7 @@ public void bind(final VoterData voterData) {
7373
voterData.getUsername()));
7474
voterName.setText(voterData.getUsername());
7575
votePercent.setText(voterData.getPerecent());
76-
reputation.setText(voterData.getReputation());
76+
voteValue.setText(voterData.getVoteValue());
7777
itemView.setOnClickListener(new View.OnClickListener() {
7878
@Override
7979
public void onClick(View view) {

app/src/main/java/com/hapramp/utils/JsonParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private ArrayList<Voter> readVoters(JSONObject rootObject) throws JSONException
179179
voters.add(new Voter(
180180
__voter.getString("voter"),
181181
__voter.getInt("percent"),
182-
__voter.getString("reputation"),
182+
__voter.getLong("rshares"),
183183
__voter.getString("time")
184184
));
185185
}
@@ -342,7 +342,7 @@ public ArrayList<Voter> parseVoters(String response) {
342342
voters.add(new Voter(
343343
__voter.getString("voter"),
344344
__voter.getInt("percent"),
345-
__voter.getString("reputation"),
345+
__voter.getLong("rshares"),
346346
__voter.getString("time")
347347
));
348348
}

app/src/main/java/com/hapramp/views/post/PostItemView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ private void navigateToCommentsPage() {
212212

213213
private void openVotersList() {
214214
Intent intent = new Intent(mContext, VotersListActivity.class);
215+
intent.putExtra(VotersListActivity.EXTRA_TOTAL_EARNING,mFeed.getManagedPayout());
215216
intent.putParcelableArrayListExtra(VotersListActivity.EXTRA_USER_LIST, mFeed.getVoters());
216217
mContext.startActivity(intent);
217218
}

0 commit comments

Comments
 (0)