diff --git a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java index f872aac3..2dcd99ec 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java @@ -3,28 +3,28 @@ package it.niedermann.owncloud.notes.preferences; import android.os.Bundle; import androidx.annotation.Nullable; +import androidx.lifecycle.ViewModelProvider; import it.niedermann.owncloud.notes.LockedActivity; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ActivityPreferencesBinding; -/** - * Allows to change application settings. - */ - public class PreferencesActivity extends LockedActivity { + private PreferencesViewModel viewModel; private ActivityPreferencesBinding binding; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + viewModel = new ViewModelProvider(this).get(PreferencesViewModel.class); + viewModel.resultCode$.observe(this, this::setResult); + binding = ActivityPreferencesBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); setSupportActionBar(binding.toolbar); - setResult(RESULT_CANCELED); getSupportFragmentManager().beginTransaction() .replace(R.id.fragment_container_view, new PreferencesFragment()) .commit(); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesFragment.java index e67aab4e..a38fd56c 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesFragment.java @@ -8,6 +8,7 @@ import android.util.Log; import androidx.annotation.ColorInt; import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; +import androidx.lifecycle.ViewModelProvider; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; @@ -24,6 +25,8 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra private static final String TAG = PreferencesFragment.class.getSimpleName(); + private PreferencesViewModel viewModel; + private BrandedSwitchPreference fontPref; private BrandedSwitchPreference lockPref; private BrandedSwitchPreference wifiOnlyPref; @@ -31,15 +34,12 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra private BrandedSwitchPreference preventScreenCapturePref; private BrandedSwitchPreference backgroundSyncPref; - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.preferences); + viewModel = new ViewModelProvider(requireActivity()).get(PreferencesViewModel.class); + fontPref = findPreference(getString(R.string.pref_key_font)); gridViewPref = findPreference(getString(R.string.pref_key_gridview)); @@ -47,7 +47,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra gridViewPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { final Boolean gridView = (Boolean) newValue; Log.v(TAG, "gridView: " + gridView); - requireActivity().setResult(Activity.RESULT_OK); + viewModel.resultCode$.setValue(Activity.RESULT_OK); NotesApplication.updateGridViewEnabled(gridView); return true; }); @@ -78,7 +78,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra assert themePref != null; themePref.setOnPreferenceChangeListener((preference, newValue) -> { NotesApplication.setAppTheme(DarkModeSetting.valueOf((String) newValue)); - requireActivity().setResult(Activity.RESULT_OK); + viewModel.resultCode$.setValue(Activity.RESULT_OK); ActivityCompat.recreate(requireActivity()); return true; }); @@ -114,6 +114,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra /** * Change color for backgroundSyncPref as well * https://github.com/stefan-niedermann/nextcloud-deck/issues/531 + * * @param mainColor color of main brand * @param textColor color of text */ diff --git a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesViewModel.java b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesViewModel.java new file mode 100644 index 00000000..dfde6c92 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesViewModel.java @@ -0,0 +1,9 @@ +package it.niedermann.owncloud.notes.preferences; + +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; + +public class PreferencesViewModel extends ViewModel { + + public final MutableLiveData resultCode$ = new MutableLiveData<>(); +} diff --git a/fastlane/metadata/android/en-US/changelogs/3004011.txt b/fastlane/metadata/android/en-US/changelogs/3004011.txt index 0c1f8eb0..5af56e89 100644 --- a/fastlane/metadata/android/en-US/changelogs/3004011.txt +++ b/fastlane/metadata/android/en-US/changelogs/3004011.txt @@ -1,2 +1,3 @@ - ✅ Checkboxes using an uppercase X can not be toggled (#1276) -- 🐞 Search field does not immediately focus (#1282) \ No newline at end of file +- 🐞 Search field does not immediately focus (#1282) +- 🐞 Change grid view option not always applied directly (#1254) \ No newline at end of file