Replace deprecated Html#fromHtml with HtmlCompat#fromHtml

This commit is contained in:
TacoTheDank 2020-08-27 16:59:09 -04:00 committed by Stypox
parent f86b40302d
commit 6c5ef567ed
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
2 changed files with 9 additions and 16 deletions

View File

@ -16,9 +16,9 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import androidx.core.text.HtmlCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import android.provider.Settings; import android.provider.Settings;
import android.text.Html;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.util.Linkify; import android.text.util.Linkify;
@ -1303,18 +1303,12 @@ public class VideoDetailFragment
if (description.getType() == Description.HTML) { if (description.getType() == Description.HTML) {
disposables.add(Single.just(description.getContent()) disposables.add(Single.just(description.getContent())
.map((@NonNull String descriptionText) -> { .map((@NonNull final String descriptionText) ->
final Spanned parsedDescription; HtmlCompat.fromHtml(descriptionText,
if (Build.VERSION.SDK_INT >= 24) { HtmlCompat.FROM_HTML_MODE_LEGACY))
parsedDescription = Html.fromHtml(descriptionText, 0);
} else {
parsedDescription = Html.fromHtml(descriptionText);
}
return parsedDescription;
})
.subscribeOn(Schedulers.computation()) .subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe((@NonNull Spanned spanned) -> { .subscribe((@NonNull final Spanned spanned) -> {
videoDescriptionView.setText(spanned); videoDescriptionView.setText(spanned);
videoDescriptionView.setVisibility(View.VISIBLE); videoDescriptionView.setVisibility(View.VISIBLE);
})); }));

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import androidx.core.text.HtmlCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import android.text.Editable; import android.text.Editable;
import android.text.Html; import android.text.Html;
@ -73,7 +74,6 @@ import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.PublishSubject; import io.reactivex.subjects.PublishSubject;
import static android.text.Html.escapeHtml;
import static androidx.recyclerview.widget.ItemTouchHelper.Callback.makeMovementFlags; import static androidx.recyclerview.widget.ItemTouchHelper.Callback.makeMovementFlags;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static org.schabi.newpipe.util.AnimationUtils.animateView; import static org.schabi.newpipe.util.AnimationUtils.animateView;
@ -1005,10 +1005,9 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
: R.string.did_you_mean); : R.string.did_you_mean);
final String highlightedSearchSuggestion = final String highlightedSearchSuggestion =
"<b><i>" + escapeHtml(searchSuggestion) + "</i></b>"; "<b><i>" + Html.escapeHtml(searchSuggestion) + "</i></b>";
correctSuggestion.setText( final String text = String.format(helperText, highlightedSearchSuggestion);
Html.fromHtml(String.format(helperText, highlightedSearchSuggestion))); correctSuggestion.setText(HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY));
correctSuggestion.setOnClickListener(v -> { correctSuggestion.setOnClickListener(v -> {
correctSuggestion.setVisibility(View.GONE); correctSuggestion.setVisibility(View.GONE);