Commit e92ea31f by krocard Committed by Ian Baker

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
parent 2fd8cf02
...@@ -84,6 +84,7 @@ public final class SubtitleView extends ViewGroup implements TextOutput { ...@@ -84,6 +84,7 @@ public final class SubtitleView extends ViewGroup implements TextOutput {
@Retention(SOURCE) @Retention(SOURCE)
public @interface ViewType {} public @interface ViewType {}
private @ViewType int viewType;
private Output output; private Output output;
private View innerSubtitleView; private View innerSubtitleView;
...@@ -97,6 +98,7 @@ public final class SubtitleView extends ViewGroup implements TextOutput { ...@@ -97,6 +98,7 @@ public final class SubtitleView extends ViewGroup implements TextOutput {
output = subtitleTextView; output = subtitleTextView;
innerSubtitleView = subtitleTextView; innerSubtitleView = subtitleTextView;
addView(innerSubtitleView); addView(innerSubtitleView);
viewType = VIEW_TYPE_TEXT;
} }
@Override @Override
...@@ -126,14 +128,18 @@ public final class SubtitleView extends ViewGroup implements TextOutput { ...@@ -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 * <p>NOTE: {@link #VIEW_TYPE_WEB} is currently very experimental, and doesn't support most
* styling and layout properties of {@link Cue}. * styling and layout properties of {@link Cue}.
*/ */
public void setViewType(@ViewType int viewType) { public void setViewType(@ViewType int newViewType) {
if (viewType == VIEW_TYPE_TEXT && !(innerSubtitleView instanceof SubtitleTextView)) { if (viewType == newViewType) {
return;
}
if (newViewType == VIEW_TYPE_TEXT) {
setView(new SubtitleTextView(getContext())); setView(new SubtitleTextView(getContext()));
} else if (viewType == VIEW_TYPE_WEB && !(innerSubtitleView instanceof SubtitleWebView)) { } else if (newViewType == VIEW_TYPE_WEB) {
setView(new SubtitleWebView(getContext())); setView(new SubtitleWebView(getContext()));
} else { } else {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
viewType = newViewType;
} }
private <T extends View & Output> void setView(T view) { private <T extends View & Output> void setView(T view) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment