Skip to content

Commit f0859ae

Browse files
committed
🚧 Contextual identity now shows on address bar.
1 parent 10e528d commit f0859ae

File tree

13 files changed

+167
-20
lines changed

13 files changed

+167
-20
lines changed

‎.idea/misc.xml‎

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app/build.gradle‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ android {
1414
versionName "1.0"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
vectorDrawables.useSupportLibrary = true
1718
}
1819

1920
buildTypes {
@@ -32,7 +33,7 @@ android {
3233
sourceSets {
3334
main {
3435
assets {
35-
srcDirs 'src\\main\\assets', 'src\\main\\java\\co\\dothq\\browser\\config'
36+
srcDirs 'src\\main\\assets', 'src\\main\\java\\co\\dothq\\browser\\config', 'src\\main\\java\\co\\dothq\\browser\\extensions\\search'
3637
}
3738
}
3839
}

‎app/src/main/java/co/dothq/browser/BrowserActivity.kt‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import android.content.Intent
55
import android.net.Uri
66
import android.os.Bundle
77
import android.view.View
8+
import android.widget.ImageView
89
import android.widget.LinearLayout
10+
import android.widget.TextView
911
import android.widget.Toast
1012
import androidx.activity.result.contract.ActivityResultContracts
1113
import androidx.appcompat.app.AppCompatActivity
14+
import androidx.core.net.toUri
1215
import co.dothq.browser.managers.ApplicationManager
1316
import co.dothq.browser.managers.PreferencesManager
1417
import co.dothq.browser.managers.StorageManager
@@ -35,11 +38,12 @@ class BrowserActivity : AppCompatActivity() {
3538

3639
if (appSetup == false) return;
3740
val view = findViewById<GeckoView>(R.id.geckoview)
38-
val session = GeckoSession()
3941
val runtime = GeckoRuntime.getDefault(this)
42+
val session = GeckoSession()
4043

4144
session.open(runtime)
4245
view.setSession(session)
46+
4347
session.navigationDelegate = BrowserDelegates().createNavigationDelegate("main", this, applicationContext);
4448
session.progressDelegate = BrowserDelegates().createProgressDelegate("main", this, applicationContext);
4549

@@ -48,7 +52,17 @@ class BrowserActivity : AppCompatActivity() {
4852
// There are no request codes
4953
val data: Intent? = result.data
5054

51-
session.loadUri(data?.getStringExtra("targetURI").toString())
55+
val url = data?.getStringExtra("targetURI")?.toUri();
56+
57+
val host = url?.host.toString();
58+
val path = url.toString().replace("${url?.scheme}://${url?.host}", "");
59+
60+
findViewById<TextView>(R.id.addressBarDomain).text = host.toString();
61+
62+
if (path != "/") findViewById<TextView>(R.id.addressBarPath).text = path
63+
if (path == "/") findViewById<TextView>(R.id.addressBarPath).text = ""
64+
65+
session.loadUri(url.toString())
5266
}
5367
}
5468

@@ -57,6 +71,7 @@ class BrowserActivity : AppCompatActivity() {
5771

5872
addressBar.setOnClickListener {
5973
val addressBarIntent = Intent(this, AddressBar::class.java);
74+
val contextualIdentityIcon = findViewById<ImageView>(R.id.contextIdentityIcon);
6075

6176
addressBarIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
6277
addressBarIntent.putExtra("currentURI", StorageManager().get(applicationContext, "currentUri", "appValues", "about:blank").toString())
@@ -75,6 +90,11 @@ class BrowserActivity : AppCompatActivity() {
7590
}
7691
}
7792

93+
override fun onBackPressed() {
94+
super.onBackPressed()
95+
finish()
96+
}
97+
7898
fun initStatusbar() {
7999
if (resources.getString(R.string.mode) == "Day") {
80100
getWindow().getDecorView()

‎app/src/main/java/co/dothq/browser/BrowserDelegates.kt‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ class BrowserDelegates {
2424

2525
if (area == "main") {
2626
val activity: Activity = (context as Activity)
27-
val contextualIdIcon = activity.findViewById<ImageView>(R.id.contextIdentityIcon);
27+
val contextualIdIcon = activity.findViewById<ImageView>(R.id.contextIdentityIcon)
28+
29+
2830

2931
if (securityInfo.isSecure) contextualIdIcon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_secure_filled))
3032
if (!securityInfo.isSecure) contextualIdIcon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_unsecure_filled))
31-
Toast.makeText(context, securityInfo.securityMode.toString(), Toast.LENGTH_LONG).show()
33+
34+
StorageManager().set(applicationCtx, "contextualIdentity", securityInfo.isSecure, "appValues");
3235
}
3336
}
3437

@@ -45,6 +48,7 @@ class BrowserDelegates {
4548

4649
public fun createNavigationDelegate(area: String, context: Context, applicationCtx: Context): GeckoSession.NavigationDelegate {
4750
return object : GeckoSession.NavigationDelegate {
51+
var canGoBack = false
4852

4953
override fun onLocationChange(session: GeckoSession, url: String?) {
5054
super.onLocationChange(session, url)
@@ -67,12 +71,22 @@ class BrowserDelegates {
6771

6872
if (path != "/") activity.findViewById<TextView>(R.id.addressBarPath).text = path
6973
if (path == "/") activity.findViewById<TextView>(R.id.addressBarPath).text = ""
74+
75+
if (path == "about:blank") {
76+
activity.findViewById<TextView>(R.id.addressBarDomain).text = ""
77+
activity.findViewById<TextView>(R.id.addressBarPath).text = ""
78+
}
7079
}
7180
}
7281

7382
override fun onLoadRequest(session: GeckoSession, request: GeckoSession.NavigationDelegate.LoadRequest): GeckoResult<AllowOrDeny>? {
83+
84+
val activity: Activity = (context as Activity)
85+
val contextualIdIcon = activity.findViewById<ImageView>(R.id.contextIdentityIcon)
86+
contextualIdIcon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_globe))
7487
return (GeckoResult.allow())
7588
}
89+
7690
}
7791
}
7892
}

‎app/src/main/java/co/dothq/browser/managers/StorageManager.kt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class StorageManager {
1818

1919
val type = typePreferences.getString(id, null);
2020

21-
Log.d("sex", "${type} (${id})")
2221
if (type == "String") {
2322
return preferences.getString(id, null) ?: defaultValue;
2423
}
@@ -28,7 +27,6 @@ class StorageManager {
2827
}
2928

3029
if (type == "Boolean") {
31-
Log.d("sex", preferences.getBoolean(id, false).toString())
3230
return preferences.getBoolean(id, false) ?: defaultValue;
3331
}
3432

‎app/src/main/java/co/dothq/browser/subactivities/AddressBar.kt‎

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ import android.app.Activity
44
import android.content.Context
55
import android.content.Intent
66
import android.os.Bundle
7+
import android.text.Editable
8+
import android.text.TextWatcher
79
import android.view.KeyEvent
810
import android.view.View
911
import android.view.WindowManager
1012
import android.view.inputmethod.InputMethodManager
1113
import android.widget.EditText
14+
import android.widget.ImageView
1215
import android.widget.Toast
1316
import androidx.appcompat.app.AppCompatActivity
17+
import androidx.core.content.ContextCompat
1418
import co.dothq.browser.R
19+
import co.dothq.browser.managers.PreferencesManager
1520
import co.dothq.browser.managers.StorageManager
1621

1722

@@ -22,26 +27,80 @@ class AddressBar : AppCompatActivity() {
2227
setContentView(R.layout.activity_address_bar)
2328
val uri :String = intent.getStringExtra("currentURI").toString();
2429

30+
val contextualIdentity = StorageManager().get(applicationContext, "contextualIdentity", "appValues", false);
31+
32+
val contextualIdentityIcon = findViewById<ImageView>(R.id.contextIdentityIcon);
33+
34+
contextualIdentityIcon.setImageDrawable(
35+
ContextCompat.getDrawable(this, R.drawable.ic_unsecure_filled));
36+
37+
if (contextualIdentity is Boolean) {
38+
if (contextualIdentity) contextualIdentityIcon.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_secure_filled))
39+
if (!contextualIdentity) contextualIdentityIcon.setImageDrawable(
40+
ContextCompat.getDrawable(this, R.drawable.ic_unsecure_filled));
41+
}
42+
2543
val editBox = findViewById<EditText>(R.id.urlEnterBox);
2644
editBox.setText(uri);
2745

2846
editBox.requestFocus();
2947
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
3048
editBox.selectAll()
3149

50+
editBox.addTextChangedListener(object : TextWatcher {
51+
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
52+
var text = editBox.text.toString().trim();
53+
54+
val uriRegex = """^(?:\w+:)?\/\/([^\s.]+\.\S{2}|localhost[:?\d]*)\S*$""".toRegex()
55+
56+
if (!uriRegex.matches(text)) {
57+
if (uriRegex.matches("http://${text}")) {
58+
text = "http://${text}"
59+
contextualIdentityIcon.setImageDrawable(
60+
ContextCompat.getDrawable(this@AddressBar, R.drawable.ic_globe));
61+
} else {
62+
text = "https://duckduckgo.com/?q=%s".replace("%s", text)
63+
contextualIdentityIcon.setImageDrawable(
64+
ContextCompat.getDrawable(this@AddressBar, R.drawable.ic_search));
65+
}
66+
} else {
67+
contextualIdentityIcon.setImageDrawable(
68+
ContextCompat.getDrawable(this@AddressBar, R.drawable.ic_globe));
69+
}
70+
}
71+
72+
override fun afterTextChanged(s: Editable?) {}
73+
74+
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
75+
})
76+
3277
editBox.setOnKeyListener(View.OnKeyListener { v, keyCode, event ->
78+
79+
var text = editBox.text.toString().trim();
80+
81+
if (event.action == KeyEvent.ACTION_UP) {
82+
val uriRegex = """^(?:\w+:)?\/\/([^\s.]+\.\S{2}|localhost[:?\d]*)\S*$""".toRegex()
83+
84+
if (!uriRegex.matches(text)) {
85+
if (uriRegex.matches("http://${text}")) {
86+
text = "http://${text}"
87+
} else {
88+
text = "https://duckduckgo.com/?q=%s".replace("%s", text)
89+
}
90+
}
91+
}
92+
3393
if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP) {
3494

35-
var text = editBox.text.toString();
3695
if (text.trim() == "") {
3796
setResult(Activity.RESULT_CANCELED)
3897
finish()
3998
overridePendingTransition(0, 0)
4099
} else {
41100

42101
val data = Intent()
43-
data.putExtra("targetURI", text.trim());
44-
// more handling here
102+
103+
data.putExtra("targetURI", text);
45104
setResult(Activity.RESULT_OK, data);
46105
finish()
47106
overridePendingTransition(0, 0)

‎app/src/main/java/co/dothq/browser/util/defaultProfile.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class defaultProfile {
2222

2323
// dot.newtab
2424
pref("dot.newtab.enabled", true, context)
25-
pref("dot.newtab.urls", "about:home", context) // accepts a single URL or urls split by |
25+
pref("dot.newtab.urls", "about:home", context)
26+
pref("dot.search.engine_id", "ddg@search.dothq.co", context);
27+
2628
}
2729
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24">
6+
<path
7+
android:pathData="M12,12m-10,0a10,10 0,1 1,20 0a10,10 0,1 1,-20 0"
8+
android:strokeLineJoin="round"
9+
android:strokeWidth="2"
10+
android:fillColor="#00000000"
11+
android:strokeColor="?colorSecondary"
12+
android:strokeLineCap="round"/>
13+
<path
14+
android:pathData="M2,12L22,12"
15+
android:strokeLineJoin="round"
16+
android:strokeWidth="2"
17+
android:fillColor="#00000000"
18+
android:strokeColor="?colorSecondary"
19+
android:strokeLineCap="round"/>
20+
<path
21+
android:pathData="M12,2a15.3,15.3 0,0 1,4 10,15.3 15.3,0 0,1 -4,10 15.3,15.3 0,0 1,-4 -10,15.3 15.3,0 0,1 4,-10z"
22+
android:strokeLineJoin="round"
23+
android:strokeWidth="2"
24+
android:fillColor="#00000000"
25+
android:strokeColor="?colorSecondary"
26+
android:strokeLineCap="round"/>
27+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="16dp"
3+
android:height="16dp"
4+
android:viewportWidth="16"
5+
android:viewportHeight="16">
6+
<path
7+
android:pathData="M13,6.5C13,2.9102 10.0899,0 6.5,0C2.9102,0 0,2.9102 0,6.5C0,10.0899 2.9102,13 6.5,13C7.8573,13 9.1173,12.584 10.1597,11.8726C10.2616,11.8031 10.399,11.8132 10.4862,11.9004L14.2929,15.7071C14.6834,16.0976 15.3166,16.0976 15.7071,15.7071C16.0976,15.3166 16.0976,14.6834 15.7071,14.2929L11.9004,10.4862C11.8132,10.399 11.8031,10.2616 11.8726,10.1597C12.584,9.1173 13,7.8573 13,6.5ZM11,6.5C11,4.0147 8.9853,2 6.5,2C4.0147,2 2,4.0147 2,6.5C2,8.9853 4.0147,11 6.5,11C8.9853,11 11,8.9853 11,6.5Z"
8+
android:fillColor="?colorSecondary"
9+
android:fillType="evenOdd"/>
10+
</vector>

‎app/src/main/res/drawable/ic_secure_filled.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
android:viewportHeight="16">
77
<path
88
android:pathData="M12.2499,5.0103C12.1123,4.9989 12,4.8881 12,4.75V4C12,1.7909 10.2091,0 8,0C5.7909,0 4,1.7909 4,4V4.75C4,4.8881 3.8877,4.9989 3.7501,5.0103C2.2102,5.1373 1,6.4273 1,8V13C1,14.6569 2.3431,16 4,16H12C13.6569,16 15,14.6569 15,13V8C15,6.4273 13.7898,5.1373 12.2499,5.0103ZM10,4C10,2.8954 9.1046,2 8,2C6.8954,2 6,2.8954 6,4V4.75C6,4.8881 6.1119,5 6.25,5H9.75C9.8881,5 10,4.8881 10,4.75V4Z"
9-
android:fillColor="#000000"
9+
android:fillColor="?colorSecondary"
1010
android:fillType="evenOdd"/>
1111
</vector>

0 commit comments

Comments
 (0)