Revision e9e744f7
Added by Leszek Koltunski almost 2 years ago
src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java | ||
---|---|---|
194 | 194 |
try |
195 | 195 |
{ |
196 | 196 |
JsonReader reader = JsonReader.getInstance(); |
197 |
reader.readNumScramblesAndIsFree(act,objectName);
|
|
197 |
reader.readNumScramblesAndPrice(act,objectName);
|
|
198 | 198 |
mInfo.mNumScrambles = reader.getNumScrambles(); |
199 |
mInfo.mIsFree = reader.isFree();
|
|
200 |
if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "Read from JSON numScrambles="+mInfo.mNumScrambles+" isFree="+mInfo.mIsFree);
|
|
199 |
mInfo.mPrice = reader.getPrice();
|
|
200 |
if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "Read from JSON numScrambles="+mInfo.mNumScrambles+" price="+mInfo.mPrice);
|
|
201 | 201 |
|
202 | 202 |
if( mInfo.mExtrasStream!=null ) |
203 | 203 |
{ |
... | ... | |
213 | 213 |
|
214 | 214 |
if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "1"); |
215 | 215 |
|
216 |
boolean success = RubikObjectList.addDownloadedObject(act, mInfo.mObjectShortName, mInfo.mNumScrambles, mInfo.mIsFree,
|
|
216 |
boolean success = RubikObjectList.addDownloadedObject(act, mInfo.mObjectShortName, mInfo.mNumScrambles, mInfo.mPrice,
|
|
217 | 217 |
mInfo.mObjectMinorVersion, mInfo.mExtrasMinorVersion, mIconSaved, oSuccess, eSuccess); |
218 | 218 |
if( success ) |
219 | 219 |
{ |
src/main/java/org/distorted/external/RubikScores.java | ||
---|---|---|
241 | 241 |
public void changeNumStars(int stars) |
242 | 242 |
{ |
243 | 243 |
mNumStars += stars; |
244 |
if( mNumStars<0 ) mNumStars = 0; |
|
244 | 245 |
} |
245 | 246 |
|
246 | 247 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/external/RubikUpdates.java | ||
---|---|---|
36 | 36 |
public final boolean mUpdateExtras; |
37 | 37 |
|
38 | 38 |
public int mNumScrambles; |
39 |
public boolean mIsFree;
|
|
39 |
public int mPrice;
|
|
40 | 40 |
public Bitmap mIcon; |
41 | 41 |
public InputStream mObjectStream; |
42 | 42 |
public InputStream mExtrasStream; |
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
63 | 63 |
{ |
64 | 64 |
public static final boolean SHOW_DOWNLOADED_DEBUG = false; |
65 | 65 |
public static final boolean SHOW_SOLVED_DEBUG = true; |
66 |
public static final boolean USE_IAP = false; |
|
66 | 67 |
|
67 | 68 |
public static final float PADDING = 0.01f; |
68 | 69 |
public static final float SMALL_MARGIN = 0.004f; |
... | ... | |
106 | 107 |
private boolean mPolicyAccepted, mIsChinese; |
107 | 108 |
private int mCurrentApiVersion; |
108 | 109 |
private int mHeightUpperBar, mHeightLowerBar; |
110 |
private int mOldVersion1, mOldVersion2, mOldVersion3; |
|
111 |
private String mCurrVersion; |
|
109 | 112 |
|
110 | 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
111 | 114 |
|
... | ... | |
131 | 134 |
cutoutHack(); |
132 | 135 |
computeBarHeights(); |
133 | 136 |
|
137 |
mCurrVersion = getAppVers(); |
|
138 |
|
|
134 | 139 |
Thread thread = new Thread() |
135 | 140 |
{ |
136 | 141 |
public void run() |
... | ... | |
309 | 314 |
SharedPreferences.Editor editor = preferences.edit(); |
310 | 315 |
|
311 | 316 |
editor.putBoolean("policyAccepted", mPolicyAccepted); |
312 |
editor.putString("appVersion", getAppVers() );
|
|
317 |
editor.putString("appVersion", mCurrVersion );
|
|
313 | 318 |
|
314 | 319 |
for (int i=0; i<BaseEffect.Type.LENGTH; i++) |
315 | 320 |
{ |
... | ... | |
350 | 355 |
{ |
351 | 356 |
mPolicyAccepted = preferences.getBoolean("policyAccepted", false); |
352 | 357 |
String oldVersion = preferences.getString("appVersion",""); |
358 |
parseVersion(oldVersion); |
|
353 | 359 |
|
354 | 360 |
RubikObjectList.restorePreferences(this,preferences,justStarted); |
355 | 361 |
|
... | ... | |
363 | 369 |
ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences); |
364 | 370 |
} |
365 | 371 |
|
366 |
// this needs to be after the above ScreenList.restore as that restores the Records which we need here |
|
367 |
if( justStarted ) RubikObjectList.setObjectFreeState(); |
|
372 |
RubikScores scores = RubikScores.getInstance(); |
|
373 |
|
|
374 |
if( scores.isVerified() ) |
|
375 |
{ |
|
376 |
FirebaseAnalytics analytics = getAnalytics(); |
|
377 |
analytics.setUserId(scores.getName()); |
|
378 |
} |
|
379 |
|
|
380 |
// all old users upgrading from version <1.11.4, where there was no concept of 'stars', |
|
381 |
// get all the stars they have earned |
|
382 |
int numStars = scores.getNumStars(); |
|
383 |
|
|
384 |
if( justStarted && numStars==0 && oldVersionLessThan(1,11,4) ) |
|
385 |
{ |
|
386 |
scores.correctNumStars(); |
|
387 |
} |
|
388 |
|
|
389 |
// in 1.11.5 we have introduced IAP. When upgrading from something less than 1.11.5 to |
|
390 |
// something at least 1.11.5, mark all solved objects as free. |
|
391 |
// this needs to be after the above ScreenList.getScreen(i).getScreenClass().restorePreferences() |
|
392 |
// as that restores the Records which we need here |
|
393 |
// also needs to be after RubikObjectList.restorePreferences() |
|
394 |
if( USE_IAP && justStarted && oldVersionLessThan(1,11,5) && !mCurrVersion.equals("1.11.4") ) |
|
395 |
{ |
|
396 |
RubikObjectList.firstUpgradeMarkAllSolvedAsFree(); |
|
397 |
} |
|
368 | 398 |
|
369 | 399 |
ScreenList.restorePreferences(preferences); |
370 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
371 | 400 |
|
372 | 401 |
// Versions <= 1.8.6 did not save their 'appVersion' to preferences, therefore in their |
373 | 402 |
// case the 'mOldVersion' - version of the app which saved the preferences on the last |
... | ... | |
380 | 409 |
|
381 | 410 |
if( !oldVersion.equals("") ) |
382 | 411 |
{ |
412 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
383 | 413 |
view.getObjectControl().restorePreferences(preferences); |
384 | 414 |
} |
415 |
} |
|
385 | 416 |
|
386 |
RubikScores scores = RubikScores.getInstance();
|
|
417 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
387 | 418 |
|
388 |
if( scores.isVerified() ) |
|
389 |
{ |
|
390 |
FirebaseAnalytics analytics = getAnalytics(); |
|
391 |
analytics.setUserId(scores.getName()); |
|
392 |
} |
|
419 |
private void parseVersion(String version) |
|
420 |
{ |
|
421 |
if( version==null ) return; |
|
393 | 422 |
|
394 |
// all old users upgrading from version <1.11.4, where there was no concept of 'stars',
|
|
395 |
// get all the stars they have earned
|
|
396 |
int numStars = scores.getNumStars();
|
|
423 |
try
|
|
424 |
{
|
|
425 |
String[] parts = version.split("\\.");
|
|
397 | 426 |
|
398 |
if( numStars==0 && upgradingFromVersionWithNoStars(oldVersion) ) |
|
427 |
if( parts.length==3 ) |
|
428 |
{ |
|
429 |
mOldVersion1 = Integer.parseInt(parts[0]); |
|
430 |
mOldVersion2 = Integer.parseInt(parts[1]); |
|
431 |
mOldVersion3 = Integer.parseInt(parts[2]); |
|
432 |
} |
|
433 |
} |
|
434 |
catch(Exception ignored) |
|
399 | 435 |
{ |
400 |
scores.correctNumStars(); |
|
436 |
mOldVersion1 = 0; |
|
437 |
mOldVersion2 = 0; |
|
438 |
mOldVersion3 = 0; |
|
401 | 439 |
} |
402 | 440 |
} |
403 | 441 |
|
404 | 442 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
405 | 443 |
|
406 |
private boolean upgradingFromVersionWithNoStars(String version)
|
|
444 |
private boolean oldVersionLessThan(int v1, int v2, int v3)
|
|
407 | 445 |
{ |
408 |
if( version!=null ) |
|
409 |
{ |
|
410 |
try |
|
411 |
{ |
|
412 |
int dot = version.indexOf('.',2); |
|
413 |
|
|
414 |
if( dot>2 ) |
|
415 |
{ |
|
416 |
String middle = version.substring(2,dot); |
|
417 |
int middleInt = Integer.parseInt(middle); |
|
418 |
|
|
419 |
if( middleInt<11 ) return true; |
|
420 |
if( middleInt==11 ) |
|
421 |
{ |
|
422 |
String end = version.substring(dot+1); |
|
423 |
int endInt = Integer.parseInt(end); |
|
424 |
return endInt<4; |
|
425 |
} |
|
426 |
} |
|
427 |
} |
|
428 |
catch(Exception ignored) {} |
|
429 |
} |
|
430 |
|
|
431 |
return false; |
|
446 |
if( mOldVersion1<v1 ) return true; |
|
447 |
if( mOldVersion1>v1 ) return false; |
|
448 |
if( mOldVersion2<v2 ) return true; |
|
449 |
if( mOldVersion2>v2 ) return false; |
|
450 |
return mOldVersion3<v3; |
|
432 | 451 |
} |
433 | 452 |
|
434 | 453 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/main/RubikObjectLibInterface.java | ||
---|---|---|
450 | 450 |
|
451 | 451 |
switch(mIsNewRecord) |
452 | 452 |
{ |
453 |
case RECORD_FIRST : RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
454 |
int level = play.getLevel(); |
|
455 |
RubikScores scores = RubikScores.getInstance(); |
|
456 |
int newStars = scores.computeNumStars(level); |
|
457 |
int totStars = scores.getNumStars(); |
|
458 |
scores.changeNumStars(newStars); |
|
459 |
DistortedScreen screen = act.getScreen(); |
|
460 |
OverlayStars stars = new OverlayStars(); |
|
461 |
DataStars data = new DataStars(totStars,newStars,act.getResources()); |
|
462 |
stars.startOverlay(screen,this,data); |
|
453 |
case RECORD_FIRST : if( RubikActivity.USE_IAP ) |
|
454 |
{ |
|
455 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
456 |
int level = play.getLevel(); |
|
457 |
RubikScores scores = RubikScores.getInstance(); |
|
458 |
int newStars = scores.computeNumStars(level); |
|
459 |
int totStars = scores.getNumStars(); |
|
460 |
scores.changeNumStars(newStars); |
|
461 |
DistortedScreen screen = act.getScreen(); |
|
462 |
OverlayStars stars = new OverlayStars(); |
|
463 |
DataStars data = new DataStars(totStars,newStars,act.getResources()); |
|
464 |
stars.startOverlay(screen,this,data); |
|
465 |
} |
|
466 |
else |
|
467 |
{ |
|
468 |
RubikDialogNewRecord d2 = new RubikDialogNewRecord(); |
|
469 |
d2.setArguments(bundle); |
|
470 |
d2.show( act.getSupportFragmentManager(), RubikDialogNewRecord.getDialogTag() ); |
|
471 |
} |
|
463 | 472 |
break; |
464 | 473 |
case RECORD_NEW : RubikDialogNewRecord d2 = new RubikDialogNewRecord(); |
465 | 474 |
d2.setArguments(bundle); |
src/main/java/org/distorted/objects/RubikObject.java | ||
---|---|---|
24 | 24 |
import org.distorted.external.RubikFiles; |
25 | 25 |
import org.distorted.jsons.ObjectJson; |
26 | 26 |
import org.distorted.main.R; |
27 |
import org.distorted.main.RubikActivity; |
|
27 | 28 |
import org.distorted.objectlib.json.JsonWriter; |
28 | 29 |
import org.distorted.objectlib.main.ObjectType; |
29 | 30 |
import org.distorted.patterns.RubikPatternList; |
... | ... | |
42 | 43 |
private final String[][] mPatterns; |
43 | 44 |
|
44 | 45 |
private boolean mIsFree; |
46 |
private int mPrice; |
|
45 | 47 |
private int mJsonID, mMeshID, mExtrasID; |
46 | 48 |
private int mObjectMinor, mExtrasMinor; |
47 | 49 |
private int mNumScramble; |
... | ... | |
58 | 60 |
mUpperName = type.name(); |
59 | 61 |
mLowerName = type.name().toLowerCase(Locale.ENGLISH); |
60 | 62 |
mNumScramble = type.getNumScramble(); |
61 |
mIsFree = type.isFree(); |
|
63 |
mPrice = type.getPrice(); |
|
64 |
mIsFree = mPrice==0; |
|
62 | 65 |
|
63 | 66 |
mIconID = type.getIconID(); |
64 | 67 |
mJsonID = ObjectJson.getObjectJsonID(ordinal); |
... | ... | |
87 | 90 |
mLowerName = object.shortName; |
88 | 91 |
mUpperName = object.shortName.toUpperCase(Locale.ENGLISH); |
89 | 92 |
mNumScramble = object.numScrambles; |
90 |
mIsFree = object.free; |
|
93 |
mPrice = object.price; |
|
94 |
mIsFree = mPrice==0; |
|
91 | 95 |
mObjectMinor = object.objectMinor; |
92 | 96 |
mExtrasMinor = object.extrasMinor; |
93 | 97 |
|
... | ... | |
215 | 219 |
} |
216 | 220 |
|
217 | 221 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
218 |
// temporarily switch off IAP (charging for objects) - all objects are free! |
|
222 |
|
|
223 |
public int getPrice() |
|
224 |
{ |
|
225 |
return mPrice; |
|
226 |
} |
|
227 |
|
|
228 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
219 | 229 |
|
220 | 230 |
public boolean isFree() |
221 | 231 |
{ |
222 |
return mIsFree;
|
|
232 |
return (!RubikActivity.USE_IAP || mIsFree);
|
|
223 | 233 |
} |
224 | 234 |
|
225 | 235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
226 | 236 |
|
227 | 237 |
public void markFree() |
228 | 238 |
{ |
229 |
mIsFree = true;
|
|
239 |
mIsFree=true;
|
|
230 | 240 |
} |
231 | 241 |
|
232 | 242 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/RubikObjectList.java | ||
---|---|---|
21 | 21 |
import org.distorted.objectlib.main.ObjectSignatures; |
22 | 22 |
import org.distorted.objectlib.main.ObjectType; |
23 | 23 |
|
24 |
import static org.distorted.main.RubikActivity.SHOW_SOLVED_DEBUG; |
|
24 | 25 |
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE; |
25 | 26 |
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS; |
26 | 27 |
import static org.distorted.main.RubikActivity.SHOW_DOWNLOADED_DEBUG; |
... | ... | |
40 | 41 |
public static class DownloadedObject |
41 | 42 |
{ |
42 | 43 |
String shortName; |
43 |
boolean icon,object,extras,free;
|
|
44 |
int numScrambles, objectMinor, extrasMinor; |
|
44 |
boolean icon,object,extras; |
|
45 |
int numScrambles, objectMinor, extrasMinor, price;
|
|
45 | 46 |
|
46 |
DownloadedObject(String sName, int scrambles, boolean isFree, int oMinor, int eMinor, boolean i, boolean o, boolean e)
|
|
47 |
DownloadedObject(String sName, int scrambles, int pr, int oMinor, int eMinor, boolean i, boolean o, boolean e)
|
|
47 | 48 |
{ |
48 |
shortName = sName; |
|
49 |
|
|
49 |
shortName = sName; |
|
50 | 50 |
numScrambles= scrambles; |
51 |
free = isFree;
|
|
51 |
price = pr;
|
|
52 | 52 |
objectMinor = oMinor; |
53 | 53 |
extrasMinor = eMinor; |
54 | 54 |
|
... | ... | |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
private static ArrayList<DownloadedObject> mDownloadedObjects; |
62 |
/* |
|
63 |
private static String mFreeSolvedObjects; |
|
64 |
private static String mFreeBoughtObjects; |
|
65 |
private static int mNumFreeSolved; |
|
66 |
*/ |
|
62 |
|
|
63 |
private static String mBoughtObjects; |
|
64 |
|
|
67 | 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 66 |
|
69 | 67 |
private RubikObjectList() |
70 | 68 |
{ |
71 |
mNumObjects = 0; |
|
72 |
mNumExtras = 0; |
|
73 |
//mNumFreeSolved = 0; |
|
74 |
|
|
69 |
mNumObjects = 0; |
|
70 |
mNumExtras = 0; |
|
75 | 71 |
mObjects = new ArrayList<>(); |
76 | 72 |
mDownloadedObjects = new ArrayList<>(); |
77 | 73 |
|
... | ... | |
120 | 116 |
RubikObject obj = new RubikObject(object); |
121 | 117 |
mObjects.add(obj); |
122 | 118 |
mNumObjects++; |
123 |
/* |
|
124 |
int numUnclaimed = getNumUnclaimedSolves(); |
|
125 | 119 |
|
126 |
if( numUnclaimed>0 && !obj.isFree() ) |
|
127 |
{ |
|
128 |
String objname = obj.getUpperName(); |
|
129 |
if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "downloadedObject: "+objname+" making it solved. Unclaimed: "+numUnclaimed); |
|
130 |
solveObject(obj,objname); |
|
131 |
} |
|
132 |
*/ |
|
133 | 120 |
if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "creating downloaded object "+obj.getUpperName() ); |
134 | 121 |
|
135 | 122 |
if( obj.hasExtras() ) |
... | ... | |
151 | 138 |
|
152 | 139 |
private static void restoreFreedObjects(SharedPreferences preferences) |
153 | 140 |
{ |
154 |
/* |
|
155 |
mFreeSolvedObjects = preferences.getString("rol_freeSolved", ""); |
|
156 |
mFreeBoughtObjects = preferences.getString("rol_freeBought", ""); |
|
141 |
mBoughtObjects = preferences.getString("rol_bought", ""); |
|
157 | 142 |
|
158 | 143 |
if( SHOW_SOLVED_DEBUG ) |
159 | 144 |
{ |
160 |
android.util.Log.e("D", "freeSolved: "+mFreeSolvedObjects); |
|
161 |
android.util.Log.e("D", "freeBought: "+mFreeBoughtObjects); |
|
145 |
android.util.Log.e("D", "bought objects: "+mBoughtObjects); |
|
162 | 146 |
} |
163 | 147 |
|
164 |
if( mFreeBoughtObjects.length()>0 )
|
|
148 |
if( mBoughtObjects.length()>0 ) |
|
165 | 149 |
{ |
166 |
if( mFreeBoughtObjects.charAt(0)=='*' )
|
|
150 |
if( mBoughtObjects.charAt(0)=='*' ) |
|
167 | 151 |
{ |
168 | 152 |
for(int i=0; i<mNumObjects; i++) |
169 | 153 |
{ |
170 | 154 |
RubikObject o = mObjects.get(i); |
171 |
o.markFree(); |
|
155 |
if( o!=null ) o.markFree();
|
|
172 | 156 |
} |
173 | 157 |
} |
174 | 158 |
else |
175 | 159 |
{ |
176 |
String[] objs = mFreeBoughtObjects.split(",");
|
|
160 |
String[] objs = mBoughtObjects.split(","); |
|
177 | 161 |
|
178 | 162 |
for( String obj : objs ) |
179 | 163 |
{ |
... | ... | |
182 | 166 |
} |
183 | 167 |
} |
184 | 168 |
} |
185 |
|
|
186 |
if( mFreeSolvedObjects.length()>0 ) |
|
187 |
{ |
|
188 |
String[] objs = mFreeSolvedObjects.split(","); |
|
189 |
mNumFreeSolved = objs.length; |
|
190 |
|
|
191 |
for( String obj : objs ) |
|
192 |
{ |
|
193 |
RubikObject o = getObject(obj); |
|
194 |
if( o!=null ) o.markFree(); |
|
195 |
} |
|
196 |
} |
|
197 |
*/ |
|
198 |
} |
|
199 |
|
|
200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
201 |
|
|
202 |
private static int getNumUnclaimedSolves() |
|
203 |
{ |
|
204 |
/* |
|
205 |
RubikScores scores = RubikScores.getInstance(); |
|
206 |
int numMAXes = scores.numberOfSolvedMAXes(); |
|
207 |
return numMAXes-mNumFreeSolved; |
|
208 |
*/ |
|
209 |
|
|
210 |
return 0; |
|
211 |
} |
|
212 |
|
|
213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
214 |
|
|
215 |
private static int markAllSolvedAsFree() |
|
216 |
{ |
|
217 |
RubikScores scores = RubikScores.getInstance(); |
|
218 |
int numObjects = RubikObjectList.getNumObjects(); |
|
219 |
int ret = 0; |
|
220 |
|
|
221 |
for(int obj=0; obj<numObjects; obj++) |
|
222 |
{ |
|
223 |
RubikObject object = getObject(obj); |
|
224 |
|
|
225 |
if( object!=null && !object.isFree() && scores.isSolved(obj,LEVELS_SHOWN) ) |
|
226 |
{ |
|
227 |
solveObject(object.getUpperName()); |
|
228 |
ret++; |
|
229 |
} |
|
230 |
} |
|
231 |
|
|
232 |
return ret; |
|
233 |
} |
|
234 |
|
|
235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
236 |
|
|
237 |
private static void markAsFree(int numToBeMarked) |
|
238 |
{ |
|
239 |
int numObjects = RubikObjectList.getNumObjects(); |
|
240 |
|
|
241 |
for(int obj=0; obj<numObjects && numToBeMarked>0; obj++) |
|
242 |
{ |
|
243 |
RubikObject object = getObject(obj); |
|
244 |
|
|
245 |
if( object!=null && !object.isFree() ) |
|
246 |
{ |
|
247 |
solveObject(object.getUpperName()); |
|
248 |
numToBeMarked--; |
|
249 |
} |
|
250 |
} |
|
251 |
} |
|
252 |
|
|
253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
254 |
|
|
255 |
public static boolean solveObject(RubikObject object, String shortName) |
|
256 |
{ |
|
257 |
/* |
|
258 |
if( object!=null && !object.isFree() ) |
|
259 |
{ |
|
260 |
if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "object "+shortName+" marked as solved"); |
|
261 |
object.markFree(); |
|
262 |
String add = mFreeSolvedObjects.length()==0 ? shortName : (","+shortName); |
|
263 |
mFreeSolvedObjects += add; |
|
264 |
mNumFreeSolved++; |
|
265 |
return true; |
|
266 |
} |
|
267 |
*/ |
|
268 |
return false; |
|
269 | 169 |
} |
270 | 170 |
|
271 | 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
272 | 172 |
// PUBLIC API |
273 | 173 |
|
274 |
public static boolean addDownloadedObject(Context context, String shortName, int numScrambles, boolean isFree, int objectMinor,
|
|
174 |
public static boolean addDownloadedObject(Context context, String shortName, int numScrambles, int price, int objectMinor,
|
|
275 | 175 |
int extrasMinor, boolean icon, boolean object, boolean extras) |
276 | 176 |
{ |
277 | 177 |
if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "New downloaded object "+shortName+" icon="+icon+" object="+object+" extras="+extras); |
... | ... | |
309 | 209 |
if( !object ) objectMinor=-1; |
310 | 210 |
if( !extras ) extrasMinor=-1; |
311 | 211 |
|
312 |
DownloadedObject obj = new DownloadedObject(shortName,numScrambles,isFree,objectMinor,extrasMinor,icon,object,extras);
|
|
212 |
DownloadedObject obj = new DownloadedObject(shortName,numScrambles,price,objectMinor,extrasMinor,icon,object,extras);
|
|
313 | 213 |
if ( internalAddDownloadedObject(obj) ) |
314 | 214 |
{ |
315 | 215 |
if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "Adding new downloaded object "+shortName+" icon="+obj.icon+" object="+obj.object+" extras="+obj.extras); |
... | ... | |
361 | 261 |
|
362 | 262 |
public static boolean allAlreadyBought() |
363 | 263 |
{ |
364 |
//return mFreeBoughtObjects.equals("*"); |
|
365 |
return false; |
|
264 |
return mBoughtObjects.equals("*"); |
|
366 | 265 |
} |
367 | 266 |
|
368 | 267 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
380 | 279 |
|
381 | 280 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
382 | 281 |
|
383 |
public static boolean objectAlreadyBought(String shortName)
|
|
282 |
public static boolean objectAlreadyBought(RubikObject object)
|
|
384 | 283 |
{ |
385 |
RubikObject o = getObject(shortName); |
|
386 |
return ( o!=null && o.isFree() ); |
|
284 |
return ( object!=null && object.isFree() ); |
|
387 | 285 |
} |
388 | 286 |
|
389 | 287 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
288 |
// calling PurchaseScreenPane charges the user. |
|
390 | 289 |
|
391 | 290 |
public static void buyAll() |
392 | 291 |
{ |
393 |
/* |
|
394 |
mFreeBoughtObjects = "*"; |
|
292 |
mBoughtObjects = "*"; |
|
395 | 293 |
if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "all objects marked as bought"); |
396 | 294 |
|
397 | 295 |
for(int i=0; i<mNumObjects; i++) |
... | ... | |
399 | 297 |
RubikObject o = mObjects.get(i); |
400 | 298 |
o.markFree(); |
401 | 299 |
} |
402 |
*/ |
|
403 | 300 |
} |
404 | 301 |
|
405 | 302 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
303 |
// calling PurchaseScreenPane charges the user. |
|
406 | 304 |
|
407 |
public static boolean buyObject(String shortName)
|
|
305 |
public static void buyObject(RubikObject object)
|
|
408 | 306 |
{ |
409 |
/* |
|
410 |
RubikObject o = getObject(shortName); |
|
411 |
|
|
412 |
if( o!=null && !o.isFree() ) |
|
307 |
if( object!=null && !object.isFree() ) |
|
413 | 308 |
{ |
309 |
String shortName = object.getUpperName(); |
|
414 | 310 |
if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "object "+shortName+" marked as bought"); |
415 |
o.markFree(); |
|
416 |
String add = mFreeBoughtObjects.length()==0 ? shortName : (","+shortName); |
|
417 |
mFreeBoughtObjects += add; |
|
418 |
return true; |
|
311 |
object.markFree(); |
|
312 |
String add = mBoughtObjects.length()==0 ? shortName : (","+shortName); |
|
313 |
mBoughtObjects += add; |
|
419 | 314 |
} |
420 |
*/ |
|
421 |
return false; |
|
422 |
} |
|
423 |
|
|
424 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
425 |
|
|
426 |
public static boolean solveObject(String shortName) |
|
427 |
{ |
|
428 |
RubikObject object = getObject(shortName); |
|
429 |
return solveObject(object,shortName); |
|
430 | 315 |
} |
431 | 316 |
|
432 | 317 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
461 | 346 |
downloadedObjects.append(' '); |
462 | 347 |
downloadedObjects.append(object.extras ? "1":"0"); |
463 | 348 |
downloadedObjects.append(' '); |
464 |
downloadedObjects.append(object.free ? "true":"false");
|
|
349 |
downloadedObjects.append(object.price);
|
|
465 | 350 |
} |
466 | 351 |
|
467 | 352 |
String objects = downloadedObjects.toString(); |
... | ... | |
472 | 357 |
{ |
473 | 358 |
editor.putString("rol_downloaded", "" ); |
474 | 359 |
} |
475 |
/* |
|
476 |
editor.putString("rol_freeSolved", mFreeSolvedObjects); |
|
477 |
editor.putString("rol_freeBought", mFreeBoughtObjects); |
|
478 | 360 |
|
479 |
if( SHOW_SOLVED_DEBUG )
|
|
361 |
if( RubikActivity.USE_IAP )
|
|
480 | 362 |
{ |
481 |
android.util.Log.e("D", "saving solved objects: "+mFreeSolvedObjects); |
|
482 |
android.util.Log.e("D", "saving bought objects: "+mFreeBoughtObjects); |
|
363 |
editor.putString("rol_bought", mBoughtObjects); |
|
364 |
|
|
365 |
if( SHOW_SOLVED_DEBUG ) |
|
366 |
{ |
|
367 |
android.util.Log.e("D", "saving bought objects: "+mBoughtObjects); |
|
368 |
} |
|
483 | 369 |
} |
484 |
*/ |
|
485 | 370 |
} |
486 | 371 |
|
487 | 372 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
512 | 397 |
String icon = parts[4]; |
513 | 398 |
String obje = parts[5]; |
514 | 399 |
String extr = parts[6]; |
515 |
boolean isFree = (length==7 || Boolean.parseBoolean(parts[7])); |
|
400 |
|
|
401 |
int price; |
|
402 |
|
|
403 |
if( length==7 ) price=0; |
|
404 |
else |
|
405 |
{ |
|
406 |
char c = parts[7].charAt(0); |
|
407 |
if( c=='t' ) price = 0; |
|
408 |
else if( c=='f' ) price = ObjectType.DEFAULT_PRICE_OF_OLD_OBJECTS; |
|
409 |
else price = Integer.parseInt(parts[7]); |
|
410 |
} |
|
516 | 411 |
|
517 | 412 |
int scrambles = Integer.parseInt(scra); |
518 | 413 |
int oMinor = Integer.parseInt(objM); |
... | ... | |
522 | 417 |
boolean bObje = obje.equals("1"); |
523 | 418 |
boolean bExtr = extr.equals("1"); |
524 | 419 |
|
525 |
addDownloadedObject(context,name,scrambles,isFree,oMinor,eMinor,bIcon,bObje,bExtr);
|
|
420 |
addDownloadedObject(context,name,scrambles,price,oMinor,eMinor,bIcon,bObje,bExtr);
|
|
526 | 421 |
} |
527 | 422 |
} |
528 | 423 |
} |
... | ... | |
533 | 428 |
mObject = getOrdinal(objName); |
534 | 429 |
if( mObject<0 || mObject>=mNumObjects ) mObject = DEF_OBJECT; |
535 | 430 |
|
536 |
if( justStarted) restoreFreedObjects(preferences);
|
|
431 |
if( RubikActivity.USE_IAP && justStarted ) restoreFreedObjects(preferences);
|
|
537 | 432 |
} |
538 | 433 |
|
539 | 434 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
555 | 450 |
|
556 | 451 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
557 | 452 |
|
558 |
public static void setObjectFreeState()
|
|
453 |
public static void firstUpgradeMarkAllSolvedAsFree()
|
|
559 | 454 |
{ |
560 |
int numUnclaimed = getNumUnclaimedSolves(); |
|
455 |
RubikScores scores = RubikScores.getInstance(); |
|
456 |
int numUnclaimed = scores.numberOfSolvedMAXes(); |
|
561 | 457 |
|
562 | 458 |
if( numUnclaimed>0 ) |
563 | 459 |
{ |
564 |
int marked = markAllSolvedAsFree(); |
|
460 |
int marked = markAllSolvedAsFree(scores);
|
|
565 | 461 |
int stillUnclaimed = numUnclaimed-marked; |
566 |
if( stillUnclaimed>0) markAsFree(stillUnclaimed); |
|
462 |
if( stillUnclaimed>0) markObjectsAsFree(scores,stillUnclaimed); |
|
463 |
} |
|
464 |
} |
|
465 |
|
|
466 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
467 |
|
|
468 |
private static int markAllSolvedAsFree(RubikScores scores) |
|
469 |
{ |
|
470 |
int numObjects = RubikObjectList.getNumObjects(); |
|
471 |
int ret = 0; |
|
472 |
|
|
473 |
for(int obj=0; obj<numObjects; obj++) |
|
474 |
{ |
|
475 |
RubikObject object = getObject(obj); |
|
476 |
|
|
477 |
if( object!=null && !object.isFree() && scores.isSolved(obj,LEVELS_SHOWN) ) |
|
478 |
{ |
|
479 |
if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "object "+object.getUpperName()+" marked as free"); |
|
480 |
object.markFree(); |
|
481 |
int price = object.getPrice(); |
|
482 |
scores.changeNumStars(-price); |
|
483 |
ret++; |
|
484 |
} |
|
485 |
} |
|
486 |
|
|
487 |
return ret; |
|
488 |
} |
|
489 |
|
|
490 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
491 |
|
|
492 |
private static void markObjectsAsFree(RubikScores scores, int numToBeMarked) |
|
493 |
{ |
|
494 |
int numObjects = RubikObjectList.getNumObjects(); |
|
495 |
|
|
496 |
for(int obj=0; obj<numObjects && numToBeMarked>0; obj++) |
|
497 |
{ |
|
498 |
RubikObject object = getObject(obj); |
|
499 |
|
|
500 |
if( object!=null && !object.isFree() ) |
|
501 |
{ |
|
502 |
if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "object "+object.getUpperName()+" marked as free"); |
|
503 |
object.markFree(); |
|
504 |
int price = object.getPrice(); |
|
505 |
scores.changeNumStars(-price); |
|
506 |
numToBeMarked--; |
|
507 |
} |
|
567 | 508 |
} |
568 | 509 |
} |
569 | 510 |
|
src/main/java/org/distorted/purchase/PurchaseScreenPane.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
public class PurchaseScreenPane |
29 | 29 |
{ |
30 |
private static final int UNLOCK_ALL_PRICE = 1000; |
|
31 |
|
|
30 | 32 |
private static final int[] IMAGES = |
31 | 33 |
{ |
32 | 34 |
R.drawable.difficulty1, |
... | ... | |
43 | 45 |
private RubikObject mObject; |
44 | 46 |
|
45 | 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 |
// TODO |
|
48 |
// TODO: charge the user an amount of stars
|
|
47 | 49 |
|
48 |
private boolean buyOne(String shortName)
|
|
50 |
private boolean chargeUser(RubikObject object)
|
|
49 | 51 |
{ |
50 | 52 |
return true; |
51 | 53 |
} |
52 | 54 |
|
53 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
54 |
// TODO |
|
56 |
// TODO: charge the user an amount of stars
|
|
55 | 57 |
|
56 |
private boolean buyAll()
|
|
58 |
private boolean chargeUser()
|
|
57 | 59 |
{ |
58 | 60 |
return true; |
59 | 61 |
} |
... | ... | |
64 | 66 |
{ |
65 | 67 |
if( mObject!=null ) |
66 | 68 |
{ |
67 |
String shortName = mObject.getUpperName(); |
|
68 |
|
|
69 |
if( !RubikObjectList.objectAlreadyBought(shortName) && buyOne(shortName) ) |
|
69 |
if( !RubikObjectList.objectAlreadyBought(mObject) && chargeUser(mObject) ) |
|
70 | 70 |
{ |
71 |
android.util.Log.e("D", "buying "+shortName); |
|
72 |
|
|
73 |
RubikObjectList.buyObject(shortName); |
|
71 |
android.util.Log.e("D", "buying "+mObject.getUpperName()); |
|
72 |
RubikObjectList.buyObject(mObject); |
|
74 | 73 |
} |
75 | 74 |
} |
76 | 75 |
} |
... | ... | |
79 | 78 |
|
80 | 79 |
private void allButtonClicked() |
81 | 80 |
{ |
82 |
if( !RubikObjectList.allAlreadyBought() && buyAll() )
|
|
81 |
if( !RubikObjectList.allAlreadyBought() && chargeUser() )
|
|
83 | 82 |
{ |
84 | 83 |
RubikObjectList.buyAll(); |
85 | 84 |
} |
Also available in: Unified diff
Changes to the initialization - initialize the 'bought objects'