mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Moved single-use code out of Utils over to where it's actually used.
This commit is contained in:
parent
388f588301
commit
d0a85dbd82
12 changed files with 184 additions and 217 deletions
|
|
@ -1,12 +1,13 @@
|
|||
package fr.free.nrw.commons.ui.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.v7.widget.AppCompatTextView;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import fr.free.nrw.commons.Utils;
|
||||
|
||||
/**
|
||||
* An {@link AppCompatTextView} which formats the text to HTML displayable text and makes any
|
||||
* links clickable.
|
||||
|
|
@ -17,10 +18,25 @@ public class HtmlTextView extends AppCompatTextView {
|
|||
super(context, attrs);
|
||||
|
||||
setMovementMethod(LinkMovementMethod.getInstance());
|
||||
setText(Utils.fromHtml(getText().toString()));
|
||||
setText(fromHtml(getText().toString()));
|
||||
}
|
||||
|
||||
public void setHtmlText(String newText) {
|
||||
setText(Utils.fromHtml(newText));
|
||||
setText(fromHtml(newText));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix Html.fromHtml is deprecated problem
|
||||
*
|
||||
* @param source provided Html string
|
||||
* @return returned Spanned of appropriate method according to version check
|
||||
*/
|
||||
private static Spanned fromHtml(String source) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY);
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
return Html.fromHtml(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue