NewPipe-app-android/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelAboutFragment.java

93 lines
2.6 KiB
Java
Raw Normal View History

2022-10-23 10:27:35 +02:00
package org.schabi.newpipe.fragments.list.channel;
2022-10-23 17:01:39 +02:00
import static org.schabi.newpipe.extractor.stream.StreamExtractor.UNKNOWN_SUBSCRIBER_COUNT;
import android.content.Context;
import android.os.Bundle;
2022-10-23 10:27:35 +02:00
import android.view.LayoutInflater;
import android.view.View;
2022-10-23 17:01:39 +02:00
import android.widget.LinearLayout;
2022-10-23 10:27:35 +02:00
import androidx.annotation.Nullable;
2022-10-23 17:01:39 +02:00
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.StreamingService;
2022-10-23 17:01:39 +02:00
import org.schabi.newpipe.extractor.channel.ChannelInfo;
import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.fragments.detail.BaseDescriptionFragment;
import org.schabi.newpipe.util.DeviceUtils;
2022-10-23 17:01:39 +02:00
import org.schabi.newpipe.util.Localization;
import java.util.List;
import icepick.State;
2022-10-23 10:27:35 +02:00
public class ChannelAboutFragment extends BaseDescriptionFragment {
2022-10-23 17:01:39 +02:00
@State
protected ChannelInfo channelInfo;
2022-10-23 10:27:35 +02:00
public static ChannelAboutFragment getInstance(final ChannelInfo channelInfo) {
final ChannelAboutFragment fragment = new ChannelAboutFragment();
2022-10-23 17:01:39 +02:00
fragment.channelInfo = channelInfo;
2022-10-23 10:27:35 +02:00
return fragment;
}
public ChannelAboutFragment() {
2022-10-23 10:27:35 +02:00
super();
}
@Override
protected void initViews(final View rootView, final Bundle savedInstanceState) {
super.initViews(rootView, savedInstanceState);
binding.constraintLayout.setPadding(0, DeviceUtils.dpToPx(8, requireContext()), 0, 0);
}
@Nullable
2022-10-23 10:27:35 +02:00
@Override
protected Description getDescription() {
if (channelInfo == null) {
return null;
}
return new Description(channelInfo.getDescription(), Description.PLAIN_TEXT);
2022-10-23 10:27:35 +02:00
}
@Nullable
2022-10-23 17:01:39 +02:00
@Override
protected StreamingService getService() {
if (channelInfo == null) {
return null;
2022-10-23 17:01:39 +02:00
}
return channelInfo.getService();
2022-10-23 17:01:39 +02:00
}
@Override
protected int getServiceId() {
return channelInfo.getServiceId();
2022-10-23 17:01:39 +02:00
}
@Nullable
@Override
protected String getStreamUrl() {
return null;
2022-10-23 17:01:39 +02:00
}
@Nullable
@Override
public List<String> getTags() {
if (channelInfo == null) {
return null;
2022-10-23 17:01:39 +02:00
}
return channelInfo.getTags();
2022-10-23 17:01:39 +02:00
}
protected void setupMetadata(final LayoutInflater inflater,
final LinearLayout layout) {
final Context context = getContext();
2022-10-23 17:01:39 +02:00
if (channelInfo.getSubscriberCount() != UNKNOWN_SUBSCRIBER_COUNT) {
addMetadataItem(inflater, layout, false, R.string.metadata_subscribers,
Localization.localizeNumber(context, channelInfo.getSubscriberCount()));
}
2022-10-23 17:01:39 +02:00
}
2022-10-23 10:27:35 +02:00
}