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

Refactor usage of Html.fromHtml to handle deprecation #6002 #6074

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Html;
Expand Down Expand Up @@ -167,7 +168,11 @@ public View onCreateView(
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setSearchThisAreaButtonVisibility(false);
binding.tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
binding.tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution), Html.FROM_HTML_MODE_LEGACY));
} else {
binding.tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution)));
}
initNetworkBroadCastReceiver();
locationPermissionsHelper = new LocationPermissionsHelper(getActivity(),locationManager,this);
if (presenter == null) {
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/fr/free/nrw/commons/feedback/FeedbackDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fr.free.nrw.commons.feedback

import android.app.Dialog
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.text.Html
import android.text.Spanned
Expand All @@ -26,11 +27,13 @@ class FeedbackDialog(
private val onFeedbackSubmitCallback: OnFeedbackSubmitCallback) : Dialog(context) {
private var _binding: DialogFeedbackBinding? = null
private val binding get() = _binding!!
// TODO("Remove Deprecation") Issue : #6002
// 'fromHtml(String!): Spanned!' is deprecated. Deprecated in Java
@Suppress("DEPRECATION")
private var feedbackDestinationHtml: Spanned = Html.fromHtml(
context.getString(R.string.feedback_destination_note))
// Refactored to handle deprecation for Html.fromHtml()
private var feedbackDestinationHtml: Spanned = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(context.getString(R.string.feedback_destination_note), Html.FROM_HTML_MODE_LEGACY)
} else {
@Suppress("DEPRECATION")
Html.fromHtml(context.getString(R.string.feedback_destination_note))
}


public override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
Expand Down Expand Up @@ -511,7 +512,12 @@ public boolean onZoom(ZoomEvent event) {
moveCameraToPosition(lastMapFocus);
initRvNearbyList();
onResume();
binding.tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
binding.tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution), Html.FROM_HTML_MODE_LEGACY));
} else {
//noinspection deprecation
binding.tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution)));
}
binding.tvAttribution.setMovementMethod(LinkMovementMethod.getInstance());
binding.nearbyFilterList.btnAdvancedOptions.setOnClickListener(v -> {
binding.nearbyFilter.searchViewLayout.searchView.clearFocus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ class ReviewImageFragment : CommonsDaggerSupportFragment() {
R.string.review_category_explanation,
formattedCatString
)
return Html.fromHtml(stringToConvertHtml).toString()
val formattedString = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
Html.fromHtml(stringToConvertHtml, Html.FROM_HTML_MODE_LEGACY).toString()
} else {
Html.fromHtml(stringToConvertHtml).toString()
}
return formattedString
}
}
return getString(R.string.review_no_category)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fr.free.nrw.commons.upload.license

import android.app.Activity
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.text.Html
import android.text.SpannableStringBuilder
Expand Down Expand Up @@ -151,7 +152,11 @@ class MediaLicenseFragment : UploadBaseFragment(), MediaLicenseContract.View {
}

private fun setTextViewHTML(textView: TextView, text: String) {
val sequence: CharSequence = Html.fromHtml(text)
val sequence: CharSequence = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY)
} else {
Html.fromHtml(text)
}
val strBuilder = SpannableStringBuilder(sequence)
val urls = strBuilder.getSpans(
0, sequence.length,
Expand Down
Loading