Skip to content

Commit f3ce9f5

Browse files
committed
Sorted voters list according to vote value, add line dividers
1 parent 6e1c82f commit f3ce9f5

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
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/models/VoterData.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
public class VoterData {
44
private String username;
55
private String perecent;
6+
private long rshare;
67
private String voteValue;
78

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

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

32+
public long getRshare() {
33+
return rshare;
34+
}
35+
36+
public void setRshare(long rshare) {
37+
this.rshare = rshare;
38+
}
39+
3040
public String getVoteValue() {
3141
return voteValue;
3242
}
3343

3444
public void setVoteValue(String reputation) {
3545
this.voteValue = reputation;
3646
}
47+
48+
@Override
49+
public String toString() {
50+
return "VoterData{" +
51+
"username='" + username + '\'' +
52+
", perecent='" + perecent + '\'' +
53+
", rshare=" + rshare +
54+
", voteValue='" + voteValue + '\'' +
55+
'}';
56+
}
3757
}

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

Lines changed: 22 additions & 3 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,8 +15,11 @@
1315
import com.hapramp.models.VoterData;
1416
import com.hapramp.steem.models.Voter;
1517
import com.hapramp.ui.adapters.VoterListAdapter;
18+
import com.hapramp.utils.ViewItemDecoration;
1619

1720
import java.util.ArrayList;
21+
import java.util.Collections;
22+
import java.util.Comparator;
1823
import java.util.Locale;
1924

2025
import butterknife.BindView;
@@ -33,6 +38,13 @@ public class VotersListActivity extends AppCompatActivity {
3338
RecyclerView userListRecyclerView;
3439
private ArrayList<Voter> voters;
3540
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+
};
3648

3749
@Override
3850
protected void onCreate(Bundle savedInstanceState) {
@@ -55,6 +67,9 @@ public void onClick(View view) {
5567
private void initList() {
5668
totalEarning = getIntent().getDoubleExtra(EXTRA_TOTAL_EARNING, 0);
5769
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);
5873
userListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
5974
VoterListAdapter voterListAdapter = new VoterListAdapter();
6075
userListRecyclerView.setAdapter(voterListAdapter);
@@ -70,12 +85,16 @@ private ArrayList<VoterData> processVoterData(ArrayList<Voter> voters) {
7085

7186
for (int i = 0; i < voters.size(); i++) {
7287
double percent = voters.get(i).getPercent();
73-
double rshare = voters.get(i).getRshare();
88+
long rshare = voters.get(i).getRshare();
7489
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+
7593
processedData.add(new VoterData(voters.get(i).getVoter(),
76-
String.format(Locale.US, String.format(Locale.US, "%.2f", percent / 100)),
77-
String.format(Locale.US, "$%.2f", voteValue)));
94+
String.format(Locale.US, String.format(Locale.US, "%.2f", percent / 100)) + "%",
95+
rshare, voteValueString));
7896
}
97+
Collections.sort(processedData, votersComparator);
7998
return processedData;
8099
}
81100

0 commit comments

Comments
 (0)