Skip to content

Commit ad2a80c

Browse files
author
Bot
committed
UI Refactoring
1 parent 9a618dc commit ad2a80c

5 files changed

Lines changed: 70 additions & 28 deletions

File tree

app/src/main/java/org/bepass/oblivion/ui/DnsSettingsSheet.kt

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,59 @@ fun DnsSettingsSheet(onDismiss: () -> Unit, viewModel: SettingsViewModel = hiltV
4949
containerColor = MaterialTheme.colorScheme.surface,
5050
contentColor = MaterialTheme.colorScheme.onSurface,
5151
) {
52-
Column(Modifier.padding(20.dp).verticalScroll(rememberScrollState()), verticalArrangement = Arrangement.spacedBy(12.dp)) {
52+
Column(
53+
Modifier.padding(20.dp).verticalScroll(rememberScrollState()),
54+
verticalArrangement = Arrangement.spacedBy(12.dp),
55+
) {
5356
Text(stringResource(R.string.dnsText))
54-
Text(state.runtimePlan.sectionSummaries.values.joinToString("\n").ifBlank { stringResource(R.string.dns_runtime_default) })
57+
Text(
58+
state.runtimePlan.sectionSummaries.values.joinToString("\n").ifBlank {
59+
stringResource(R.string.dns_runtime_default)
60+
}
61+
)
5562
state.refreshMessage?.let { Text(it) }
5663
state.warnings.forEach { Text(stringResource(R.string.dns_warning_format, it)) }
5764
Button(enabled = !state.isRefreshing, onClick = viewModel::refreshDnsCatalog) {
58-
Text(if (state.isRefreshing) stringResource(R.string.refreshing) else stringResource(R.string.refresh_dns_catalog))
65+
Text(
66+
if (state.isRefreshing) stringResource(R.string.refreshing)
67+
else stringResource(R.string.refresh_dns_catalog)
68+
)
5969
}
60-
DnsSectionBlock(DnsSection.GLOBAL, viewModel, onProvider = { providerSection = it }, onManual = { section, input ->
61-
manualSection = section
62-
manualText = input
63-
})
64-
USER_CONFIGURABLE_DNS_SECTIONS.forEach { section ->
65-
DnsSectionBlock(section, viewModel, onProvider = { providerSection = it }, onManual = { sec, input ->
66-
manualSection = sec
70+
DnsSectionBlock(
71+
DnsSection.GLOBAL,
72+
viewModel,
73+
onProvider = { providerSection = it },
74+
onManual = { section, input ->
75+
manualSection = section
6776
manualText = input
68-
})
77+
},
78+
)
79+
USER_CONFIGURABLE_DNS_SECTIONS.forEach { section ->
80+
DnsSectionBlock(
81+
section,
82+
viewModel,
83+
onProvider = { providerSection = it },
84+
onManual = { sec, input ->
85+
manualSection = sec
86+
manualText = input
87+
},
88+
)
6989
}
7090
}
7191
}
7292

7393
providerSection?.let { section ->
7494
val options =
75-
state.filteredProviders(DnsUiCatalogFilters(region = DnsCatalogRegionFilter.ALL))
95+
state
96+
.filteredProviders(DnsUiCatalogFilters(region = DnsCatalogRegionFilter.ALL))
7697
.filter { section in it.supportsInLayers }
7798
.flatMap { provider ->
78-
provider.transports.filterNot { it == DnsTransport.SYSTEM }.sortedBy { it.name }.map {
79-
Triple(provider.providerId, provider.label, it)
80-
}
99+
provider.transports
100+
.filterNot { it == DnsTransport.SYSTEM }
101+
.sortedBy { it.name }
102+
.map {
103+
Triple(provider.providerId, provider.label, it)
104+
}
81105
}
82106
OptionDialog(
83107
title = section.displayName(),
@@ -95,15 +119,25 @@ fun DnsSettingsSheet(onDismiss: () -> Unit, viewModel: SettingsViewModel = hiltV
95119
AlertDialog(
96120
onDismissRequest = { manualSection = null },
97121
title = { Text(section.displayName()) },
98-
text = { OutlinedTextField(value = manualText, onValueChange = { manualText = it }, modifier = Modifier.fillMaxWidth()) },
122+
text = {
123+
OutlinedTextField(
124+
value = manualText,
125+
onValueChange = { manualText = it },
126+
modifier = Modifier.fillMaxWidth(),
127+
)
128+
},
99129
confirmButton = {
100-
TextButton(onClick = {
101-
if (viewModel.setDnsManual(section, manualText) == null) manualSection = null
102-
}) {
130+
TextButton(
131+
onClick = {
132+
if (viewModel.setDnsManual(section, manualText) == null) manualSection = null
133+
}
134+
) {
103135
Text(stringResource(R.string.update))
104136
}
105137
},
106-
dismissButton = { TextButton(onClick = { manualSection = null }) { Text(stringResource(R.string.cancel)) } },
138+
dismissButton = {
139+
TextButton(onClick = { manualSection = null }) { Text(stringResource(R.string.cancel)) }
140+
},
107141
)
108142
}
109143
}

app/src/main/java/org/bepass/oblivion/ui/InfoScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.bepass.oblivion.ui
33
import android.content.ActivityNotFoundException
44
import android.content.Context
55
import android.content.Intent
6-
import android.net.Uri
76
import android.widget.Toast
87
import androidx.compose.foundation.Image
98
import androidx.compose.foundation.background
@@ -41,6 +40,7 @@ import androidx.compose.ui.text.font.FontWeight
4140
import androidx.compose.ui.text.style.TextAlign
4241
import androidx.compose.ui.unit.dp
4342
import androidx.compose.ui.unit.sp
43+
import androidx.core.net.toUri
4444
import org.bepass.oblivion.BuildConfig
4545
import org.bepass.oblivion.R
4646

@@ -166,7 +166,7 @@ fun InfoScreen(onBack: () -> Unit) {
166166
private fun openExternalUri(context: Context, url: String) {
167167
try {
168168
context.startActivity(
169-
Intent(Intent.ACTION_VIEW, Uri.parse(url)).addCategory(Intent.CATEGORY_BROWSABLE)
169+
Intent(Intent.ACTION_VIEW, url.toUri()).addCategory(Intent.CATEGORY_BROWSABLE)
170170
)
171171
} catch (expected: ActivityNotFoundException) {
172172
Toast.makeText(context, R.string.no_browser_available, Toast.LENGTH_LONG).show()

app/src/main/java/org/bepass/oblivion/ui/SplitTunnelScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.bepass.oblivion.ui
22

3+
import android.content.pm.PackageManager
34
import androidx.compose.foundation.Image
45
import androidx.compose.foundation.background
56
import androidx.compose.foundation.clickable
@@ -160,7 +161,7 @@ private fun SplitTunnelAppRow(
160161
val pm = context.packageManager
161162
val appInfo = pm.getApplicationInfo(app.packageName, 0)
162163
appInfo.loadIcon(pm).toBitmap(64, 64).asImageBitmap()
163-
} catch (e: Exception) {
164+
} catch (expectedMissingPackage: PackageManager.NameNotFoundException) {
164165
null
165166
}
166167
}

app/src/main/java/org/bepass/oblivion/ui/viewmodel/SettingsViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
55
import androidx.lifecycle.viewModelScope
66
import dagger.hilt.android.lifecycle.HiltViewModel
77
import dagger.hilt.android.qualifiers.ApplicationContext
8+
import java.io.IOException
89
import java.net.InetSocketAddress
910
import java.net.Socket
1011
import javax.inject.Inject
@@ -174,7 +175,7 @@ constructor(
174175
}
175176
}
176177
time
177-
} catch (e: Exception) {
178+
} catch (expectedProbeFailure: IOException) {
178179
null
179180
}
180181
}

app/src/main/java/org/bepass/oblivion/utils/ColorUtils.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ package org.bepass.oblivion.utils
22

33
import androidx.annotation.ColorInt
44

5+
private const val RED_LUMINANCE_WEIGHT = 0.299
6+
private const val GREEN_LUMINANCE_WEIGHT = 0.587
7+
private const val BLUE_LUMINANCE_WEIGHT = 0.114
8+
private const val MAX_COLOR_CHANNEL = 255.0
9+
private const val DARK_LUMINANCE_THRESHOLD = 0.5
10+
511
fun @receiver:ColorInt Int.isColorDark(): Boolean {
612
val luminance =
7-
(0.299 * android.graphics.Color.red(this) +
8-
0.587 * android.graphics.Color.green(this) +
9-
0.114 * android.graphics.Color.blue(this)) / 255.0
10-
return luminance <= 0.5
13+
(RED_LUMINANCE_WEIGHT * android.graphics.Color.red(this) +
14+
GREEN_LUMINANCE_WEIGHT * android.graphics.Color.green(this) +
15+
BLUE_LUMINANCE_WEIGHT * android.graphics.Color.blue(this)) / MAX_COLOR_CHANNEL
16+
return luminance <= DARK_LUMINANCE_THRESHOLD
1117
}

0 commit comments

Comments
 (0)