Page MenuHomePhabricator

Replace deprecated calls to Html.fromHtml(string) with calls to Html.fromHtml(string, int)
Closed, ResolvedPublic

Description

The app makes extensive use of Html.fromHtml(string), which is now deprecated. The official migration path seems to be to replace those calls with calls to Html.fromHtml(string, int) where the int is a code on the kind of conversion that should be done, e.g. Html.FROM_HTML_MODE_LEGACY.

The app should replace these deprecated function calls with their new, non-deprecated version.

Event Timeline

Should we just replaced Html.fromHtml(x) with Html.fromHtml(x, Html.FROM_HTML_MODE_LEGACY) in all cases? That seems to be what is suggested, but it seems to be avoiding the problem. Thoughts?

@Deskana, that sounds right. Something like[0,1]:

@NonNull public Spanned fromHtml(@NonNull String source) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY);
  } else {
    return Html.fromHtml(source);
  }
}

It could live in a util class, maybe StringUtil? If we need to change it, at least it'd only be in one spot.

[0] http://stackoverflow.com/a/37905107/970346
[1] http://stackoverflow.com/a/37899941/970346

@Niedzielski That makes sense. Cool! I'll take a look at that later.

Change 312646 had a related patch set uploaded (by Mholloway):
StringUtil: Replace deprecated Html.fromHtml(String) calls

https://gerrit.wikimedia.org/r/312646

Change 312646 merged by jenkins-bot:
StringUtil: Replace deprecated Html.fromHtml(String) calls

https://gerrit.wikimedia.org/r/312646

Mholloway added a subscriber: Mholloway.

Congrats and thanks for the patch, @Nes!