From 62f25e73b27a30ae541b7d51d0fe843388f0da94 Mon Sep 17 00:00:00 2001 From: Ejaz Ali Date: Sat, 15 Jan 2022 20:01:30 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Better=20Deeplinking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/co/dothq/browser/BrowserActivity.kt | 1 - .../java/co/dothq/browser/BrowserDelegates.kt | 21 +++++++++++++------ app/src/main/res/layout/activity_main.xml | 4 ++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/co/dothq/browser/BrowserActivity.kt b/app/src/main/java/co/dothq/browser/BrowserActivity.kt index efa039f..0b3ca5f 100644 --- a/app/src/main/java/co/dothq/browser/BrowserActivity.kt +++ b/app/src/main/java/co/dothq/browser/BrowserActivity.kt @@ -16,7 +16,6 @@ import co.dothq.browser.subactivities.AddressBar import org.mozilla.geckoview.GeckoRuntime import org.mozilla.geckoview.GeckoSession import org.mozilla.geckoview.GeckoView -import java.net.MalformedURLException import java.net.URL diff --git a/app/src/main/java/co/dothq/browser/BrowserDelegates.kt b/app/src/main/java/co/dothq/browser/BrowserDelegates.kt index 0b3d21c..ab57825 100644 --- a/app/src/main/java/co/dothq/browser/BrowserDelegates.kt +++ b/app/src/main/java/co/dothq/browser/BrowserDelegates.kt @@ -2,11 +2,9 @@ package co.dothq.browser import android.app.Activity import android.content.Context -import android.graphics.drawable.Drawable import android.net.Uri import android.widget.ImageView import android.widget.TextView -import android.widget.Toast import androidx.core.content.ContextCompat import androidx.core.net.toUri import co.dothq.browser.managers.StorageManager @@ -25,11 +23,14 @@ class BrowserDelegates { if (area == "main") { val activity: Activity = (context as Activity) val contextualIdIcon = activity.findViewById(R.id.contextIdentityIcon) + val deeplinkContextualIdIcon = activity.findViewById(R.id.deeplinkContextIdentityIcon) - - if (securityInfo.isSecure) contextualIdIcon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_secure_filled)) - if (!securityInfo.isSecure) contextualIdIcon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_unsecure_filled)) + if (securityInfo.isSecure) { + contextualIdIcon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_secure_filled)) + } else { + contextualIdIcon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_unsecure_filled)) + } StorageManager().set(applicationCtx, "contextualIdentity", securityInfo.isSecure, "appValues"); } @@ -60,7 +61,12 @@ class BrowserDelegates { ) val uri: Uri = url.toString().toUri(); - val host = uri.host.toString(); + var host = uri.host.toString(); + + if (host.startsWith("www.")) { + host = host.replace("www.", "") + } + val path = url.toString().replace("${uri.scheme}://${uri.host}", ""); if (area == "main") { @@ -68,12 +74,15 @@ class BrowserDelegates { activity.findViewById(R.id.addressBarDomain).text = host.toString(); + activity.findViewById(R.id.deeplinkAddressBarDomain).text = + host.toString(); if (path != "/") activity.findViewById(R.id.addressBarPath).text = path if (path == "/") activity.findViewById(R.id.addressBarPath).text = "" if (path == "about:blank") { activity.findViewById(R.id.addressBarDomain).text = "" + activity.findViewById(R.id.deeplinkAddressBarDomain).text = "" activity.findViewById(R.id.addressBarPath).text = "" } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 0443a4f..079315a 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -62,7 +62,7 @@ android:orientation="vertical">