-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move description to a tab alongside related streams and comments
- Loading branch information
Showing
12 changed files
with
187 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.