M2: loading bar, live URL sync, fwd state, autocomplete suggestions
Browse files
app/src/main/java/dev/nova/browser/BrowserActivity.kt
CHANGED
|
@@ -12,6 +12,9 @@ import androidx.compose.foundation.lazy.items
|
|
| 12 |
import androidx.compose.material3.*
|
| 13 |
import androidx.compose.runtime.*
|
| 14 |
import androidx.compose.ui.Modifier
|
|
|
|
|
|
|
|
|
|
| 15 |
import androidx.compose.ui.unit.dp
|
| 16 |
import androidx.compose.ui.viewinterop.AndroidView
|
| 17 |
import org.mozilla.geckoview.GeckoResult
|
|
@@ -108,26 +111,38 @@ class BrowserActivity : ComponentActivity() {
|
|
| 108 |
}
|
| 109 |
|
| 110 |
// ------------------------------------------------------------------
|
| 111 |
-
// UI (
|
| 112 |
// ------------------------------------------------------------------
|
| 113 |
@Composable
|
| 114 |
private fun NovaUI() {
|
| 115 |
var urlInput by remember { mutableStateOf("https://example.com") }
|
|
|
|
| 116 |
var trayOpen by remember { mutableStateOf(false) }
|
| 117 |
val geckoView = remember { GeckoView(this) }
|
|
|
|
| 118 |
val activeId by tabManager.activeTabId
|
| 119 |
-
val canGoBack by remember {
|
| 120 |
-
derivedStateOf { tabManager.canGoBack() }
|
| 121 |
-
}
|
| 122 |
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
LaunchedEffect(activeId) {
|
| 125 |
val id = activeId ?: return@LaunchedEffect
|
| 126 |
val tab = tabManager.tabs.firstOrNull { t -> t.id == id } ?: return@LaunchedEffect
|
| 127 |
geckoView.setSession(tab.session)
|
| 128 |
-
// Sync the URL bar with the tab we just activated.
|
| 129 |
-
tabManager.lastUrls[id]?.let { urlInput = it }
|
| 130 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
if (trayOpen) {
|
| 133 |
TabTray(
|
|
@@ -146,22 +161,67 @@ class BrowserActivity : ComponentActivity() {
|
|
| 146 |
OutlinedTextField(
|
| 147 |
value = urlInput,
|
| 148 |
onValueChange = { urlInput = it },
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
label = { Text("Search or enter address") },
|
| 151 |
singleLine = true,
|
| 152 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
Row(Modifier.padding(horizontal = 8.dp)) {
|
| 154 |
TextButton(
|
| 155 |
onClick = { tabManager.activeSession()?.goBack() },
|
| 156 |
enabled = canGoBack,
|
| 157 |
) { Text("◀") }
|
| 158 |
-
TextButton(
|
|
|
|
|
|
|
|
|
|
| 159 |
TextButton(onClick = { tabManager.activeSession()?.reload() }) { Text("��") }
|
| 160 |
-
TextButton(onClick = {
|
|
|
|
|
|
|
|
|
|
| 161 |
TextButton(onClick = { tabManager.open("about:blank") }) { Text("+") }
|
| 162 |
TextButton(onClick = { trayOpen = true }) { Text("Tabs ${tabManager.tabs.size}") }
|
| 163 |
}
|
| 164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
// Tab strip
|
| 166 |
LazyRow(Modifier.padding(horizontal = 8.dp)) {
|
| 167 |
items(tabManager.tabs, key = { it.id }) { tab ->
|
|
|
|
| 12 |
import androidx.compose.material3.*
|
| 13 |
import androidx.compose.runtime.*
|
| 14 |
import androidx.compose.ui.Modifier
|
| 15 |
+
import androidx.compose.ui.focus.onFocusChanged
|
| 16 |
+
import androidx.compose.ui.platform.LocalFocusManager
|
| 17 |
+
import androidx.compose.ui.text.style.TextOverflow
|
| 18 |
import androidx.compose.ui.unit.dp
|
| 19 |
import androidx.compose.ui.viewinterop.AndroidView
|
| 20 |
import org.mozilla.geckoview.GeckoResult
|
|
|
|
| 111 |
}
|
| 112 |
|
| 113 |
// ------------------------------------------------------------------
|
| 114 |
+
// UI (M2: toolbar polish; extension manager UI is the M3 milestone)
|
| 115 |
// ------------------------------------------------------------------
|
| 116 |
@Composable
|
| 117 |
private fun NovaUI() {
|
| 118 |
var urlInput by remember { mutableStateOf("https://example.com") }
|
| 119 |
+
var urlFocused by remember { mutableStateOf(false) }
|
| 120 |
var trayOpen by remember { mutableStateOf(false) }
|
| 121 |
val geckoView = remember { GeckoView(this) }
|
| 122 |
+
val focusManager = LocalFocusManager.current
|
| 123 |
val activeId by tabManager.activeTabId
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
+
val canGoBack by remember { derivedStateOf { tabManager.canGoBack() } }
|
| 126 |
+
val canGoForward by remember { derivedStateOf { tabManager.canGoForward() } }
|
| 127 |
+
|
| 128 |
+
// M2: loading state + progress of the active tab
|
| 129 |
+
val loading = activeId != null && tabManager.loadingStates[activeId!!] == true
|
| 130 |
+
val progress = activeId?.let { tabManager.progressStates[it] } ?: 0
|
| 131 |
+
|
| 132 |
+
// M2: live URL sync — follow the active tab's navigation while the
|
| 133 |
+
// user is not editing the address bar.
|
| 134 |
+
val activeUrl = activeId?.let { tabManager.lastUrls[it] }
|
| 135 |
LaunchedEffect(activeId) {
|
| 136 |
val id = activeId ?: return@LaunchedEffect
|
| 137 |
val tab = tabManager.tabs.firstOrNull { t -> t.id == id } ?: return@LaunchedEffect
|
| 138 |
geckoView.setSession(tab.session)
|
|
|
|
|
|
|
| 139 |
}
|
| 140 |
+
LaunchedEffect(activeUrl) {
|
| 141 |
+
if (!urlFocused && activeUrl != null) urlInput = activeUrl
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
// M2: autocomplete suggestions from history while typing
|
| 145 |
+
val suggestions = if (urlFocused) tabManager.suggestionsFor(urlInput) else emptyList()
|
| 146 |
|
| 147 |
if (trayOpen) {
|
| 148 |
TabTray(
|
|
|
|
| 161 |
OutlinedTextField(
|
| 162 |
value = urlInput,
|
| 163 |
onValueChange = { urlInput = it },
|
| 164 |
+
onNavigateToSuggestion = null,
|
| 165 |
+
modifier = Modifier
|
| 166 |
+
.fillMaxWidth()
|
| 167 |
+
.padding(horizontal = 8.dp, vertical = 4.dp)
|
| 168 |
+
.onFocusChanged { urlFocused = it.isFocused },
|
| 169 |
label = { Text("Search or enter address") },
|
| 170 |
singleLine = true,
|
| 171 |
)
|
| 172 |
+
|
| 173 |
+
// Autocomplete dropdown (history matches, most recent first)
|
| 174 |
+
if (urlFocused && suggestions.isNotEmpty()) {
|
| 175 |
+
Surface(
|
| 176 |
+
tonalElevation = 4.dp,
|
| 177 |
+
modifier = Modifier
|
| 178 |
+
.fillMaxWidth()
|
| 179 |
+
.padding(horizontal = 8.dp),
|
| 180 |
+
) {
|
| 181 |
+
Column {
|
| 182 |
+
suggestions.forEach { suggestion ->
|
| 183 |
+
TextButton(
|
| 184 |
+
onClick = {
|
| 185 |
+
urlInput = suggestion
|
| 186 |
+
urlFocused = false
|
| 187 |
+
focusManager.clearFocus()
|
| 188 |
+
tabManager.activeSession()?.loadUri(suggestion)
|
| 189 |
+
},
|
| 190 |
+
modifier = Modifier.fillMaxWidth(),
|
| 191 |
+
) {
|
| 192 |
+
Text(suggestion, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
Row(Modifier.padding(horizontal = 8.dp)) {
|
| 200 |
TextButton(
|
| 201 |
onClick = { tabManager.activeSession()?.goBack() },
|
| 202 |
enabled = canGoBack,
|
| 203 |
) { Text("◀") }
|
| 204 |
+
TextButton(
|
| 205 |
+
onClick = { tabManager.activeSession()?.goForward() },
|
| 206 |
+
enabled = canGoForward,
|
| 207 |
+
) { Text("▶") }
|
| 208 |
TextButton(onClick = { tabManager.activeSession()?.reload() }) { Text("��") }
|
| 209 |
+
TextButton(onClick = {
|
| 210 |
+
focusManager.clearFocus()
|
| 211 |
+
tabManager.activeSession()?.loadUri(normalize(urlInput))
|
| 212 |
+
}) { Text("Go") }
|
| 213 |
TextButton(onClick = { tabManager.open("about:blank") }) { Text("+") }
|
| 214 |
TextButton(onClick = { trayOpen = true }) { Text("Tabs ${tabManager.tabs.size}") }
|
| 215 |
}
|
| 216 |
|
| 217 |
+
// M2: loading bar for the active tab
|
| 218 |
+
if (loading) {
|
| 219 |
+
LinearProgressIndicator(
|
| 220 |
+
progress = { progress / 100f },
|
| 221 |
+
modifier = Modifier.fillMaxWidth(),
|
| 222 |
+
)
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
// Tab strip
|
| 226 |
LazyRow(Modifier.padding(horizontal = 8.dp)) {
|
| 227 |
items(tabManager.tabs, key = { it.id }) { tab ->
|