Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0925290e authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

Fix #1254 🐞 Change grid view option not always applied directly

parent 632804ce
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -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();
+8 −7
Original line number Diff line number Diff line
@@ -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
     */
+9 −0
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.preferences;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class PreferencesViewModel extends ViewModel {

    public final MutableLiveData<Integer> resultCode$ = new MutableLiveData<>();
}
+2 −1
Original line number Diff line number Diff line
- ✅ Checkboxes using an uppercase X can not be toggled (#1276)
- 🐞 Search field does not immediately focus (#1282)
- 🐞 Change grid view option not always applied directly (#1254)
 No newline at end of file