Revision ebaa194f
Added by Leszek Koltunski 6 months ago
| src/main/java/org/distorted/dialogs/DialogNewRecord.java | ||
|---|---|---|
| 35 | 35 |
|
| 36 | 36 |
public void positiveAction() |
| 37 | 37 |
{
|
| 38 |
RubikScores scores = RubikScores.getInstance(); |
|
| 38 |
RubikScores scores = RubikScores.getInstance(getActivity());
|
|
| 39 | 39 |
String name = scores.getName(); |
| 40 | 40 |
Bundle bundle = new Bundle(); |
| 41 | 41 |
PlayActivity act = (PlayActivity)getActivity(); |
| 42 | 42 |
|
| 43 | 43 |
if( act!=null ) |
| 44 | 44 |
{
|
| 45 |
if(name.length()>0)
|
|
| 45 |
if( !name.isEmpty() )
|
|
| 46 | 46 |
{
|
| 47 | 47 |
bundle.putString("argument", "true");
|
| 48 | 48 |
DialogScores scoresDiag = new DialogScores(); |
| src/main/java/org/distorted/dialogs/DialogScoresPagerAdapter.java | ||
|---|---|---|
| 110 | 110 |
{
|
| 111 | 111 |
case '1': message(mAct.getString(R.string.networkError)); |
| 112 | 112 |
break; |
| 113 |
case '2': RubikScores scores = RubikScores.getInstance(); |
|
| 113 |
case '2': RubikScores scores = RubikScores.getInstance(mAct);
|
|
| 114 | 114 |
Bundle bundle = new Bundle(); |
| 115 | 115 |
bundle.putString("argument", scores.getName() );
|
| 116 | 116 |
|
| src/main/java/org/distorted/dialogs/DialogScoresView.java | ||
|---|---|---|
| 80 | 80 |
|
| 81 | 81 |
Resources res = act.getResources(); |
| 82 | 82 |
String packageName = act.getPackageName(); |
| 83 |
RubikScores scores = RubikScores.getInstance(); |
|
| 83 |
RubikScores scores = RubikScores.getInstance(act);
|
|
| 84 | 84 |
|
| 85 | 85 |
boolean inserted = false; |
| 86 | 86 |
int myRecordInMillis = scores.getRecord(tab, level); |
| 87 | 87 |
String myRecord = ( myRecordInMillis<RubikScores.NO_RECORD ) ? formatRecord(myRecordInMillis) : "??"; |
| 88 | 88 |
String myName = scores.getName(); |
| 89 |
if( myName.length()==0 ) myName = act.getString(R.string.you);
|
|
| 89 |
if( myName.isEmpty() ) myName = act.getString(R.string.you);
|
|
| 90 | 90 |
int myCountryID = res.getIdentifier( scores.getCountry(), "drawable", packageName); |
| 91 | 91 |
String theirTime; |
| 92 | 92 |
int theirCountryID; |
| src/main/java/org/distorted/dialogs/DialogSetName.java | ||
|---|---|---|
| 49 | 49 |
if( positiveButton!=null ) |
| 50 | 50 |
{
|
| 51 | 51 |
String editName = mEdit.getText().toString(); |
| 52 |
positiveButton.setEnabled(editName.length()>0);
|
|
| 52 |
positiveButton.setEnabled(!editName.isEmpty());
|
|
| 53 | 53 |
} |
| 54 | 54 |
} |
| 55 | 55 |
} |
| ... | ... | |
| 57 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 58 | 58 |
|
| 59 | 59 |
public int getResource() { return R.layout.dialog_set_name; }
|
| 60 |
public int getTitleResource() { return mArgument.length()==0 ? R.string.choose_name : R.string.name_taken; }
|
|
| 60 |
public int getTitleResource() { return mArgument.isEmpty() ? R.string.choose_name : R.string.name_taken; }
|
|
| 61 | 61 |
public boolean hasArgument() { return true; }
|
| 62 | 62 |
public int getPositive() { return R.string.ok; }
|
| 63 | 63 |
public int getNegative() { return -1; }
|
| ... | ... | |
| 81 | 81 |
try |
| 82 | 82 |
{
|
| 83 | 83 |
PlayActivity act = (PlayActivity)getActivity(); |
| 84 |
RubikScores.getInstance().setName(name); |
|
| 84 |
RubikScores.getInstance(act).setName(name);
|
|
| 85 | 85 |
Bundle bundle = new Bundle(); |
| 86 | 86 |
bundle.putString("argument", "true");
|
| 87 | 87 |
DialogScores scores = new DialogScores(); |
| ... | ... | |
| 112 | 112 |
mEdit.setHeight( (int)(2*mTitleSize) ); |
| 113 | 113 |
mEdit.setTextSize(TypedValue.COMPLEX_UNIT_PX, 1.5f*mTitleSize); |
| 114 | 114 |
|
| 115 |
if( mArgument.length()==0 )
|
|
| 115 |
if( mArgument.isEmpty() )
|
|
| 116 | 116 |
{
|
| 117 | 117 |
text.setText(R.string.new_name); |
| 118 | 118 |
} |
| src/main/java/org/distorted/helpers/RubikNetwork.java | ||
|---|---|---|
| 21 | 21 |
import java.util.ArrayList; |
| 22 | 22 |
|
| 23 | 23 |
import android.app.Activity; |
| 24 |
import android.content.Context; |
|
| 25 | 24 |
import android.content.pm.PackageInfo; |
| 26 | 25 |
import android.content.pm.PackageManager; |
| 27 | 26 |
import android.graphics.Bitmap; |
| ... | ... | |
| 166 | 165 |
|
| 167 | 166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 168 | 167 |
|
| 169 |
private boolean fillValuesNormal(ScoresReceiver receiver) |
|
| 168 |
private boolean fillValuesNormal(Activity act, ScoresReceiver receiver)
|
|
| 170 | 169 |
{
|
| 171 | 170 |
int begin=-1 ,end, len = mScores.length(); |
| 172 | 171 |
String row; |
| ... | ... | |
| 196 | 195 |
try |
| 197 | 196 |
{
|
| 198 | 197 |
row = mScores.substring(begin+1,end); |
| 199 |
fillRow(row); |
|
| 198 |
fillRow(act,row);
|
|
| 200 | 199 |
} |
| 201 | 200 |
catch(Exception ex) |
| 202 | 201 |
{
|
| ... | ... | |
| 211 | 210 |
|
| 212 | 211 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 213 | 212 |
|
| 214 |
private void fillRow(String row) |
|
| 213 |
private void fillRow(Activity act, String row)
|
|
| 215 | 214 |
{
|
| 216 | 215 |
int s1 = row.indexOf(' ');
|
| 217 | 216 |
int s2 = row.indexOf(' ',s1+1);
|
| ... | ... | |
| 247 | 246 |
} |
| 248 | 247 |
else |
| 249 | 248 |
{
|
| 250 |
tryDoCommand(row); |
|
| 249 |
tryDoCommand(act,row);
|
|
| 251 | 250 |
} |
| 252 | 251 |
} |
| 253 | 252 |
|
| 254 | 253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 255 | 254 |
|
| 256 |
private void tryDoCommand(String row) |
|
| 255 |
private void tryDoCommand(Activity act, String row)
|
|
| 257 | 256 |
{
|
| 258 | 257 |
if( row.startsWith("comm") )
|
| 259 | 258 |
{
|
| ... | ... | |
| 276 | 275 |
if(number==1) |
| 277 | 276 |
{
|
| 278 | 277 |
String country = row.substring(colon+1); |
| 279 |
RubikScores scores = RubikScores.getInstance(); |
|
| 278 |
RubikScores scores = RubikScores.getInstance(act);
|
|
| 280 | 279 |
scores.setCountry(country); |
| 281 | 280 |
} |
| 282 | 281 |
} |
| ... | ... | |
| 375 | 374 |
|
| 376 | 375 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 377 | 376 |
|
| 378 |
private String constructSuspiciousURL(String suspURL) |
|
| 377 |
private String constructSuspiciousURL(Activity act, String suspURL)
|
|
| 379 | 378 |
{
|
| 380 |
RubikScores scores = RubikScores.getInstance(); |
|
| 379 |
RubikScores scores = RubikScores.getInstance(act);
|
|
| 381 | 380 |
int deviceID = scores.getDeviceID(); |
| 382 | 381 |
String suspicious = URLencode(suspURL); |
| 383 | 382 |
|
| ... | ... | |
| 388 | 387 |
|
| 389 | 388 |
private String constructTokenURL(String token) |
| 390 | 389 |
{
|
| 391 |
RubikScores scores = RubikScores.getInstance(); |
|
| 392 |
String name = URLencode(scores.getName()); |
|
| 393 |
int deviceID= scores.getDeviceID(); |
|
| 394 |
String country = scores.getCountry(); |
|
| 395 | 390 |
String version = mVersion==null ? "null" : mVersion; |
| 396 | 391 |
String tkn = URLencode(token); |
| 392 |
RubikScores scores = RubikScores.getInstance(); |
|
| 397 | 393 |
|
| 398 |
return SERVER+"token.cgi?n="+name+"&i="+deviceID+"&e="+version+"&c="+country+"&t="+tkn; |
|
| 394 |
if( scores!=null ) |
|
| 395 |
{
|
|
| 396 |
String name = URLencode(scores.getName()); |
|
| 397 |
int deviceID= scores.getDeviceID(); |
|
| 398 |
String country = scores.getCountry(); |
|
| 399 |
|
|
| 400 |
return SERVER+"token.cgi?n="+name+"&i="+deviceID+"&e="+version+"&c="+country+"&t="+tkn; |
|
| 401 |
} |
|
| 402 |
|
|
| 403 |
return SERVER+"token.cgi?e="+version+"&t="+tkn; |
|
| 399 | 404 |
} |
| 400 | 405 |
|
| 401 | 406 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 402 | 407 |
|
| 403 |
private String constructUpdatesURL() |
|
| 408 |
private String constructUpdatesURL(Activity act)
|
|
| 404 | 409 |
{
|
| 405 |
RubikScores sco = RubikScores.getInstance(); |
|
| 410 |
RubikScores sco = RubikScores.getInstance(act);
|
|
| 406 | 411 |
String name = URLencode(sco.getName()); |
| 407 | 412 |
int numRuns = sco.getNumRuns(); |
| 408 | 413 |
int numPlay = sco.getNumPlays(); |
| ... | ... | |
| 418 | 423 |
|
| 419 | 424 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 420 | 425 |
|
| 421 |
private String constructDownloadURL() |
|
| 426 |
private String constructDownloadURL(Activity act)
|
|
| 422 | 427 |
{
|
| 423 |
RubikScores scores = RubikScores.getInstance(); |
|
| 428 |
RubikScores scores = RubikScores.getInstance(act);
|
|
| 424 | 429 |
String name = URLencode(scores.getName()); |
| 425 | 430 |
int numRuns = scores.getNumRuns(); |
| 426 | 431 |
int numPlay = scores.getNumPlays(); |
| ... | ... | |
| 431 | 436 |
|
| 432 | 437 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 433 | 438 |
|
| 434 |
private String constructSubmitURL() |
|
| 439 |
private String constructSubmitURL(Activity act)
|
|
| 435 | 440 |
{
|
| 436 |
RubikScores scores = RubikScores.getInstance(); |
|
| 441 |
RubikScores scores = RubikScores.getInstance(act);
|
|
| 437 | 442 |
String name = URLencode(scores.getName()); |
| 438 | 443 |
String veri = scores.isVerified() ? "1" : ""; |
| 439 | 444 |
int numRuns = scores.getNumRuns(); |
| ... | ... | |
| 472 | 477 |
|
| 473 | 478 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 474 | 479 |
|
| 475 |
private void downloadThread(ScoresReceiver receiver) |
|
| 480 |
private void downloadThread(Activity act, ScoresReceiver receiver)
|
|
| 476 | 481 |
{
|
| 477 | 482 |
boolean receiveValues = true; |
| 478 | 483 |
|
| ... | ... | |
| 481 | 486 |
if( mScores.isEmpty() && !mDowRunning ) |
| 482 | 487 |
{
|
| 483 | 488 |
mDowRunning = true; |
| 484 |
receiveValues = network(constructDownloadURL(),receiver); |
|
| 489 |
receiveValues = network(constructDownloadURL(act),receiver);
|
|
| 485 | 490 |
|
| 486 | 491 |
if( mDowRunning ) |
| 487 | 492 |
{
|
| 488 |
receiveValues = fillValuesNormal(receiver); |
|
| 493 |
receiveValues = fillValuesNormal(act,receiver);
|
|
| 489 | 494 |
mDowRunning = false; |
| 490 | 495 |
} |
| 491 | 496 |
} |
| ... | ... | |
| 499 | 504 |
|
| 500 | 505 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 501 | 506 |
|
| 502 |
private void submitThread(ScoresReceiver receiver) |
|
| 507 |
private void submitThread(Activity act, ScoresReceiver receiver)
|
|
| 503 | 508 |
{
|
| 504 | 509 |
try |
| 505 | 510 |
{
|
| 506 |
RubikScores scores = RubikScores.getInstance(); |
|
| 511 |
RubikScores scores = RubikScores.getInstance(act);
|
|
| 507 | 512 |
|
| 508 | 513 |
if( scores.thereAreUnsubmittedRecords() && !mSubRunning ) |
| 509 | 514 |
{
|
| 510 | 515 |
mSubRunning = true; |
| 511 |
boolean receiveValues = network(constructSubmitURL(),receiver); |
|
| 516 |
boolean receiveValues = network(constructSubmitURL(act),receiver);
|
|
| 512 | 517 |
|
| 513 | 518 |
if( mSubRunning ) |
| 514 | 519 |
{
|
| 515 |
receiveValues = fillValuesNormal(receiver); |
|
| 520 |
receiveValues = fillValuesNormal(act,receiver);
|
|
| 516 | 521 |
mSubRunning = false; |
| 517 | 522 |
} |
| 518 | 523 |
|
| 519 | 524 |
if( receiveValues ) |
| 520 | 525 |
{
|
| 521 |
RubikScores.getInstance().successfulSubmit(); |
|
| 526 |
RubikScores.getInstance(act).successfulSubmit();
|
|
| 522 | 527 |
receiver.receive(mCountry, mName, mTime); |
| 523 | 528 |
} |
| 524 | 529 |
} |
| ... | ... | |
| 531 | 536 |
|
| 532 | 537 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 533 | 538 |
|
| 534 |
private void updatesThread() |
|
| 539 |
private void updatesThread(Activity act)
|
|
| 535 | 540 |
{
|
| 536 |
String url = constructUpdatesURL(); |
|
| 541 |
String url = constructUpdatesURL(act);
|
|
| 537 | 542 |
|
| 538 | 543 |
try |
| 539 | 544 |
{
|
| ... | ... | |
| 592 | 597 |
|
| 593 | 598 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 594 | 599 |
|
| 595 |
private void suspiciousThread(String suspURL) |
|
| 600 |
private void suspiciousThread(Activity act, String suspURL)
|
|
| 596 | 601 |
{
|
| 597 |
String url = constructSuspiciousURL(suspURL); |
|
| 602 |
String url = constructSuspiciousURL(act,suspURL);
|
|
| 598 | 603 |
|
| 599 | 604 |
try |
| 600 | 605 |
{
|
| ... | ... | |
| 667 | 672 |
|
| 668 | 673 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 669 | 674 |
|
| 670 |
private void iconThread(Context context, IconReceiver receiver)
|
|
| 675 |
private void iconThread(Activity act, IconReceiver receiver)
|
|
| 671 | 676 |
{
|
| 672 | 677 |
int numC = mUpdates.getCompletedNumber(); |
| 673 | 678 |
int numS = mUpdates.getStartedNumber(); |
| ... | ... | |
| 679 | 684 |
if( iconPresent!=0 ) |
| 680 | 685 |
{
|
| 681 | 686 |
boolean downloaded = false; |
| 682 |
Bitmap icon = mUpdates.getCompletedIcon(context,c);
|
|
| 687 |
Bitmap icon = mUpdates.getCompletedIcon(act,c);
|
|
| 683 | 688 |
|
| 684 | 689 |
if( icon==null ) |
| 685 | 690 |
{
|
| ... | ... | |
| 704 | 709 |
if( iconPresent!=0 ) |
| 705 | 710 |
{
|
| 706 | 711 |
boolean downloaded = false; |
| 707 |
Bitmap icon = mUpdates.getStartedIcon(context,s);
|
|
| 712 |
Bitmap icon = mUpdates.getStartedIcon(act,s);
|
|
| 708 | 713 |
|
| 709 | 714 |
if( icon==null ) |
| 710 | 715 |
{
|
| ... | ... | |
| 813 | 818 |
{
|
| 814 | 819 |
public void run() |
| 815 | 820 |
{
|
| 816 |
downloadThread(receiver); |
|
| 821 |
downloadThread(act,receiver);
|
|
| 817 | 822 |
} |
| 818 | 823 |
}; |
| 819 | 824 |
|
| ... | ... | |
| 831 | 836 |
{
|
| 832 | 837 |
public void run() |
| 833 | 838 |
{
|
| 834 |
submitThread(receiver); |
|
| 839 |
submitThread(act,receiver);
|
|
| 835 | 840 |
} |
| 836 | 841 |
}; |
| 837 | 842 |
|
| ... | ... | |
| 850 | 855 |
{
|
| 851 | 856 |
public void run() |
| 852 | 857 |
{
|
| 853 |
updatesThread(); |
|
| 858 |
updatesThread(act);
|
|
| 854 | 859 |
} |
| 855 | 860 |
}; |
| 856 | 861 |
|
| ... | ... | |
| 868 | 873 |
{
|
| 869 | 874 |
public void run() |
| 870 | 875 |
{
|
| 871 |
suspiciousThread(suspicious); |
|
| 876 |
suspiciousThread(act,suspicious);
|
|
| 872 | 877 |
} |
| 873 | 878 |
}; |
| 874 | 879 |
|
| ... | ... | |
| 926 | 931 |
|
| 927 | 932 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 928 | 933 |
|
| 929 |
public void downloadIcons(final Context context, final IconReceiver receiver)
|
|
| 934 |
public void downloadIcons(final Activity act, final IconReceiver receiver)
|
|
| 930 | 935 |
{
|
| 931 | 936 |
initializeStatics(); |
| 932 | 937 |
|
| ... | ... | |
| 934 | 939 |
{
|
| 935 | 940 |
public void run() |
| 936 | 941 |
{
|
| 937 |
iconThread(context,receiver);
|
|
| 942 |
iconThread(act,receiver);
|
|
| 938 | 943 |
} |
| 939 | 944 |
}; |
| 940 | 945 |
|
| src/main/java/org/distorted/helpers/RubikScores.java | ||
|---|---|---|
| 12 | 12 |
import java.util.HashMap; |
| 13 | 13 |
import java.util.UUID; |
| 14 | 14 |
|
| 15 |
import android.app.Activity; |
|
| 15 | 16 |
import android.content.Context; |
| 16 | 17 |
import android.content.SharedPreferences; |
| 17 | 18 |
import android.telephony.TelephonyManager; |
| 18 | 19 |
|
| 20 |
import androidx.preference.PreferenceManager; |
|
| 21 |
|
|
| 19 | 22 |
import com.google.firebase.crashlytics.FirebaseCrashlytics; |
| 20 | 23 |
|
| 21 | 24 |
import org.distorted.main.BuildConfig; |
| ... | ... | |
| 34 | 37 |
public static final int RECORD_NEW = 1; |
| 35 | 38 |
public static final int RECORD_NOT_NEW = 2; |
| 36 | 39 |
|
| 40 |
public static final String SCORES_NAME = "scores_name"; |
|
| 41 |
public static final String SCORES_ISVE = "scores_isVerified"; |
|
| 42 |
public static final String SCORES_NUMP = "scores_numPlays"; |
|
| 43 |
public static final String SCORES_NUMR = "scores_numRuns"; |
|
| 44 |
public static final String SCORES_DEID = "scores_deviceid"; |
|
| 45 |
public static final String SCORES_NUMW = "scores_review"; // legacy |
|
| 46 |
public static final String SCORES_NUMS = "scores_numStars"; |
|
| 47 |
|
|
| 37 | 48 |
public static final int MAX_RECORD = 10; |
| 38 | 49 |
private static final int MULT = 1000000; |
| 39 | 50 |
public static final int NO_RECORD = Integer.MAX_VALUE; |
| ... | ... | |
| 45 | 56 |
private int mNumPlays; |
| 46 | 57 |
private int mNumWins; |
| 47 | 58 |
private int mDeviceID; |
| 48 |
private int mNumStars; |
|
| 49 | 59 |
|
| 50 | 60 |
private static class MapValue |
| 51 | 61 |
{
|
| ... | ... | |
| 60 | 70 |
} |
| 61 | 71 |
|
| 62 | 72 |
private final HashMap<Integer,MapValue> mMap; |
| 73 |
private final SharedPreferences mPreferences; |
|
| 63 | 74 |
|
| 64 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 65 | 76 |
|
| 66 |
private RubikScores() |
|
| 77 |
private RubikScores(Activity act)
|
|
| 67 | 78 |
{
|
| 68 | 79 |
mMap = new HashMap<>(); |
| 69 | 80 |
|
| ... | ... | |
| 76 | 87 |
mNumRuns = -1; |
| 77 | 88 |
mDeviceID= -1; |
| 78 | 89 |
mNumWins = 0; |
| 79 |
mNumStars= 0; |
|
| 90 |
|
|
| 91 |
mPreferences = PreferenceManager.getDefaultSharedPreferences(act); |
|
| 80 | 92 |
} |
| 81 | 93 |
|
| 82 | 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 117 | 129 |
MapValue value = mMap.get(key); |
| 118 | 130 |
if( value!=null ) value.submitted = true; |
| 119 | 131 |
} |
| 132 |
|
|
| 133 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 134 |
editor.putBoolean( SCORES_ISVE, mNameIsVerified); |
|
| 135 |
|
|
| 136 |
for(int level=0; level<=MAX_RECORD; level++) saveRecordLevel(editor,level); |
|
| 137 |
editor.apply(); |
|
| 120 | 138 |
} |
| 121 | 139 |
|
| 122 | 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 186 | 204 |
public int getNumRuns() { return mNumRuns; }
|
| 187 | 205 |
public String getName() { return mName; }
|
| 188 | 206 |
public String getCountry() { return mCountry; }
|
| 189 |
public void incrementNumPlays() { mNumPlays++; }
|
|
| 190 |
public void incrementNumRuns() { mNumRuns++; }
|
|
| 191 |
|
|
| 192 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 193 |
|
|
| 194 |
public int incrementNumWins() |
|
| 195 |
{
|
|
| 196 |
mNumWins++; |
|
| 197 |
return mNumWins; |
|
| 198 |
} |
|
| 199 | 207 |
|
| 200 | 208 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 201 | 209 |
|
| 202 |
public void changeNumStars(int stars)
|
|
| 210 |
public void incrementNumPlays()
|
|
| 203 | 211 |
{
|
| 204 |
mNumStars += stars; |
|
| 205 |
if( mNumStars<0 ) mNumStars = 0; |
|
| 212 |
mNumPlays++; |
|
| 213 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 214 |
editor.putInt( SCORES_NUMP, mNumPlays); |
|
| 215 |
editor.apply(); |
|
| 206 | 216 |
} |
| 207 | 217 |
|
| 208 | 218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 209 | 219 |
|
| 210 |
public int getNumStars()
|
|
| 220 |
public void incrementNumRuns()
|
|
| 211 | 221 |
{
|
| 212 |
return mNumStars; |
|
| 222 |
mNumRuns++; |
|
| 223 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 224 |
editor.putInt( SCORES_NUMR, mNumRuns); |
|
| 225 |
editor.apply(); |
|
| 213 | 226 |
} |
| 214 | 227 |
|
| 215 | 228 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 216 | 229 |
|
| 217 |
public void correctNumStars()
|
|
| 230 |
public int incrementNumWins()
|
|
| 218 | 231 |
{
|
| 219 |
int numObjects = RubikObjectList.getNumObjects(); |
|
| 220 |
|
|
| 221 |
for(int obj=0; obj<numObjects; obj++) |
|
| 222 |
{
|
|
| 223 |
for(int level=0; level<=LEVELS_SHOWN; level++) |
|
| 224 |
{
|
|
| 225 |
if( isSolved(obj,level) ) |
|
| 226 |
{
|
|
| 227 |
int numStars = computeNumStars(level+1); |
|
| 228 |
mNumStars += numStars; |
|
| 229 |
} |
|
| 230 |
} |
|
| 231 |
} |
|
| 232 |
} |
|
| 233 |
|
|
| 234 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 232 |
mNumWins++; |
|
| 233 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 234 |
editor.putInt( SCORES_NUMW, mNumWins); |
|
| 235 |
editor.apply(); |
|
| 235 | 236 |
|
| 236 |
public int computeNumStars(int level) |
|
| 237 |
{
|
|
| 238 |
return level>LEVELS_SHOWN ? 50 : level; |
|
| 237 |
return mNumWins; |
|
| 239 | 238 |
} |
| 240 | 239 |
|
| 241 | 240 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 243 | 242 |
public void setName(String newName) |
| 244 | 243 |
{
|
| 245 | 244 |
mName = newName; |
| 245 |
|
|
| 246 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 247 |
editor.putString( SCORES_NAME, mName); |
|
| 248 |
editor.apply(); |
|
| 246 | 249 |
} |
| 247 | 250 |
|
| 248 | 251 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 256 | 259 |
{
|
| 257 | 260 |
MapValue value = new MapValue(record,0); |
| 258 | 261 |
mMap.put(key,value); |
| 262 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 263 |
saveRecordLevel(editor,level); |
|
| 264 |
editor.apply(); |
|
| 259 | 265 |
return RECORD_FIRST; |
| 260 | 266 |
} |
| 261 | 267 |
|
| ... | ... | |
| 265 | 271 |
{
|
| 266 | 272 |
MapValue value = new MapValue(record,0); |
| 267 | 273 |
mMap.put(key,value); |
| 274 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 275 |
saveRecordLevel(editor,level); |
|
| 276 |
editor.apply(); |
|
| 268 | 277 |
return RECORD_NEW; |
| 269 | 278 |
} |
| 270 | 279 |
|
| ... | ... | |
| 305 | 314 |
} |
| 306 | 315 |
} |
| 307 | 316 |
|
| 308 |
// Special case: Dominicana. Its ISO-3166-alpha-2 country code is 'do' which we can't have here |
|
| 309 |
// because we later on map this to a resource name (the flag) and 'do' is a reserved Java keyword |
|
| 310 |
// and can't be a resource name. |
|
| 311 |
|
|
| 312 |
if( mCountry.equals("do") ) mCountry = "dm";
|
|
| 317 |
dominicana(); |
|
| 313 | 318 |
} |
| 314 | 319 |
|
| 315 | 320 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 317 | 322 |
public void setCountry(String country) |
| 318 | 323 |
{
|
| 319 | 324 |
mCountry = country; |
| 325 |
dominicana(); |
|
| 326 |
} |
|
| 327 |
|
|
| 328 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 329 |
// Special case: Dominicana. Its ISO-3166-alpha-2 country code is 'do' which we can't have here |
|
| 330 |
// because we later on map this to a resource name (the flag) and 'do' is a reserved Java keyword |
|
| 331 |
// and can't be a resource name. |
|
| 320 | 332 |
|
| 321 |
if( mCountry.equals("do") ) mCountry = "dm"; // see above
|
|
| 333 |
private void dominicana() |
|
| 334 |
{
|
|
| 335 |
if( mCountry.equals("do") ) mCountry = "dm";
|
|
| 336 |
} |
|
| 337 |
|
|
| 338 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 339 |
|
|
| 340 |
public static RubikScores getInstance(Activity act) |
|
| 341 |
{
|
|
| 342 |
if( mThis==null ) mThis = new RubikScores(act); |
|
| 343 |
return mThis; |
|
| 322 | 344 |
} |
| 323 | 345 |
|
| 324 | 346 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 325 | 347 |
|
| 326 | 348 |
public static RubikScores getInstance() |
| 327 | 349 |
{
|
| 328 |
if( mThis==null ) mThis = new RubikScores(); |
|
| 329 | 350 |
return mThis; |
| 330 | 351 |
} |
| 331 | 352 |
|
| 332 | 353 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 333 | 354 |
|
| 334 |
public synchronized void savePreferences(SharedPreferences.Editor editor)
|
|
| 355 |
private void saveRecordLevel(SharedPreferences.Editor editor, int level)
|
|
| 335 | 356 |
{
|
| 336 | 357 |
int numObjects = RubikObjectList.getNumObjects(); |
| 337 | 358 |
StringBuilder builder = new StringBuilder(); |
| 338 | 359 |
|
| 339 |
for(int level=0; level<=MAX_RECORD; level++)
|
|
| 360 |
for(int object=0; object<numObjects; object++)
|
|
| 340 | 361 |
{
|
| 341 |
builder.setLength(0); |
|
| 362 |
int key = mapKey(object,level); |
|
| 363 |
RubikObject obj = RubikObjectList.getObject(object); |
|
| 364 |
MapValue value = mMap.get(key); |
|
| 342 | 365 |
|
| 343 |
for(int object=0; object<numObjects; object++)
|
|
| 366 |
if( obj!=null && value!=null && value.record<NO_RECORD )
|
|
| 344 | 367 |
{
|
| 345 |
int key = mapKey(object,level); |
|
| 346 |
RubikObject obj = RubikObjectList.getObject(object); |
|
| 347 |
MapValue value = mMap.get(key); |
|
| 348 |
|
|
| 349 |
if( obj!=null && value!=null && value.record<NO_RECORD ) |
|
| 350 |
{
|
|
| 351 |
builder.append(obj.getUpperName()); |
|
| 352 |
builder.append("=");
|
|
| 353 |
builder.append(value.record); |
|
| 354 |
builder.append(",");
|
|
| 355 |
builder.append(value.submitted ? 1:0 ); |
|
| 356 |
builder.append(" ");
|
|
| 357 |
} |
|
| 368 |
builder.append(obj.getUpperName()); |
|
| 369 |
builder.append("=");
|
|
| 370 |
builder.append(value.record); |
|
| 371 |
builder.append(",");
|
|
| 372 |
builder.append(value.submitted ? 1:0 ); |
|
| 373 |
builder.append(" ");
|
|
| 358 | 374 |
} |
| 359 |
|
|
| 360 |
editor.putString("scores_record"+level, builder.toString());
|
|
| 361 | 375 |
} |
| 362 | 376 |
|
| 363 |
editor.putString("scores_name" , mName );
|
|
| 364 |
editor.putBoolean("scores_isVerified", mNameIsVerified);
|
|
| 365 |
editor.putInt("scores_numPlays", mNumPlays);
|
|
| 366 |
editor.putInt("scores_numRuns" , mNumRuns );
|
|
| 367 |
editor.putInt("scores_deviceid", mDeviceID);
|
|
| 368 |
editor.putInt("scores_review" , mNumWins ); // legacy name
|
|
| 369 |
editor.putInt("scores_numStars", mNumStars );
|
|
| 370 |
} |
|
| 371 |
|
|
| 372 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 373 |
|
|
| 374 |
public synchronized void savePreferencesMinimal(SharedPreferences.Editor editor) |
|
| 375 |
{
|
|
| 376 |
editor.putInt("scores_numStars", mNumStars );
|
|
| 377 |
editor.putString("scores_record"+level, builder.toString());
|
|
| 377 | 378 |
} |
| 378 | 379 |
|
| 379 | 380 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 447 | 448 |
} |
| 448 | 449 |
} |
| 449 | 450 |
|
| 450 |
mName = preferences.getString("scores_name" , "" );
|
|
| 451 |
mNameIsVerified = preferences.getBoolean("scores_isVerified", false);
|
|
| 452 |
mNumPlays = preferences.getInt("scores_numPlays", 0);
|
|
| 453 |
mNumRuns = preferences.getInt("scores_numRuns" , 0);
|
|
| 454 |
mDeviceID = preferences.getInt("scores_deviceid",-1);
|
|
| 455 |
mNumWins = preferences.getInt("scores_review" , 0);
|
|
| 456 |
mNumStars = preferences.getInt("scores_numStars", 0);
|
|
| 451 |
mName = preferences.getString( SCORES_NAME , "" ); |
|
| 452 |
mNameIsVerified = preferences.getBoolean( SCORES_ISVE, false); |
|
| 453 |
mNumPlays = preferences.getInt( SCORES_NUMP, 0); |
|
| 454 |
mNumRuns = preferences.getInt( SCORES_NUMR, 0); |
|
| 455 |
mDeviceID = preferences.getInt( SCORES_DEID,-1); |
|
| 456 |
mNumWins = preferences.getInt( SCORES_NUMW, 0); |
|
| 457 | 457 |
|
| 458 |
if( mDeviceID==-1 ) mDeviceID = privateGetDeviceID(); |
|
| 458 |
if( mDeviceID==-1 ) |
|
| 459 |
{
|
|
| 460 |
mDeviceID = privateGetDeviceID(); |
|
| 461 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 462 |
editor.putInt( SCORES_DEID, mDeviceID); |
|
| 463 |
editor.apply(); |
|
| 464 |
} |
|
| 459 | 465 |
|
| 460 | 466 |
if( thereWasError ) recordDBError(errorStr); |
| 461 | 467 |
} |
| src/main/java/org/distorted/main/MainActivity.java | ||
|---|---|---|
| 155 | 155 |
mJustStarted = false; |
| 156 | 156 |
|
| 157 | 157 |
network.downloadUpdates(this); |
| 158 |
RubikScores scores = RubikScores.getInstance(); |
|
| 158 |
RubikScores scores = RubikScores.getInstance(this);
|
|
| 159 | 159 |
scores.incrementNumRuns(); |
| 160 | 160 |
scores.setCountry(this); |
| 161 | 161 |
} |
| ... | ... | |
| 220 | 220 |
mSortMode = preferences.getInt("sortMode", MainSettingsPopup.SORT_DEFAULT);
|
| 221 | 221 |
|
| 222 | 222 |
RubikObjectList.restorePreferences(this,preferences,justStarted); |
| 223 |
RubikScores scores = RubikScores.getInstance(); |
|
| 223 |
RubikScores scores = RubikScores.getInstance(this);
|
|
| 224 | 224 |
scores.restorePreferences(preferences); |
| 225 | 225 |
|
| 226 | 226 |
if( scores.isVerified() ) |
| src/main/java/org/distorted/main/MainObjectPopup.java | ||
|---|---|---|
| 196 | 196 |
|
| 197 | 197 |
private void setupLevelButtons(MainActivity act, RubikObject object, View layout, int width,int padding, int margin, int darkC, int passedC) |
| 198 | 198 |
{
|
| 199 |
RubikScores scores = RubikScores.getInstance(); |
|
| 199 |
RubikScores scores = RubikScores.getInstance(act);
|
|
| 200 | 200 |
Resources res = act.getResources(); |
| 201 | 201 |
ColorStateList colorG = ColorStateList.valueOf(res.getColor(passedC)); |
| 202 | 202 |
ColorStateList colorD = ColorStateList.valueOf(res.getColor(darkC)); |
| src/main/java/org/distorted/messaging/RubikMessagingService.java | ||
|---|---|---|
| 52 | 52 |
{
|
| 53 | 53 |
Log.e(TAG, "From: " + remoteMessage.getFrom()); |
| 54 | 54 |
|
| 55 |
if (remoteMessage.getData().size() > 0)
|
|
| 55 |
if( !remoteMessage.getData().isEmpty() )
|
|
| 56 | 56 |
{
|
| 57 | 57 |
Log.e(TAG, "Message data payload: " + remoteMessage.getData()); |
| 58 | 58 |
|
| src/main/java/org/distorted/objects/RubikObjectList.java | ||
|---|---|---|
| 12 | 12 |
import java.util.ArrayList; |
| 13 | 13 |
import java.util.Locale; |
| 14 | 14 |
|
| 15 |
import android.app.Activity; |
|
| 15 | 16 |
import android.content.Context; |
| 16 | 17 |
import android.content.SharedPreferences; |
| 17 | 18 |
|
| ... | ... | |
| 82 | 83 |
|
| 83 | 84 |
private static boolean allObjectsUnlocked() |
| 84 | 85 |
{
|
| 85 |
return mBoughtObjects!=null && |
|
| 86 |
mBoughtObjects.length()>0 && |
|
| 87 |
mBoughtObjects.charAt(0)=='*'; |
|
| 86 |
return mBoughtObjects!=null && !mBoughtObjects.isEmpty() && mBoughtObjects.charAt(0)=='*'; |
|
| 88 | 87 |
} |
| 89 | 88 |
|
| 90 | 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 168 | 167 |
android.util.Log.e("D", "bought objects: "+mBoughtObjects);
|
| 169 | 168 |
} |
| 170 | 169 |
|
| 171 |
if( mBoughtObjects.length()>0 )
|
|
| 170 |
if( !mBoughtObjects.isEmpty() )
|
|
| 172 | 171 |
{
|
| 173 | 172 |
if( mBoughtObjects.charAt(0)=='*' ) |
| 174 | 173 |
{
|
| ... | ... | |
| 286 | 285 |
String shortName = object.getUpperName(); |
| 287 | 286 |
if( SHOW_IAP_DEBUG ) android.util.Log.e("D", "object "+shortName+" marked as bought");
|
| 288 | 287 |
object.markFree(); |
| 289 |
String add = mBoughtObjects.length()==0 ? shortName : (","+shortName);
|
|
| 288 |
String add = mBoughtObjects.isEmpty() ? shortName : (","+shortName);
|
|
| 290 | 289 |
mBoughtObjects += add; |
| 291 | 290 |
} |
| 292 | 291 |
} |
| ... | ... | |
| 363 | 362 |
|
| 364 | 363 |
if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", downloaded);
|
| 365 | 364 |
|
| 366 |
if( !downloaded.equals(""))
|
|
| 365 |
if( !downloaded.isEmpty() )
|
|
| 367 | 366 |
{
|
| 368 | 367 |
String[] dObjects = downloaded.split(",");
|
| 369 | 368 |
|
| ... | ... | |
| 425 | 424 |
|
| 426 | 425 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 427 | 426 |
|
| 428 |
public static void firstUpgradeMarkAllSolvedAsFree() |
|
| 427 |
public static void firstUpgradeMarkAllSolvedAsFree(Activity act)
|
|
| 429 | 428 |
{
|
| 430 |
RubikScores scores = RubikScores.getInstance(); |
|
| 429 |
RubikScores scores = RubikScores.getInstance(act);
|
|
| 431 | 430 |
int numUnclaimed = scores.numberOfSolvedMAXes(); |
| 432 | 431 |
|
| 433 | 432 |
if( numUnclaimed>0 ) |
| ... | ... | |
| 484 | 483 |
String shortName = object.getUpperName(); |
| 485 | 484 |
if( SHOW_IAP_DEBUG ) android.util.Log.e("D", "object "+object.getUpperName()+" marked as free");
|
| 486 | 485 |
object.markFree(); |
| 487 |
int price = object.getPrice(); |
|
| 488 |
scores.changeNumStars(-price); |
|
| 489 |
String add = mBoughtObjects.length()==0 ? shortName : (","+shortName);
|
|
| 486 |
String add = mBoughtObjects.isEmpty() ? shortName : (","+shortName);
|
|
| 490 | 487 |
mBoughtObjects += add; |
| 491 | 488 |
} |
| 492 | 489 |
|
| src/main/java/org/distorted/play/PlayActivity.java | ||
|---|---|---|
| 23 | 23 |
import com.google.firebase.analytics.FirebaseAnalytics; |
| 24 | 24 |
|
| 25 | 25 |
import org.distorted.dialogs.DialogScores; |
| 26 |
import org.distorted.helpers.RubikScores; |
|
| 27 | 26 |
import org.distorted.helpers.BaseActivity; |
| 28 | 27 |
import org.distorted.library.main.DistortedLibrary; |
| 29 | 28 |
import org.distorted.objectlib.main.InitAssets; |
| ... | ... | |
| 198 | 197 |
solv.saveMovePreferences(KEY_SOLV,editor); |
| 199 | 198 |
} |
| 200 | 199 |
|
| 201 |
RubikScores scores = RubikScores.getInstance(); |
|
| 202 |
scores.savePreferences(editor); |
|
| 203 |
|
|
| 204 | 200 |
editor.apply(); |
| 205 | 201 |
} |
| 206 | 202 |
|
| src/main/java/org/distorted/play/PlayLibInterface.java | ||
|---|---|---|
| 96 | 96 |
|
| 97 | 97 |
private void reportRecord(PlayActivity act, long startTime, long endTime, int scrambleNum) |
| 98 | 98 |
{
|
| 99 |
RubikScores scores = RubikScores.getInstance(); |
|
| 99 |
RubikScores scores = RubikScores.getInstance(act);
|
|
| 100 | 100 |
int objectOrdinal = act.getObjectOrdinal(); |
| 101 | 101 |
String name = scores.getName(); |
| 102 | 102 |
RubikObject obj = RubikObjectList.getObject(objectOrdinal); |
| ... | ... | |
| 149 | 149 |
android.util.Log.e("D", "ASKING FOR REVIEW");
|
| 150 | 150 |
|
| 151 | 151 |
mReviewAsked = true; |
| 152 |
final String name = RubikScores.getInstance().getName(); |
|
| 152 |
final String name = RubikScores.getInstance(act).getName();
|
|
| 153 | 153 |
final long timeBegin = System.currentTimeMillis(); |
| 154 | 154 |
final ReviewManager manager = ReviewManagerFactory.create(act); |
| 155 | 155 |
Task<ReviewInfo> request = manager.requestReviewFlow(); |
| ... | ... | |
| 194 | 194 |
if( ScreenList.getCurrentScreen()==ScreenList.SCRA ) |
| 195 | 195 |
{
|
| 196 | 196 |
PlayActivity act = mAct.get(); |
| 197 |
RubikScores.getInstance().incrementNumPlays(); |
|
| 197 |
RubikScores.getInstance(act).incrementNumPlays();
|
|
| 198 | 198 |
|
| 199 | 199 |
act.runOnUiThread(new Runnable() |
| 200 | 200 |
{
|
| ... | ... | |
| 280 | 280 |
int objectOrdinal = act.getObjectOrdinal(); |
| 281 | 281 |
ScreenSolving solving = (ScreenSolving)ScreenList.SOLV.getScreenClass(); |
| 282 | 282 |
mNewRecord = solving.stopTimerAndGetRecord(); |
| 283 |
mIsNewRecord = submittable ? solving.setRecord(objectOrdinal) : RECORD_NOT_NEW; |
|
| 283 |
mIsNewRecord = submittable ? solving.setRecord(act,objectOrdinal) : RECORD_NOT_NEW;
|
|
| 284 | 284 |
} |
| 285 | 285 |
} |
| 286 | 286 |
|
| ... | ... | |
| 297 | 297 |
|
| 298 | 298 |
if( submittable ) reportRecord(act,startTime,endTime,scrambleNum); |
| 299 | 299 |
|
| 300 |
RubikScores scores = RubikScores.getInstance(); |
|
| 300 |
RubikScores scores = RubikScores.getInstance(act);
|
|
| 301 | 301 |
int numWins = scores.incrementNumWins(); |
| 302 | 302 |
int numRuns = scores.getNumRuns(); |
| 303 | 303 |
|
| src/main/java/org/distorted/play/ScreenSolving.java | ||
|---|---|---|
| 9 | 9 |
|
| 10 | 10 |
package org.distorted.play; |
| 11 | 11 |
|
| 12 |
import android.app.Activity; |
|
| 12 | 13 |
import android.content.SharedPreferences; |
| 13 | 14 |
import android.util.TypedValue; |
| 14 | 15 |
import android.view.LayoutInflater; |
| ... | ... | |
| 34 | 35 |
private Timer mTimer; |
| 35 | 36 |
private long mStartTime; |
| 36 | 37 |
private boolean mRunning; |
| 37 |
private final RubikScores mScores; |
|
| 38 | 38 |
private long mElapsed; |
| 39 | 39 |
private int mLevel; |
| 40 | 40 |
private TransparentImageButton mBackButton; |
| 41 | 41 |
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
|
|
| 44 |
ScreenSolving() |
|
| 45 |
{
|
|
| 46 |
mScores = RubikScores.getInstance(); |
|
| 47 |
} |
|
| 48 |
|
|
| 49 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 50 | 43 |
|
| 51 | 44 |
void leaveScreen(PlayActivity act) |
| ... | ... | |
| 177 | 170 |
|
| 178 | 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 179 | 172 |
|
| 180 |
public int setRecord(int object) |
|
| 173 |
public int setRecord(Activity act, int object)
|
|
| 181 | 174 |
{
|
| 182 |
return mScores.setRecord(object, mLevel, (int)mElapsed); |
|
| 175 |
RubikScores scores = RubikScores.getInstance(act); |
|
| 176 |
return scores.setRecord(object, mLevel, (int)mElapsed); |
|
| 183 | 177 |
} |
| 184 | 178 |
|
| 185 | 179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
big change to SharedPreferences: make all the values in RubikScores save their preferences just-in-time, and not on the exit of the app.