Merge pull request #10781 from Profpatsch/BaseDescriptionFragment-assert-member-is-initialized
BaseDescriptionFragment: Assert member is initialized
This commit is contained in:
commit
10c57b15da
4 changed files with 30 additions and 66 deletions
|
@ -64,7 +64,7 @@ public abstract class BaseDescriptionFragment extends BaseFragment {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the description to display.
|
* Get the description to display.
|
||||||
* @return description object
|
* @return description object, if available
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected abstract Description getDescription();
|
protected abstract Description getDescription();
|
||||||
|
@ -73,7 +73,7 @@ public abstract class BaseDescriptionFragment extends BaseFragment {
|
||||||
* Get the streaming service. Used for generating description links.
|
* Get the streaming service. Used for generating description links.
|
||||||
* @return streaming service
|
* @return streaming service
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@NonNull
|
||||||
protected abstract StreamingService getService();
|
protected abstract StreamingService getService();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,7 +93,7 @@ public abstract class BaseDescriptionFragment extends BaseFragment {
|
||||||
* Get the list of tags to display below the description.
|
* Get the list of tags to display below the description.
|
||||||
* @return tag list
|
* @return tag list
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@NonNull
|
||||||
public abstract List<String> getTags();
|
public abstract List<String> getTags();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,7 +158,7 @@ public abstract class BaseDescriptionFragment extends BaseFragment {
|
||||||
final LinearLayout layout,
|
final LinearLayout layout,
|
||||||
final boolean linkifyContent,
|
final boolean linkifyContent,
|
||||||
@StringRes final int type,
|
@StringRes final int type,
|
||||||
@Nullable final String content) {
|
@NonNull final String content) {
|
||||||
if (isBlank(content)) {
|
if (isBlank(content)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -221,16 +221,12 @@ public abstract class BaseDescriptionFragment extends BaseFragment {
|
||||||
urls.append(imageSizeToText(image.getWidth()));
|
urls.append(imageSizeToText(image.getWidth()));
|
||||||
} else {
|
} else {
|
||||||
switch (image.getEstimatedResolutionLevel()) {
|
switch (image.getEstimatedResolutionLevel()) {
|
||||||
case LOW:
|
case LOW -> urls.append(getString(R.string.image_quality_low));
|
||||||
urls.append(getString(R.string.image_quality_low));
|
case MEDIUM -> urls.append(getString(R.string.image_quality_medium));
|
||||||
break;
|
case HIGH -> urls.append(getString(R.string.image_quality_high));
|
||||||
default: // unreachable, Image.ResolutionLevel.UNKNOWN is already filtered out
|
default -> {
|
||||||
case MEDIUM:
|
// unreachable, Image.ResolutionLevel.UNKNOWN is already filtered out
|
||||||
urls.append(getString(R.string.image_quality_medium));
|
}
|
||||||
break;
|
|
||||||
case HIGH:
|
|
||||||
urls.append(getString(R.string.image_quality_high));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +251,7 @@ public abstract class BaseDescriptionFragment extends BaseFragment {
|
||||||
private void addTagsMetadataItem(final LayoutInflater inflater, final LinearLayout layout) {
|
private void addTagsMetadataItem(final LayoutInflater inflater, final LinearLayout layout) {
|
||||||
final List<String> tags = getTags();
|
final List<String> tags = getTags();
|
||||||
|
|
||||||
if (tags != null && !tags.isEmpty()) {
|
if (!tags.isEmpty()) {
|
||||||
final var itemBinding = ItemMetadataTagsBinding.inflate(inflater, layout, false);
|
final var itemBinding = ItemMetadataTagsBinding.inflate(inflater, layout, false);
|
||||||
|
|
||||||
tags.stream().sorted(String.CASE_INSENSITIVE_ORDER).forEach(tag -> {
|
tags.stream().sorted(String.CASE_INSENSITIVE_ORDER).forEach(tag -> {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
|
|
||||||
|
@ -23,56 +24,39 @@ import icepick.State;
|
||||||
public class DescriptionFragment extends BaseDescriptionFragment {
|
public class DescriptionFragment extends BaseDescriptionFragment {
|
||||||
|
|
||||||
@State
|
@State
|
||||||
StreamInfo streamInfo = null;
|
StreamInfo streamInfo;
|
||||||
|
|
||||||
public DescriptionFragment() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public DescriptionFragment(final StreamInfo streamInfo) {
|
public DescriptionFragment(final StreamInfo streamInfo) {
|
||||||
this.streamInfo = streamInfo;
|
this.streamInfo = streamInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
protected Description getDescription() {
|
|
||||||
if (streamInfo == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return streamInfo.getDescription();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
protected Description getDescription() {
|
||||||
|
return streamInfo.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
protected StreamingService getService() {
|
protected StreamingService getService() {
|
||||||
if (streamInfo == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return streamInfo.getService();
|
return streamInfo.getService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getServiceId() {
|
protected int getServiceId() {
|
||||||
if (streamInfo == null) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return streamInfo.getServiceId();
|
return streamInfo.getServiceId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected String getStreamUrl() {
|
protected String getStreamUrl() {
|
||||||
if (streamInfo == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return streamInfo.getUrl();
|
return streamInfo.getUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public List<String> getTags() {
|
public List<String> getTags() {
|
||||||
if (streamInfo == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return streamInfo.getTags();
|
return streamInfo.getTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,12 @@ package org.schabi.newpipe.fragments.list.channel;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.stream.StreamExtractor.UNKNOWN_SUBSCRIBER_COUNT;
|
import static org.schabi.newpipe.extractor.stream.StreamExtractor.UNKNOWN_SUBSCRIBER_COUNT;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
|
@ -26,15 +26,10 @@ public class ChannelAboutFragment extends BaseDescriptionFragment {
|
||||||
@State
|
@State
|
||||||
protected ChannelInfo channelInfo;
|
protected ChannelInfo channelInfo;
|
||||||
|
|
||||||
public static ChannelAboutFragment getInstance(final ChannelInfo channelInfo) {
|
ChannelAboutFragment(@NonNull final ChannelInfo channelInfo) {
|
||||||
final ChannelAboutFragment fragment = new ChannelAboutFragment();
|
this.channelInfo = channelInfo;
|
||||||
fragment.channelInfo = channelInfo;
|
|
||||||
return fragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChannelAboutFragment() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initViews(final View rootView, final Bundle savedInstanceState) {
|
protected void initViews(final View rootView, final Bundle savedInstanceState) {
|
||||||
|
@ -45,26 +40,17 @@ public class ChannelAboutFragment extends BaseDescriptionFragment {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
protected Description getDescription() {
|
protected Description getDescription() {
|
||||||
if (channelInfo == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Description(channelInfo.getDescription(), Description.PLAIN_TEXT);
|
return new Description(channelInfo.getDescription(), Description.PLAIN_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected StreamingService getService() {
|
protected StreamingService getService() {
|
||||||
if (channelInfo == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return channelInfo.getService();
|
return channelInfo.getService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getServiceId() {
|
protected int getServiceId() {
|
||||||
if (channelInfo == null) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return channelInfo.getServiceId();
|
return channelInfo.getServiceId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,12 +60,9 @@ public class ChannelAboutFragment extends BaseDescriptionFragment {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public List<String> getTags() {
|
public List<String> getTags() {
|
||||||
if (channelInfo == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return channelInfo.getTags();
|
return channelInfo.getTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,10 +76,11 @@ public class ChannelAboutFragment extends BaseDescriptionFragment {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Context context = getContext();
|
|
||||||
if (channelInfo.getSubscriberCount() != UNKNOWN_SUBSCRIBER_COUNT) {
|
if (channelInfo.getSubscriberCount() != UNKNOWN_SUBSCRIBER_COUNT) {
|
||||||
addMetadataItem(inflater, layout, false, R.string.metadata_subscribers,
|
addMetadataItem(inflater, layout, false, R.string.metadata_subscribers,
|
||||||
Localization.localizeNumber(context, channelInfo.getSubscriberCount()));
|
Localization.localizeNumber(
|
||||||
|
requireContext(),
|
||||||
|
channelInfo.getSubscriberCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
addImagesMetadataItem(inflater, layout, R.string.metadata_avatars,
|
addImagesMetadataItem(inflater, layout, R.string.metadata_avatars,
|
||||||
|
|
|
@ -474,7 +474,7 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
|
||||||
if (ChannelTabHelper.showChannelTab(
|
if (ChannelTabHelper.showChannelTab(
|
||||||
context, preferences, R.string.show_channel_tabs_about)) {
|
context, preferences, R.string.show_channel_tabs_about)) {
|
||||||
tabAdapter.addFragment(
|
tabAdapter.addFragment(
|
||||||
ChannelAboutFragment.getInstance(currentInfo),
|
new ChannelAboutFragment(currentInfo),
|
||||||
context.getString(R.string.channel_tab_about));
|
context.getString(R.string.channel_tab_about));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue