Revision 7480fbab
Added by Leszek Koltunski about 2 years ago
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
253 | 253 |
DistortedLibrary.onResume(ACTIVITY_NUMBER); |
254 | 254 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
255 | 255 |
view.onResume(); |
256 |
restorePreferences(); |
|
256 |
restorePreferences(mJustStarted);
|
|
257 | 257 |
|
258 | 258 |
ScreenList.setScreen(this); |
259 | 259 |
unblockEverything(); |
... | ... | |
339 | 339 |
solv.saveMovePreferences(KEY_SOLV,editor); |
340 | 340 |
} |
341 | 341 |
|
342 |
editor.apply(); |
|
342 |
boolean success = editor.commit(); |
|
343 |
if( !success ) android.util.Log.e("D", "Failed to save preferences"); |
|
343 | 344 |
} |
344 | 345 |
|
345 | 346 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
346 | 347 |
|
347 |
private void restorePreferences() |
|
348 |
private void restorePreferences(boolean justStarted)
|
|
348 | 349 |
{ |
349 | 350 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
350 | 351 |
|
351 | 352 |
mPolicyAccepted = preferences.getBoolean("policyAccepted", false); |
352 | 353 |
String oldVersion = preferences.getString("appVersion",""); |
353 | 354 |
|
354 |
RubikObjectList.restorePreferences(this,preferences); |
|
355 |
RubikObjectList.restorePreferences(this,preferences,justStarted);
|
|
355 | 356 |
|
356 | 357 |
for (int i=0; i<BaseEffect.Type.LENGTH; i++) |
357 | 358 |
{ |
src/main/java/org/distorted/objects/RubikObjectList.java | ||
---|---|---|
222 | 222 |
} |
223 | 223 |
} |
224 | 224 |
|
225 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
226 |
|
|
227 |
public static boolean allAlreadyBought() |
|
228 |
{ |
|
229 |
return mFreeBoughtObjects.equals("*"); |
|
230 |
} |
|
231 |
|
|
232 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
233 |
|
|
234 |
public static boolean objectAlreadyBought(String shortName) |
|
235 |
{ |
|
236 |
RubikObject o = getObject(shortName); |
|
237 |
return ( o!=null && o.isFree() ); |
|
238 |
} |
|
239 |
|
|
225 | 240 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
226 | 241 |
|
227 | 242 |
public static void buyAll() |
... | ... | |
244 | 259 |
if( o!=null && !o.isFree() ) |
245 | 260 |
{ |
246 | 261 |
o.markFree(); |
247 |
mFreeBoughtObjects += (","+shortName); |
|
262 |
String add = mFreeBoughtObjects.length()==0 ? shortName : (","+shortName); |
|
263 |
mFreeBoughtObjects += add; |
|
248 | 264 |
return true; |
249 | 265 |
} |
250 | 266 |
|
... | ... | |
260 | 276 |
if( o!=null && !o.isFree() ) |
261 | 277 |
{ |
262 | 278 |
o.markFree(); |
263 |
mFreeSolvedObjects += (","+shortName); |
|
279 |
String add = mFreeSolvedObjects.length()==0 ? shortName : (","+shortName); |
|
280 |
mFreeSolvedObjects += add; |
|
264 | 281 |
return true; |
265 | 282 |
} |
266 | 283 |
|
... | ... | |
317 | 334 |
|
318 | 335 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
319 | 336 |
|
320 |
public static void restorePreferences(Context context, SharedPreferences preferences) |
|
337 |
public static void restorePreferences(Context context, SharedPreferences preferences, boolean justStarted)
|
|
321 | 338 |
{ |
322 | 339 |
if( mThis==null ) mThis = new RubikObjectList(); |
323 | 340 |
|
... | ... | |
364 | 381 |
mObject = getOrdinal(objName); |
365 | 382 |
if( mObject<0 || mObject>=mNumObjects ) mObject = DEF_OBJECT; |
366 | 383 |
|
367 |
mFreeSolvedObjects = preferences.getString("rol_freeSolved", ""); |
|
368 |
mFreeBoughtObjects = preferences.getString("rol_freeBought", ""); |
|
369 |
|
|
370 |
if( mFreeBoughtObjects.length()>0 ) |
|
384 |
if( justStarted ) |
|
371 | 385 |
{ |
372 |
if( mFreeBoughtObjects.charAt(0)=='*' ) |
|
386 |
mFreeSolvedObjects = preferences.getString("rol_freeSolved", ""); |
|
387 |
mFreeBoughtObjects = preferences.getString("rol_freeBought", ""); |
|
388 |
|
|
389 |
if( mFreeBoughtObjects.length()>0 ) |
|
373 | 390 |
{ |
374 |
for(int i=0; i<mNumObjects; i++) |
|
391 |
if( mFreeBoughtObjects.charAt(0)=='*' ) |
|
392 |
{ |
|
393 |
for(int i=0; i<mNumObjects; i++) |
|
394 |
{ |
|
395 |
RubikObject o = mObjects.get(i); |
|
396 |
o.markFree(); |
|
397 |
} |
|
398 |
} |
|
399 |
else |
|
375 | 400 |
{ |
376 |
RubikObject o = mObjects.get(i); |
|
377 |
o.markFree(); |
|
401 |
String[] objs = mFreeBoughtObjects.split(","); |
|
402 |
|
|
403 |
for( String obj : objs ) |
|
404 |
{ |
|
405 |
RubikObject o = getObject(obj); |
|
406 |
if( o!=null ) o.markFree(); |
|
407 |
} |
|
378 | 408 |
} |
379 | 409 |
} |
380 |
else |
|
410 |
|
|
411 |
if( mFreeSolvedObjects.length()>0 ) |
|
381 | 412 |
{ |
382 |
String[] objs = mFreeBoughtObjects.split(",");
|
|
413 |
String[] objs = mFreeSolvedObjects.split(",");
|
|
383 | 414 |
|
384 | 415 |
for( String obj : objs ) |
385 | 416 |
{ |
... | ... | |
388 | 419 |
} |
389 | 420 |
} |
390 | 421 |
} |
391 |
|
|
392 |
if( mFreeSolvedObjects.length()>0 ) |
|
393 |
{ |
|
394 |
String[] objs = mFreeSolvedObjects.split(","); |
|
395 |
|
|
396 |
for( String obj : objs ) |
|
397 |
{ |
|
398 |
RubikObject o = getObject(obj); |
|
399 |
if( o!=null ) o.markFree(); |
|
400 |
} |
|
401 |
} |
|
402 | 422 |
} |
403 | 423 |
|
404 | 424 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/purchase/PurchaseScreenPane.java | ||
---|---|---|
10 | 10 |
package org.distorted.purchase; |
11 | 11 |
|
12 | 12 |
import android.util.TypedValue; |
13 |
import android.view.View; |
|
14 |
import android.widget.Button; |
|
13 | 15 |
import android.widget.ImageView; |
14 | 16 |
import android.widget.LinearLayout; |
15 | 17 |
import android.widget.TextView; |
... | ... | |
38 | 40 |
public static final float PADDING_RATIO = 0.025f; |
39 | 41 |
private static final float TEXT_RATIO = 0.050f; |
40 | 42 |
|
43 |
private RubikObject mObject; |
|
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
// TODO |
|
47 |
|
|
48 |
private boolean buyOne(String shortName) |
|
49 |
{ |
|
50 |
return true; |
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
// TODO |
|
55 |
|
|
56 |
private boolean buyAll() |
|
57 |
{ |
|
58 |
return true; |
|
59 |
} |
|
60 |
|
|
61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
62 |
|
|
63 |
private void oneButtonClicked() |
|
64 |
{ |
|
65 |
if( mObject!=null ) |
|
66 |
{ |
|
67 |
String shortName = mObject.getUpperName(); |
|
68 |
|
|
69 |
if( !RubikObjectList.objectAlreadyBought(shortName) && buyOne(shortName) ) |
|
70 |
{ |
|
71 |
android.util.Log.e("D", "buying "+shortName); |
|
72 |
|
|
73 |
RubikObjectList.buyObject(shortName); |
|
74 |
} |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
|
80 |
private void allButtonClicked() |
|
81 |
{ |
|
82 |
if( !RubikObjectList.allAlreadyBought() && buyAll() ) |
|
83 |
{ |
|
84 |
RubikObjectList.buyAll(); |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 |
|
|
90 |
private void setUpButtons(LinearLayout one, LinearLayout all) |
|
91 |
{ |
|
92 |
Button butO = one.findViewById(R.id.purchaseButtonOne); |
|
93 |
Button butA = all.findViewById(R.id.purchaseButtonAll); |
|
94 |
|
|
95 |
butO.setOnClickListener( new View.OnClickListener() |
|
96 |
{ |
|
97 |
@Override |
|
98 |
public void onClick(View v) |
|
99 |
{ |
|
100 |
oneButtonClicked(); |
|
101 |
} |
|
102 |
}); |
|
103 |
|
|
104 |
butA.setOnClickListener( new View.OnClickListener() |
|
105 |
{ |
|
106 |
@Override |
|
107 |
public void onClick(View v) |
|
108 |
{ |
|
109 |
allButtonClicked(); |
|
110 |
} |
|
111 |
}); |
|
112 |
} |
|
113 |
|
|
41 | 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
42 | 115 |
|
43 | 116 |
void updatePane(PurchaseActivity act, int objectOrdinal) |
44 | 117 |
{ |
45 |
RubikObject object = RubikObjectList.getObject(objectOrdinal);
|
|
118 |
mObject = RubikObjectList.getObject(objectOrdinal);
|
|
46 | 119 |
|
47 |
if( object!=null )
|
|
120 |
if( mObject!=null )
|
|
48 | 121 |
{ |
49 |
InputStream stream = object.getObjectStream(act);
|
|
122 |
InputStream stream = mObject.getObjectStream(act);
|
|
50 | 123 |
JsonReader reader = JsonReader.getInstance(); |
51 | 124 |
String author, name; |
52 | 125 |
int year, difficulty; |
... | ... | |
128 | 201 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
129 | 202 |
text = allLayout.findViewById(R.id.purchaseTextAll); |
130 | 203 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
204 |
|
|
205 |
setUpButtons(oneLayout,allLayout); |
|
131 | 206 |
} |
132 | 207 |
} |
Also available in: Unified diff
Progress with marking objects as free.