Reduce `minSdkVersion` to 18, backfill missing methods

Alex Palaistras created

This reduces the minimum SDK version to 18 (Android 4.3), which notably is
the last supported version for the BlackBerry OS 10.3 Android compatibility
layer.

Change summary

build.gradle                                                |  2 
src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java | 21 ++++++
2 files changed, 21 insertions(+), 2 deletions(-)

Detailed changes

build.gradle 🔗

@@ -73,7 +73,7 @@ android {
     compileSdkVersion 28
 
     defaultConfig {
-        minSdkVersion 19
+        minSdkVersion 18
         targetSdkVersion 28
         versionCode 307
         versionName "2.3.9"

src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java 🔗

@@ -29,6 +29,7 @@
 
 package eu.siacs.conversations.ui.util;
 
+import android.os.Build;
 import android.text.Editable;
 import android.text.util.Linkify;
 
@@ -80,7 +81,7 @@ public class MyLinkify {
         if (end < cs.length()) {
             // Reject strings that were probably matched only because they contain a dot followed by
             // by some known TLD (see also comment for WORD_BOUNDARY in Patterns.java)
-            if (Character.isAlphabetic(cs.charAt(end-1)) && Character.isAlphabetic(cs.charAt(end))) {
+            if (isAlphabetic(cs.charAt(end-1)) && isAlphabetic(cs.charAt(end))) {
                 return false;
             }
         }
@@ -93,6 +94,24 @@ public class MyLinkify {
         return uri.isJidValid();
     };
 
+    private static boolean isAlphabetic(final int code) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+            return Character.isAlphabetic(code);
+        }
+
+        switch (Character.getType(code)) {
+            case Character.UPPERCASE_LETTER:
+            case Character.LOWERCASE_LETTER:
+            case Character.TITLECASE_LETTER:
+            case Character.MODIFIER_LETTER:
+            case Character.OTHER_LETTER:
+            case Character.LETTER_NUMBER:
+                return true;
+            default:
+                return false;
+        }
+    }
+
     public static void addLinks(Editable body, boolean includeGeo) {
         Linkify.addLinks(body, Patterns.XMPP_PATTERN, "xmpp", XMPPURI_MATCH_FILTER, null);
         Linkify.addLinks(body, Patterns.AUTOLINK_WEB_URL, "http", WEBURL_MATCH_FILTER, WEBURL_TRANSFORM_FILTER);