Do not throw on valid SubtitleView.setViewType

Calling setViewType with the same view type as the
subtitleView is using would throw InvalidArgumentException
instead of being a noop.

PiperOrigin-RevId: 291937202
This commit is contained in:
krocard 2020-01-28 16:21:50 +00:00 committed by Ian Baker
parent 2fd8cf0206
commit e92ea31fcd

View File

@ -84,6 +84,7 @@ public final class SubtitleView extends ViewGroup implements TextOutput {
@Retention(SOURCE)
public @interface ViewType {}
private @ViewType int viewType;
private Output output;
private View innerSubtitleView;
@ -97,6 +98,7 @@ public final class SubtitleView extends ViewGroup implements TextOutput {
output = subtitleTextView;
innerSubtitleView = subtitleTextView;
addView(innerSubtitleView);
viewType = VIEW_TYPE_TEXT;
}
@Override
@ -126,14 +128,18 @@ public final class SubtitleView extends ViewGroup implements TextOutput {
* <p>NOTE: {@link #VIEW_TYPE_WEB} is currently very experimental, and doesn't support most
* styling and layout properties of {@link Cue}.
*/
public void setViewType(@ViewType int viewType) {
if (viewType == VIEW_TYPE_TEXT && !(innerSubtitleView instanceof SubtitleTextView)) {
public void setViewType(@ViewType int newViewType) {
if (viewType == newViewType) {
return;
}
if (newViewType == VIEW_TYPE_TEXT) {
setView(new SubtitleTextView(getContext()));
} else if (viewType == VIEW_TYPE_WEB && !(innerSubtitleView instanceof SubtitleWebView)) {
} else if (newViewType == VIEW_TYPE_WEB) {
setView(new SubtitleWebView(getContext()));
} else {
throw new IllegalArgumentException();
}
viewType = newViewType;
}
private <T extends View & Output> void setView(T view) {