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

Commit 2bba6ac2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add visibility control for the UiBlocker" into tm-dev am: a3872976

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/17119094

Change-Id: Ie0493ba0da7865dcbc4fe9cd1b20e079664d7781
parents 47f05534 a3872976
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -121,10 +121,13 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl

    protected final String mPreferenceKey;
    protected UiBlockListener mUiBlockListener;
    protected boolean mUiBlockerFinished;
    private boolean mIsForWork;
    @Nullable
    private UserHandle mWorkProfileUser;
    private int mMetricsCategory;
    private boolean mIsFirstLaunch;
    private boolean mPrefVisibility;

    /**
     * Instantiate a controller as specified controller type and user-defined key.
@@ -195,6 +198,8 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
    public BasePreferenceController(Context context, String preferenceKey) {
        super(context);
        mPreferenceKey = preferenceKey;
        mIsFirstLaunch = true;
        mPrefVisibility = true;
        if (TextUtils.isEmpty(mPreferenceKey)) {
            throw new IllegalArgumentException("Preference key must be set");
        }
@@ -326,6 +331,13 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
        }
    }

    /**
     * Set back the value of whether this is the first launch.
     */
    public void revokeFirstLaunch() {
        mIsFirstLaunch = false;
    }

    /**
     * Launches the specified fragment for the work profile user if the associated
     * {@link Preference} is clicked.  Otherwise just forward it to the super class.
@@ -378,6 +390,14 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
        mUiBlockListener = uiBlockListener;
    }

    public void setUiBlockerFinished(boolean isFinished) {
        mUiBlockerFinished = isFinished;
    }

    public boolean getSavedPrefVisibility() {
        return mPrefVisibility;
    }

    /**
     * Listener to invoke when background job is finished
     */
@@ -428,4 +448,28 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
    protected UserHandle getWorkProfileUser() {
        return mWorkProfileUser;
    }

    /**
     * Used for {@link BasePreferenceController} that implements {@link UiBlocker} to control the
     * preference visibility.
     */
    protected void updatePreferenceVisibilityDelegate(Preference preference, boolean isVisible) {
        if (mUiBlockerFinished || !mIsFirstLaunch) {
            preference.setVisible(isVisible);
            return;
        }

        savePrefVisibility(isVisible);

        // Preferences that should be invisible have a high priority to be updated since the
        // whole UI should be blocked/invisible. While those that should be visible will be
        // updated once the blocker work is finished. That's done in DashboardFragment.
        if (!isVisible) {
            preference.setVisible(false);
        }
    }

    private void savePrefVisibility(boolean isVisible) {
        mPrefVisibility = isVisible;
    }
}
+14 −1
Original line number Diff line number Diff line
@@ -250,6 +250,11 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
            }
            mListeningToCategoryChange = false;
        }
        mControllers.forEach(controller -> {
            if (controller instanceof BasePreferenceController.UiBlocker) {
                ((BasePreferenceController) controller).revokeFirstLaunch();
            }
        });
    }

    @Override
@@ -424,7 +429,14 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
            for (AbstractPreferenceController controller : controllerList) {
                final String key = controller.getPreferenceKey();
                final Preference preference = findPreference(key);
                if (preference != null) {
                if (preference == null) {
                    continue;
                }
                if (controller instanceof BasePreferenceController.UiBlocker) {
                    final boolean prefVisible =
                            ((BasePreferenceController) controller).getSavedPrefVisibility();
                    preference.setVisible(visible && controller.isAvailable() && prefVisible);
                } else {
                    preference.setVisible(visible && controller.isAvailable());
                }
            }
@@ -496,6 +508,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
    @Override
    public void onBlockerWorkFinished(BasePreferenceController controller) {
        mBlockerController.countDown(controller.getPreferenceKey());
        controller.setUiBlockerFinished(mBlockerController.isBlockerFinished());
    }

    protected Preference createPreference(Tile tile) {
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit;
 */
public class UiBlockerController {
    private static final String TAG = "UiBlockerController";
    private static final int TIMEOUT_MILLIS = 500;
    private static final int TIMEOUT_MILLIS = 300;

    private CountDownLatch mCountDownLatch;
    private boolean mBlockerFinished;