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

Commit 2b771d94 authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

Make graphical preference for en/disabling GridView

parent 00e1b5d6
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ import it.niedermann.owncloud.notes.util.NoteUtil;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static androidx.preference.PreferenceManager.getDefaultSharedPreferences;
import static it.niedermann.owncloud.notes.branding.BrandingUtil.getSecondaryForegroundColorDependingOnTheme;
import static it.niedermann.owncloud.notes.util.ColorUtil.contrastRatioIsSufficient;
import static it.niedermann.owncloud.notes.util.SSOUtil.askForNewAccount;
@@ -92,7 +93,7 @@ public class NotesListViewActivity extends LockedActivity implements NoteClickLi

    private static final String TAG = NotesListViewActivity.class.getSimpleName();

    public static final boolean FEATURE_TOGGLE_GRID_VIEW = true;
    private boolean gridView = true;

    public static final String CREATED_NOTE = "it.niedermann.owncloud.notes.created_notes";
    public static final String ADAPTER_KEY_RECENT = "recent";
@@ -181,6 +182,8 @@ public class NotesListViewActivity extends LockedActivity implements NoteClickLi

        db = NotesDatabase.getInstance(this);

        gridView = getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_key_gridview), false);

        setupToolbars();
        setupNavigationList(categoryAdapterSelectedItem);
        setupNavigationMenu();
@@ -233,7 +236,7 @@ public class NotesListViewActivity extends LockedActivity implements NoteClickLi
            try {
                BrandingUtil.saveBrandColors(this, localAccount.getColor(), localAccount.getTextColor());
                ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(getApplicationContext());
                new NotesListViewItemTouchHelper(ssoAccount, this, db, adapter, syncCallBack, this::refreshLists, swipeRefreshLayout, this, FEATURE_TOGGLE_GRID_VIEW)
                new NotesListViewItemTouchHelper(ssoAccount, this, db, adapter, syncCallBack, this::refreshLists, swipeRefreshLayout, this, gridView)
                        .attachToRecyclerView(listView);
                synchronize();
            } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
@@ -594,13 +597,13 @@ public class NotesListViewActivity extends LockedActivity implements NoteClickLi
    }

    private void initList() {
        adapter = new ItemAdapter(this, FEATURE_TOGGLE_GRID_VIEW);
        adapter = new ItemAdapter(this, gridView);
        listView.setAdapter(adapter);

        final DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        int spanCount = (int) ((displayMetrics.widthPixels / displayMetrics.density) / getResources().getInteger(R.integer.max_dp_grid_view));
        listView.setLayoutManager(
                FEATURE_TOGGLE_GRID_VIEW
                gridView
                        ? new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL)
                        : new LinearLayoutManager(this)
        );
+14 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
    private BrandedSwitchPreference lockPref;
    private BrandedSwitchPreference wifiOnlyPref;
    private BrandedSwitchPreference brandingPref;
    private BrandedSwitchPreference gridViewPref;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -56,6 +57,18 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
            Log.e(TAG, "Could not find preference with key: \"" + getString(R.string.pref_key_branding) + "\"");
        }

        gridViewPref = findPreference(getString(R.string.pref_key_gridview));
        if (gridViewPref != null) {
            gridViewPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
                final Boolean gridView = (Boolean) newValue;
                Log.v(TAG, "gridView: " + gridView);
                requireActivity().setResult(Activity.RESULT_OK);
                return true;
            });
        } else {
            Log.e(TAG, "Could not find preference with key: \"" + getString(R.string.pref_key_branding) + "\"");
        }

        lockPref = findPreference(getString(R.string.pref_key_lock));
        if (lockPref != null) {
            if (!DeviceCredentialUtil.areCredentialsAvailable(requireContext())) {
@@ -119,5 +132,6 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
        lockPref.applyBrand(mainColor, textColor);
        wifiOnlyPref.applyBrand(mainColor, textColor);
        brandingPref.applyBrand(mainColor, textColor);
        gridViewPref.applyBrand(mainColor, textColor);
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ public class BrandingUtil {

    }


    public static boolean isBrandingEnabled(@NonNull Context context) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        return prefs.getBoolean(context.getString(R.string.pref_key_branding), true);
+5 −0
Original line number Diff line number Diff line
<vector android:autoMirrored="true" android:height="24dp"
    android:tint="#757575" android:viewportHeight="24"
    android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="@android:color/white" android:pathData="M3,13h8L11,3L3,3v10zM3,21h8v-6L3,15v6zM13,21h8L21,11h-8v10zM13,3v6h8L21,3h-8z"/>
</vector>
+2 −0
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@
    <string name="pref_key_theme" translatable="false">darkTheme</string>
    <string name="pref_key_font" translatable="false">font</string>
    <string name="pref_key_branding" translatable="false">branding</string>
    <string name="pref_key_gridview" translatable="false">gridview</string>
    <string name="pref_key_font_size" translatable="false">fontSize</string>
    <string name="pref_key_wifi_only" translatable="false">wifiOnly</string>
    <string name="pref_key_lock" translatable="false">lock</string>
@@ -191,6 +192,7 @@
    <string name="shared_text_empty">Shared text was empty</string>
    <string name="append_to_note">Append to note</string>
    <string name="settings_branding">Branding</string>
    <string name="settings_gridview">Grid view</string>
    <string name="simple_security">Security</string>
    <string name="simple_appearance">Appearance</string>
    <string name="simple_synchronization">Synchronization</string>
Loading