Fix UI issue in LocationSettings

- Add WorkPreferenceController to support directly use work profile
related feature in xml
- Get only work/personal infos in RecentLocationRequestPreferenceController
and RecentLocationRequestSeeAllPreferenceController
- Remove ProfileSelectStorageFragment

Bug: 141601408
Fixes: 146080649
Test: manual, robolectric
Change-Id: Ide39c7a3796e16421f3a5690309c3d746a956de8
This commit is contained in:
Raff Tsai
2019-12-13 16:46:33 +08:00
parent d230b552f5
commit 5ec8efe7e0
21 changed files with 442 additions and 246 deletions

View File

@@ -15,16 +15,21 @@
*/
package com.android.settings.location;
import android.content.Context;
import static com.android.settings.location.RecentLocationRequestPreferenceController.createAppPreference;
import static com.android.settings.location.RecentLocationRequestPreferenceController.isRequestMatchesProfileType;
import android.content.Context;
import android.os.UserManager;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settingslib.location.RecentLocationApps;
import com.android.settingslib.widget.apppreference.AppPreference;
import java.util.ArrayList;
import java.util.List;
/** Preference controller for preference category displaying all recent location requests. */
@@ -35,6 +40,7 @@ public class RecentLocationRequestSeeAllPreferenceController
private RecentLocationApps mRecentLocationApps;
private boolean mShowSystem = false;
private Preference mPreference;
private int mType = ProfileSelectFragment.ProfileType.ALL;
public RecentLocationRequestSeeAllPreferenceController(Context context, String key) {
super(context, key);
@@ -56,33 +62,39 @@ public class RecentLocationRequestSeeAllPreferenceController
public void updateState(Preference preference) {
mCategoryAllRecentLocationRequests.removeAll();
mPreference = preference;
List<RecentLocationApps.Request> requests = mRecentLocationApps.getAppListSorted(
mShowSystem);
if (requests.isEmpty()) {
final UserManager userManager = UserManager.get(mContext);
final List<RecentLocationApps.Request> recentLocationRequests = new ArrayList<>();
for (RecentLocationApps.Request request : mRecentLocationApps.getAppListSorted(
mShowSystem)) {
if (isRequestMatchesProfileType(userManager, request, mType)) {
recentLocationRequests.add(request);
}
}
if (recentLocationRequests.isEmpty()) {
// If there's no item to display, add a "No recent apps" item.
final Preference banner = new AppPreference(mContext);
banner.setTitle(R.string.location_no_recent_apps);
banner.setSelectable(false);
mCategoryAllRecentLocationRequests.addPreference(banner);
} else {
for (RecentLocationApps.Request request : requests) {
Preference appPreference = createAppPreference(preference.getContext(), request);
for (RecentLocationApps.Request request : recentLocationRequests) {
final Preference appPreference = createAppPreference(
preference.getContext(),
request, mFragment);
mCategoryAllRecentLocationRequests.addPreference(appPreference);
}
}
}
@VisibleForTesting
AppPreference createAppPreference(
Context prefContext, RecentLocationApps.Request request) {
final AppPreference pref = new AppPreference(prefContext);
pref.setSummary(request.contentDescription);
pref.setIcon(request.icon);
pref.setTitle(request.label);
pref.setOnPreferenceClickListener(
new RecentLocationRequestPreferenceController.PackageEntryClickedListener(
mFragment, request.packageName, request.userHandle));
return pref;
/**
* Initialize {@link ProfileSelectFragment.ProfileType} of the controller
*
* @param type {@link ProfileSelectFragment.ProfileType} of the controller.
*/
public void setProfileType(@ProfileSelectFragment.ProfileType int type) {
mType = type;
}
public void setShowSystem(boolean showSystem) {