Skip to content

Commit 42f7616

Browse files
committed
android: fix Kotlin compiler warnings
fixes tailscale/corp#40476 Correcting all of the compiler warnings and code formatting issues. This also fixes the ‘make fmt’ recipe so it doesn’t build anything, it just formats the kt files. Signed-off-by: Jonathan Nobels <jonathan@tailscale.com>
1 parent 23dcc59 commit 42f7616

11 files changed

Lines changed: 149 additions & 172 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ test: gradle-dependencies ## Run the Android tests
327327
(cd android && ./gradlew test)
328328

329329
.PHONY: fmt
330-
fmt: gradle-dependencies ## Format the Android code
330+
fmt: ## Format the Android code
331331
(cd android && ./gradlew ktfmtFormat)
332332

333333
.PHONY: fmt-check
334-
fmt-check: gradle-dependencies ## Check the Android code is formatted
334+
fmt-check: ## Check the Android code is formatted
335335
(cd android && ./gradlew ktfmtCheck)
336336

337337
.PHONY: emulator

android/src/main/java/com/tailscale/ipn/App.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import kotlinx.coroutines.SupervisorJob
5252
import kotlinx.coroutines.cancel
5353
import kotlinx.coroutines.flow.combine
5454
import kotlinx.coroutines.flow.distinctUntilChanged
55-
import kotlinx.coroutines.flow.first
5655
import kotlinx.coroutines.launch
5756
import kotlinx.serialization.Serializable
5857
import kotlinx.serialization.encodeToString
@@ -174,8 +173,9 @@ class App : UninitializedApp(), libtailscale.AppContext, ViewModelStoreOwner {
174173
NetworkChangeCallback.monitorDnsChanges(connectivityManager, dns)
175174
initViewModels()
176175
applicationScope.launch {
177-
val rm = getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
178-
MDMSettings.update(get(), rm)
176+
val restrictionsManager =
177+
getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
178+
MDMSettings.update(get(), restrictionsManager)
179179
}
180180
applicationScope.launch {
181181
Notifier.state.collect { _ ->
@@ -208,9 +208,6 @@ class App : UninitializedApp(), libtailscale.AppContext, ViewModelStoreOwner {
208208
}
209209
}
210210
}
211-
applicationScope.launch {
212-
val hideDisconnectAction = MDMSettings.forceEnabled.flow.first()
213-
}
214211
TSLog.init(this)
215212
FeatureFlags.initialize(mapOf("enable_new_search" to true))
216213
}

android/src/main/java/com/tailscale/ipn/MainActivity.kt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class MainActivity : ComponentActivity() {
337337
loginAtUrl = ::login,
338338
navigation = mainViewNav,
339339
viewModel = viewModel,
340-
appViewModel = appViewModel)
340+
)
341341
}
342342
composable("search") {
343343
val autoFocus = viewModel.autoFocusSearch
@@ -473,17 +473,13 @@ class MainActivity : ComponentActivity() {
473473
if (this::navController.isInitialized) {
474474
val previousEntry = navController.previousBackStackEntry
475475
TSLog.d("MainActivity", "onNewIntent: previousBackStackEntry = $previousEntry")
476-
if (this::navController.isInitialized) {
477-
val previousEntry = navController.previousBackStackEntry
478-
TSLog.d("MainActivity", "onNewIntent: previousBackStackEntry = $previousEntry")
479-
if (previousEntry != null) {
480-
navController.popBackStack(route = "main", inclusive = false)
481-
} else {
482-
TSLog.e(
483-
"MainActivity",
484-
"onNewIntent: No previous back stack entry, navigating directly to 'main'")
485-
navController.navigate("main") { popUpTo("main") { inclusive = true } }
486-
}
476+
if (previousEntry != null) {
477+
navController.popBackStack(route = "main", inclusive = false)
478+
} else {
479+
TSLog.e(
480+
"MainActivity",
481+
"onNewIntent: No previous back stack entry, navigating directly to 'main'")
482+
navController.navigate("main") { popUpTo("main") { inclusive = true } }
487483
}
488484
}
489485
}

android/src/main/java/com/tailscale/ipn/ui/util/Lists.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
package com.tailscale.ipn.ui.util
55

66
import androidx.compose.foundation.background
7+
import androidx.compose.foundation.clickable
78
import androidx.compose.foundation.focusable
89
import androidx.compose.foundation.layout.Box
910
import androidx.compose.foundation.layout.fillMaxWidth
1011
import androidx.compose.foundation.layout.padding
1112
import androidx.compose.foundation.layout.size
1213
import androidx.compose.foundation.lazy.LazyItemScope
1314
import androidx.compose.foundation.lazy.LazyListScope
14-
import androidx.compose.foundation.text.ClickableText
1515
import androidx.compose.material3.HorizontalDivider
1616
import androidx.compose.material3.ListItem
1717
import androidx.compose.material3.MaterialTheme
@@ -95,7 +95,10 @@ object Lists {
9595
headlineContent = {
9696
Box(modifier = Modifier.padding(vertical = 4.dp)) {
9797
onClick?.let {
98-
ClickableText(text = text as AnnotatedString, style = style, onClick = { onClick() })
98+
Text(
99+
text = text as AnnotatedString,
100+
style = style,
101+
modifier = Modifier.clickable { onClick() })
99102
} ?: run { Text(text as String, style = style) }
100103
}
101104
})

android/src/main/java/com/tailscale/ipn/ui/view/BugReportView.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import androidx.compose.foundation.layout.fillMaxHeight
88
import androidx.compose.foundation.layout.fillMaxWidth
99
import androidx.compose.foundation.layout.padding
1010
import androidx.compose.foundation.rememberScrollState
11-
import androidx.compose.foundation.text.ClickableText
1211
import androidx.compose.foundation.verticalScroll
1312
import androidx.compose.material3.MaterialTheme
1413
import androidx.compose.material3.Scaffold
14+
import androidx.compose.material3.Text
1515
import androidx.compose.runtime.Composable
1616
import androidx.compose.runtime.collectAsState
1717
import androidx.compose.runtime.getValue
1818
import androidx.compose.ui.Modifier
19-
import androidx.compose.ui.platform.LocalUriHandler
2019
import androidx.compose.ui.res.stringResource
2120
import androidx.compose.ui.text.AnnotatedString
21+
import androidx.compose.ui.text.LinkAnnotation
2222
import androidx.compose.ui.text.SpanStyle
2323
import androidx.compose.ui.text.buildAnnotatedString
2424
import androidx.compose.ui.text.style.TextDecoration
@@ -36,7 +36,6 @@ import com.tailscale.ipn.ui.viewModel.BugReportViewModel
3636

3737
@Composable
3838
fun BugReportView(backToSettings: BackNavigation, model: BugReportViewModel = viewModel()) {
39-
val handler = LocalUriHandler.current
4039
val bugReportID by model.bugReportID.collectAsState()
4140

4241
Scaffold(topBar = { Header(R.string.bug_report_title, onBack = backToSettings) }) { innerPadding
@@ -48,10 +47,7 @@ fun BugReportView(backToSettings: BackNavigation, model: BugReportViewModel = vi
4847
.fillMaxHeight()
4948
.verticalScroll(rememberScrollState())) {
5049
Lists.MultilineDescription {
51-
ClickableText(
52-
text = contactText(),
53-
style = MaterialTheme.typography.bodyMedium,
54-
onClick = { handler.openUri(Links.SUPPORT_URL) })
50+
Text(text = contactText(), style = MaterialTheme.typography.bodyMedium)
5551
}
5652

5753
ClipboardValueView(bugReportID, title = stringResource(R.string.bug_report_id))
@@ -68,7 +64,7 @@ fun contactText(): AnnotatedString {
6864
append(stringResource(id = R.string.bug_report_instructions_prefix))
6965
}
7066

71-
pushStringAnnotation(tag = "reportLink", annotation = Links.SUPPORT_URL)
67+
pushLink(LinkAnnotation.Url(Links.SUPPORT_URL))
7268
withStyle(
7369
style =
7470
SpanStyle(

android/src/main/java/com/tailscale/ipn/ui/view/MainView.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ fun MainView(
129129
loginAtUrl: (String) -> Unit,
130130
navigation: MainViewNavigation,
131131
viewModel: MainViewModel,
132-
appViewModel: AppViewModel
133132
) {
134133
val currentPingDevice by viewModel.pingViewModel.peer.collectAsState()
135134
val healthIcon by viewModel.healthIcon.collectAsState()
@@ -829,5 +828,5 @@ fun MainViewPreview() {
829828
onNavigateToHealth = {},
830829
onNavigateToSearch = {}),
831830
vm,
832-
appViewModel)
831+
)
833832
}

0 commit comments

Comments
 (0)