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

Add a secondary control panel to video detail fragment #4534

Merged
merged 9 commits into from
Jan 17, 2021
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,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;
}
}
}
Loading