Project

General

Profile

« Previous | Next » 

Revision 044529c1

Added by Leszek Koltunski over 4 years ago

Remember state of the dialog.

View differences:

src/main/java/org/distorted/dialog/RubikDialogPattern.java
129 129
      }
130 130
    }
131 131

  
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

  
134
  public void rememberCategories()
135
    {
136
    mPagerAdapter.rememberCategories();
137
    }
138

  
132 139
///////////////////////////////////////////////////////////////////////////////////////////////////
133 140

  
134 141
  public static String getDialogTag()
src/main/java/org/distorted/dialog/RubikDialogPatternPagerAdapter.java
50 50
    viewPager.setOffscreenPageLimit(mNumTabs-1);
51 51
    }
52 52

  
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

  
55
  void rememberCategories()
56
    {
57
    RubikPattern pattern = RubikPattern.getInstance();
58

  
59
    for(int i=0; i<mNumTabs; i++)
60
      {
61
      int cat = mViews[i].getCurrentCategory();
62
      pattern.rememberCategory(i,cat);
63
      }
64
    }
65

  
53 66
///////////////////////////////////////////////////////////////////////////////////////////////////
54 67

  
55 68
  @Override
src/main/java/org/distorted/dialog/RubikDialogPatternView.java
33 33

  
34 34
import org.distorted.magic.R;
35 35
import org.distorted.magic.RubikActivity;
36
import org.distorted.object.RubikObjectList;
36 37
import org.distorted.patterns.RubikPattern;
37 38
import org.distorted.uistate.RubikState;
38 39
import org.distorted.uistate.RubikStatePattern;
......
43 44
  {
44 45
  private LinearLayout mLayout;
45 46
  private RubikDialogPattern mDialog;
46
  private int mPosition;
47
  private int mTab, mPos;
47 48

  
48 49
///////////////////////////////////////////////////////////////////////////////////////////////////
49 50

  
......
66 67
    super(act);
67 68

  
68 69
    mDialog = dialog;
69
    mPosition = position;
70
    mTab = position;
70 71
    View tab = inflate( act, R.layout.dialog_pattern_tab, null);
71 72
    mLayout = tab.findViewById(R.id.tabLayout);
72 73

  
......
79 80
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
80 81
    spinner.setAdapter(adapter);
81 82

  
82
    spinner.setSelection(0);
83
    RubikPattern pattern = RubikPattern.getInstance();
84
    spinner.setSelection(pattern.recallCategory(mTab));
83 85

  
84 86
    addView(tab);
85 87
    }
......
89 91
  private String[] createCategories()
90 92
    {
91 93
    RubikPattern pattern = RubikPattern.getInstance();
92
    int numCat = pattern.getNumCategories(mPosition);
94
    int numCat = pattern.getNumCategories(mTab);
93 95

  
94 96
    String[] ret = new String[numCat];
95 97

  
96 98
    for(int i=0; i<numCat; i++)
97 99
      {
98
      ret[i] = pattern.getCategoryName(mPosition,i);
100
      ret[i] = pattern.getCategoryName(mTab,i);
99 101
      }
100 102

  
101 103
    return ret;
......
106 108
  private String[] createPatterns(int category)
107 109
    {
108 110
    RubikPattern pattern = RubikPattern.getInstance();
109
    int numPat = pattern.getNumPatterns(mPosition, category);
111
    int numPat = pattern.getNumPatterns(mTab, category);
110 112

  
111 113
    String[] ret = new String[numPat];
112 114

  
113 115
    for(int i=0; i<numPat; i++)
114 116
      {
115
      ret[i] = pattern.getPatternName(mPosition, category, i);
117
      ret[i] = pattern.getPatternName(mTab, category, i);
116 118
      }
117 119

  
118 120
    return ret;
......
148 150
        public void onClick(View view)
149 151
          {
150 152
          RubikStatePattern state = (RubikStatePattern) RubikState.PATT.getStateClass();
151
          state.setPattern(mPosition, category, ii);
153
          state.setPattern(mTab, category, ii);
154
          int[] sizes = RubikObjectList.CUBE.getSizes();
155
          act.changeObject(RubikObjectList.CUBE,sizes[mTab]);
156
          mDialog.rememberCategories();
152 157
          mDialog.dismiss();
153 158
          }
154 159
        });
......
157 162
      }
158 163
    }
159 164

  
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

  
167
  int getCurrentCategory()
168
    {
169
    return mPos;
170
    }
171

  
160 172
///////////////////////////////////////////////////////////////////////////////////////////////////
161 173

  
162 174
  @Override
......
164 176
    {
165 177
    if( parent.getId() == R.id.pattern_category_spinner )
166 178
      {
179
      mPos = pos;
167 180
      fillPatterns(pos);
168 181
      }
169 182
    }
src/main/java/org/distorted/patterns/RubikPattern.java
29 29
  public static final int MAX_CUBE  = 5;
30 30
  public static final int NUM_CUBES = MAX_CUBE-MIN_CUBE+1;
31 31

  
32
  private int[] numCategories = new int[NUM_CUBES];
32
  private int[] numCategories   = new int[NUM_CUBES];
33
  private int[] currentCategory = new int[NUM_CUBES];
33 34
  private Vector<Category>[] mCategories;
34 35
  private static RubikPattern mThis;
35 36

  
......
310 311
    return null;
311 312
    }
312 313

  
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315

  
316
  public void rememberCategory(int size,int num)
317
    {
318
    if( size>=0 && size<NUM_CUBES )
319
      {
320
      currentCategory[size] = num;
321
      }
322
    }
323

  
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

  
326
  public int recallCategory(int size)
327
    {
328
    return size>=0 && size<NUM_CUBES ? currentCategory[size] : 0;
329
    }
330

  
313 331
///////////////////////////////////////////////////////////////////////////////////////////////////
314 332

  
315 333
  public String getPatternName(int size, int cat, int pat)
src/main/java/org/distorted/uistate/RubikStatePattern.java
153 153
          }
154 154
        else
155 155
          {
156
          diag.rememberCategories();
156 157
          diag.dismiss();
157 158
          RubikState.goBack(act);
158 159
          }
......
164 165

  
165 166
  public void setPattern(int sizeIndex, int category, int pattern)
166 167
    {
168
    mSize = RubikObjectList.CUBE.getSizes()[sizeIndex];
169

  
167 170
    RubikPattern patt = RubikPattern.getInstance();
168 171
    String patternName = patt.getPatternName(sizeIndex,category,pattern);
169 172
    mText.setText(patternName);

Also available in: Unified diff