Refresh conditions only when it changes.
- Instead of force refresh when user tap action button, we not wait until state changes for each conditional cards. Test: robotests Change-Id: I2eca59a06b8cb332b7b99f017baefb3d5b53234b
This commit is contained in:
@@ -28,9 +28,14 @@ public class BackgroundDataConditionController implements ConditionalCardControl
|
||||
static final int ID = Objects.hash("BackgroundDataConditionController");
|
||||
|
||||
private final Context mAppContext;
|
||||
private final ConditionManager mConditionManager;
|
||||
private final NetworkPolicyManager mNetworkPolicyManager;
|
||||
|
||||
public BackgroundDataConditionController(Context appContext) {
|
||||
public BackgroundDataConditionController(Context appContext, ConditionManager manager) {
|
||||
mAppContext = appContext;
|
||||
mConditionManager = manager;
|
||||
mNetworkPolicyManager =
|
||||
(NetworkPolicyManager) appContext.getSystemService(Context.NETWORK_POLICY_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,7 +45,7 @@ public class BackgroundDataConditionController implements ConditionalCardControl
|
||||
|
||||
@Override
|
||||
public boolean isDisplayable() {
|
||||
return NetworkPolicyManager.from(mAppContext).getRestrictBackground();
|
||||
return mNetworkPolicyManager.getRestrictBackground();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,7 +55,8 @@ public class BackgroundDataConditionController implements ConditionalCardControl
|
||||
|
||||
@Override
|
||||
public void onActionClick() {
|
||||
NetworkPolicyManager.from(mAppContext).setRestrictBackground(false);
|
||||
mNetworkPolicyManager.setRestrictBackground(false);
|
||||
mConditionManager.onConditionChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -100,7 +100,6 @@ public class ConditionManager {
|
||||
*/
|
||||
public void onActionClick(long id) {
|
||||
getController(id).onActionClick();
|
||||
onConditionChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,15 +154,16 @@ public class ConditionManager {
|
||||
private void initCandidates() {
|
||||
// Initialize controllers first.
|
||||
mCardControllers.add(new AirplaneModeConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new BackgroundDataConditionController(mAppContext));
|
||||
mCardControllers.add(
|
||||
new BackgroundDataConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new BatterySaverConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new CellularDataConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new DndConditionCardController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new HotspotConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new NightDisplayConditionController(mAppContext));
|
||||
mCardControllers.add(new NightDisplayConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new RingerVibrateConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new RingerMutedConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new WorkModeConditionController(mAppContext));
|
||||
mCardControllers.add(new WorkModeConditionController(mAppContext, this /* manager */));
|
||||
|
||||
// Initialize ui model later. UI model depends on controller.
|
||||
mCandidates.add(new AirplaneModeConditionCard(mAppContext));
|
||||
|
@@ -30,10 +30,12 @@ public class NightDisplayConditionController implements ConditionalCardControlle
|
||||
ColorDisplayController.Callback {
|
||||
static final int ID = Objects.hash("NightDisplayConditionController");
|
||||
|
||||
private final ConditionManager mConditionManager;
|
||||
private final ColorDisplayController mController;
|
||||
|
||||
public NightDisplayConditionController(Context appContext) {
|
||||
public NightDisplayConditionController(Context appContext, ConditionManager manager) {
|
||||
mController = new ColorDisplayController(appContext);
|
||||
mConditionManager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,4 +71,9 @@ public class NightDisplayConditionController implements ConditionalCardControlle
|
||||
public void stopMonitoringStateChange() {
|
||||
mController.setListener(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivated(boolean activated) {
|
||||
mConditionManager.onConditionChanged();
|
||||
}
|
||||
}
|
||||
|
@@ -16,11 +16,14 @@
|
||||
|
||||
package com.android.settings.homepage.conditional;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
|
||||
@@ -31,13 +34,25 @@ public class WorkModeConditionController implements ConditionalCardController {
|
||||
|
||||
static final int ID = Objects.hash("WorkModeConditionController");
|
||||
|
||||
private static final IntentFilter FILTER = new IntentFilter();
|
||||
|
||||
static {
|
||||
FILTER.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
|
||||
FILTER.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
|
||||
}
|
||||
|
||||
private final Context mAppContext;
|
||||
private final UserManager mUm;
|
||||
private final ConditionManager mConditionManager;
|
||||
private final Receiver mReceiver;
|
||||
|
||||
private UserHandle mUserHandle;
|
||||
|
||||
public WorkModeConditionController(Context appContext) {
|
||||
public WorkModeConditionController(Context appContext, ConditionManager manager) {
|
||||
mAppContext = appContext;
|
||||
mUm = mAppContext.getSystemService(UserManager.class);
|
||||
mConditionManager = manager;
|
||||
mReceiver = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,12 +81,12 @@ public class WorkModeConditionController implements ConditionalCardController {
|
||||
|
||||
@Override
|
||||
public void startMonitoringStateChange() {
|
||||
|
||||
mAppContext.registerReceiver(mReceiver, FILTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMonitoringStateChange() {
|
||||
|
||||
mAppContext.unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
private void updateUserHandle() {
|
||||
@@ -87,4 +102,15 @@ public class WorkModeConditionController implements ConditionalCardController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (TextUtils.equals(action, Intent.ACTION_MANAGED_PROFILE_AVAILABLE)
|
||||
|| TextUtils.equals(action, Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)) {
|
||||
mConditionManager.onConditionChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user