Revision 3e5ad461
Added by Leszek Koltunski about 5 years ago
| src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java | ||
|---|---|---|
| 44 | 44 |
private ViewPager mViewPager; |
| 45 | 45 |
private int mNumTabs; |
| 46 | 46 |
private boolean mIsSubmitting; |
| 47 |
private int mToDoTab, mToDoLvl; |
|
| 47 | 48 |
|
| 48 | 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 49 | 50 |
|
| 50 |
public void receive(final String[][][] country, final String[][][] name, final float[][][] time)
|
|
| 51 |
private void addSection(int tab, int level, final RubikDialogScoresView view, final String[] country, final String[] name, final float[] time)
|
|
| 51 | 52 |
{
|
| 52 |
prepareView();
|
|
| 53 |
final LinearLayout section = view.createSection(mAct, tab, level, country, name, time);
|
|
| 53 | 54 |
|
| 54 |
boolean[] tabDone = new boolean[mNumTabs]; |
|
| 55 |
for(int i=0; i<mNumTabs; i++) tabDone[i] = false; |
|
| 56 |
int toDo, doneTabs=0; |
|
| 55 |
mAct.runOnUiThread(new Runnable() |
|
| 56 |
{
|
|
| 57 |
@Override |
|
| 58 |
public void run() |
|
| 59 |
{
|
|
| 60 |
view.addSection(section); |
|
| 61 |
} |
|
| 62 |
}); |
|
| 57 | 63 |
|
| 58 |
while( doneTabs<mNumTabs )
|
|
| 64 |
try
|
|
| 59 | 65 |
{
|
| 60 |
toDo = mViewPager.getCurrentItem(); |
|
| 66 |
Thread.sleep(50); |
|
| 67 |
} |
|
| 68 |
catch( InterruptedException ignored) |
|
| 69 |
{
|
|
| 70 |
|
|
| 71 |
} |
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 61 | 75 |
|
| 62 |
if( tabDone[toDo] ) |
|
| 76 |
private void getNext(int currentTab, int[] toDoTab, int[] maxTab) |
|
| 77 |
{
|
|
| 78 |
if( toDoTab[currentTab]<maxTab[currentTab] ) |
|
| 79 |
{
|
|
| 80 |
mToDoTab = currentTab; |
|
| 81 |
mToDoLvl = toDoTab[currentTab]; |
|
| 82 |
toDoTab[currentTab]++; |
|
| 83 |
} |
|
| 84 |
else |
|
| 85 |
{
|
|
| 86 |
for(int tab=0; tab<mNumTabs; tab++) |
|
| 63 | 87 |
{
|
| 64 |
for(int i=0; i<mNumTabs; i++)
|
|
| 88 |
if( toDoTab[tab]<maxTab[tab] )
|
|
| 65 | 89 |
{
|
| 66 |
if( !tabDone[i] ) |
|
| 67 |
{
|
|
| 68 |
toDo = i; |
|
| 69 |
break; |
|
| 70 |
} |
|
| 90 |
mToDoTab = tab; |
|
| 91 |
mToDoLvl = toDoTab[tab]; |
|
| 92 |
toDoTab[tab]++; |
|
| 93 |
break; |
|
| 71 | 94 |
} |
| 72 | 95 |
} |
| 96 |
} |
|
| 97 |
} |
|
| 73 | 98 |
|
| 74 |
addPage(toDo, mViews[toDo],country[toDo],name[toDo],time[toDo]);
|
|
| 99 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
| 75 | 100 |
|
| 76 |
doneTabs++; |
|
| 77 |
tabDone[toDo] = true; |
|
| 101 |
public void receive(final String[][][] country, final String[][][] name, final float[][][] time) |
|
| 102 |
{
|
|
| 103 |
prepareView(); |
|
| 104 |
|
|
| 105 |
int toDo=0; |
|
| 106 |
int[] toDoTab = new int[mNumTabs]; |
|
| 107 |
int[] maxTab = new int[mNumTabs]; |
|
| 108 |
|
|
| 109 |
for(int i=0; i<mNumTabs; i++) |
|
| 110 |
{
|
|
| 111 |
int object = RubikObjectList.unpackObject(i); |
|
| 112 |
int sizeIndex= RubikObjectList.unpackSizeIndex(i); |
|
| 113 |
maxTab[i] = RubikObjectList.getMaxLevel(object, sizeIndex); |
|
| 114 |
toDoTab[i] = 0; |
|
| 115 |
|
|
| 116 |
toDo += maxTab[i]; |
|
| 117 |
} |
|
| 118 |
|
|
| 119 |
while( toDo>0 ) |
|
| 120 |
{
|
|
| 121 |
toDo--; |
|
| 122 |
getNext(mViewPager.getCurrentItem(),toDoTab,maxTab); |
|
| 123 |
addSection( mToDoTab,mToDoLvl, mViews[mToDoTab], |
|
| 124 |
country[mToDoTab][mToDoLvl],name[mToDoTab][mToDoLvl],time[mToDoTab][mToDoLvl]); |
|
| 78 | 125 |
} |
| 79 | 126 |
} |
| 80 | 127 |
|
| ... | ... | |
| 147 | 194 |
} |
| 148 | 195 |
} |
| 149 | 196 |
|
| 150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 151 |
|
|
| 152 |
private void addPage(int tab, final RubikDialogScoresView view, final String[][] country, final String[][] name, final float[][] time) |
|
| 153 |
{
|
|
| 154 |
int object = RubikObjectList.unpackObject(tab); |
|
| 155 |
int sizeIndex= RubikObjectList.unpackSizeIndex(tab); |
|
| 156 |
int maxLevel = RubikObjectList.getMaxLevel(object, sizeIndex); |
|
| 157 |
|
|
| 158 |
for(int i=0; i<maxLevel; i++) |
|
| 159 |
{
|
|
| 160 |
final LinearLayout section = view.createSection(mAct, tab, i, country[i], name[i], time[i]); |
|
| 161 |
|
|
| 162 |
mAct.runOnUiThread(new Runnable() |
|
| 163 |
{
|
|
| 164 |
@Override |
|
| 165 |
public void run() |
|
| 166 |
{
|
|
| 167 |
view.addSection(section); |
|
| 168 |
} |
|
| 169 |
}); |
|
| 170 |
|
|
| 171 |
try |
|
| 172 |
{
|
|
| 173 |
Thread.sleep(50); |
|
| 174 |
} |
|
| 175 |
catch( InterruptedException ignored) |
|
| 176 |
{
|
|
| 177 |
|
|
| 178 |
} |
|
| 179 |
} |
|
| 180 |
} |
|
| 181 |
|
|
| 182 | 197 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 183 | 198 |
|
| 184 | 199 |
RubikDialogScoresPagerAdapter(FragmentActivity act, ViewPager viewPager, boolean isSubmitting, RubikDialogScores diag) |
Also available in: Unified diff
Improve the Scores dialog: now level sections are added one-by-one.