Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseDescriptionFragment: Assert member is initialized #10781

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void onDestroy() {

/**
* Get the description to display.
* @return description object
* @return description object, if available
*/
@Nullable
protected abstract Description getDescription();
Expand All @@ -73,7 +73,7 @@ public void onDestroy() {
* Get the streaming service. Used for generating description links.
* @return streaming service
*/
@Nullable
@NonNull
protected abstract StreamingService getService();

/**
Expand All @@ -93,7 +93,7 @@ public void onDestroy() {
* Get the list of tags to display below the description.
* @return tag list
*/
@Nullable
@NonNull
public abstract List<String> getTags();

/**
Expand Down Expand Up @@ -158,7 +158,7 @@ protected void addMetadataItem(final LayoutInflater inflater,
final LinearLayout layout,
final boolean linkifyContent,
@StringRes final int type,
@Nullable final String content) {
@NonNull final String content) {
if (isBlank(content)) {
return;
}
Expand Down Expand Up @@ -221,16 +221,12 @@ protected void addImagesMetadataItem(final LayoutInflater inflater,
urls.append(imageSizeToText(image.getWidth()));
} else {
switch (image.getEstimatedResolutionLevel()) {
case LOW:
urls.append(getString(R.string.image_quality_low));
break;
default: // unreachable, Image.ResolutionLevel.UNKNOWN is already filtered out
case MEDIUM:
urls.append(getString(R.string.image_quality_medium));
break;
case HIGH:
urls.append(getString(R.string.image_quality_high));
break;
case LOW -> urls.append(getString(R.string.image_quality_low));
case MEDIUM -> urls.append(getString(R.string.image_quality_medium));
case HIGH -> urls.append(getString(R.string.image_quality_high));
default -> {
// unreachable, Image.ResolutionLevel.UNKNOWN is already filtered out
}
}
}

Expand All @@ -255,7 +251,7 @@ public void onClick(@NonNull final View widget) {
private void addTagsMetadataItem(final LayoutInflater inflater, final LinearLayout layout) {
final List<String> tags = getTags();

if (tags != null && !tags.isEmpty()) {
if (!tags.isEmpty()) {
final var itemBinding = ItemMetadataTagsBinding.inflate(inflater, layout, false);

tags.stream().sorted(String.CASE_INSENSITIVE_ORDER).forEach(tag -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

Expand All @@ -23,56 +24,39 @@
public class DescriptionFragment extends BaseDescriptionFragment {

@State
StreamInfo streamInfo = null;

public DescriptionFragment() {
}
StreamInfo streamInfo;

public DescriptionFragment(final StreamInfo streamInfo) {
this.streamInfo = streamInfo;
}


@Nullable
@Override
protected Description getDescription() {
if (streamInfo == null) {
return null;
}
return streamInfo.getDescription();
}

@Nullable
@NonNull
@Override
protected StreamingService getService() {
if (streamInfo == null) {
return null;
}
return streamInfo.getService();
}

@Override
protected int getServiceId() {
if (streamInfo == null) {
return -1;
}
return streamInfo.getServiceId();
}

@Nullable
@NonNull
@Override
protected String getStreamUrl() {
if (streamInfo == null) {
return null;
}
return streamInfo.getUrl();
}

@Nullable
@NonNull
@Override
public List<String> getTags() {
if (streamInfo == null) {
return null;
}
return streamInfo.getTags();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import static org.schabi.newpipe.extractor.stream.StreamExtractor.UNKNOWN_SUBSCRIBER_COUNT;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.schabi.newpipe.R;
Expand All @@ -26,15 +26,10 @@ public class ChannelAboutFragment extends BaseDescriptionFragment {
@State
protected ChannelInfo channelInfo;

public static ChannelAboutFragment getInstance(final ChannelInfo channelInfo) {
final ChannelAboutFragment fragment = new ChannelAboutFragment();
fragment.channelInfo = channelInfo;
return fragment;
ChannelAboutFragment(@NonNull final ChannelInfo channelInfo) {
this.channelInfo = channelInfo;
}

public ChannelAboutFragment() {
super();
}
Comment on lines -35 to -37
Copy link
Member

@Stypox Stypox Mar 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the empty constructors are needed when resuming a fragment from memory:

Caused by: java.lang.NoSuchMethodException: org.schabi.newpipe.fragments.list.channel.ChannelAboutFragment.<init> []

The problem probably lies in IcePick which is 9 (!) years old (actually, not in IcePick itself, but in the way it suggests to save fragment state)

Fixed in 5e7ad6f


@Override
protected void initViews(final View rootView, final Bundle savedInstanceState) {
Expand All @@ -45,26 +40,17 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) {
@Nullable
@Override
protected Description getDescription() {
if (channelInfo == null) {
return null;
}
return new Description(channelInfo.getDescription(), Description.PLAIN_TEXT);
}

@Nullable
@NonNull
@Override
protected StreamingService getService() {
if (channelInfo == null) {
return null;
}
return channelInfo.getService();
}

@Override
protected int getServiceId() {
if (channelInfo == null) {
return -1;
}
return channelInfo.getServiceId();
}

Expand All @@ -74,12 +60,9 @@ protected String getStreamUrl() {
return null;
}

@Nullable
@NonNull
@Override
public List<String> getTags() {
if (channelInfo == null) {
return null;
}
return channelInfo.getTags();
}

Expand All @@ -93,10 +76,11 @@ protected void setupMetadata(final LayoutInflater inflater,
return;
}

final Context context = getContext();
if (channelInfo.getSubscriberCount() != UNKNOWN_SUBSCRIBER_COUNT) {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ private void updateTabs() {
if (ChannelTabHelper.showChannelTab(
context, preferences, R.string.show_channel_tabs_about)) {
tabAdapter.addFragment(
ChannelAboutFragment.getInstance(currentInfo),
new ChannelAboutFragment(currentInfo),
context.getString(R.string.channel_tab_about));
}
}
Expand Down
Loading