Revision 00af5060
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java | ||
---|---|---|
30 | 30 |
import android.view.ViewGroup; |
31 | 31 |
import android.widget.LinearLayout; |
32 | 32 |
|
33 |
import org.distorted.main.R; |
|
33 | 34 |
import org.distorted.scores.RubikScores; |
34 | 35 |
import org.distorted.scores.RubikScoresDownloader; |
35 | 36 |
import org.distorted.objects.ObjectList; |
37 |
import org.distorted.states.RubikStatePlay; |
|
36 | 38 |
|
37 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 40 |
|
39 | 41 |
class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresDownloader.Receiver |
40 | 42 |
{ |
41 |
private FragmentActivity mAct; |
|
42 |
private RubikDialogScores mDialog; |
|
43 |
private RubikDialogScoresView[] mViews; |
|
44 |
private ViewPager mViewPager; |
|
45 |
private int mNumTabs; |
|
46 |
private boolean mIsSubmitting; |
|
43 |
private final FragmentActivity mAct;
|
|
44 |
private final RubikDialogScores mDialog;
|
|
45 |
private final RubikDialogScoresView[] mViews;
|
|
46 |
private final ViewPager mViewPager;
|
|
47 |
private final int mNumTabs;
|
|
48 |
private final boolean mIsSubmitting;
|
|
47 | 49 |
private int mToDoTab, mToDoLvl; |
48 | 50 |
|
49 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
50 | 52 |
|
51 |
private void addSection(int tab, int level, final RubikDialogScoresView view, final String[] country, final String[] name, final float[] time) |
|
53 |
private void addSection(int tab, int level, int lastLevel, final RubikDialogScoresView view, final String[] country, final String[] name, final float[] time)
|
|
52 | 54 |
{ |
53 |
final LinearLayout section = view.createSection(mAct, tab, level, country, name, time); |
|
55 |
String title = level==lastLevel-1 ? |
|
56 |
mAct.getString(R.string.level_full) : |
|
57 |
mAct.getString(R.string.lv_placeholder,level+1); |
|
58 |
|
|
59 |
final LinearLayout section = view.createSection(mAct, tab, title, level, country, name, time); |
|
54 | 60 |
|
55 | 61 |
mAct.runOnUiThread(new Runnable() |
56 | 62 |
{ |
... | ... | |
73 | 79 |
|
74 | 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
75 | 81 |
|
76 |
private void getNext(int currentTab, int[] toDoTab, int[] maxTab) |
|
82 |
private void getNext(int currentTab, int[] toDoTab, int[] maxTab, int[] lastTab)
|
|
77 | 83 |
{ |
78 | 84 |
if( toDoTab[currentTab]<maxTab[currentTab] ) |
79 | 85 |
{ |
80 | 86 |
mToDoTab = currentTab; |
81 |
mToDoLvl = toDoTab[currentTab]; |
|
87 |
mToDoLvl = toDoTab[currentTab]<maxTab[currentTab]-1 ? toDoTab[currentTab] : lastTab[currentTab]-1;
|
|
82 | 88 |
toDoTab[currentTab]++; |
83 | 89 |
} |
84 | 90 |
else |
... | ... | |
88 | 94 |
if( toDoTab[tab]<maxTab[tab] ) |
89 | 95 |
{ |
90 | 96 |
mToDoTab = tab; |
91 |
mToDoLvl = toDoTab[tab]; |
|
97 |
mToDoLvl = toDoTab[tab]<maxTab[tab]-1 ? toDoTab[tab] : lastTab[tab]-1;
|
|
92 | 98 |
toDoTab[tab]++; |
93 | 99 |
break; |
94 | 100 |
} |
... | ... | |
102 | 108 |
{ |
103 | 109 |
prepareView(); |
104 | 110 |
|
111 |
int MAX = RubikStatePlay.LEVELS_SHOWN; |
|
105 | 112 |
int toDo=0; |
106 | 113 |
int[] toDoTab = new int[mNumTabs]; |
107 | 114 |
int[] maxTab = new int[mNumTabs]; |
115 |
int[] lastTab = new int[mNumTabs]; |
|
108 | 116 |
|
109 | 117 |
for(int i=0; i<mNumTabs; i++) |
110 | 118 |
{ |
111 | 119 |
int object = ObjectList.unpackObject(i); |
112 | 120 |
int sizeIndex= ObjectList.unpackSizeIndex(i); |
113 |
maxTab[i] = ObjectList.getMaxLevel(object, sizeIndex); |
|
121 |
lastTab[i] = ObjectList.getMaxLevel(object, sizeIndex); |
|
122 |
maxTab[i] = Math.min(lastTab[i],MAX); |
|
114 | 123 |
toDoTab[i] = 0; |
115 | 124 |
|
116 | 125 |
toDo += maxTab[i]; |
... | ... | |
119 | 128 |
while( toDo>0 ) |
120 | 129 |
{ |
121 | 130 |
toDo--; |
122 |
getNext(mViewPager.getCurrentItem(),toDoTab,maxTab); |
|
123 |
addSection( mToDoTab,mToDoLvl, mViews[mToDoTab], |
|
131 |
getNext(mViewPager.getCurrentItem(),toDoTab,maxTab,lastTab);
|
|
132 |
addSection( mToDoTab,mToDoLvl, lastTab[mToDoTab], mViews[mToDoTab],
|
|
124 | 133 |
country[mToDoTab][mToDoLvl],name[mToDoTab][mToDoLvl],time[mToDoTab][mToDoLvl]); |
125 | 134 |
} |
126 | 135 |
} |
Also available in: Unified diff
Always use only (max) 10 levels - (max) 9 'initial' Levels + Full Scramble.