Skip to content

Commit fc3e77b

Browse files
committed
improve UI
1 parent 3c9f0ce commit fc3e77b

9 files changed

Lines changed: 83 additions & 7 deletions

File tree

.idea/misc.xml

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

app/src/main/java/com/caniwebview/android/ui/config/ConfigFragment.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
package com.caniwebview.android.ui.config
22

33
import android.content.Context
4+
import android.content.Intent
45
import android.content.SharedPreferences
6+
import android.net.Uri
57
import android.os.Bundle
68
import android.view.LayoutInflater
9+
import android.view.Menu
10+
import android.view.MenuInflater
11+
import android.view.MenuItem
712
import android.view.View
813
import android.view.ViewGroup
14+
import androidx.core.view.MenuHost
15+
import androidx.core.view.MenuProvider
916
import androidx.fragment.app.Fragment
17+
import androidx.lifecycle.Lifecycle
18+
import com.caniwebview.android.R
1019
import com.caniwebview.android.databinding.FragmentConfigBinding
1120

1221
class ConfigFragment : Fragment() {
@@ -25,13 +34,43 @@ class ConfigFragment : Fragment() {
2534

2635
sharedPreferences = requireActivity().getSharedPreferences("WebViewSettings", Context.MODE_PRIVATE)
2736

37+
// Add the MenuProvider
38+
setupMenu()
39+
2840
// Initialize UI elements and load saved settings
2941
setupUI()
3042
loadSettings()
3143

3244
return root
3345
}
3446

47+
private fun setupMenu() {
48+
// The usage of an interface lets you inject your own implementation.
49+
val menuHost: MenuHost = requireActivity()
50+
51+
// Add menu items without using the Fragment Menu APIs
52+
// Note how we can tie the MenuProvider to the viewLifecycleOwner
53+
// and an optional Lifecycle.State.
54+
menuHost.addMenuProvider(object : MenuProvider {
55+
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
56+
// Add menu items here
57+
menuInflater.inflate(R.menu.menu_config, menu)
58+
}
59+
60+
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
61+
// Handle the menu selection
62+
return when (menuItem.itemId) {
63+
R.id.action_github -> {
64+
openGitHub()
65+
true
66+
}
67+
68+
else -> false
69+
}
70+
}
71+
}, viewLifecycleOwner, Lifecycle.State.RESUMED)
72+
}
73+
3574
private fun setupUI() {
3675
binding.javaScriptEnabledCheckBox.setOnCheckedChangeListener { _, isChecked ->
3776
saveSetting("javaScriptEnabled", isChecked)
@@ -63,6 +102,11 @@ class ConfigFragment : Fragment() {
63102
}
64103
}
65104

105+
private fun openGitHub() {
106+
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/WebView-CG/CanIAndroidWebView"))
107+
startActivity(intent)
108+
}
109+
66110
override fun onDestroyView() {
67111
super.onDestroyView()
68112
_binding = null
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M17.6,9.48l1.84,-3.18c0.16,-0.31 0.04,-0.69 -0.26,-0.85c-0.29,-0.15 -0.65,-0.06 -0.83,0.22l-1.88,3.24c-2.86,-1.21 -6.08,-1.21 -8.94,0L5.65,5.67c-0.19,-0.29 -0.58,-0.38 -0.87,-0.2C4.5,5.65 4.41,6.01 4.56,6.3L6.4,9.48C3.3,11.25 1.28,14.44 1,18h22C22.72,14.44 20.7,11.25 17.6,9.48zM7,15.25c-0.69,0 -1.25,-0.56 -1.25,-1.25c0,-0.69 0.56,-1.25 1.25,-1.25S8.25,13.31 8.25,14C8.25,14.69 7.69,15.25 7,15.25zM17,15.25c-0.69,0 -1.25,-0.56 -1.25,-1.25c0,-0.69 0.56,-1.25 1.25,-1.25s1.25,0.56 1.25,1.25C18.25,14.69 17.69,15.25 17,15.25z"/>
4+
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M19,4L5,4c-1.11,0 -2,0.9 -2,2v12c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,6c0,-1.1 -0.89,-2 -2,-2zM19,18L5,18L5,8h14v10z"/>
4+
5+
</vector>

app/src/main/res/layout/fragment_webview.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@
1313
android:layout_width="0dp"
1414
android:layout_height="wrap_content"
1515
android:layout_weight="1"
16-
android:hint="Enter URL"
17-
android:text="@string/default_url"
18-
android:padding="8dp" />
16+
android:autofillHints="url"
17+
android:hint="@string/enter_url"
18+
android:inputType="textUri"
19+
android:minHeight="48dp"
20+
android:padding="8dp"
21+
android:text="@string/default_url" />
1922

2023
<Button
2124
android:id="@+id/load_button"
2225
android:layout_width="wrap_content"
2326
android:layout_height="wrap_content"
24-
android:text="Load"
27+
android:text="@string/load"
2528
android:padding="8dp" />
2629
</LinearLayout>
2730

app/src/main/res/menu/bottom_nav_menu.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<item
55
android:id="@+id/navigation_webview"
6-
android:icon="@drawable/ic_home_black_24dp"
6+
android:icon="@drawable/ic_baseline_web_asset_24"
77
android:title="@string/title_webview" />
88

99
<item
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
<item
5+
android:id="@+id/action_github"
6+
android:title="@string/github"
7+
app:showAsAction="never" />
8+
</menu>

app/src/main/res/navigation/mobile_navigation.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
android:id="@+id/navigation_webview"
1010
android:name="com.caniwebview.android.ui.webview.WebViewFragment"
1111
android:label="@string/title_webview"
12-
tools:layout="@layout/fragment_dashboard" />
12+
tools:layout="@layout/fragment_webview" />
1313

1414
<fragment
1515
android:id="@+id/navigation_config"
1616
android:name="com.caniwebview.android.ui.config.ConfigFragment"
1717
android:label="@string/title_config"
18-
tools:layout="@layout/fragment_webviewsettings" />
18+
tools:layout="@layout/fragment_config" />
1919

2020
</navigation>

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77
<string name="javascript_can_open_windows">JavaScript Can Open Windows</string>
88
<string name="dom_storage_enabled">DOM Storage Enabled</string>
99
<string name="geolocation_enabled">Geolocation Enabled</string>
10+
<string name="enter_url">Enter URL</string>
11+
<string name="load">Load</string>
12+
<string name="code">Code</string>
13+
<string name="github">GitHub</string>
1014
</resources>

0 commit comments

Comments
 (0)