1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.car.systembar; 18 19 import android.view.View; 20 21 import androidx.annotation.VisibleForTesting; 22 23 import com.android.car.datasubscription.DataSubscription; 24 import com.android.car.datasubscription.Flags; 25 import com.android.systemui.car.systembar.element.CarSystemBarElementController; 26 import com.android.systemui.car.systembar.element.CarSystemBarElementStateController; 27 import com.android.systemui.car.systembar.element.CarSystemBarElementStatusBarDisableController; 28 import com.android.systemui.car.systembar.element.layout.CarSystemBarImageView; 29 30 import dagger.assisted.Assisted; 31 import dagger.assisted.AssistedFactory; 32 import dagger.assisted.AssistedInject; 33 34 /** 35 * Controller to display the unseen icon for signal status icon 36 */ 37 public class DataSubscriptionUnseenIconController extends 38 CarSystemBarElementController<CarSystemBarImageView> 39 implements DataSubscription.DataSubscriptionChangeListener{ 40 private DataSubscription mSubscription; 41 42 @AssistedInject DataSubscriptionUnseenIconController(@ssisted CarSystemBarImageView view, CarSystemBarElementStatusBarDisableController disableController, CarSystemBarElementStateController stateController)43 DataSubscriptionUnseenIconController(@Assisted CarSystemBarImageView view, 44 CarSystemBarElementStatusBarDisableController disableController, 45 CarSystemBarElementStateController stateController) { 46 super(view, disableController, stateController); 47 mSubscription = new DataSubscription(mView.getContext()); 48 } 49 50 @Override onChange(int value)51 public void onChange(int value) { 52 updateShouldDisplayUnseenIcon(); 53 } 54 55 @AssistedFactory 56 public interface Factory extends 57 CarSystemBarElementController.Factory<CarSystemBarImageView, 58 DataSubscriptionUnseenIconController> { 59 } 60 61 @Override onViewAttached()62 protected void onViewAttached() { 63 super.onViewAttached(); 64 if (Flags.dataSubscriptionPopUp()) { 65 if (mSubscription.isDataSubscriptionInactive()) { 66 mView.setVisibility(View.VISIBLE); 67 } 68 mSubscription.addDataSubscriptionListener(this); 69 } 70 } 71 72 @Override onViewDetached()73 protected void onViewDetached() { 74 super.onViewDetached(); 75 if (Flags.dataSubscriptionPopUp()) { 76 mSubscription.removeDataSubscriptionListener(); 77 } 78 } 79 80 81 /** 82 * update unseen icon's visibility based on data subscription status 83 */ updateShouldDisplayUnseenIcon()84 public void updateShouldDisplayUnseenIcon() { 85 mView.post(() -> { 86 if (mSubscription.isDataSubscriptionInactive()) { 87 mView.setVisibility(View.VISIBLE); 88 } else { 89 mView.setVisibility(View.GONE); 90 } 91 }); 92 } 93 94 95 @VisibleForTesting setSubscription(DataSubscription subscription)96 void setSubscription(DataSubscription subscription) { 97 mSubscription = subscription; 98 } 99 } 100