Skip to content

Commit

Permalink
Merge branch 'add-konsist-tests-droid-380'
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-mullvad committed Oct 2, 2023
2 parents c2183ff + 54a8e71 commit bb3737b
Show file tree
Hide file tree
Showing 50 changed files with 297 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ class SelectLocationScreenTest {
uiState =
SelectLocationUiState.ShowData(
countries =
DUMMY_RELAY_COUNTRIES.apply {
this[0].expanded = true
this[0].cities[0].expanded = true
DUMMY_RELAY_COUNTRIES.let {
val cities = it[0].cities.toMutableList()
val city = cities.removeAt(0)
cities.add(0, city.copy(expanded = true))
it.toMutableList()[0] =
it[0].copy(expanded = true, cities = cities.toList())
it
},
selectedRelay = DUMMY_RELAY_COUNTRIES[0].cities[0].relays[0]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fun ConnectionButton(

@Preview
@Composable
fun PreviewConnectionButton() {
private fun PreviewConnectionButton() {
AppTheme {
ConnectionButton(
text = "Disconnect",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import net.mullvad.mullvadvpn.lib.theme.Dimens

@Preview
@Composable
fun PreviewSwitchLocationButton() {
private fun PreviewSwitchLocationButton() {
AppTheme {
SpacedColumn {
SwitchLocationButton(onClick = {}, text = "Switch Location", showChevron = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import net.mullvad.mullvadvpn.lib.theme.Dimens

@Preview
@Composable
fun PreviewCustomPortCell() {
private fun PreviewCustomPortCell() {
AppTheme {
SpacedColumn(Modifier.background(MaterialTheme.colorScheme.background)) {
CustomPortCell(title = "Title", isSelected = true, port = "444")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import net.mullvad.talpid.tunnel.ErrorStateCause

@Preview
@Composable
fun PreviewConnectionStatusText() {
private fun PreviewConnectionStatusText() {
AppTheme {
SpacedColumn {
ConnectionStatusText(TunnelState.Disconnected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import net.mullvad.mullvadvpn.lib.theme.typeface.listItemText

@Preview
@Composable
fun PreviewListItem() {
private fun PreviewListItem() {
AppTheme {
Column {
ListItem(text = "No subtext No icon not loading", isLoading = false, onClick = {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import net.mullvad.talpid.net.TransportProtocol

@Preview
@Composable
fun PreviewLocationInfo() {
private fun PreviewLocationInfo() {
AppTheme {
LocationInfo(
onToggleTunnelInfo = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import org.joda.time.DateTime

@Preview
@Composable
fun PreviewNotificationBanner() {
private fun PreviewNotificationBanner() {
AppTheme {
SpacedColumn(Modifier.background(color = MaterialTheme.colorScheme.background)) {
val versionInfoNotification =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private val FadeOutAnimationSpec =

@Preview(widthDp = 400, heightDp = 400, showBackground = true)
@Composable
internal fun ScrollbarPreview() {
private fun PreviewScrollbar() {
val state = rememberScrollState()
Column(
modifier = Modifier.drawVerticalScrollbar(state).verticalScroll(state),
Expand All @@ -300,7 +300,7 @@ internal fun ScrollbarPreview() {

@Preview(widthDp = 400, heightDp = 400, showBackground = true)
@Composable
internal fun LazyListScrollbarPreview() {
private fun PreviewLazyListScrollbar() {
val state = rememberLazyListState()
LazyColumn(modifier = Modifier.drawVerticalScrollbar(state), state = state) {
items(50) {
Expand All @@ -311,7 +311,7 @@ internal fun LazyListScrollbarPreview() {

@Preview(widthDp = 400, showBackground = true)
@Composable
internal fun HorizontalScrollbarPreview() {
private fun PreviewHorizontalScrollbar() {
val state = rememberScrollState()
Row(modifier = Modifier.drawHorizontalScrollbar(state).horizontalScroll(state)) {
repeat(50) {
Expand All @@ -325,7 +325,7 @@ internal fun HorizontalScrollbarPreview() {

@Preview(widthDp = 400, showBackground = true)
@Composable
internal fun LazyListHorizontalScrollbarPreview() {
private fun PreviewLazyListHorizontalScrollbar() {
val state = rememberLazyListState()
LazyRow(modifier = Modifier.drawHorizontalScrollbar(state), state = state) {
items(50) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import net.mullvad.mullvadvpn.util.isPortInValidRanges

@Preview
@Composable
fun PreviewCustomPortDialog() {
private fun PreviewCustomPortDialog() {
AppTheme {
CustomPortDialog(
onSave = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private const val CONNECT_BUTTON_THROTTLE_MILLIS = 1000

@Preview
@Composable
fun PreviewConnectScreen() {
private fun PreviewConnectScreen() {
val state = ConnectUiState.INITIAL
AppTheme {
ConnectScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import net.mullvad.mullvadvpn.util.formatDate

@Composable
@Preview
fun PreviewDeviceListScreen() {
private fun PreviewDeviceListScreen() {
AppTheme {
DeviceListScreen(
state =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import net.mullvad.mullvadvpn.lib.theme.AppTheme

@Preview
@Composable
fun PreivewDeviceRevokedScreen() {
private fun PreviewDeviceRevokedScreen() {
AppTheme { DeviceRevokedScreen(state = DeviceRevokedUiState.SECURED) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import net.mullvad.mullvadvpn.lib.theme.AppTheme

@Preview
@Composable
fun PreviewPrivacyDisclaimerScreen() {
private fun PreviewPrivacyDisclaimerScreen() {
AppTheme { PrivacyDisclaimerScreen({}, {}) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
Expand Down Expand Up @@ -54,7 +53,7 @@ import net.mullvad.mullvadvpn.relaylist.RelayItem

@Preview
@Composable
fun PreviewSelectLocationScreen() {
private fun PreviewSelectLocationScreen() {
val state =
SelectLocationUiState.ShowData(
countries = listOf(RelayCountry("Country 1", "Code 1", false, emptyList())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import net.mullvad.mullvadvpn.lib.theme.Dimens

@Preview
@Composable
fun PreviewSplitTunnelingScreen() {
private fun PreviewSplitTunnelingScreen() {
AppTheme {
SplitTunnelingScreen(
uiState =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ data class Relay(
override val type = RelayItemType.Relay
override val hasChildren = false

override var expanded
get() = false
set(_) {}
override val expanded = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data class RelayCity(
override val name: String,
override val code: String,
override val location: GeographicLocationConstraint,
override var expanded: Boolean,
override val expanded: Boolean,
val relays: List<Relay>
) : RelayItem {
override val type = RelayItemType.City
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import net.mullvad.mullvadvpn.model.GeographicLocationConstraint
data class RelayCountry(
override val name: String,
override val code: String,
override var expanded: Boolean,
override val expanded: Boolean,
val cities: List<RelayCity>
) : RelayItem {
override val type = RelayItemType.Country
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ interface RelayItem {
val locationName: String
get() = name

var expanded: Boolean
val expanded: Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ fun List<RelayCountry>.filterOnSearchTerm(
// Finally if the city has not already been added to the filtered list, add it, but
// do not expand it yet.
if (relayCity.name.contains(other = searchTerm, ignoreCase = true)) {
if (filteredCountries.containsKey(relayCountry.code)) {
filteredCountries[relayCountry.code]?.expanded = true
val value = filteredCountries[relayCountry.code]
if (value != null) {
filteredCountries[relayCountry.code] = value.copy(expanded = true)
} else {
filteredCountries[relayCountry.code] =
relayCountry.copy(expanded = true, cities = cities)
Expand All @@ -141,15 +142,23 @@ fun List<RelayCountry>.filterOnSearchTerm(
// if so expand it, if not add it to the filtered list and expand it.
// Finally add the relay to the list.
if (relay.name.contains(other = searchTerm, ignoreCase = true)) {
if (filteredCountries.containsKey(relayCountry.code)) {
filteredCountries[relayCountry.code]?.expanded = true
val value = filteredCountries[relayCountry.code]
if (value != null) {
filteredCountries[relayCountry.code] = value.copy(expanded = true)
} else {
filteredCountries[relayCountry.code] =
relayCountry.copy(expanded = true, cities = cities)
}
val city = cities.find { it.code == relayCity.code }
city?.let { city.expanded = true }
?: run { cities.add(relayCity.copy(expanded = true, relays = relays)) }
val cityIndex = cities.indexOfFirst { it.code == relayCity.code }

// No city found
if (cityIndex < 0) {
cities.add(relayCity.copy(expanded = true, relays = relays))
} else {
// Update found city as expanded
cities[cityIndex] = cities[cityIndex].copy(expanded = true)
}

relays.add(relay.copy())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AccountViewModel(
}
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), AccountUiState.default())

@Suppress("konsist.ensurePublicPropertiesUsePermittedNames")
@Suppress("konsist.ensure public properties use permitted names")
val enterTransitionEndAction = _enterTransitionEndAction.asSharedFlow()

fun onManageAccountClick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class DeviceListViewModel(
private val _loadingDevices = MutableStateFlow<List<DeviceId>>(emptyList())

private val _toastMessages = MutableSharedFlow<String>(extraBufferCapacity = 1)
@Suppress("konsist.ensurePublicPropertiesUsePermittedNames")
@Suppress("konsist.ensure public properties use permitted names")
val toastMessages = _toastMessages.asSharedFlow()

@Suppress("konsist.ensurePublicPropertiesUsePermittedNames") var accountToken: String? = null
@Suppress("konsist.ensure public properties use permitted names")
var accountToken: String? = null
private var cachedDeviceList: List<Device>? = null

val uiState =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class SelectLocationViewModel(private val serviceConnectionManager: ServiceConne
SelectLocationUiState.Loading
)

@Suppress("konsist.ensurePublicPropertiesUsePermittedNames")
@Suppress("konsist.ensure public properties use permitted names")
val uiCloseAction = _closeAction.asSharedFlow()
@Suppress("konsist.ensurePublicPropertiesUsePermittedNames")
@Suppress("konsist.ensure public properties use permitted names")
val enterTransitionEndAction = _enterTransitionEndAction.asSharedFlow()

fun selectRelay(relayItem: RelayItem?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SettingsViewModel(
SettingsUiState(appVersion = "", isLoggedIn = false, isUpdateAvailable = false)
)

@Suppress("konsist.ensurePublicPropertiesUsePermittedNames")
@Suppress("konsist.ensure public properties use permitted names")
val enterTransitionEndAction = _enterTransitionEndAction.asSharedFlow()

fun onTransitionAnimationEnd() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class VpnSettingsViewModel(
) : ViewModel() {

private val _toastMessages = MutableSharedFlow<String>(extraBufferCapacity = 1)
@Suppress("konsist.ensurePublicPropertiesUsePermittedNames")
@Suppress("konsist.ensure public properties use permitted names")
val toastMessages = _toastMessages.asSharedFlow()

private val dialogState =
Expand Down
3 changes: 3 additions & 0 deletions android/buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ object Dependencies {
const val uiTooling = "androidx.compose.ui:ui-tooling:${Versions.Compose.base}"
const val uiToolingPreview =
"androidx.compose.ui:ui-tooling-preview:${Versions.Compose.base}"
const val uiToolingAndroidPreview =
"androidx.compose.ui:ui-tooling-preview-android:${Versions.Compose.base}"

}

object Koin {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.mullvad.mullvadvpn.model

data class RelayConstraintsUpdate(
var location: Constraint<LocationConstraint>?,
var wireguardConstraints: WireguardConstraints?
val location: Constraint<LocationConstraint>?,
val wireguardConstraints: WireguardConstraints?
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package net.mullvad.mullvadvpn.model
sealed class RelaySettingsUpdate {
object CustomTunnelEndpoint : RelaySettingsUpdate()

data class Normal(var constraints: RelayConstraintsUpdate) : RelaySettingsUpdate()
data class Normal(val constraints: RelayConstraintsUpdate) : RelaySettingsUpdate()
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ sealed class TunnelState : Parcelable {
}
}

override fun toString(): String =
when (this) {
is Disconnected -> DISCONNECTED
is Connecting -> CONNECTING
is Connected -> CONNECTED
is Disconnecting -> {
if (actionAfterDisconnect == ActionAfterDisconnect.Reconnect) {
RECONNECTING
} else {
DISCONNECTING
}
}
is Error -> {
if (errorState.isBlocking) {
BLOCKING
} else {
ERROR
}
}
}

companion object {
const val DISCONNECTED = "disconnected"
const val CONNECTING = "connecting"
Expand All @@ -58,25 +79,4 @@ sealed class TunnelState : Parcelable {
}
}
}

override fun toString(): String =
when (this) {
is Disconnected -> DISCONNECTED
is Connecting -> CONNECTING
is Connected -> CONNECTED
is Disconnecting -> {
if (actionAfterDisconnect == ActionAfterDisconnect.Reconnect) {
RECONNECTING
} else {
DISCONNECTING
}
}
is Error -> {
if (errorState.isBlocking) {
BLOCKING
} else {
ERROR
}
}
}
}
Loading

0 comments on commit bb3737b

Please sign in to comment.