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

Commit f07da5f8 authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski
Browse files

Follow up for disabling creating archives in resources.

Test: Unit tests.
Bug: 35403496
Change-Id: I88555dadf37cbbbacd78f59d8cfa25688680338d
parent 9ed50758
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
    <string name="trusted_quick_viewer_package" translatable="false"></string>

    <bool name="show_documents_root">false</bool>
    <bool name="enable_compressing">false</bool>
    <bool name="enable_archive_creation">false</bool>

    <!-- Indicates if search view is taking the whole toolbar space. On larger
         layouts we reduce this to an input-box adjacent to menu actions. -->
+0 −7
Original line number Diff line number Diff line
@@ -251,13 +251,6 @@ public final class Shared {
        return context.getResources().getBoolean(R.bool.show_documents_root);
    }

    /**
     * Returns true if compressing is enabled.
     */
    public static boolean isCompressingEnabled(Context context) {
        return context.getResources().getBoolean(R.bool.enable_compressing);
    }

    /*
     * Returns true if the local/device storage root must be visible (this also hides
     * the option to toggle visibility in the menu.)
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ public class FilesActivity extends BaseActivity implements ActionHandler.Addons
            getColor(R.color.accent_dark));

        mInjector.menuManager = new MenuManager(
                this,
                mInjector.prefs,
                mSearchManager,
                mState,
                new DirectoryDetails(this) {
+5 −5
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.documentsui.files;

import android.app.Fragment;
import android.content.Context;
import android.view.KeyEvent;
import android.view.KeyboardShortcutGroup;
import android.view.KeyboardShortcutInfo;
@@ -31,21 +30,22 @@ import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.Shared;
import com.android.documentsui.base.State;
import com.android.documentsui.prefs.ScopedPreferences;
import com.android.documentsui.queries.SearchViewManager;

import java.util.List;
import java.util.function.IntFunction;

public final class MenuManager extends com.android.documentsui.MenuManager {
    private final Context mContext;
    private final ScopedPreferences mPreferences;

    public MenuManager(
            Context context,
            ScopedPreferences preferences,
            SearchViewManager searchManager,
            State displayState,
            DirectoryDetails dirDetails) {
        super(searchManager, displayState, dirDetails);
        mContext = context;
        mPreferences = preferences;
    }

    @Override
@@ -180,7 +180,7 @@ public final class MenuManager extends com.android.documentsui.MenuManager {
    @Override
    protected void updateCompress(MenuItem compress, SelectionDetails selectionDetails) {
        final boolean readOnly = !mDirDetails.canCreateDoc();
        compress.setVisible(Shared.isCompressingEnabled(mContext));
        compress.setVisible(mPreferences.getEnableArchiveCreation());
        compress.setEnabled(!readOnly && !selectionDetails.containsPartialFiles() &&
                !selectionDetails.canExtract());
    }
+23 −2
Original line number Diff line number Diff line
@@ -17,9 +17,12 @@ package com.android.documentsui.prefs;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.text.TextUtils;

import com.android.documentsui.R;

/**
 * Provides an interface (and runtime implementation) for preferences that are
 * scoped (presumably to an activity). This eliminates the need to pass
@@ -29,27 +32,34 @@ import android.text.TextUtils;
public interface ScopedPreferences {

    static final String INCLUDE_DEVICE_ROOT = "includeDeviceRoot-";
    static final String ENABLE_ARCHIVE_CREATION = "enableArchiveCreation-";

    boolean getShowDeviceRoot();
    void setShowDeviceRoot(boolean display);

    boolean getEnableArchiveCreation();
    void setEnableArchiveCreation(boolean enabled);

    /**
     * @param scope An arbitrary string representitive of the scope
     *        for prefs that are set using this object.
     */
    public static ScopedPreferences create(Context context, String scope) {
        return new RuntimeScopedPreferences(
        return new RuntimeScopedPreferences(context.getResources(),
                PreferenceManager.getDefaultSharedPreferences(context), scope);
    }

    static final class RuntimeScopedPreferences implements ScopedPreferences {

        private Resources mResources;
        private SharedPreferences mSharedPrefs;
        private String mScope;

        private RuntimeScopedPreferences(SharedPreferences sharedPrefs, String scope)  {
        private RuntimeScopedPreferences(Resources resources, SharedPreferences sharedPrefs,
                String scope)  {
            assert(!TextUtils.isEmpty(scope));

            mResources = resources;
            mSharedPrefs = sharedPrefs;
            mScope = scope;
        }
@@ -63,6 +73,17 @@ public interface ScopedPreferences {
        public void setShowDeviceRoot(boolean display) {
            mSharedPrefs.edit().putBoolean(INCLUDE_DEVICE_ROOT + mScope, display).apply();
        }

        @Override
        public boolean getEnableArchiveCreation() {
            final boolean defaultValue = mResources.getBoolean(R.bool.enable_archive_creation);
            return mSharedPrefs.getBoolean(ENABLE_ARCHIVE_CREATION + mScope, defaultValue);
        }

        @Override
        public void setEnableArchiveCreation(boolean enabled) {
            mSharedPrefs.edit().putBoolean(ENABLE_ARCHIVE_CREATION + mScope, enabled).apply();
        }
    }

    static boolean shouldBackup(String s) {
Loading