From 6c5ef567edecbc084aa6919fdeea21b757ed1b3a Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 27 Aug 2020 16:59:09 -0400 Subject: [PATCH] Replace deprecated Html#fromHtml with HtmlCompat#fromHtml --- .../fragments/detail/VideoDetailFragment.java | 16 +++++----------- .../fragments/list/search/SearchFragment.java | 9 ++++----- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 2885c9f7b..5e202eaa6 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -16,9 +16,9 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; +import androidx.core.text.HtmlCompat; import androidx.preference.PreferenceManager; import android.provider.Settings; -import android.text.Html; import android.text.Spanned; import android.text.TextUtils; import android.text.util.Linkify; @@ -1303,18 +1303,12 @@ public class VideoDetailFragment if (description.getType() == Description.HTML) { disposables.add(Single.just(description.getContent()) - .map((@NonNull String descriptionText) -> { - final Spanned parsedDescription; - if (Build.VERSION.SDK_INT >= 24) { - parsedDescription = Html.fromHtml(descriptionText, 0); - } else { - parsedDescription = Html.fromHtml(descriptionText); - } - return parsedDescription; - }) + .map((@NonNull final String descriptionText) -> + HtmlCompat.fromHtml(descriptionText, + HtmlCompat.FROM_HTML_MODE_LEGACY)) .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe((@NonNull Spanned spanned) -> { + .subscribe((@NonNull final Spanned spanned) -> { videoDescriptionView.setText(spanned); videoDescriptionView.setVisibility(View.VISIBLE); })); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index 18c7fb1dd..7ce4c6c84 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import androidx.core.text.HtmlCompat; import androidx.preference.PreferenceManager; import android.text.Editable; import android.text.Html; @@ -73,7 +74,6 @@ import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; -import static android.text.Html.escapeHtml; import static androidx.recyclerview.widget.ItemTouchHelper.Callback.makeMovementFlags; import static java.util.Arrays.asList; import static org.schabi.newpipe.util.AnimationUtils.animateView; @@ -1005,10 +1005,9 @@ public class SearchFragment extends BaseListFragment" + escapeHtml(searchSuggestion) + ""; - correctSuggestion.setText( - Html.fromHtml(String.format(helperText, highlightedSearchSuggestion))); - + "" + Html.escapeHtml(searchSuggestion) + ""; + final String text = String.format(helperText, highlightedSearchSuggestion); + correctSuggestion.setText(HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY)); correctSuggestion.setOnClickListener(v -> { correctSuggestion.setVisibility(View.GONE);