Merge "Disable buttons with no action intent" into rvc-dev

This commit is contained in:
Beth Thibodeau
2020-06-12 03:38:29 +00:00
committed by Android (Google) Code Review
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)
}