Removing unnecessary work adapter wrapper

Simplifying view type constants to make it easier to add new view types

Bug: 234008165
Test: Verified on device
Change-Id: I96589ceba362ea7e75afdfc3fe8da3be214aa682
This commit is contained in:
Sunny Goyal
2022-07-15 16:23:02 -07:00
parent 6c057718ac
commit cba5f9a64e
8 changed files with 87 additions and 172 deletions
@@ -15,6 +15,8 @@
*/
package com.android.launcher3.allapps;
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_WORK_DISABLED_CARD;
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_WORK_EDU_CARD;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_SHORTCUT_PERMISSION;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_CHANGE_PERMISSION;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_ENABLED;
@@ -31,13 +33,14 @@ import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.function.Predicate;
/**
@@ -48,13 +51,12 @@ import java.util.function.Predicate;
public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActivePageChangedListener {
private static final String TAG = "WorkProfileManager";
public static final String KEY_WORK_EDU_STEP = "showed_work_profile_edu";
public static final int STATE_ENABLED = 1;
public static final int STATE_DISABLED = 2;
public static final int STATE_TRANSITION = 3;
private final UserManager mUserManager;
/**
* Work profile manager states
*/
@@ -64,26 +66,23 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
STATE_TRANSITION
})
@Retention(RetentionPolicy.SOURCE)
public @interface WorkProfileState {
}
public @interface WorkProfileState { }
private final UserManager mUserManager;
private final BaseAllAppsContainerView<?> mAllApps;
private final WorkAdapterProvider mAdapterProvider;
private final Predicate<ItemInfo> mMatcher;
private WorkModeSwitch mWorkModeSwitch;
private final DeviceProfile mDeviceProfile;
@WorkProfileState
private int mCurrentState;
private SharedPreferences mPreferences;
public WorkProfileManager(UserManager userManager, BaseAllAppsContainerView<?> allApps,
SharedPreferences preferences, DeviceProfile deviceProfile) {
public WorkProfileManager(
UserManager userManager, BaseAllAppsContainerView<?> allApps, SharedPreferences prefs) {
mUserManager = userManager;
mAllApps = allApps;
mDeviceProfile = deviceProfile;
mAdapterProvider = new WorkAdapterProvider(allApps.mActivityContext, preferences);
mPreferences = prefs;
mMatcher = mAllApps.mPersonalMatcher.negate();
}
@@ -120,7 +119,6 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
private void updateCurrentState(@WorkProfileState int currentState) {
mCurrentState = currentState;
mAdapterProvider.updateCurrentState(currentState);
if (getAH() != null) {
getAH().mAppsList.updateAdapterItems();
}
@@ -161,10 +159,6 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
mWorkModeSwitch = null;
}
public WorkAdapterProvider getAdapterProvider() {
return mAdapterProvider;
}
public Predicate<ItemInfo> getMatcher() {
return mMatcher;
}
@@ -181,4 +175,28 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
public int getCurrentState() {
return mCurrentState;
}
/**
* returns whether or not work apps should be visible in work tab.
*/
public boolean shouldShowWorkApps() {
return mCurrentState != WorkProfileManager.STATE_DISABLED;
}
/**
* Adds work profile specific adapter items to adapterItems and returns number of items added
*/
public int addWorkItems(ArrayList<AdapterItem> adapterItems) {
if (mCurrentState == WorkProfileManager.STATE_DISABLED) {
//add disabled card here.
adapterItems.add(new AdapterItem(VIEW_TYPE_WORK_DISABLED_CARD));
} else if (mCurrentState == WorkProfileManager.STATE_ENABLED && !isEduSeen()) {
adapterItems.add(new AdapterItem(VIEW_TYPE_WORK_EDU_CARD));
}
return adapterItems.size();
}
private boolean isEduSeen() {
return mPreferences.getInt(KEY_WORK_EDU_STEP, 0) != 0;
}
}