Fix switch listener on app notif page

Test: RoboTests, manually change setting
Fixes: 193442605
Change-Id: Ie93469479e252811921a6451853b073dadb0d0a1
This commit is contained in:
Julia Reynolds
2021-07-13 11:38:22 -04:00
parent bc7e4bcd46
commit e41c89da2a
5 changed files with 28 additions and 31 deletions

View File

@@ -24,8 +24,10 @@ import android.os.UserManager;
import android.text.format.DateUtils;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.Switch;
import com.android.settings.R;
@@ -222,26 +224,18 @@ public class AppStateNotificationBridge extends AppStateBaseBridge {
return userId + "|" + pkg;
}
public View.OnClickListener getSwitchOnClickListener(final AppEntry entry) {
if (entry != null) {
return v -> {
ViewGroup view = (ViewGroup) v;
Switch toggle = view.findViewById(R.id.switchWidget);
if (toggle != null) {
if (!toggle.isEnabled()) {
return;
}
toggle.toggle();
mBackend.setNotificationsEnabledForPackage(
entry.info.packageName, entry.info.uid, toggle.isChecked());
NotificationsSentState stats = getNotificationsSentState(entry);
if (stats != null) {
stats.blocked = !toggle.isChecked();
}
}
};
public CompoundButton.OnCheckedChangeListener getSwitchOnCheckedListener(final AppEntry entry) {
if (entry == null) {
return null;
}
return null;
return (buttonView, isChecked) -> {
mBackend.setNotificationsEnabledForPackage(
entry.info.packageName, entry.info.uid, isChecked);
NotificationsSentState stats = getNotificationsSentState(entry);
if (stats != null) {
stats.blocked = !isChecked;
}
};
}
public static final AppFilter FILTER_APP_NOTIFICATION_RECENCY = new AppFilter() {

View File

@@ -155,13 +155,13 @@ public class ApplicationViewHolder extends RecyclerView.ViewHolder {
}
}
void updateSwitch(View.OnClickListener listener, boolean enabled, boolean checked) {
void updateSwitch(Switch.OnCheckedChangeListener listener, boolean enabled, boolean checked) {
if (mSwitch != null && mWidgetContainer != null) {
mWidgetContainer.setOnClickListener(listener);
mWidgetContainer.setFocusable(false);
mWidgetContainer.setClickable(false);
mSwitch.setFocusable(true);
mSwitch.setClickable(true);
mSwitch.setOnCheckedChangeListener(listener);
mSwitch.setChecked(checked);
mSwitch.setEnabled(enabled);
}

View File

@@ -1505,7 +1505,7 @@ public class ManageApplications extends InstrumentedFragment
switch (mManageApplications.mListType) {
case LIST_TYPE_NOTIFICATION:
holder.updateSwitch(((AppStateNotificationBridge) mExtraInfoBridge)
.getSwitchOnClickListener(entry),
.getSwitchOnCheckedListener(entry),
AppStateNotificationBridge.enableSwitch(entry),
AppStateNotificationBridge.checkSwitch(entry));
if (entry.extraInfo != null