summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-05-16 08:26:14 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2024-05-16 12:13:45 +0200
commit3865c81e96432638f3f4cc2ba4eeb481da1c6ebb (patch)
tree9a2d75f51599d999617d3962f2beaf6767728e41 /android
parent4d4c31349468e68a405887050114d2f3da3547c6 (diff)
android: Drop indirection listening to pref change
Let `LibreOfficeMainActivity` implement the standard Android `SharedPreferences.OnSharedPreferenceChangeListener` interface directly, rather than having a custom `SettingsListenerModel.OnSettingsPreferenceChangedListener` indirection and the `SettingsFragment` implementing the standard interface. This simplifies the code and removes one level of indirection. Drop the now unused `SettingsListenerModel`. Change-Id: I8c7d6088e711631409f9189bba966439db3daa44 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167723 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'android')
-rw-r--r--android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java10
-rw-r--r--android/source/src/java/org/libreoffice/SettingsActivity.java21
-rw-r--r--android/source/src/java/org/libreoffice/SettingsListenerModel.java56
3 files changed, 8 insertions, 79 deletions
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 315656b6ef7e..8bacb3f0df72 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -57,7 +57,7 @@ import java.util.UUID;
/**
* Main activity of the LibreOffice App. It is started in the UI thread.
*/
-public class LibreOfficeMainActivity extends AppCompatActivity implements SettingsListenerModel.OnSettingsPreferenceChangedListener {
+public class LibreOfficeMainActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String LOGTAG = "LibreOfficeMainActivity";
public static final String ENABLE_EXPERIMENTAL_PREFS_KEY = "ENABLE_EXPERIMENTAL";
@@ -125,8 +125,9 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
Log.w(LOGTAG, "onCreate..");
super.onCreate(savedInstanceState);
- SettingsListenerModel.getInstance().setListener(this);
updatePreferences();
+ PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
+ .registerOnSharedPreferenceChangeListener(this);
setContentView(R.layout.activity_main);
@@ -492,6 +493,9 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
@Override
protected void onDestroy() {
Log.i(LOGTAG, "onDestroy..");
+ PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
+ .unregisterOnSharedPreferenceChangeListener(this);
+
LOKitShell.sendCloseEvent();
mLayerClient.destroy();
super.onDestroy();
@@ -842,7 +846,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
}
@Override
- public void settingsPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.matches(ENABLE_EXPERIMENTAL_PREFS_KEY)) {
Log.d(LOGTAG, "Editing Preference Changed");
mIsExperimentalMode = sharedPreferences.getBoolean(ENABLE_EXPERIMENTAL_PREFS_KEY, false);
diff --git a/android/source/src/java/org/libreoffice/SettingsActivity.java b/android/source/src/java/org/libreoffice/SettingsActivity.java
index 90d3f95459e4..39102aee5a0f 100644
--- a/android/source/src/java/org/libreoffice/SettingsActivity.java
+++ b/android/source/src/java/org/libreoffice/SettingsActivity.java
@@ -25,7 +25,7 @@ public class SettingsActivity extends FragmentActivity {
.commit();
}
- public static class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
+ public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@@ -41,25 +41,6 @@ public class SettingsActivity extends FragmentActivity {
generalGroup.removePreference(generalGroup.findPreference("ENABLE_DEVELOPER"));
}
}
-
- @Override
- public void onResume() {
- super.onResume();
- getPreferenceScreen().getSharedPreferences()
- .registerOnSharedPreferenceChangeListener(this);
- }
-
- @Override
- public void onPause() {
- super.onPause();
- getPreferenceScreen().getSharedPreferences()
- .unregisterOnSharedPreferenceChangeListener(this);
- }
-
- @Override
- public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- SettingsListenerModel.getInstance().changePreferenceState(sharedPreferences, key);
- }
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/source/src/java/org/libreoffice/SettingsListenerModel.java b/android/source/src/java/org/libreoffice/SettingsListenerModel.java
deleted file mode 100644
index 1b5a909e1e65..000000000000
--- a/android/source/src/java/org/libreoffice/SettingsListenerModel.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- *
- * * This file is part of the LibreOffice project.
- * * This Source Code Form is subject to the terms of the Mozilla Public
- * * License, v. 2.0. If a copy of the MPL was not distributed with this
- * * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- */
-package org.libreoffice;
-
-import android.content.SharedPreferences;
-
-public class SettingsListenerModel {
-
- public interface OnSettingsPreferenceChangedListener {
- void settingsPreferenceChanged(SharedPreferences sharedPreferences, String key);
- }
-
- private static SettingsListenerModel mInstance;
- private OnSettingsPreferenceChangedListener mListener;
- private SharedPreferences sharedPreferences;
- private String key;
-
- private SettingsListenerModel() {}
-
- public static SettingsListenerModel getInstance() {
- if(mInstance == null) {
- mInstance = new SettingsListenerModel();
- }
- return mInstance;
- }
-
- public void setListener(OnSettingsPreferenceChangedListener listener) {
- mListener = listener;
- }
-
- public void changePreferenceState(SharedPreferences sharedPreferences, String key) {
- if(mListener != null) {
- this.sharedPreferences = sharedPreferences;
- this.key = key;
- notifyPreferenceChange(sharedPreferences, key);
- }
- }
-
- public SharedPreferences getSharedPreferences() {
- return sharedPreferences;
- }
-
- public String getKey(){
- return key;
- }
-
- private void notifyPreferenceChange(SharedPreferences preferences, String key) {
- mListener.settingsPreferenceChanged(preferences, key);
- }
-}