Revision 1c90c64a
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/dialog/RubikDialogScoresView.java | ||
---|---|---|
30 | 30 |
import android.widget.TextView; |
31 | 31 |
|
32 | 32 |
import org.distorted.magic.R; |
33 |
import org.distorted.object.RubikObjectList; |
|
34 |
import org.distorted.scores.RubikScores; |
|
35 |
|
|
33 | 36 |
import static org.distorted.scores.RubikScoresDownloader.MAX_PLACES; |
34 | 37 |
|
35 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
64 | 67 |
|
65 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
66 | 69 |
|
67 |
LinearLayout createSection(FragmentActivity act, int scramble, final String[] country, final String[] name, final String[] time)
|
|
70 |
LinearLayout createSection(FragmentActivity act, int tab, int scramble, final String[] country, final String[] name, final float[] time)
|
|
68 | 71 |
{ |
69 | 72 |
LinearLayout level = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null); |
70 | 73 |
TextView text = level.findViewById(R.id.scoresScrambleTitle); |
... | ... | |
73 | 76 |
Resources res = act.getResources(); |
74 | 77 |
String packageName = act.getPackageName(); |
75 | 78 |
|
76 |
for(int j=0; j<MAX_PLACES; j++) |
|
77 |
{ |
|
78 |
if( name[j] != null ) |
|
79 |
{ |
|
80 |
View row = inflate(act, R.layout.dialog_scores_scramble_row, null); |
|
81 |
|
|
82 |
ImageView imgCoun = row.findViewById(R.id.scoresScrambleRowCountry); |
|
83 |
TextView textName = row.findViewById(R.id.scoresScrambleRowName); |
|
84 |
TextView textTime = row.findViewById(R.id.scoresScrambleRowTime); |
|
79 |
int object = RubikObjectList.unpackObject(tab); |
|
80 |
int size = RubikObjectList.unpackSize(tab); |
|
81 |
RubikScores scores = RubikScores.getInstance(); |
|
85 | 82 |
|
86 |
int resID = res.getIdentifier( country[j], "drawable", packageName); |
|
83 |
boolean inserted = false; |
|
84 |
long myRecordInSeconds = scores.getRecord(object, size, scramble); |
|
85 |
String myName = scores.getName(); |
|
86 |
int myCountryID = scores.getCountryID(); |
|
87 |
String myRecord = ( myRecordInSeconds<RubikScores.NO_RECORD ) ? Float.toString((myRecordInSeconds/100)/10.0f) : "??"; |
|
88 |
String theirTime; |
|
89 |
int theirCountryID; |
|
87 | 90 |
|
88 |
imgCoun.setImageResource(resID!=0 ? resID : R.drawable.unk); |
|
89 |
textName.setText(name[j]); |
|
90 |
textTime.setText(time[j]); |
|
91 |
int white = res.getColor(R.color.white); |
|
92 |
int red = res.getColor(R.color.red); |
|
91 | 93 |
|
94 |
for(int j=0; j<MAX_PLACES-1; j++) |
|
95 |
{ |
|
96 |
if( name[j] != null ) |
|
97 |
{ |
|
98 |
if( myRecordInSeconds<time[j] && !inserted ) |
|
99 |
{ |
|
100 |
inserted = true; |
|
101 |
View row = createRow(act, myCountryID, myName, myRecord, red); |
|
102 |
level.addView(row); |
|
103 |
} |
|
104 |
|
|
105 |
theirCountryID = res.getIdentifier( country[j], "drawable", packageName); |
|
106 |
theirTime = Float.toString(time[j]); |
|
107 |
View row = createRow(act, theirCountryID, name[j], theirTime, white); |
|
92 | 108 |
level.addView(row); |
93 | 109 |
} |
94 | 110 |
} |
95 | 111 |
|
112 |
if( !inserted ) |
|
113 |
{ |
|
114 |
View row = createRow(act, myCountryID, myName, myRecord, red); |
|
115 |
level.addView(row); |
|
116 |
} |
|
117 |
|
|
96 | 118 |
return level; |
97 | 119 |
} |
98 | 120 |
|
121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
122 |
|
|
123 |
private View createRow(FragmentActivity act, int countryID, String name, String time, int color) |
|
124 |
{ |
|
125 |
View row = inflate(act, R.layout.dialog_scores_scramble_row, null); |
|
126 |
|
|
127 |
ImageView imgCoun = row.findViewById(R.id.scoresScrambleRowCountry); |
|
128 |
TextView textName = row.findViewById(R.id.scoresScrambleRowName); |
|
129 |
TextView textTime = row.findViewById(R.id.scoresScrambleRowTime); |
|
130 |
|
|
131 |
imgCoun.setImageResource(countryID!=0 ? countryID : R.drawable.unk); |
|
132 |
textName.setText(name); |
|
133 |
textTime.setText(time); |
|
134 |
|
|
135 |
textName.setTextColor(color); |
|
136 |
textTime.setTextColor(color); |
|
137 |
|
|
138 |
return row; |
|
139 |
} |
|
140 |
|
|
99 | 141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
100 | 142 |
// needs to run on UI thread |
101 | 143 |
|
Also available in: Unified diff
Incorporate myRecords into the Scores dialog.