Merge "Removing unnecessary work adapter wrapper" into tm-qpr-dev am: 7dcc9831e2
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/19292690 Change-Id: If250bdf55756344cac0cb3858810048d50adc2b4 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -50,7 +50,7 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement
|
||||
|
||||
public static final String TAG = "AlphabeticalAppsList";
|
||||
|
||||
private final WorkAdapterProvider mWorkAdapterProvider;
|
||||
private final WorkProfileManager mWorkProviderManager;
|
||||
|
||||
/**
|
||||
* Info about a fast scroller section, depending if sections are merged, the fast scroller
|
||||
@@ -92,11 +92,11 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement
|
||||
private Predicate<ItemInfo> mItemFilter;
|
||||
|
||||
public AlphabeticalAppsList(Context context, @Nullable AllAppsStore appsStore,
|
||||
WorkAdapterProvider adapterProvider) {
|
||||
WorkProfileManager workProfileManager) {
|
||||
mAllAppsStore = appsStore;
|
||||
mActivityContext = ActivityContext.lookupContext(context);
|
||||
mAppNameComparator = new AppInfoComparator(context);
|
||||
mWorkAdapterProvider = adapterProvider;
|
||||
mWorkProviderManager = workProfileManager;
|
||||
mNumAppsPerRowAllApps = mActivityContext.getDeviceProfile().inv.numAllAppsColumns;
|
||||
if (mAllAppsStore != null) {
|
||||
mAllAppsStore.addUpdateListener(this);
|
||||
@@ -260,9 +260,9 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement
|
||||
}
|
||||
} else {
|
||||
int position = 0;
|
||||
if (mWorkAdapterProvider != null) {
|
||||
position += mWorkAdapterProvider.addWorkItems(mAdapterItems);
|
||||
if (!mWorkAdapterProvider.shouldShowWorkApps()) {
|
||||
if (mWorkProviderManager != null) {
|
||||
position += mWorkProviderManager.addWorkItems(mAdapterItems);
|
||||
if (!mWorkProviderManager.shouldShowWorkApps()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,11 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
// A divider that separates the apps list and the search market button
|
||||
public static final int VIEW_TYPE_ALL_APPS_DIVIDER = 1 << 4;
|
||||
|
||||
public static final int VIEW_TYPE_WORK_EDU_CARD = 1 << 5;
|
||||
public static final int VIEW_TYPE_WORK_DISABLED_CARD = 1 << 6;
|
||||
|
||||
public static final int NEXT_ID = 7;
|
||||
|
||||
// Common view type masks
|
||||
public static final int VIEW_TYPE_MASK_DIVIDER = VIEW_TYPE_ALL_APPS_DIVIDER;
|
||||
public static final int VIEW_TYPE_MASK_ICON = VIEW_TYPE_ICON;
|
||||
@@ -225,6 +230,12 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
case VIEW_TYPE_ALL_APPS_DIVIDER:
|
||||
return new ViewHolder(mLayoutInflater.inflate(
|
||||
R.layout.all_apps_divider, parent, false));
|
||||
case VIEW_TYPE_WORK_EDU_CARD:
|
||||
return new ViewHolder(mLayoutInflater.inflate(
|
||||
R.layout.work_apps_edu, parent, false));
|
||||
case VIEW_TYPE_WORK_DISABLED_CARD:
|
||||
return new ViewHolder(mLayoutInflater.inflate(
|
||||
R.layout.work_apps_paused, parent, false));
|
||||
default:
|
||||
BaseAdapterProvider adapterProvider = getAdapterProvider(viewType);
|
||||
if (adapterProvider != null) {
|
||||
@@ -258,8 +269,12 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
}
|
||||
break;
|
||||
case VIEW_TYPE_ALL_APPS_DIVIDER:
|
||||
case VIEW_TYPE_WORK_DISABLED_CARD:
|
||||
// nothing to do
|
||||
break;
|
||||
case VIEW_TYPE_WORK_EDU_CARD:
|
||||
((WorkEduCard) holder.itemView).setPosition(position);
|
||||
break;
|
||||
default:
|
||||
BaseAdapterProvider adapterProvider = getAdapterProvider(holder.getItemViewType());
|
||||
if (adapterProvider != null) {
|
||||
|
||||
@@ -147,8 +147,7 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte
|
||||
|
||||
mWorkManager = new WorkProfileManager(
|
||||
mActivityContext.getSystemService(UserManager.class),
|
||||
this,
|
||||
Utilities.getPrefs(mActivityContext), mActivityContext.getDeviceProfile());
|
||||
this, Utilities.getPrefs(mActivityContext));
|
||||
mAH = Arrays.asList(null, null, null);
|
||||
mAH.set(AdapterHolder.MAIN, new AdapterHolder(AdapterHolder.MAIN));
|
||||
mAH.set(AdapterHolder.WORK, new AdapterHolder(AdapterHolder.WORK));
|
||||
@@ -800,12 +799,9 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte
|
||||
mType = type;
|
||||
mAppsList = new AlphabeticalAppsList<>(mActivityContext,
|
||||
isSearch() ? null : mAllAppsStore,
|
||||
isWork() ? mWorkManager.getAdapterProvider() : null);
|
||||
|
||||
isWork() ? mWorkManager : null);
|
||||
BaseAdapterProvider[] adapterProviders =
|
||||
isWork() ? new BaseAdapterProvider[]{mMainAdapterProvider,
|
||||
mWorkManager.getAdapterProvider()}
|
||||
: new BaseAdapterProvider[]{mMainAdapterProvider};
|
||||
new BaseAdapterProvider[]{mMainAdapterProvider};
|
||||
|
||||
mAdapter = createAdapter(mAppsList, adapterProviders);
|
||||
mAppsList.setAdapter(mAdapter);
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.launcher3.allapps;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem;
|
||||
import com.android.launcher3.model.StringCache;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A UI expansion wrapper providing for providing work profile specific views
|
||||
*/
|
||||
public class WorkAdapterProvider extends BaseAdapterProvider {
|
||||
|
||||
public static final String KEY_WORK_EDU_STEP = "showed_work_profile_edu";
|
||||
|
||||
private static final int VIEW_TYPE_WORK_EDU_CARD = 1 << 20;
|
||||
private static final int VIEW_TYPE_WORK_DISABLED_CARD = 1 << 21;
|
||||
|
||||
@WorkProfileManager.WorkProfileState
|
||||
private int mState;
|
||||
private ActivityContext mActivityContext;
|
||||
private SharedPreferences mPreferences;
|
||||
|
||||
WorkAdapterProvider(ActivityContext activityContext, SharedPreferences prefs) {
|
||||
mActivityContext = activityContext;
|
||||
mPreferences = prefs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindView(AllAppsGridAdapter.ViewHolder holder, int position) {
|
||||
if (holder.itemView instanceof WorkEduCard) {
|
||||
((WorkEduCard) holder.itemView).setPosition(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllAppsGridAdapter.ViewHolder onCreateViewHolder(LayoutInflater layoutInflater,
|
||||
ViewGroup parent, int viewType) {
|
||||
int viewId = viewType == VIEW_TYPE_WORK_DISABLED_CARD ? R.layout.work_apps_paused
|
||||
: R.layout.work_apps_edu;
|
||||
View view = layoutInflater.inflate(viewId, parent, false);
|
||||
setDeviceManagementResources(view, viewType);
|
||||
return new AllAppsGridAdapter.ViewHolder(view);
|
||||
}
|
||||
|
||||
private void setDeviceManagementResources(View view, int viewType) {
|
||||
StringCache cache = mActivityContext.getStringCache();
|
||||
if (cache == null) {
|
||||
return;
|
||||
}
|
||||
if (viewType == VIEW_TYPE_WORK_DISABLED_CARD) {
|
||||
setWorkProfilePausedResources(view, cache);
|
||||
} else {
|
||||
setWorkProfileEduResources(view, cache);
|
||||
}
|
||||
}
|
||||
|
||||
private void setWorkProfilePausedResources(View view, StringCache cache) {
|
||||
TextView title = view.findViewById(R.id.work_apps_paused_title);
|
||||
title.setText(cache.workProfilePausedTitle);
|
||||
|
||||
TextView body = view.findViewById(R.id.work_apps_paused_content);
|
||||
body.setText(cache.workProfilePausedDescription);
|
||||
|
||||
TextView button = view.findViewById(R.id.enable_work_apps);
|
||||
button.setText(cache.workProfileEnableButton);
|
||||
}
|
||||
|
||||
private void setWorkProfileEduResources(View view, StringCache cache) {
|
||||
TextView title = view.findViewById(R.id.work_apps_paused_title);
|
||||
title.setText(cache.workProfileEdu);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* returns whether or not work apps should be visible in work tab.
|
||||
*/
|
||||
public boolean shouldShowWorkApps() {
|
||||
return mState != WorkProfileManager.STATE_DISABLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds work profile specific adapter items to adapterItems and returns number of items added
|
||||
*/
|
||||
public int addWorkItems(ArrayList<AllAppsGridAdapter.AdapterItem> adapterItems) {
|
||||
if (mState == WorkProfileManager.STATE_DISABLED) {
|
||||
//add disabled card here.
|
||||
adapterItems.add(new AdapterItem(VIEW_TYPE_WORK_DISABLED_CARD));
|
||||
} else if (mState == WorkProfileManager.STATE_ENABLED && !isEduSeen()) {
|
||||
adapterItems.add(new AdapterItem(VIEW_TYPE_WORK_EDU_CARD));
|
||||
}
|
||||
|
||||
return adapterItems.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current state of work profile
|
||||
*/
|
||||
public void updateCurrentState(@WorkProfileManager.WorkProfileState int state) {
|
||||
mState = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewSupported(int viewType) {
|
||||
return viewType == VIEW_TYPE_WORK_DISABLED_CARD || viewType == VIEW_TYPE_WORK_EDU_CARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemsPerRow(int viewType, int appsPerRow) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
private boolean isEduSeen() {
|
||||
return mPreferences.getInt(KEY_WORK_EDU_STEP, 0) != 0;
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,11 @@ import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.model.StringCache;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
|
||||
/**
|
||||
@@ -72,12 +74,18 @@ public class WorkEduCard extends FrameLayout implements
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
findViewById(R.id.action_btn).setOnClickListener(this);
|
||||
|
||||
StringCache cache = mActivityContext.getStringCache();
|
||||
if (cache != null) {
|
||||
TextView title = findViewById(R.id.work_apps_paused_title);
|
||||
title.setText(cache.workProfileEdu);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startAnimation(mDismissAnim);
|
||||
Utilities.getPrefs(getContext()).edit().putInt(WorkAdapterProvider.KEY_WORK_EDU_STEP,
|
||||
Utilities.getPrefs(getContext()).edit().putInt(WorkProfileManager.KEY_WORK_EDU_STEP,
|
||||
1).apply();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,11 @@ import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.model.StringCache;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
|
||||
/**
|
||||
@@ -49,12 +51,27 @@ public class WorkPausedCard extends LinearLayout implements View.OnClickListener
|
||||
mActivityContext = ActivityContext.lookupContext(getContext());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
mBtn = findViewById(R.id.enable_work_apps);
|
||||
mBtn.setOnClickListener(this);
|
||||
|
||||
StringCache cache = mActivityContext.getStringCache();
|
||||
if (cache != null) {
|
||||
setWorkProfilePausedResources(cache);
|
||||
}
|
||||
}
|
||||
|
||||
private void setWorkProfilePausedResources(StringCache cache) {
|
||||
TextView title = findViewById(R.id.work_apps_paused_title);
|
||||
title.setText(cache.workProfilePausedTitle);
|
||||
|
||||
TextView body = findViewById(R.id.work_apps_paused_content);
|
||||
body.setText(cache.workProfilePausedDescription);
|
||||
|
||||
TextView button = findViewById(R.id.enable_work_apps);
|
||||
button.setText(cache.workProfileEnableButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.allapps.ActivityAllAppsContainerView;
|
||||
import com.android.launcher3.allapps.AllAppsPagedView;
|
||||
import com.android.launcher3.allapps.WorkAdapterProvider;
|
||||
import com.android.launcher3.allapps.WorkEduCard;
|
||||
import com.android.launcher3.allapps.WorkPausedCard;
|
||||
import com.android.launcher3.allapps.WorkProfileManager;
|
||||
@@ -155,7 +154,7 @@ public class WorkProfileTest extends AbstractLauncherUiTest {
|
||||
public void testEdu() {
|
||||
waitForWorkTabSetup();
|
||||
executeOnLauncher(l -> {
|
||||
l.getSharedPrefs().edit().putInt(WorkAdapterProvider.KEY_WORK_EDU_STEP, 0).commit();
|
||||
l.getSharedPrefs().edit().putInt(WorkProfileManager.KEY_WORK_EDU_STEP, 0).commit();
|
||||
((AllAppsPagedView) l.getAppsView().getContentView()).setCurrentPage(WORK_PAGE);
|
||||
l.getAppsView().getWorkManager().reset();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user