Split LauncherPrefs into abs class / impl.
Splitting allows easily making a fake that doesn't have to override the implementation details of LauncherPrefs. The fake should not deal with SharedPreferences. LauncherPrefs could be an interface, but then the companion object has more limitations. The solution there is to have a dedicated object class, e.g. `LauncherPrefItems`. I went with an abs class to make the refactor simpler. Flag: EXEMPT refactor Bug: 369641781 Test: go/testedequals Change-Id: I97a2d495d3b5fa892fa53a11fb3f7a7dfb98515b
This commit is contained in:
1 parent
9dcf307a62
commit
9cbc478574
9 files changed
+251
-185
No files matched your search
@@ -35,7 +35,6 @@ import android.annotation.SuppressLint;
|
||||
import android.content.ComponentCallbacks;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
@@ -51,6 +50,7 @@ import androidx.annotation.UiThread;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.launcher3.InvariantDeviceProfile.DeviceType;
|
||||
import com.android.launcher3.LauncherPrefChangeListener;
|
||||
import com.android.launcher3.LauncherPrefs;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.logging.FileLog;
|
||||
@@ -116,8 +116,7 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable {
|
||||
private Info mInfo;
|
||||
private boolean mDestroyed = false;
|
||||
|
||||
private SharedPreferences.OnSharedPreferenceChangeListener
|
||||
mTaskbarPinningPreferenceChangeListener;
|
||||
private LauncherPrefChangeListener mTaskbarPinningPreferenceChangeListener;
|
||||
|
||||
@VisibleForTesting
|
||||
protected DisplayController(Context context) {
|
||||
@@ -142,19 +141,18 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable {
|
||||
}
|
||||
|
||||
private void attachTaskbarPinningSharedPreferenceChangeListener(Context context) {
|
||||
mTaskbarPinningPreferenceChangeListener =
|
||||
(sharedPreferences, key) -> {
|
||||
LauncherPrefs prefs = LauncherPrefs.get(mContext);
|
||||
boolean isTaskbarPinningChanged = TASKBAR_PINNING_KEY.equals(key)
|
||||
&& mInfo.mIsTaskbarPinned != prefs.get(TASKBAR_PINNING);
|
||||
boolean isTaskbarPinningDesktopModeChanged =
|
||||
TASKBAR_PINNING_DESKTOP_MODE_KEY.equals(key)
|
||||
&& mInfo.mIsTaskbarPinnedInDesktopMode != prefs.get(
|
||||
TASKBAR_PINNING_IN_DESKTOP_MODE);
|
||||
if (isTaskbarPinningChanged || isTaskbarPinningDesktopModeChanged) {
|
||||
notifyConfigChange();
|
||||
}
|
||||
};
|
||||
mTaskbarPinningPreferenceChangeListener = key -> {
|
||||
LauncherPrefs prefs = LauncherPrefs.get(mContext);
|
||||
boolean isTaskbarPinningChanged = TASKBAR_PINNING_KEY.equals(key)
|
||||
&& mInfo.mIsTaskbarPinned != prefs.get(TASKBAR_PINNING);
|
||||
boolean isTaskbarPinningDesktopModeChanged =
|
||||
TASKBAR_PINNING_DESKTOP_MODE_KEY.equals(key)
|
||||
&& mInfo.mIsTaskbarPinnedInDesktopMode != prefs.get(
|
||||
TASKBAR_PINNING_IN_DESKTOP_MODE);
|
||||
if (isTaskbarPinningChanged || isTaskbarPinningDesktopModeChanged) {
|
||||
notifyConfigChange();
|
||||
}
|
||||
};
|
||||
|
||||
LauncherPrefs.get(context).addListener(
|
||||
mTaskbarPinningPreferenceChangeListener, TASKBAR_PINNING);
|
||||
|
||||
Reference in new issue
Block a user