commit 814934023f2a4477f722d2ec3b6e4dd5642c5592
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Mar 31 22:48:14 2022 +0200

    delete icon, object and extras files from local storage when:
    
    1) we delete a locally produced bandaged 3x3
    2) it turns out that a downloaded object is already built-in (which can happen if we download an object and then upgrade to app version which builts it in)

diff --git a/src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java b/src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java
index 1877793e..f3c0e642 100644
--- a/src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java
+++ b/src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java
@@ -34,6 +34,7 @@ import androidx.appcompat.app.AppCompatActivity;
 import com.google.firebase.analytics.FirebaseAnalytics;
 
 import org.distorted.dialogs.RubikDialogError;
+import org.distorted.external.RubikFiles;
 import org.distorted.library.main.DistortedLibrary;
 import org.distorted.main.R;
 import org.distorted.main.RubikActivity;
@@ -266,6 +267,10 @@ public class BandagedCreatorActivity extends AppCompatActivity
     public void deleteObject(String name)
       {
       mScreen.deleteObject(this,name);
+
+      RubikFiles files = RubikFiles.getInstance();
+      files.deleteIcon(this,name);
+      files.deleteJsonObject(this,name);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java b/src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java
index a54b94ea..80e56864 100644
--- a/src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java
+++ b/src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java
@@ -222,7 +222,8 @@ public class RubikDialogUpdateView implements RubikNetwork.Downloadee
 
         if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "1");
 
-        RubikObjectList.addDownloadedObject(mInfo.mObjectShortName,mInfo.mNumScrambles, mInfo.mObjectMinorVersion,
+        Activity act = mAct.get();
+        RubikObjectList.addDownloadedObject(act, mInfo.mObjectShortName,mInfo.mNumScrambles, mInfo.mObjectMinorVersion,
                                             mInfo.mExtrasMinorVersion, mIconSaved, oSuccess, eSuccess);
 
         if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "2");
diff --git a/src/main/java/org/distorted/external/RubikFiles.java b/src/main/java/org/distorted/external/RubikFiles.java
index cf9bdf88..d2c036f9 100644
--- a/src/main/java/org/distorted/external/RubikFiles.java
+++ b/src/main/java/org/distorted/external/RubikFiles.java
@@ -133,4 +133,34 @@ public class RubikFiles
       return false;
       }
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void deleteIcon(Context context, String name)
+    {
+    String filename = name.toLowerCase() + ".png";
+    boolean success = context.deleteFile(filename);
+    if( !success ) android.util.Log.e("D", "failed to delete "+filename);
+    else android.util.Log.e("D", "successfully deleted "+filename);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void deleteJsonObject(Context context, String name)
+    {
+    String filename = name.toLowerCase() + "_object.json";
+    boolean success = context.deleteFile(filename);
+    if( !success ) android.util.Log.e("D", "failed to delete "+filename);
+    else android.util.Log.e("D", "successfully deleted "+filename);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void deleteJsonExtras(Context context, String name)
+    {
+    String filename = name.toLowerCase() + "_extras.json";
+    boolean success = context.deleteFile(filename);
+    if( !success ) android.util.Log.e("D", "failed to delete "+filename);
+    else android.util.Log.e("D", "successfully deleted "+filename);
+    }
   }
diff --git a/src/main/java/org/distorted/main/RubikActivity.java b/src/main/java/org/distorted/main/RubikActivity.java
index 3a2e92b0..ac0abde3 100644
--- a/src/main/java/org/distorted/main/RubikActivity.java
+++ b/src/main/java/org/distorted/main/RubikActivity.java
@@ -329,7 +329,7 @@ public class RubikActivity extends AppCompatActivity
       mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
       String oldVersion = preferences.getString("appVersion","");
 
-      RubikObjectList.restorePreferences(preferences);
+      RubikObjectList.restorePreferences(this,preferences);
 
       for (int i=0; i< BaseEffect.Type.LENGTH; i++)
         {
diff --git a/src/main/java/org/distorted/objects/RubikObjectList.java b/src/main/java/org/distorted/objects/RubikObjectList.java
index b5009376..6ecf2aa6 100644
--- a/src/main/java/org/distorted/objects/RubikObjectList.java
+++ b/src/main/java/org/distorted/objects/RubikObjectList.java
@@ -21,8 +21,10 @@ package org.distorted.objects;
 
 import java.util.ArrayList;
 
+import android.content.Context;
 import android.content.SharedPreferences;
 
+import org.distorted.external.RubikFiles;
 import org.distorted.main.RubikActivity;
 import org.distorted.objectlib.main.ObjectSignatures;
 import org.distorted.objectlib.main.ObjectType;
@@ -196,8 +198,8 @@ public class RubikObjectList
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public static void addDownloadedObject(String shortName, int numScrambles, int objectMinor, int extrasMinor,
-                                         boolean icon, boolean object, boolean extras)
+  public static void addDownloadedObject(Context context, String shortName, int numScrambles, int objectMinor,
+                                         int extrasMinor, boolean icon, boolean object, boolean extras)
     {
     if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "New downloaded object "+shortName+" icon="+icon+" object="+object+" extras="+extras);
 
@@ -230,6 +232,15 @@ public class RubikObjectList
       if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "Adding new downloaded object "+shortName+" icon="+obj.icon+" object="+obj.object+" extras="+obj.extras);
       mDownloadedObjects.add(obj);
       }
+    else
+      {
+      if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "New downloaded object "+shortName+" is already built-in, deleting");
+
+      RubikFiles files = RubikFiles.getInstance();
+      files.deleteIcon(context,shortName);
+      files.deleteJsonObject(context,shortName);
+      files.deleteJsonExtras(context,shortName);
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -304,7 +315,7 @@ public class RubikObjectList
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public static void restorePreferences(SharedPreferences preferences)
+  public static void restorePreferences(Context context, SharedPreferences preferences)
     {
     if( mThis==null ) mThis = new RubikObjectList();
 
@@ -338,7 +349,7 @@ public class RubikObjectList
           boolean bObje = obje.equals("1");
           boolean bExtr = extr.equals("1");
 
-          addDownloadedObject(name,scrambles,oMinor,eMinor,bIcon,bObje,bExtr);
+          addDownloadedObject(context,name,scrambles,oMinor,eMinor,bIcon,bObje,bExtr);
           }
         }
       }
