Option to disable custom tab

Stephen Paul Weber created

Change summary

src/cheogram/java/com/cheogram/android/BrowserHelper.java | 14 +++++++++
src/cheogram/res/values/strings.xml                       |  2 +
src/main/res/values/defaults.xml                          |  1 
src/main/res/xml/preferences_interface.xml                |  6 +++
4 files changed, 23 insertions(+)

Detailed changes

src/cheogram/java/com/cheogram/android/BrowserHelper.java 🔗

@@ -9,7 +9,9 @@ import android.content.pm.ResolveInfo;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Build;
+import android.preference.PreferenceManager;
 import android.content.ActivityNotFoundException;
+import android.widget.Toast;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -79,6 +81,18 @@ public class BrowserHelper {
 				launchNativeApi30(context, uri) :
 				launchNativeBeforeApi30(context, uri);
 
+      final var custom_tab = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("custom_tab", context.getResources().getBoolean(R.bool.default_custom_tab));
+		if (!custom_tab) {
+			try {
+				final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
+				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
+				context.startActivity(intent);
+				return;
+			} catch (ActivityNotFoundException e) {
+			    Toast.makeText(context, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
+			}
+		}
+
 		if (!launched) {
 			var builder = new CustomTabsIntent.Builder()
 				.setShowTitle(true)

src/cheogram/res/values/strings.xml 🔗

@@ -49,4 +49,6 @@
     <string name="add_bookmark">Add Chat</string>
     <string name="received_invite_from_stranger">Received invite from stranger</string>
     <string name="pref_chat_requests">Hide chats in Chat Requests area</string>
+    <string name="pref_custom_tab">Integrate Browser UI</string>
+    <string name="pref_custom_tab_summary">Ask your browser to render as if integrated with this app ("custom tab")</string>
 </resources>

src/main/res/values/defaults.xml 🔗

@@ -56,4 +56,5 @@
     <bool name="compose_rich_text">true</bool>
     <bool name="auto_accept_unmetered">true</bool>
     <string name="default_chat_requests">spam</string>
+    <bool name="default_custom_tab">true</bool>
 </resources>

src/main/res/xml/preferences_interface.xml 🔗

@@ -113,6 +113,12 @@
             android:key="allow_screenshots"
             android:summary="@string/pref_allow_screenshots_summary"
             android:title="@string/pref_allow_screenshots" />
+        <SwitchPreferenceCompat
+            android:defaultValue="@bool/default_custom_tab"
+            android:icon="@drawable/ic_link_24dp"
+            android:key="custom_tab"
+            android:summary="@string/pref_custom_tab_summary"
+            android:title="@string/pref_custom_tab" />
     </PreferenceCategory>
     <PreferenceCategory android:title="@string/pref_input_options">
         <ListPreference