1
1
package com .hapramp .ui .activity ;
2
2
3
+ import android .graphics .drawable .Drawable ;
3
4
import android .os .Bundle ;
5
+ import android .support .v4 .content .ContextCompat ;
4
6
import android .support .v7 .app .AppCompatActivity ;
5
7
import android .support .v7 .widget .LinearLayoutManager ;
6
8
import android .support .v7 .widget .RecyclerView ;
13
15
import com .hapramp .models .VoterData ;
14
16
import com .hapramp .steem .models .Voter ;
15
17
import com .hapramp .ui .adapters .VoterListAdapter ;
18
+ import com .hapramp .utils .ViewItemDecoration ;
16
19
17
20
import java .util .ArrayList ;
21
+ import java .util .Collections ;
22
+ import java .util .Comparator ;
18
23
import java .util .Locale ;
19
24
20
25
import butterknife .BindView ;
@@ -33,6 +38,13 @@ public class VotersListActivity extends AppCompatActivity {
33
38
RecyclerView userListRecyclerView ;
34
39
private ArrayList <Voter > voters ;
35
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
+ };
36
48
37
49
@ Override
38
50
protected void onCreate (Bundle savedInstanceState ) {
@@ -55,6 +67,9 @@ public void onClick(View view) {
55
67
private void initList () {
56
68
totalEarning = getIntent ().getDoubleExtra (EXTRA_TOTAL_EARNING , 0 );
57
69
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 );
58
73
userListRecyclerView .setLayoutManager (new LinearLayoutManager (this ));
59
74
VoterListAdapter voterListAdapter = new VoterListAdapter ();
60
75
userListRecyclerView .setAdapter (voterListAdapter );
@@ -70,12 +85,16 @@ private ArrayList<VoterData> processVoterData(ArrayList<Voter> voters) {
70
85
71
86
for (int i = 0 ; i < voters .size (); i ++) {
72
87
double percent = voters .get (i ).getPercent ();
73
- double rshare = voters .get (i ).getRshare ();
88
+ long rshare = voters .get (i ).getRshare ();
74
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
+
75
93
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 ));
78
96
}
97
+ Collections .sort (processedData , votersComparator );
79
98
return processedData ;
80
99
}
81
100
0 commit comments