diff options
5 files changed, 90 insertions, 44 deletions
diff --git a/android/source/res/menu/view_menu.xml b/android/source/res/menu/view_menu.xml index fe28da2cf701..3c0003b96fe0 100644 --- a/android/source/res/menu/view_menu.xml +++ b/android/source/res/menu/view_menu.xml @@ -7,24 +7,15 @@ android:title="@string/sort" android:icon="@drawable/ic_sort_black_24dp" app:showAsAction="ifRoom"> - <menu> - <item android:id="@+id/menu_sort_size" android:title="@string/menu_sort_size" /> <item android:id="@+id/menu_sort_az" android:title="@string/menu_sort_az"/> <item android:id="@+id/menu_sort_modified" android:title="@string/menu_sort_modified"/> - - </menu> - </item> - - <item android:id="@+id/menu_view_toggle" - android:title="@string/grid_view"/> - <item android:id="@+id/menu_storage_preferences" android:title="@string/storage_provider_settings"/> <item android:id="@+id/action_about" diff --git a/android/source/res/xml/libreoffice_preferences.xml b/android/source/res/xml/libreoffice_preferences.xml index 17256b74b870..4d80f2815cf3 100644 --- a/android/source/res/xml/libreoffice_preferences.xml +++ b/android/source/res/xml/libreoffice_preferences.xml @@ -18,7 +18,7 @@ android:entryValues="@array/ViewModeStringValues" android:title="Default File Explorer View" android:key="EXPLORER_VIEW_TYPE" - android:summary="View files as a grid or in a list. #not functional, yet."/> + android:summary="View files as a grid or in a list."/> </PreferenceCategory> <PreferenceCategory android:title="@string/pref_category_general" diff --git a/android/source/src/java/org/libreoffice/SettingsActivity.java b/android/source/src/java/org/libreoffice/SettingsActivity.java index c453798a108a..4ef7277d7d53 100644 --- a/android/source/src/java/org/libreoffice/SettingsActivity.java +++ b/android/source/src/java/org/libreoffice/SettingsActivity.java @@ -9,11 +9,10 @@ package org.libreoffice; import android.app.Activity; +import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceFragment; -import org.libreoffice.R; - public class SettingsActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { @@ -25,13 +24,31 @@ public class SettingsActivity extends Activity { .commit(); } - public static class SettingsFragment extends PreferenceFragment { + public static class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.libreoffice_preferences); } + + @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 new file mode 100644 index 000000000000..1b5a909e1e65 --- /dev/null +++ b/android/source/src/java/org/libreoffice/SettingsListenerModel.java @@ -0,0 +1,56 @@ +/* + * + * * 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); + } +} diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index c842abcc55e2..47207853d916 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -54,6 +54,7 @@ import org.libreoffice.AboutDialogFragment; import org.libreoffice.LibreOfficeMainActivity; import org.libreoffice.R; import org.libreoffice.SettingsActivity; +import org.libreoffice.SettingsListenerModel; import org.libreoffice.storage.DocumentProviderFactory; import org.libreoffice.storage.DocumentProviderSettingsActivity; import org.libreoffice.storage.IDocumentProvider; @@ -72,8 +73,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -public class LibreOfficeUIActivity extends AppCompatActivity { - private static final String LOGTAG = LibreOfficeUIActivity.class.getSimpleName(); +public class LibreOfficeUIActivity extends AppCompatActivity implements SettingsListenerModel.OnSettingsPreferenceChangedListener{ + private String LOGTAG = LibreOfficeUIActivity.class.getSimpleName(); private SharedPreferences prefs; private int filterMode = FileUtilities.ALL; private int viewMode; @@ -116,9 +117,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity { documentProviderFactory = DocumentProviderFactory.getInstance(); PreferenceManager.setDefaultValues(this, R.xml.documentprovider_preferences, false); - readPreferences(); - + SettingsListenerModel.getInstance().setListener(this); // init UI and populate with contents from the provider switchToDocumentProvider(documentProviderFactory.getDefaultProvider()); createUI(); @@ -523,16 +523,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.view_menu, menu); - MenuItem item = menu.findItem(R.id.menu_view_toggle); - if (viewMode == GRID_VIEW) { - item.setTitle(R.string.list_view); - item.setIcon(R.drawable.light_view_as_list); - } else { - item.setTitle(R.string.grid_view); - item.setIcon(R.drawable.light_view_as_grid); - } - - item = menu.findItem(R.id.menu_sort_size); + MenuItem item = menu.findItem(R.id.menu_sort_size); if (sortMode == FileUtilities.SORT_LARGEST) { item.setTitle(R.string.sort_smallest); } else { @@ -569,20 +560,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity { openParentDirectory(); } break; - case R.id.menu_view_toggle: - if (viewMode == GRID_VIEW){ - viewMode = LIST_VIEW; - item.setTitle(R.string.grid_view); // Button points to next view. - item.setIcon(R.drawable.light_view_as_grid); - prefs.edit().putInt(EXPLORER_VIEW_TYPE_KEY, LIST_VIEW).apply(); - } else { - viewMode = GRID_VIEW; - item.setTitle(R.string.list_view); // Button points to next view. - item.setIcon(R.drawable.light_view_as_list); - prefs.edit().putInt(EXPLORER_VIEW_TYPE_KEY, GRID_VIEW).apply(); - } - createUI(); - break; case R.id.menu_sort_size: case R.id.menu_sort_az: case R.id.menu_sort_modified: @@ -643,9 +620,9 @@ public class LibreOfficeUIActivity extends AppCompatActivity { public void readPreferences(){ prefs = getSharedPreferences(EXPLORER_PREFS_KEY, MODE_PRIVATE); - viewMode = prefs.getInt(EXPLORER_VIEW_TYPE_KEY, GRID_VIEW); sortMode = prefs.getInt(SORT_MODE_KEY, FileUtilities.SORT_AZ); SharedPreferences defaultPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); + viewMode = Integer.valueOf(defaultPrefs.getString(EXPLORER_VIEW_TYPE_KEY, ""+ GRID_VIEW)); filterMode = Integer.valueOf(defaultPrefs.getString(FILTER_MODE_KEY , "-1")); Intent i = this.getIntent(); @@ -671,6 +648,12 @@ public class LibreOfficeUIActivity extends AppCompatActivity { } @Override + public void settingsPreferenceChanged(SharedPreferences sharedPreferences, String key) { + readPreferences(); + refreshView(); + } + + @Override protected void onSaveInstanceState(Bundle outState) { // TODO Auto-generated method stub super.onSaveInstanceState(outState); @@ -711,7 +694,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity { @Override protected void onPause() { - //prefs.edit().putInt(EXPLORER_VIEW_TYPE, viewType).commit(); super.onPause(); Log.d(LOGTAG, "onPause"); } |