Skip to content

Commit

Permalink
Move description to a tab alongside related streams and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Nov 27, 2020
1 parent fda232a commit 4046b35
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 191 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/org/schabi/newpipe/BaseFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void useAsFrontPage(final boolean value) {
//////////////////////////////////////////////////////////////////////////*/

@Override
public void onAttach(final Context context) {
public void onAttach(@NonNull final Context context) {
super.onAttach(context);
activity = (AppCompatActivity) context;
}
Expand All @@ -61,7 +61,7 @@ public void onCreate(final Bundle savedInstanceState) {


@Override
public void onViewCreated(final View rootView, final Bundle savedInstanceState) {
public void onViewCreated(@NonNull final View rootView, final Bundle savedInstanceState) {
super.onViewCreated(rootView, savedInstanceState);
if (DEBUG) {
Log.d(TAG, "onViewCreated() called with: "
Expand All @@ -73,7 +73,7 @@ public void onViewCreated(final View rootView, final Bundle savedInstanceState)
}

@Override
public void onSaveInstanceState(final Bundle outState) {
public void onSaveInstanceState(@NonNull final Bundle outState) {
super.onSaveInstanceState(outState);
Icepick.saveInstanceState(this, outState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.widget.TextView;
import android.widget.Toast;

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

Expand Down Expand Up @@ -56,7 +57,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
private TextView errorTextView;

@Override
public void onViewCreated(final View rootView, final Bundle savedInstanceState) {
public void onViewCreated(@NonNull final View rootView, final Bundle savedInstanceState) {
super.onViewCreated(rootView, savedInstanceState);
doInitialLoadLogic();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package org.schabi.newpipe.fragments.detail;

import android.os.Bundle;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.text.HtmlCompat;

import org.schabi.newpipe.BaseFragment;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.views.LargeTextMovementMethod;

import icepick.State;
import io.noties.markwon.Markwon;
import io.noties.markwon.linkify.LinkifyPlugin;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class DescriptionFragment extends BaseFragment {

@State
StreamInfo streamInfo = null;
@Nullable
Disposable descriptionDisposable = null;

public DescriptionFragment() {
}

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

@Override
public View onCreateView(@NonNull final LayoutInflater inflater,
@Nullable final ViewGroup container,
@Nullable final Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_description, container, false);
if (streamInfo != null) {
setupUploadDate(view.findViewById(R.id.detail_upload_date_view));
setupDescription(view.findViewById(R.id.detail_description_view));
}
return view;
}

@Override
public void onDestroy() {
super.onDestroy();
if (descriptionDisposable != null) {
descriptionDisposable.dispose();
}
}

private void setupUploadDate(final TextView uploadDateTextView) {
if (streamInfo.getUploadDate() != null) {
uploadDateTextView.setText(Localization
.localizeUploadDate(activity, streamInfo.getUploadDate().offsetDateTime()));
} else {
uploadDateTextView.setVisibility(View.GONE);
}
}

private void setupDescription(final TextView descriptionTextView) {
final Description description = streamInfo.getDescription();
if (description == null || TextUtils.isEmpty(description.getContent())
|| description == Description.emptyDescription) {
descriptionTextView.setVisibility(View.GONE);
return;
}

descriptionTextView.setMovementMethod(new LargeTextMovementMethod());
if (description.getType() == Description.HTML) {
descriptionDisposable = Single.just(description.getContent())
.map((@NonNull final String descriptionText) ->
HtmlCompat.fromHtml(descriptionText,
HtmlCompat.FROM_HTML_MODE_LEGACY))
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((Consumer<Spanned>) descriptionTextView::setText);

} else if (description.getType() == Description.MARKDOWN) {
final Markwon markwon = Markwon.builder(requireContext())
.usePlugin(LinkifyPlugin.create())
.build();

descriptionDisposable = Single.just(description.getContent())
.map(markwon::toMarkdown)
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(spanned -> markwon.setParsedMarkdown(descriptionTextView, spanned));
} else /* == Description.PLAIN_TEXT */ {
descriptionTextView.setAutoLinkMask(Linkify.WEB_URLS);
descriptionTextView.setText(description.getContent(), TextView.BufferType.SPANNABLE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.os.Looper;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.util.Linkify;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -69,14 +68,12 @@
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.Stream;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.fragments.BackPressable;
import org.schabi.newpipe.fragments.BaseStateFragment;
import org.schabi.newpipe.fragments.EmptyFragment;
import org.schabi.newpipe.fragments.list.comments.CommentsFragment;
import org.schabi.newpipe.fragments.list.videos.RelatedVideosFragment;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
Expand Down Expand Up @@ -107,7 +104,6 @@
import org.schabi.newpipe.util.ShareUtils;
import org.schabi.newpipe.util.ThemeHelper;
import org.schabi.newpipe.views.AnimatedProgressBar;
import org.schabi.newpipe.views.LargeTextMovementMethod;

import java.util.Iterator;
import java.util.LinkedList;
Expand Down Expand Up @@ -159,7 +155,7 @@ public final class VideoDetailFragment

private static final String COMMENTS_TAB_TAG = "COMMENTS";
private static final String RELATED_TAB_TAG = "NEXT VIDEO";
private static final String EMPTY_TAB_TAG = "EMPTY TAB";
private static final String DESCRIPTION_TAB_TAG = "DESCRIPTION TAB";

private boolean showRelatedStreams;
private boolean showComments;
Expand Down Expand Up @@ -224,10 +220,6 @@ public final class VideoDetailFragment
private TextView detailDurationView;
private TextView detailPositionView;

private LinearLayout videoDescriptionRootLayout;
private TextView videoUploadDateView;
private TextView videoDescriptionView;

private View uploaderRootLayout;
private TextView uploaderTextView;
private ImageView uploaderThumb;
Expand Down Expand Up @@ -632,21 +624,16 @@ public boolean onLongClick(final View v) {
}

private void toggleTitleAndDescription() {
if (videoDescriptionRootLayout.getVisibility() == View.VISIBLE) {
videoTitleTextView.setMaxLines(1);
videoDescriptionRootLayout.setVisibility(View.GONE);
videoDescriptionView.setFocusable(false);
videoTitleToggleArrow.setImageResource(
ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_expand_more));
detailSecondaryControlPanel.setVisibility(View.GONE);
} else {
if (videoTitleTextView.getMaxLines() == 1) {
videoTitleTextView.setMaxLines(10);
videoDescriptionRootLayout.setVisibility(View.VISIBLE);
videoDescriptionView.setFocusable(true);
videoDescriptionView.setMovementMethod(new LargeTextMovementMethod());
videoTitleToggleArrow.setImageResource(
ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_expand_less));
detailSecondaryControlPanel.setVisibility(View.VISIBLE);
} else {
videoTitleTextView.setMaxLines(1);
videoTitleToggleArrow.setImageResource(
ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_expand_more));
detailSecondaryControlPanel.setVisibility(View.GONE);
}
}

Expand Down Expand Up @@ -682,10 +669,6 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) {
detailDurationView = rootView.findViewById(R.id.detail_duration_view);
detailPositionView = rootView.findViewById(R.id.detail_position_view);

videoDescriptionRootLayout = rootView.findViewById(R.id.detail_description_root_layout);
videoUploadDateView = rootView.findViewById(R.id.detail_upload_date_view);
videoDescriptionView = rootView.findViewById(R.id.detail_description_view);

thumbsUpTextView = rootView.findViewById(R.id.detail_thumbs_up_count_view);
thumbsUpImageView = rootView.findViewById(R.id.detail_thumbs_up_img_view);
thumbsDownTextView = rootView.findViewById(R.id.detail_thumbs_down_count_view);
Expand Down Expand Up @@ -1037,15 +1020,13 @@ private void initTabs() {
CommentsFragment.getInstance(serviceId, url, title), COMMENTS_TAB_TAG);
}

if (showRelatedStreams && null == relatedStreamsLayout) {
if (showRelatedStreams && relatedStreamsLayout == null) {
//temp empty fragment. will be updated in handleResult
pageAdapter.addFragment(new Fragment(), RELATED_TAB_TAG);
}

if (pageAdapter.getCount() == 0) {
pageAdapter.addFragment(new EmptyFragment(), EMPTY_TAB_TAG);
}

//temp empty fragment. will be updated in handleResult
pageAdapter.addFragment(new Fragment(), DESCRIPTION_TAB_TAG);
pageAdapter.notifyDataSetUpdate();

if (pageAdapter.getCount() < 2) {
Expand Down Expand Up @@ -1267,37 +1248,6 @@ private void makeDefaultHeightForVideoPlaceholder() {
playerPlaceholder.requestLayout();
}

private void prepareDescription(final Description description) {
if (description == null || TextUtils.isEmpty(description.getContent())
|| description == Description.emptyDescription) {
return;
}

if (description.getType() == Description.HTML) {
disposables.add(Single.just(description.getContent())
.map(descriptionText ->
HtmlCompat.fromHtml(descriptionText,
HtmlCompat.FROM_HTML_MODE_LEGACY))
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(spanned -> {
videoDescriptionView.setText(spanned);
videoDescriptionView.setVisibility(View.VISIBLE);
}));
} else if (description.getType() == Description.MARKDOWN) {
final Markwon markwon = Markwon.builder(requireContext())
.usePlugin(LinkifyPlugin.create())
.build();
markwon.setMarkdown(videoDescriptionView, description.getContent());
videoDescriptionView.setVisibility(View.VISIBLE);
} else {
//== Description.PLAIN_TEXT
videoDescriptionView.setAutoLinkMask(Linkify.WEB_URLS);
videoDescriptionView.setText(description.getContent(), TextView.BufferType.SPANNABLE);
videoDescriptionView.setVisibility(View.VISIBLE);
}
}

private final ViewTreeObserver.OnPreDrawListener preDrawListener =
new ViewTreeObserver.OnPreDrawListener() {
@Override
Expand Down Expand Up @@ -1470,7 +1420,6 @@ public void showLoading() {
videoTitleTextView.setMaxLines(1);
animateView(videoTitleTextView, true, 0);

videoDescriptionRootLayout.setVisibility(View.GONE);
videoTitleToggleArrow.setVisibility(View.GONE);
videoTitleRoot.setClickable(false);
detailSecondaryControlPanel.setVisibility(View.GONE);
Expand Down Expand Up @@ -1498,10 +1447,9 @@ public void handleResult(@NonNull final StreamInfo info) {
setInitialData(info.getServiceId(), info.getOriginalUrl(), info.getName(), playQueue);

if (showRelatedStreams) {
if (null == relatedStreamsLayout) { //phone
if (relatedStreamsLayout == null) { //phone
pageAdapter.updateItem(RELATED_TAB_TAG,
RelatedVideosFragment.getInstance(info));
pageAdapter.notifyDataSetUpdate();
} else { //tablet
getChildFragmentManager().beginTransaction()
.replace(R.id.relatedStreamsLayout,
Expand All @@ -1511,6 +1459,10 @@ public void handleResult(@NonNull final StreamInfo info) {
player != null && player.isFullscreen() ? View.GONE : View.VISIBLE);
}
}
pageAdapter.updateItem(DESCRIPTION_TAB_TAG,
new DescriptionFragment(info));
pageAdapter.notifyDataSetUpdate();

animateView(thumbnailPlayButton, true, 200);
videoTitleTextView.setText(title);

Expand Down Expand Up @@ -1585,22 +1537,10 @@ public void handleResult(@NonNull final StreamInfo info) {
detailDurationView.setVisibility(View.GONE);
}

videoDescriptionView.setVisibility(View.GONE);
videoTitleRoot.setClickable(true);
videoTitleToggleArrow.setImageResource(
ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_expand_more));
videoTitleToggleArrow.setVisibility(View.VISIBLE);
videoDescriptionRootLayout.setVisibility(View.GONE);
detailSecondaryControlPanel.setVisibility(View.GONE);

if (info.getUploadDate() != null) {
videoUploadDateView.setText(Localization
.localizeUploadDate(activity, info.getUploadDate().offsetDateTime()));
videoUploadDateView.setVisibility(View.VISIBLE);
} else {
videoUploadDateView.setText(null);
videoUploadDateView.setVisibility(View.GONE);
}

sortedVideoStreams = ListHelper.getSortedStreamVideosList(
activity,
Expand All @@ -1609,7 +1549,6 @@ public void handleResult(@NonNull final StreamInfo info) {
false);
selectedVideoStreamIndex = ListHelper
.getDefaultResolutionIndex(activity, sortedVideoStreams);
prepareDescription(info.getDescription());
updateProgressInfo(info);
initThumbnailViews(info);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
//////////////////////////////////////////////////////////////////////////*/

@Override
public void onAttach(final Context context) {
public void onAttach(@NonNull final Context context) {
super.onAttach(context);

if (infoListAdapter == null) {
Expand Down Expand Up @@ -182,7 +182,7 @@ private void restoreFocus(final Integer position) {
}

@Override
public void onSaveInstanceState(final Bundle bundle) {
public void onSaveInstanceState(@NonNull final Bundle bundle) {
super.onSaveInstanceState(bundle);
if (useDefaultStateSaving) {
savedState = StateSaver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void setUserVisibleHint(final boolean isVisibleToUser) {
//////////////////////////////////////////////////////////////////////////*/

@Override
public void onAttach(final Context context) {
public void onAttach(@NonNull final Context context) {
super.onAttach(context);
subscriptionManager = new SubscriptionManager(activity);
}
Expand All @@ -130,7 +130,7 @@ public View onCreateView(@NonNull final LayoutInflater inflater,
}

@Override
public void onViewCreated(final View rootView, final Bundle savedInstanceState) {
public void onViewCreated(@NonNull final View rootView, final Bundle savedInstanceState) {
super.onViewCreated(rootView, savedInstanceState);
contentNotSupportedTextView = rootView.findViewById(R.id.error_content_not_supported);
kaomojiTextView = rootView.findViewById(R.id.channel_kaomoji);
Expand Down
Loading

0 comments on commit 4046b35

Please sign in to comment.