Disable buttons with no action intent

Fixes: 158728328
Test: manual
Change-Id: I8ed112b5106830943b69d8fef48a9b9e128babf3
This commit is contained in:
Beth Thibodeau
2020-06-11 19:26:54 -04:00
parent 4e86ccd2e6
commit f96f4fbf05
2 changed files with 19 additions and 11 deletions

View File

@@ -302,11 +302,14 @@ public class MediaControlPanel {
button.setContentDescription(mediaAction.getContentDescription());
Runnable action = mediaAction.getAction();
button.setOnClickListener(v -> {
if (action != null) {
if (action == null) {
button.setEnabled(false);
} else {
button.setEnabled(true);
button.setOnClickListener(v -> {
action.run();
}
});
});
}
boolean visibleInCompat = actionsWhenCollapsed.contains(i);
setVisibleAndAlpha(collapsedSet, actionId, visibleInCompat);
setVisibleAndAlpha(expandedSet, actionId, true /*visible */);

View File

@@ -366,15 +366,20 @@ class MediaDataManager @Inject constructor(
actionsToShowCollapsed.remove(index)
continue
}
val runnable = if (action.actionIntent != null) {
Runnable {
try {
action.actionIntent.send()
} catch (e: PendingIntent.CanceledException) {
Log.d(TAG, "Intent canceled", e)
}
}
} else {
null
}
val mediaAction = MediaAction(
action.getIcon().loadDrawable(packageContext),
Runnable {
try {
action.actionIntent.send()
} catch (e: PendingIntent.CanceledException) {
Log.d(TAG, "Intent canceled", e)
}
},
runnable,
action.title)
actionIcons.add(mediaAction)
}