Don't crash on linkify if webview is disabled

pull/1100/head
Alex Baker 4 years ago
parent af58f671c3
commit 15b9333008

@ -9,7 +9,6 @@ import android.app.Activity
import android.graphics.Color
import android.net.Uri
import android.text.Html
import android.text.util.Linkify
import android.view.View
import android.view.ViewGroup
import android.widget.Button
@ -23,6 +22,7 @@ import kotlinx.coroutines.launch
import org.tasks.R
import org.tasks.data.UserActivity
import org.tasks.data.UserActivityDao
import org.tasks.dialogs.Linkify
import org.tasks.files.FileHelper
import org.tasks.files.ImageHelper
import org.tasks.locale.Locale
@ -35,7 +35,8 @@ class CommentsController @Inject constructor(
private val userActivityDao: UserActivityDao,
private val activity: Activity,
private val preferences: Preferences,
private val locale: Locale) {
private val locale: Locale,
private val linkify: Linkify) {
private val items = ArrayList<UserActivity>()
private var commentItems = 10
@ -84,7 +85,7 @@ class CommentsController @Inject constructor(
// name
val nameView = view.findViewById<TextView>(R.id.title)
nameView.text = Html.fromHtml(item.message)
Linkify.addLinks(nameView, Linkify.ALL)
linkify.safeLinkify(nameView, android.text.util.Linkify.ALL)
// date
val date = view.findViewById<TextView>(R.id.date)

@ -6,7 +6,6 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.text.TextUtils
import android.text.util.Linkify
import android.view.MenuItem
import android.view.View
import android.view.inputmethod.InputMethodManager
@ -31,6 +30,7 @@ import org.tasks.data.CaldavAccount
import org.tasks.data.CaldavDao
import org.tasks.databinding.ActivityCaldavAccountSettingsBinding
import org.tasks.dialogs.DialogBuilder
import org.tasks.dialogs.Linkify
import org.tasks.injection.ThemedInjectingAppCompatActivity
import org.tasks.security.KeyStoreEncryption
import org.tasks.ui.DisplayableException
@ -48,6 +48,7 @@ abstract class BaseCaldavAccountSettingsActivity : ThemedInjectingAppCompatActiv
@Inject lateinit var taskDeleter: TaskDeleter
@Inject lateinit var inventory: Inventory
@Inject lateinit var firebase: Firebase
@Inject lateinit var linkify: Linkify
protected var caldavAccount: CaldavAccount? = null
protected lateinit var binding: ActivityCaldavAccountSettingsBinding
@ -62,7 +63,7 @@ abstract class BaseCaldavAccountSettingsActivity : ThemedInjectingAppCompatActiv
binding.nameLayout.visibility = View.GONE
binding.description.visibility = View.VISIBLE
binding.description.setText(description)
Linkify.addLinks(binding.description, Linkify.WEB_URLS)
linkify.safeLinkify(binding.description, android.text.util.Linkify.WEB_URLS)
} else {
binding.nameLayout.visibility = View.VISIBLE
binding.description.visibility = View.GONE

@ -12,11 +12,13 @@ import android.text.SpannableStringBuilder;
import android.text.style.URLSpan;
import android.view.View;
import android.widget.TextView;
import androidx.core.text.util.LinkifyCompat;
import dagger.hilt.android.qualifiers.ActivityContext;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.inject.Inject;
import org.tasks.R;
import timber.log.Timber;
public class Linkify {
@ -29,6 +31,14 @@ public class Linkify {
this.dialogBuilder = dialogBuilder;
}
public void safeLinkify(TextView textView, int mask) {
try {
LinkifyCompat.addLinks(textView, mask);
} catch (UnsatisfiedLinkError e) {
Timber.e(e);
}
}
public void linkify(TextView textView) {
linkify(textView, () -> {});
}
@ -38,7 +48,7 @@ public class Linkify {
return;
}
android.text.util.Linkify.addLinks(textView, android.text.util.Linkify.ALL);
safeLinkify(textView, android.text.util.Linkify.ALL);
textView.setOnClickListener(
v -> {

Loading…
Cancel
Save