forked from TeamNewPipe/NewPipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request TeamNewPipe#4534 from Stypox/secondary-controls
Add a secondary control panel to video detail fragment
- Loading branch information
Showing
23 changed files
with
577 additions
and
343 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
93 changes: 93 additions & 0 deletions
93
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,93 @@ | ||
package org.schabi.newpipe.fragments.detail; | ||
|
||
import android.os.Bundle; | ||
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.databinding.FragmentDescriptionBinding; | ||
import org.schabi.newpipe.extractor.stream.Description; | ||
import org.schabi.newpipe.extractor.stream.StreamInfo; | ||
import org.schabi.newpipe.util.Localization; | ||
import org.schabi.newpipe.util.TextLinkifier; | ||
|
||
import icepick.State; | ||
import io.reactivex.rxjava3.disposables.Disposable; | ||
|
||
import static android.text.TextUtils.isEmpty; | ||
|
||
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 FragmentDescriptionBinding binding = | ||
FragmentDescriptionBinding.inflate(inflater, container, false); | ||
if (streamInfo != null) { | ||
setupUploadDate(binding.detailUploadDateView); | ||
setupDescription(binding.detailDescriptionView); | ||
} | ||
return binding.getRoot(); | ||
} | ||
|
||
@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 || isEmpty(description.getContent()) | ||
|| description == Description.emptyDescription) { | ||
descriptionTextView.setText(""); | ||
return; | ||
} | ||
|
||
switch (description.getType()) { | ||
case Description.HTML: | ||
descriptionDisposable = TextLinkifier.createLinksFromHtmlBlock(requireContext(), | ||
description.getContent(), descriptionTextView, | ||
HtmlCompat.FROM_HTML_MODE_LEGACY); | ||
break; | ||
case Description.MARKDOWN: | ||
descriptionDisposable = TextLinkifier.createLinksFromMarkdownText(requireContext(), | ||
description.getContent(), descriptionTextView); | ||
break; | ||
case Description.PLAIN_TEXT: default: | ||
descriptionDisposable = TextLinkifier.createLinksFromPlainText(requireContext(), | ||
description.getContent(), descriptionTextView); | ||
break; | ||
} | ||
} | ||
} |
Oops, something went wrong.