diff --git a/src/main/java/de/blau/android/App.java b/src/main/java/de/blau/android/App.java index d818e67e0..54d079e4b 100644 --- a/src/main/java/de/blau/android/App.java +++ b/src/main/java/de/blau/android/App.java @@ -8,7 +8,6 @@ import java.io.OutputStream; import java.util.Random; import java.util.TreeMap; -import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -199,7 +198,6 @@ public class App extends Application implements android.app.Application.Activity private static boolean propertyEditorRunning; private ScheduledThreadPoolExecutor autosaveExecutor = new ScheduledThreadPoolExecutor(1); - private ScheduledFuture autosaveFuture = null; private static FSTConfiguration singletonConf; @@ -207,7 +205,13 @@ public class App extends Application implements android.app.Application.Activity protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); + setupFST(); + } + /** + * Setup the FST singleton + */ + private static void setupFST() { singletonConf = FSTConfiguration.createAndroidDefaultConfiguration(); singletonConf.registerSerializer(TreeMap.class, new FSTMapSerializer(), true); } @@ -217,10 +221,7 @@ public void onCreate() { ACRA.init(this); super.onCreate(); registerActivityLifecycleCallbacks(this); - String appName = getString(R.string.app_name); - String appVersion = getString(R.string.app_version); - userAgent = appName + "/" + appVersion; - currentInstance = this; + setupMisc(this); setConfiguration(getResources().getConfiguration()); // register a broadcast receiver for DeX mode // this will remain registered as long as the @@ -234,6 +235,16 @@ public void onCreate() { } } + /** + * Setup misc singletons + */ + private static void setupMisc(@NonNull App app) { + String appName = app.getString(R.string.app_name); + String appVersion = app.getString(R.string.app_version); + userAgent = appName + "/" + appVersion; + currentInstance = app; + } + /** * Retrieve the saved Configuration object * @@ -850,7 +861,7 @@ private void startAutosave() { final int interval = prefs.getInt(getString(R.string.config_autosaveInterval_key), 5); final int changes = prefs.getInt(getString(R.string.config_autosaveChanges_key), 1); final int maxFiles = prefs.getInt(getString(R.string.config_autosaveMaxFiles_key), 5); - autosaveFuture = autosaveExecutor.scheduleAtFixedRate(() -> { + autosaveExecutor.scheduleAtFixedRate(() -> { if (delegator.isDirty() && delegator.getApiElementCount() >= changes) { if (logic != null && saveState) { logic.save(this); @@ -902,11 +913,6 @@ public void onActivityDestroyed(Activity activity) { synchronized (this) { propertyEditorRunning = false; } - return; - } - if (activity instanceof Main && autosaveFuture != null) { - Log.i(DEBUG_TAG, "Cancelling autosave"); - autosaveFuture.cancel(false); } } diff --git a/src/main/java/de/blau/android/Main.java b/src/main/java/de/blau/android/Main.java index c3bbd2c7b..0ed5f431c 100644 --- a/src/main/java/de/blau/android/Main.java +++ b/src/main/java/de/blau/android/Main.java @@ -67,7 +67,6 @@ import android.view.View.OnLongClickListener; import android.view.View.OnTouchListener; import android.view.ViewGroup; -import android.view.ViewParent; import android.view.ViewStub; import android.widget.LinearLayout; import android.widget.RelativeLayout;