Skip to content

Commit

Permalink
Fix some minor code smells and let auto save run the whole time
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Dec 14, 2024
1 parent 4dd719e commit d07e010
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
30 changes: 18 additions & 12 deletions src/main/java/de/blau/android/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -199,15 +198,20 @@ 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;

@Override
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);
}
Expand All @@ -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
Expand All @@ -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
*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/de/blau/android/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d07e010

Please sign in to comment.