Skip to content

Commit

Permalink
Sorted voters list according to vote value, add line dividers
Browse files Browse the repository at this point in the history
  • Loading branch information
bxute committed Feb 5, 2019
1 parent 6e1c82f commit f3ce9f5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 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
22 changes: 21 additions & 1 deletion app/src/main/java/com/hapramp/models/VoterData.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
public class VoterData {
private String username;
private String perecent;
private long rshare;
private String voteValue;

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

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

public long getRshare() {
return rshare;
}

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 + '\'' +
'}';
}
}
25 changes: 22 additions & 3 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,8 +15,11 @@
import com.hapramp.models.VoterData;
import com.hapramp.steem.models.Voter;
import com.hapramp.ui.adapters.VoterListAdapter;
import com.hapramp.utils.ViewItemDecoration;

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

import butterknife.BindView;
Expand All @@ -33,6 +38,13 @@ public class VotersListActivity extends AppCompatActivity {
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,6 +67,9 @@ 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 @@ -70,12 +85,16 @@ private ArrayList<VoterData> processVoterData(ArrayList<Voter> voters) {

for (int i = 0; i < voters.size(); i++) {
double percent = voters.get(i).getPercent();
double rshare = voters.get(i).getRshare();
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, String.format(Locale.US, "%.2f", percent / 100)),
String.format(Locale.US, "$%.2f", voteValue)));
String.format(Locale.US, String.format(Locale.US, "%.2f", percent / 100)) + "%",
rshare, voteValueString));
}
Collections.sort(processedData, votersComparator);
return processedData;
}

Expand Down

0 comments on commit f3ce9f5

Please sign in to comment.