Option to disable custom tab

This commit is contained in:
Stephen Paul Weber 2024-11-17 03:10:53 +01:00 committed by Arne
parent 03986d4036
commit 18f0f2eae5
4 changed files with 23 additions and 0 deletions

View file

@ -61,4 +61,5 @@
<string name="default_chat_requests">spam</string>
<string name="default_dns_server_ipv4">194.242.2.2</string>
<string name="default_dns_server_ipv6">[2a07:e340::2]</string>
<bool name="default_custom_tab">true</bool>
</resources>

View file

@ -1337,4 +1337,6 @@
<string name="pref_auto_accept_unmetered_summary">Don\'t use the above size limit on unmetered networks</string>
<string name="unban_from_group_chat">Unban from group chat</string>
<string name="unban_from_channel">Unban from channel</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>

View file

@ -169,6 +169,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">
<SwitchPreferenceCompat

View file

@ -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)