Project

General

Profile

« Previous | Next » 

Revision c020555e

Added by Leszek Koltunski over 2 years ago

Do not crash when something's wrong with the JSON file - handle this gracefully, do not change the object then, and report this to Firebase.

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java
292 292
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
293 293
        SharedPreferences.Editor editor = preferences.edit();
294 294
        TwistyObject object = new TwistyJson( jsonStream, meshState, iconMode, null, null, 1.0f, null);
295
        object.removePreferences(editor);
295
        if( !object.getError() ) object.removePreferences(editor);
296 296
        editor.apply();
297 297
        }
298 298

  
src/main/java/org/distorted/bandaged/BandagedPlayLibInterface.java
50 50
  public void onObjectCreated(long time) { }
51 51
  public void onReplaceModeDown(int cubit, int face) { }
52 52
  public void onReplaceModeUp() { }
53
  public void reportJSONError(String error, int ordinal) { }
53 54

  
54 55
///////////////////////////////////////////////////////////////////////////////////////////////////
55 56

  
src/main/java/org/distorted/config/ConfigObjectLibInterface.java
39 39
  public void onReplaceModeUp() { }
40 40
  public void onFinishRotation(int axis, int row, int angle) { }
41 41
  public void failedToDrag() { }
42
  public void reportJSONError(String error, int ordinal) { }
42 43

  
43 44
///////////////////////////////////////////////////////////////////////////////////////////////////
44 45

  
src/main/java/org/distorted/config/ConfigScreenPane.java
78 78

  
79 79
      mObjectOrdinal = objectOrdinal;
80 80
      JsonReader reader = JsonReader.getInstance();
81
      reader.parseJsonFileMetadata(stream);
81
      String name,author;
82
      int year, difficulty;
83

  
84
      try
85
        {
86
        reader.parseJsonFileMetadata(stream);
87
        name       = reader.getObjectName();
88
        author     = reader.getInventor();
89
        year       = reader.getYearOfInvention();
90
        difficulty = reader.getComplexity();
91
        }
92
      catch(Exception ex)
93
        {
94
        name = "?";
95
        author = "?";
96
        year = 0;
97
        difficulty = 0;
98
        }
82 99

  
83
      String name = reader.getObjectName();
84
      String author = reader.getInventor();
85
      int year = reader.getYearOfInvention();
86 100
      String both = year>0 ? author+" "+year : author;
87 101

  
88 102
      LinearLayout layout = act.findViewById(R.id.configLayout);
......
91 105
      view = layout.findViewById(R.id.configDetailsAuthor2);
92 106
      view.setText(both);
93 107

  
94
      int difficulty = reader.getComplexity();
95

  
96 108
      if( difficulty<0          ) difficulty=0;
97 109
      if( difficulty>NUM_IMAGES ) difficulty=NUM_IMAGES;
98 110

  
src/main/java/org/distorted/dialogs/RubikDialogTutorialView.java
77 77

  
78 78
    if( jsonStream!=null )
79 79
      {
80
      JsonReader reader = JsonReader.getInstance();
81
      reader.parseJsonTutorial(jsonStream);
82
      tutorials = reader.getTutorials();
80
      try
81
        {
82
        JsonReader reader = JsonReader.getInstance();
83
        reader.parseJsonTutorial(jsonStream);
84
        tutorials = reader.getTutorials();
85
        }
86
      catch(Exception ex)
87
        {
88
        tutorials = null;
89
        }
83 90
      }
84 91

  
85 92
    if( tutorials!=null )
src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java
201 201

  
202 202
        if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "Saving JSON "+name+" to a file "+oSuccess);
203 203

  
204
        JsonReader reader = JsonReader.getInstance();
205
        mInfo.mNumScrambles = reader.readNumScrambles(act,name);
206

  
207
        if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "Read from JSON numScrambles="+mInfo.mNumScrambles);
204
        try
205
          {
206
          JsonReader reader = JsonReader.getInstance();
207
          mInfo.mNumScrambles = reader.readNumScrambles(act,name);
208
          if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "Read from JSON numScrambles="+mInfo.mNumScrambles);
209
          }
210
        catch(Exception ex)
211
          {
212
          mInfo.mNumScrambles = 25;
213
          if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "Error reading numScrambles");
214
          }
208 215
        }
209 216

  
210 217
      if( mInfo.mExtrasStream!=null )
src/main/java/org/distorted/main/RubikObjectLibInterface.java
436 436
      }
437 437
    }
438 438

  
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440

  
441
  public void reportJSONError(String error, int ordinal)
442
    {
443
    RubikObject object = RubikObjectList.getObject(ordinal);
444
    String name = object==null ? "NULL" : object.getUpperName();
445

  
446
    if( BuildConfig.DEBUG )
447
       {
448
       android.util.Log.e("libInterface", "name="+name+" JSON error: "+error);
449
       }
450
    else
451
      {
452
      Exception ex = new Exception(error);
453
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
454
      crashlytics.setCustomKey("name" , name );
455
      crashlytics.setCustomKey("JSONerror", error );
456
      crashlytics.recordException(ex);
457
      }
458
    }
459

  
439 460
///////////////////////////////////////////////////////////////////////////////////////////////////
440 461

  
441 462
  public void onReplaceModeDown(int cubit, int face)
src/main/java/org/distorted/tutorials/TutorialObjectLibInterface.java
48 48
  public void onObjectCreated(long time) { }
49 49
  public void onReplaceModeDown(int cubit, int face) { }
50 50
  public void onReplaceModeUp() { }
51
  public void reportJSONError(String error, int ordinal) { }
51 52

  
52 53
///////////////////////////////////////////////////////////////////////////////////////////////////
53 54

  

Also available in: Unified diff