From 5a01bf2cbdc914a3535ee6ebda3ec0f6532f9412 Mon Sep 17 00:00:00 2001 From: Ejaz Ali Date: Sun, 2 Jan 2022 00:27:10 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Address=20bar=20functionality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/deploymentTargetDropDown.xml | 17 ++++++ .idea/misc.xml | 8 ++- .idea/render.experimental.xml | 6 +++ app/build.gradle | 6 ++- .../java/co/dothq/browser/BrowserActivity.kt | 24 ++++----- .../java/co/dothq/browser/BrowserDelegates.kt | 43 ++++++++------- .../dothq/browser/subactivities/AddressBar.kt | 45 +++++++++++++++- .../main/res/drawable/input_layout_normal.xml | 2 +- .../main/res/drawable/invisible_button.xml | 7 +++ .../res/drawable/invisible_button_normal.xml | 5 ++ .../res/drawable/invisible_button_pressed.xml | 6 +++ .../main/res/layout/activity_address_bar.xml | 53 +++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 52 ++++++++++++------ app/src/main/res/values/strings.xml | 1 + 14 files changed, 223 insertions(+), 52 deletions(-) create mode 100644 .idea/deploymentTargetDropDown.xml create mode 100644 .idea/render.experimental.xml create mode 100644 app/src/main/res/drawable/invisible_button.xml create mode 100644 app/src/main/res/drawable/invisible_button_normal.xml create mode 100644 app/src/main/res/drawable/invisible_button_pressed.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..545ae16 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 281591c..732c7aa 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,16 +5,20 @@ + + + + - - + + diff --git a/.idea/render.experimental.xml b/.idea/render.experimental.xml new file mode 100644 index 0000000..8ec256a --- /dev/null +++ b/.idea/render.experimental.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index b9ec1a7..de292a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -40,6 +40,9 @@ android { dependencies { def lifecycle_version = "2.2.0" + def ff_version = "95.0" + def gecko_version = "$ff_version.20211218203254" + implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" @@ -51,7 +54,8 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.2' - implementation "org.mozilla.geckoview:geckoview:95.0.20211218203254" + implementation "org.mozilla.geckoview:geckoview:$gecko_version" + implementation "org.mozilla.components:browser-icons:$ff_version.0" implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' diff --git a/app/src/main/java/co/dothq/browser/BrowserActivity.kt b/app/src/main/java/co/dothq/browser/BrowserActivity.kt index a166f0b..ccecdd7 100644 --- a/app/src/main/java/co/dothq/browser/BrowserActivity.kt +++ b/app/src/main/java/co/dothq/browser/BrowserActivity.kt @@ -21,7 +21,6 @@ import co.dothq.browser.subactivities.AddressBar class BrowserActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState); - this.initStatusbar(); ApplicationManager().init(applicationContext, this); @@ -43,6 +42,15 @@ class BrowserActivity : AppCompatActivity() { session.navigationDelegate = BrowserDelegates().createNavigationDelegate("main", this, applicationContext); session.progressDelegate = BrowserDelegates().createProgressDelegate("main", this, applicationContext); + var addressBarLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == Activity.RESULT_OK) { + // There are no request codes + val data: Intent? = result.data + + session.loadUri(data?.getStringExtra("targetURI").toString()) + } + } + val addressBar = findViewById(R.id.addressBarContainer); @@ -50,17 +58,9 @@ class BrowserActivity : AppCompatActivity() { val addressBarIntent = Intent(this, AddressBar::class.java); addressBarIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); - - var launchAddressBar = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> - if (result.resultCode == Activity.RESULT_OK) { - val data: Intent? = result.data - if (data != null) { - session.loadUri(data.toString()); - } - } - } - - launchAddressBar.launch(addressBarIntent) + addressBarIntent.putExtra("currentURI", StorageManager().get(applicationContext, "currentUri", "appValues", "about:blank").toString()) + addressBarLauncher.launch(addressBarIntent) + overridePendingTransition(0, 0); } session.loadUri("https://ddg.gg") diff --git a/app/src/main/java/co/dothq/browser/BrowserDelegates.kt b/app/src/main/java/co/dothq/browser/BrowserDelegates.kt index 5ddd24b..516f8bc 100644 --- a/app/src/main/java/co/dothq/browser/BrowserDelegates.kt +++ b/app/src/main/java/co/dothq/browser/BrowserDelegates.kt @@ -3,10 +3,12 @@ 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 import org.mozilla.geckoview.AllowOrDeny import org.mozilla.geckoview.GeckoResult @@ -44,30 +46,33 @@ class BrowserDelegates { public fun createNavigationDelegate(area: String, context: Context, applicationCtx: Context): GeckoSession.NavigationDelegate { return object : GeckoSession.NavigationDelegate { - override fun onLoadRequest(session: GeckoSession, request: GeckoSession.NavigationDelegate.LoadRequest): GeckoResult? { - StorageManager().set(applicationCtx, "dot.current.uri", request.uri.toString(), "appValues") - val uri = request.uri; - var uriNoProtocol = uri - - if (uri.startsWith("https://")) uriNoProtocol = uriNoProtocol.replace("https://", ""); - if (uri.startsWith("http://")) uriNoProtocol = uriNoProtocol.replace("http://", ""); - - if (uriNoProtocol.startsWith("www.")) uriNoProtocol = uriNoProtocol.replace("www.", ""); + override fun onLocationChange(session: GeckoSession, url: String?) { + super.onLocationChange(session, url) + StorageManager().set( + applicationCtx, + "currentUri", + url.toString(), + "appValues" + ) - var uriSplitBySlash = uriNoProtocol.split("/"); - var uriJustHostname = uriSplitBySlash[0]; - var path = uriSplitBySlash.drop(1).joinToString("/"); + val uri: Uri = url.toString().toUri(); + val host = uri.host.toString(); + val path = url.toString().replace("${uri.scheme}://${uri.host}", ""); if (area == "main") { val activity: Activity = (context as Activity) - activity.findViewById(R.id.addressBarDomain).text = uriJustHostname.toString(); + activity.findViewById(R.id.addressBarDomain).text = + host.toString(); - if (path != "") activity.findViewById(R.id.addressBarPath).text = "/${path.toString()}"; - if (path == "") activity.findViewById(R.id.addressBarPath).text = path.toString() - } - return (GeckoResult.allow()) + if (path != "/") activity.findViewById(R.id.addressBarPath).text = path + if (path == "/") activity.findViewById(R.id.addressBarPath).text = "" + } + } + + override fun onLoadRequest(session: GeckoSession, request: GeckoSession.NavigationDelegate.LoadRequest): GeckoResult? { + return (GeckoResult.allow()) + } } } - } -} \ No newline at end of file + } \ No newline at end of file diff --git a/app/src/main/java/co/dothq/browser/subactivities/AddressBar.kt b/app/src/main/java/co/dothq/browser/subactivities/AddressBar.kt index 446d8d1..12358da 100644 --- a/app/src/main/java/co/dothq/browser/subactivities/AddressBar.kt +++ b/app/src/main/java/co/dothq/browser/subactivities/AddressBar.kt @@ -1,12 +1,55 @@ package co.dothq.browser.subactivities -import androidx.appcompat.app.AppCompatActivity +import android.app.Activity +import android.content.Intent import android.os.Bundle +import android.view.KeyEvent +import android.view.View +import android.widget.EditText +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity import co.dothq.browser.R +import co.dothq.browser.managers.StorageManager + class AddressBar : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_address_bar) + val uri :String = intent.getStringExtra("currentURI").toString(); + + val editBox = findViewById(R.id.urlEnterBox); + editBox.setText(uri); + + editBox.requestFocus(); + editBox.selectAll() + + editBox.setOnKeyListener(View.OnKeyListener { v, keyCode, event -> + if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP) { + + var text = editBox.text.toString(); + if (text.trim() == "") { + setResult(Activity.RESULT_CANCELED) + finish() + overridePendingTransition(0, 0) + } else { + + val data = Intent() + data.putExtra("targetURI", text.trim()); + // more handling here + setResult(Activity.RESULT_OK, data); + finish() + overridePendingTransition(0, 0) + } + return@OnKeyListener true + } + false + }) + + } + + override fun onBackPressed() { + super.onBackPressed() + overridePendingTransition(0, 0) } } \ No newline at end of file diff --git a/app/src/main/res/drawable/input_layout_normal.xml b/app/src/main/res/drawable/input_layout_normal.xml index fcda1d8..088f01a 100644 --- a/app/src/main/res/drawable/input_layout_normal.xml +++ b/app/src/main/res/drawable/input_layout_normal.xml @@ -1,7 +1,7 @@ - + diff --git a/app/src/main/res/drawable/invisible_button.xml b/app/src/main/res/drawable/invisible_button.xml new file mode 100644 index 0000000..55f07a3 --- /dev/null +++ b/app/src/main/res/drawable/invisible_button.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/invisible_button_normal.xml b/app/src/main/res/drawable/invisible_button_normal.xml new file mode 100644 index 0000000..351e7f8 --- /dev/null +++ b/app/src/main/res/drawable/invisible_button_normal.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/invisible_button_pressed.xml b/app/src/main/res/drawable/invisible_button_pressed.xml new file mode 100644 index 0000000..b15f076 --- /dev/null +++ b/app/src/main/res/drawable/invisible_button_pressed.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_address_bar.xml b/app/src/main/res/layout/activity_address_bar.xml index fcc218f..f8d9eff 100644 --- a/app/src/main/res/layout/activity_address_bar.xml +++ b/app/src/main/res/layout/activity_address_bar.xml @@ -6,4 +6,57 @@ android:layout_height="match_parent" tools:context=".subactivities.AddressBar"> + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index aa8d691..cb16b52 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -34,6 +34,7 @@ @@ -56,6 +57,8 @@ android:alpha="0.9" android:gravity="center" android:lines="1" + android:maxLines="1" + android:minLines="1" android:text="hostname/" android:textAlignment="viewStart" android:textColor="?colorSecondary" @@ -67,31 +70,48 @@ android:layout_height="match_parent" android:layout_weight="0" android:alpha="0.5" + android:ellipsize="end" android:gravity="center" + android:lines="1" + android:maxLines="1" + android:minLines="1" + android:paddingEnd="5sp" android:text="path" - android:textColor="?colorSecondary" /> + android:textAlignment="viewStart" + android:textColor="?colorSecondary" + app:autoSizeTextType="none" /> + android:layout_marginLeft="11dp" + android:background="@drawable/invisible_button" + android:orientation="vertical" + android:padding="5sp"> - + android:orientation="vertical"> + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 95c9155..b84a3a6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,4 +3,5 @@ Hello blank fragment GET_STARTED + Search or enter URL \ No newline at end of file