summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiulio Fiscella <fiscella@google.com>2023-01-25 13:46:24 +0000
committerGiulio Fiscella <fiscella@google.com>2023-01-25 16:23:26 +0000
commit3e53bc7ff53cd5d3cb8e2ff8d27b9c52310b197d (patch)
treeea078341151137cb27130612623105f837b13ccc
parenta89cb6b277c35e203677475c334f1a514936d4c3 (diff)
downloadPermission-3e53bc7ff53cd5d3cb8e2ff8d27b9c52310b197d.tar.gz
Only show view when all data is loaded
Avoid jankyness by waiting for all async data to be loaded before showing the QS view. We were already waiting for permission data to load now we are also waiting for sensor data to load. Relnote: N/A Bug: 263364047 Test: manual Change-Id: I808c13a6e1a4230ce0d1246c822d18a27aed214d
-rw-r--r--PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterQsFragment.java69
1 files changed, 40 insertions, 29 deletions
diff --git a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterQsFragment.java b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterQsFragment.java
index e5dc3d59b..331ae8862 100644
--- a/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterQsFragment.java
+++ b/PermissionController/src/com/android/permissioncontroller/safetycenter/ui/SafetyCenterQsFragment.java
@@ -58,11 +58,6 @@ import androidx.lifecycle.ViewModelProvider;
import com.android.permissioncontroller.R;
import com.android.permissioncontroller.permission.utils.KotlinUtils;
import com.android.permissioncontroller.permission.utils.Utils;
-import com.android.permissioncontroller.safetycenter.ui.Action;
-import com.android.permissioncontroller.safetycenter.ui.NavigationSource;
-import com.android.permissioncontroller.safetycenter.ui.SafetyCenterDashboardFragment;
-import com.android.permissioncontroller.safetycenter.ui.SafetyCenterTouchTarget;
-import com.android.permissioncontroller.safetycenter.ui.Sensor;
import com.android.permissioncontroller.safetycenter.ui.model.LiveSafetyCenterViewModelFactory;
import com.android.permissioncontroller.safetycenter.ui.model.SafetyCenterQsViewModel;
import com.android.permissioncontroller.safetycenter.ui.model.SafetyCenterQsViewModel.SensorState;
@@ -91,7 +86,8 @@ public class SafetyCenterQsFragment extends Fragment {
private long mSessionId;
private List<PermissionGroupUsage> mPermGroupUsages;
private SafetyCenterQsViewModel mViewModel;
- private View mRootView;
+ private boolean mIsPermissionUsageReady;
+ private boolean mAreSensorTogglesReady;
static {
sToggleButtons.put(CAMERA, R.id.camera_toggle);
@@ -142,13 +138,13 @@ public class SafetyCenterQsFragment extends Fragment {
mViewModel =
new ViewModelProvider(requireActivity(), factory)
.get(SafetyCenterQsViewModel.class);
- mViewModel
- .getSensorPrivacyLiveData()
- .observe(this, (v) -> setSensorToggleState(v, getView()));
+ mViewModel.getSensorPrivacyLiveData().observe(this, this::setSensorToggleState);
// LightAppPermGroupLiveDatas are kept track of in the view model,
// we need to start observing them here
if (!mPermGroupUsages.isEmpty()) {
mViewModel.getPermDataLoadedLiveData().observe(this, this::onPermissionGroupsLoaded);
+ } else {
+ mIsPermissionUsageReady = true;
}
}
@@ -156,12 +152,8 @@ public class SafetyCenterQsFragment extends Fragment {
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.safety_center_qs, container, false);
- mRootView = root;
- if (mPermGroupUsages.isEmpty()) {
- mRootView.setVisibility(View.VISIBLE);
- } else {
- mRootView.setVisibility(View.GONE);
- }
+ root.setVisibility(View.GONE);
+
root.setBackgroundColor(android.R.color.background_dark);
View closeButton = root.findViewById(R.id.close_button);
closeButton.setOnClickListener((v) -> requireActivity().finish());
@@ -212,14 +204,26 @@ public class SafetyCenterQsFragment extends Fragment {
return root;
}
+ private void maybeEnableView(@Nullable View rootView) {
+ if (rootView == null) {
+ return;
+ }
+ if (mIsPermissionUsageReady && mAreSensorTogglesReady) {
+ rootView.setVisibility(View.VISIBLE);
+ }
+ }
+
private void onPermissionGroupsLoaded(boolean initialized) {
if (initialized) {
- mRootView.setVisibility(View.VISIBLE);
- addPermissionUsageInformation(mRootView);
+ if (!mIsPermissionUsageReady) {
+ mIsPermissionUsageReady = true;
+ maybeEnableView(getView());
+ }
+ addPermissionUsageInformation(getView());
}
}
- private void addPermissionUsageInformation(View rootView) {
+ private void addPermissionUsageInformation(@Nullable View rootView) {
if (rootView == null) {
return;
}
@@ -422,16 +426,20 @@ public class SafetyCenterQsFragment extends Fragment {
ConstraintLayout parentIndicatorLayout,
ConstraintLayout expandedLayout,
ImageView expandView) {
+ View rootView = getView();
+ if (rootView == null) {
+ return;
+ }
parentIndicatorLayout.setOnClickListener(
- createExpansionListener(expandedLayout, expandView));
+ createExpansionListener(expandedLayout, expandView, rootView));
}
private View.OnClickListener createExpansionListener(
- ConstraintLayout expandedLayout, ImageView expandView) {
+ ConstraintLayout expandedLayout, ImageView expandView, View rootView) {
AutoTransition transition = new AutoTransition();
// Get the entire fragment as a viewgroup in order to animate it nicely in case of
// expand/collapse
- ViewGroup indicatorCardViewGroup = (ViewGroup) mRootView;
+ ViewGroup indicatorCardViewGroup = (ViewGroup) rootView;
return v -> {
if (expandedLayout.getVisibility() == View.VISIBLE) {
// Enable -> Press -> Hide the expanded card for a continuous ripple effect
@@ -566,15 +574,18 @@ public class SafetyCenterQsFragment extends Fragment {
return layered;
}
- private void setSensorToggleState(Map<String, SensorState> sensorStates, View rootView) {
+ private void setSensorToggleState(Map<String, SensorState> sensorStates) {
+ if (!mAreSensorTogglesReady) {
+ mAreSensorTogglesReady = true;
+ maybeEnableView(getView());
+ }
+ updateSensorToggleState(sensorStates, getView());
+ }
+
+ private void updateSensorToggleState(
+ Map<String, SensorState> sensorStates, @Nullable View rootView) {
if (rootView == null) {
- if (getView() == null) {
- return;
- }
- rootView = getView();
- if (rootView == null) {
- return;
- }
+ return;
}
if (sensorStates == null) {