diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2023-09-12 11:54:15 +0200 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2023-09-12 11:54:15 +0200 |
| commit | e05cc2afab256b7997a9c4a10125ff417c34d31a (patch) | |
| tree | ebbe7922f678f5dac0f855df22f85c8f693056f0 /android/app/src | |
| parent | fa733200f25e9ef89f138f848af2b0be9eba2e2b (diff) | |
| parent | 6e154167c65df2b863ad025bd7dc7297a70c2c2c (diff) | |
| download | mullvadvpn-e05cc2afab256b7997a9c4a10125ff417c34d31a.tar.xz mullvadvpn-e05cc2afab256b7997a9c4a10125ff417c34d31a.zip | |
Merge branch 'android-studio-lint'
Diffstat (limited to 'android/app/src')
47 files changed, 125 insertions, 688 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ListItemData.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ListItemData.kt deleted file mode 100644 index 613fe49e8f..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ListItemData.kt +++ /dev/null @@ -1,64 +0,0 @@ -package net.mullvad.mullvadvpn.applist - -import androidx.annotation.DrawableRes -import androidx.annotation.IntDef -import androidx.annotation.StringRes -import net.mullvad.mullvadvpn.ui.widget.WidgetState - -data class ListItemData -private constructor( - val identifier: String, - val text: String? = null, - @StringRes val textRes: Int? = null, - @DrawableRes val iconRes: Int?, - val isSelected: Boolean, - @ItemType val type: Int, - val widget: WidgetState? = null, - val action: ItemAction? = null -) { - - @Retention @IntDef(DIVIDER, PLAIN, ACTION) annotation class ItemType - - class Builder(private val identifier: String) { - var text: String? = null - - @StringRes var textRes: Int? = null - - @DrawableRes var iconRes: Int? = null - var isSelected: Boolean = false - - @ItemType var type: Int = 0 - var widget: WidgetState? = null - var action: ItemAction? = null - - fun build(): ListItemData { - if ((this.text == null && this.textRes == null) && type > PROGRESS) - throw IllegalArgumentException("ListItem should be configured with text") - - return ListItemData( - this.identifier, - this.text, - this.textRes, - this.iconRes, - this.isSelected, - this.type, - this.widget, - this.action - ) - } - } - - data class ItemAction(val identifier: String) - - companion object { - const val DIVIDER = 0 - const val PROGRESS = 1 - const val PLAIN = 2 - const val ACTION = 3 - const val DOUBLE_ACTION = 4 - const val APPLICATION = 5 - - fun build(identifier: String, setUp: Builder.() -> Unit): ListItemData = - Builder(identifier).also(setUp).build() - } -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ViewIntent.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ViewIntent.kt deleted file mode 100644 index 4469bd00ef..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ViewIntent.kt +++ /dev/null @@ -1,10 +0,0 @@ -package net.mullvad.mullvadvpn.applist - -sealed class ViewIntent { - // In future we will have search intent - data class ChangeApplicationGroup(val item: ListItemData) : ViewIntent() - - object ViewIsReady : ViewIntent() - - data class ShowSystemApps(internal val show: Boolean) : ViewIntent() -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/button/ConnectionButton.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/button/ConnectionButton.kt index 06b4074730..7852159247 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/button/ConnectionButton.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/button/ConnectionButton.kt @@ -100,7 +100,7 @@ fun ConnectionButton( @Preview @Composable -fun ConnectionButton() { +fun PreviewConnectionButton() { AppTheme { ConnectionButton( text = "Disconnect", diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SplitTunnelingCell.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SplitTunnelingCell.kt index dd5e075d70..72cce59124 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SplitTunnelingCell.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SplitTunnelingCell.kt @@ -29,7 +29,6 @@ import net.mullvad.mullvadvpn.R import net.mullvad.mullvadvpn.lib.theme.AppTheme import net.mullvad.mullvadvpn.lib.theme.Dimens import net.mullvad.mullvadvpn.lib.theme.typeface.listItemText -import org.koin.androidx.compose.get @Preview @Composable diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/CollapsingToolbarScaffold.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/CollapsingToolbarScaffold.kt index f4b81826bc..0856fc196f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/CollapsingToolbarScaffold.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/CollapsingToolbarScaffold.kt @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue @@ -71,7 +72,7 @@ fun CollapsingToolbarScaffold( enabled = isEnabledWhenCollapsable && isCollapsable, toolbar = { toolbar() } ) { - var bodyHeight by remember { mutableStateOf(0) } + var bodyHeight by remember { mutableIntStateOf(0) } BoxWithConstraints( modifier = diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Text.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Text.kt index 79112f58ff..39e3382a09 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Text.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Text.kt @@ -4,6 +4,7 @@ import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue @@ -71,7 +72,7 @@ fun AutoResizeText( style: TextStyle = LocalTextStyle.current, maxLines: Int = Int.MAX_VALUE, ) { - var adjustedFontSize by remember { mutableStateOf(maxTextSize.value) } + var adjustedFontSize by remember { mutableFloatStateOf(maxTextSize.value) } var isReadyToDraw by remember { mutableStateOf(false) } Text( diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/ChangelogDialog.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/ChangelogDialog.kt index df31400ca2..301ee649b1 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/ChangelogDialog.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/ChangelogDialog.kt @@ -28,7 +28,7 @@ import net.mullvad.mullvadvpn.lib.theme.Dimens @Composable fun ChangelogDialog(changesList: List<String>, version: String, onDismiss: () -> Unit) { AlertDialog( - onDismissRequest = { onDismiss() }, + onDismissRequest = onDismiss, title = { Text( text = version, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/extensions/ResourcesExtensions.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/extensions/ResourcesExtensions.kt index dca2a6aeb9..89d985a408 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/extensions/ResourcesExtensions.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/extensions/ResourcesExtensions.kt @@ -23,18 +23,14 @@ private fun getExpiryQuantityString( val remainingTimeInfo = remainingTime.toPeriodTo(accountExpiry, PeriodType.yearMonthDayTime()) - if (remainingTimeInfo.years > 0) { - return getRemainingText(resources, R.plurals.years_left, remainingTimeInfo.years) + return if (remainingTimeInfo.years > 0) { + getRemainingText(resources, R.plurals.years_left, remainingTimeInfo.years) } else if (remainingTimeInfo.months >= 3) { - return getRemainingText(resources, R.plurals.months_left, remainingTimeInfo.months) + getRemainingText(resources, R.plurals.months_left, remainingTimeInfo.months) } else if (remainingTimeInfo.months > 0 || remainingTimeInfo.days >= 1) { - return getRemainingText( - resources, - R.plurals.days_left, - remainingTime.standardDays.toInt() - ) + getRemainingText(resources, R.plurals.days_left, remainingTime.standardDays.toInt()) } else { - return resources.getString(R.string.less_than_a_day_left) + resources.getString(R.string.less_than_a_day_left) } } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreen.kt index 863d938506..df7d225deb 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreen.kt @@ -85,7 +85,7 @@ fun AccountScreen( ) CollapsingTopBar( backgroundColor = MaterialTheme.colorScheme.secondary, - onBackClicked = { onBackClick() }, + onBackClicked = onBackClick, title = stringResource(id = R.string.settings_account), progress = progress, modifier = scaffoldModifier, @@ -153,7 +153,7 @@ fun AccountScreen( if (BuildConfig.BUILD_TYPE != BuildTypes.RELEASE) { ActionButton( text = stringResource(id = R.string.manage_account), - onClick = { onManageAccountClick() }, + onClick = onManageAccountClick, modifier = Modifier.padding( start = Dimens.sideMargin, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt index 9d230a98fe..fece45f0aa 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt @@ -4,7 +4,7 @@ import net.mullvad.mullvadvpn.relaylist.RelayCountry import net.mullvad.mullvadvpn.relaylist.RelayItem sealed interface SelectLocationUiState { - object Loading : SelectLocationUiState + data object Loading : SelectLocationUiState data class ShowData(val countries: List<RelayCountry>, val selectedRelay: RelayItem?) : SelectLocationUiState diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SplitTunnelingUiState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SplitTunnelingUiState.kt index 1ebb8fb379..7752293516 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SplitTunnelingUiState.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SplitTunnelingUiState.kt @@ -3,7 +3,7 @@ package net.mullvad.mullvadvpn.compose.state import net.mullvad.mullvadvpn.applist.AppData sealed interface SplitTunnelingUiState { - object Loading : SplitTunnelingUiState + data object Loading : SplitTunnelingUiState data class ShowAppList( val excludedApps: List<AppData> = emptyList(), diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/RememberPrevious.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/RememberPrevious.kt index ef47f61472..6782e0ab55 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/RememberPrevious.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/RememberPrevious.kt @@ -31,7 +31,7 @@ fun <T> rememberPrevious( private fun <T> rememberRef(): MutableState<T?> { // for some reason it always recreated the value with vararg keys, // leaving out the keys as a parameter for remember for now - return remember() { + return remember { object : MutableState<T?> { override var value: T? = null diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt index 7104deb686..69fd7275e7 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt @@ -15,13 +15,13 @@ const val PROBLEM_REPORT_FILE = "problem_report.txt" class MullvadProblemReport { private sealed class Command { - class Collect() : Command() + data object Collect : Command() class Load(val logs: CompletableDeferred<String>) : Command() class Send(val result: CompletableDeferred<Boolean>) : Command() - class Delete() : Command() + data object Delete : Command() } val logDirectory = CompletableDeferred<File>() @@ -44,7 +44,7 @@ class MullvadProblemReport { } fun collect() { - commandChannel.trySendBlocking(Command.Collect()) + commandChannel.trySendBlocking(Command.Collect) } suspend fun load(): String { @@ -64,16 +64,15 @@ class MullvadProblemReport { } fun deleteReportFile() { - commandChannel.trySendBlocking(Command.Delete()) + commandChannel.trySendBlocking(Command.Delete) } private fun spawnActor() = GlobalScope.actor<Command>(Dispatchers.Default, Channel.UNLIMITED) { try { while (true) { - val command = channel.receive() - when (command) { + when (val command = channel.receive()) { is Command.Collect -> doCollect() is Command.Load -> command.logs.complete(doLoad()) is Command.Send -> command.result.complete(doSend()) @@ -97,10 +96,10 @@ class MullvadProblemReport { doCollect() } - if (isCollected) { - return problemReportPath.await().readText() + return if (isCollected) { + problemReportPath.await().readText() } else { - return "Failed to collect logs for problem report" + "Failed to collect logs for problem report" } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/GetItemResult.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/GetItemResult.kt deleted file mode 100644 index edbaaf39d1..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/GetItemResult.kt +++ /dev/null @@ -1,7 +0,0 @@ -package net.mullvad.mullvadvpn.relaylist - -sealed class GetItemResult { - data class Item(val item: RelayItem) : GetItemResult() - - data class Count(val count: Int) : GetItemResult() -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt index 4817b401bf..d1a3332a78 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt @@ -16,31 +16,4 @@ data class RelayCity( override val hasChildren get() = relays.isNotEmpty() - - fun getItem(position: Int): GetItemResult { - if (position == 0) { - return GetItemResult.Item(this) - } - - if (!expanded) { - return GetItemResult.Count(1) - } - - val offset = position - 1 - val relayCount = relays.size - - return if (offset >= relayCount) { - GetItemResult.Count(1 + relayCount) - } else { - GetItemResult.Item(relays[offset]) - } - } - - fun getItemCount(): Int { - return if (expanded) { - 1 + relays.size - } else { - 1 - } - } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt index e9487c7b4c..d418fd3a4a 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt @@ -16,28 +16,4 @@ data class RelayCountry( override val hasChildren get() = cities.isNotEmpty() - - fun getItem(position: Int): GetItemResult { - if (position == 0) { - return GetItemResult.Item(this) - } - - var itemCount = 1 - var remaining = position - 1 - - if (expanded) { - for (city in cities) { - - when (val itemOrCount = city.getItem(remaining)) { - is GetItemResult.Item -> return itemOrCount - is GetItemResult.Count -> { - remaining -= itemOrCount.count - itemCount += itemOrCount.count - } - } - } - } - - return GetItemResult.Count(itemCount) - } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListAdapterPosition.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListAdapterPosition.kt deleted file mode 100644 index 09dfafebc8..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListAdapterPosition.kt +++ /dev/null @@ -1,3 +0,0 @@ -package net.mullvad.mullvadvpn.relaylist - -data class RelayListAdapterPosition(var position: Int) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/BlockingController.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/BlockingController.kt deleted file mode 100644 index 4dd53fa937..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/BlockingController.kt +++ /dev/null @@ -1,39 +0,0 @@ -package net.mullvad.mullvadvpn.ui - -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.Job -import kotlinx.coroutines.launch - -class BlockingController(val blockableView: BlockableView) { - var job: Job? = null - var innerJob: Job? = null - - fun action() { - if (!(job?.isActive ?: false)) { - job = - GlobalScope.launch(Dispatchers.Main) { - blockableView.setEnabled(false) - innerJob = blockableView.onClick() - innerJob?.join() - blockableView.setEnabled(true) - } - } - } - - fun onPause() { - innerJob?.cancel() - job?.cancel() - blockableView.setEnabled(true) - } - - fun onDestroy() { - onPause() - } -} - -interface BlockableView { - fun setEnabled(enabled: Boolean) - - fun onClick(): Job -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/CollapsibleTitleController.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/CollapsibleTitleController.kt index 658fd3fed3..1c37945602 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/CollapsibleTitleController.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/CollapsibleTitleController.kt @@ -46,16 +46,15 @@ class CollapsibleTitleController(val parentView: View, scrollAreaId: Int = R.id. private val xOffsetInterpolation = LinearInterpolation() private val yOffsetInterpolation = LinearInterpolation() - private val collapsedTitleLayoutListener: LayoutListener = - LayoutListener() { collapsedTitle -> - val (x, y) = calculateViewCoordinates(collapsedTitle) + private val collapsedTitleLayoutListener: LayoutListener = LayoutListener { collapsedTitle -> + val (x, y) = calculateViewCoordinates(collapsedTitle) - collapsedTitleHeight = collapsedTitle.height.toFloat() + collapsedTitleHeight = collapsedTitle.height.toFloat() - scaleInterpolation.end = collapsedTitleHeight / maxOf(1.0f, titleHeight) - xOffsetInterpolation.end = x - yOffsetInterpolation.end = y - } + scaleInterpolation.end = collapsedTitleHeight / maxOf(1.0f, titleHeight) + xOffsetInterpolation.end = x + yOffsetInterpolation.end = y + } private val collapsedTitleView = parentView.findViewById<View>(R.id.collapsed_title).apply { @@ -63,37 +62,35 @@ class CollapsibleTitleController(val parentView: View, scrollAreaId: Int = R.id. visibility = View.INVISIBLE } - private val expandedTitleLayoutListener: LayoutListener = - LayoutListener() { expandedTitle -> - val (x, y) = calculateViewCoordinates(expandedTitle) + private val expandedTitleLayoutListener: LayoutListener = LayoutListener { expandedTitle -> + val (x, y) = calculateViewCoordinates(expandedTitle) - val expandedTitleMarginTop = - when (val layoutParams = expandedTitle.layoutParams) { - is MarginLayoutParams -> layoutParams.topMargin - else -> 0 - } + val expandedTitleMarginTop = + when (val layoutParams = expandedTitle.layoutParams) { + is MarginLayoutParams -> layoutParams.topMargin + else -> 0 + } - expandedTitleHeight = expandedTitle.height.toFloat() + expandedTitleHeight = expandedTitle.height.toFloat() - scaleInterpolation.start = expandedTitleHeight / maxOf(1.0f, titleHeight) - xOffsetInterpolation.start = x - yOffsetInterpolation.start = y + scaleInterpolation.start = expandedTitleHeight / maxOf(1.0f, titleHeight) + xOffsetInterpolation.start = x + yOffsetInterpolation.start = y - scrollInterpolation.end = expandedTitleHeight + expandedTitleMarginTop - } + scrollInterpolation.end = expandedTitleHeight + expandedTitleMarginTop + } - private val titleLayoutListener: LayoutListener = - LayoutListener() { title -> - val (x, y) = calculateViewCoordinates(title) + private val titleLayoutListener: LayoutListener = LayoutListener { title -> + val (x, y) = calculateViewCoordinates(title) - titleWidth = title.width.toFloat() - titleHeight = title.height.toFloat() + titleWidth = title.width.toFloat() + titleHeight = title.height.toFloat() - scaleInterpolation.start = expandedTitleHeight / maxOf(1.0f, titleHeight) - scaleInterpolation.end = collapsedTitleHeight / maxOf(1.0f, titleHeight) - xOffsetInterpolation.reference = x - yOffsetInterpolation.reference = y - } + scaleInterpolation.start = expandedTitleHeight / maxOf(1.0f, titleHeight) + scaleInterpolation.end = collapsedTitleHeight / maxOf(1.0f, titleHeight) + xOffsetInterpolation.reference = x + yOffsetInterpolation.reference = y + } private val titleView = parentView.findViewById<View>(R.id.title).apply { @@ -104,8 +101,9 @@ class CollapsibleTitleController(val parentView: View, scrollAreaId: Int = R.id. pivotY = 0.0f } - private val scrollAreaLayoutListener: LayoutListener = - LayoutListener() { scrollOffset = scrollArea.verticalScrollOffset.toFloat() } + private val scrollAreaLayoutListener: LayoutListener = LayoutListener { + scrollOffset = scrollArea.verticalScrollOffset.toFloat() + } private val scrollArea = parentView.findViewById<View>(scrollAreaId).let { view -> diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/CustomTransformationMethod.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/CustomTransformationMethod.kt index 083258c62d..451c51fa3f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/CustomTransformationMethod.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/CustomTransformationMethod.kt @@ -10,7 +10,7 @@ private const val DOT_CHAR = '\u2022' private const val EMPTY_STRING = "" private const val SPACE_CHAR = ' ' -class GroupedTransformationMethod() : TransformationMethod { +class GroupedTransformationMethod : TransformationMethod { override fun getTransformation(source: CharSequence?, view: View?): CharSequence { return source?.groupWithSpaces() ?: EMPTY_STRING } @@ -26,7 +26,7 @@ class GroupedTransformationMethod() : TransformationMethod { } } -class GroupedPasswordTransformationMethod() : PasswordTransformationMethod() { +class GroupedPasswordTransformationMethod : PasswordTransformationMethod() { override fun getTransformation(source: CharSequence?, view: View?): CharSequence { return if (source != null && view != null) { super.getTransformation(source, view) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemListener.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemListener.kt deleted file mode 100644 index 07c5520d34..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemListener.kt +++ /dev/null @@ -1,7 +0,0 @@ -package net.mullvad.mullvadvpn.ui - -import net.mullvad.mullvadvpn.applist.ListItemData - -interface ListItemListener { - fun onItemAction(item: ListItemData) -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/LoginFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/LoginFragment.kt index c02ed0b652..7e298e3f73 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/LoginFragment.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/LoginFragment.kt @@ -272,7 +272,7 @@ class LoginFragment : BaseFragment(), NavigationBarPainter { private fun loginFailure(description: String? = "") { title.setText(R.string.login_fail_title) - subtitle.setText(description) + subtitle.text = description loggingInStatus.visibility = View.GONE loginFailStatus.visibility = View.VISIBLE diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/OutOfTimeFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/OutOfTimeFragment.kt index 9b5eb395ad..1a59f19ff7 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/OutOfTimeFragment.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/OutOfTimeFragment.kt @@ -96,11 +96,11 @@ class OutOfTimeFragment : BaseFragment() { newAccount = false setOnClickAction("openAccountPageInBrowser", jobTracker) { - setEnabled(false) + isEnabled = false serviceConnectionManager.authTokenCache()?.fetchAuthToken()?.let { token -> context.openAccountPageInBrowser(token) } - setEnabled(true) + isEnabled = true } isEnabled = true @@ -170,10 +170,10 @@ class OutOfTimeFragment : BaseFragment() { disconnectButton.apply { if (showButton) { - setEnabled(true) + isEnabled = true visibility = View.VISIBLE } else { - setEnabled(false) + isEnabled = false visibility = View.GONE } } @@ -182,17 +182,17 @@ class OutOfTimeFragment : BaseFragment() { private fun updateBuyButtons() { val currentState = tunnelState val hasConnectivity = currentState is TunnelState.Disconnected - sitePaymentButton.setEnabled(hasConnectivity) + sitePaymentButton.isEnabled = hasConnectivity val isOffline = currentState is TunnelState.Error && currentState.errorState.cause is ErrorStateCause.IsOffline - redeemButton.setEnabled(!isOffline) + redeemButton.isEnabled = !isOffline } private fun checkExpiry(maybeExpiry: DateTime?) { maybeExpiry?.let { expiry -> - if (expiry.isAfterNow()) { + if (expiry.isAfterNow) { jobTracker.newUiJob("advanceToConnectScreen") { advanceToConnectScreen() } } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/ProblemReportFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/ProblemReportFragment.kt index 4d5ca3c9b5..b30b5713fb 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/ProblemReportFragment.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/ProblemReportFragment.kt @@ -280,7 +280,7 @@ class ProblemReportFragment : BaseFragment() { } private fun setSendButtonEnabled(enabled: Boolean) { - sendButton.setEnabled(enabled) + sendButton.isEnabled = enabled sendButton.alpha = if (enabled) 1.0F else 0.5F } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/RedeemVoucherDialogFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/RedeemVoucherDialogFragment.kt index 59318a8268..46472ea6cc 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/RedeemVoucherDialogFragment.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/RedeemVoucherDialogFragment.kt @@ -88,7 +88,7 @@ class RedeemVoucherDialogFragment : DialogFragment() { redeemButton = view.findViewById<Button>(R.id.redeem).apply { - setEnabled(false) + isEnabled = false setOnClickAction("action", jobTracker) { submitVoucher() } } @@ -130,7 +130,7 @@ class RedeemVoucherDialogFragment : DialogFragment() { } private fun updateRedeemButton() { - redeemButton?.setEnabled(voucherInputIsValid && voucherRedeemer != null) + redeemButton?.isEnabled = voucherInputIsValid && voucherRedeemer != null } private suspend fun submitVoucher() { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt index b24cda9213..bfad798e08 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/CustomDns.kt @@ -1,83 +1,13 @@ package net.mullvad.mullvadvpn.ui.serviceconnection import android.os.Messenger -import java.net.InetAddress import net.mullvad.mullvadvpn.lib.ipc.Request import net.mullvad.mullvadvpn.lib.ipc.extensions.trySendRequest import net.mullvad.mullvadvpn.model.DnsOptions -import net.mullvad.mullvadvpn.model.DnsState -import net.mullvad.talpid.util.EventNotifier -class CustomDns(private val connection: Messenger, private val settingsListener: SettingsListener) { - @Deprecated( - message = "Will soon be removed in favor of onDnsOptionsChanged.", - replaceWith = ReplaceWith("onDnsOptionsChanged") - ) - val onEnabledChanged = EventNotifier(false) - @Deprecated( - message = "Will soon be removed in favor of onDnsOptionsChanged.", - replaceWith = ReplaceWith("onDnsOptionsChanged") - ) - val onDnsServersChanged = EventNotifier<List<InetAddress>>(emptyList()) - val onDnsOptionsChanged = EventNotifier<DnsOptions?>(null) - - init { - settingsListener.dnsOptionsNotifier.subscribe(this) { maybeDnsOptions -> - maybeDnsOptions?.let { dnsOptions -> - synchronized(this) { - onEnabledChanged.notifyIfChanged(dnsOptions.state == DnsState.Custom) - onDnsServersChanged.notifyIfChanged(dnsOptions.customOptions.addresses) - onDnsOptionsChanged.notifyIfChanged(dnsOptions) - } - } - } - } - - fun enable() { - connection.send(Request.SetEnableCustomDns(true).message) - } - - fun disable() { - connection.send(Request.SetEnableCustomDns(false).message) - } - - fun isCustomDnsEnabled(): Boolean { - return onEnabledChanged.latestEvent ?: false - } - - fun addDnsServer(server: InetAddress): Boolean { - val didntAlreadyHaveServer = !onDnsServersChanged.latestEvent.contains(server) - - connection.send(Request.AddCustomDnsServer(server).message) - - return didntAlreadyHaveServer - } - - fun replaceDnsServer(oldServer: InetAddress, newServer: InetAddress): Boolean { - synchronized(this) { - val dnsServers = onDnsServersChanged.latestEvent - val containsOldServer = dnsServers.contains(oldServer) - val replacementIsValid = oldServer == newServer || !dnsServers.contains(newServer) - - connection.send(Request.ReplaceCustomDnsServer(oldServer, newServer).message) - - return containsOldServer && replacementIsValid - } - } - - fun removeDnsServer(server: InetAddress) { - connection.send(Request.RemoveCustomDnsServer(server).message) - } +class CustomDns(private val connection: Messenger) { fun setDnsOptions(dnsOptions: DnsOptions) { connection.trySendRequest(Request.SetDnsOptions(dnsOptions), false) } - - fun onDestroy() { - onEnabledChanged.unsubscribeAll() - onDnsServersChanged.unsubscribeAll() - onDnsOptionsChanged.unsubscribeAll() - - settingsListener.dnsOptionsNotifier.unsubscribe(this) - } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionContainer.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionContainer.kt index 1ca0d6642c..6dbea7a517 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionContainer.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionContainer.kt @@ -8,7 +8,6 @@ import net.mullvad.mullvadvpn.lib.ipc.DispatchingHandler import net.mullvad.mullvadvpn.lib.ipc.Event import net.mullvad.mullvadvpn.lib.ipc.Request import org.koin.core.component.KoinComponent -import org.koin.core.component.get // Container of classes that communicate with the service through an active connection // @@ -34,7 +33,7 @@ class ServiceConnectionContainer( val vpnPermission = VpnPermission(connection, dispatcher) val appVersionInfoCache = AppVersionInfoCache(dispatcher, settingsListener) - val customDns = CustomDns(connection, settingsListener) + val customDns = CustomDns(connection) var relayListListener = RelayListListener(connection, dispatcher, settingsListener) private var listenerId: Int? = null @@ -62,7 +61,6 @@ class ServiceConnectionContainer( voucherRedeemer.onDestroy() appVersionInfoCache.onDestroy() - customDns.onDestroy() relayListListener.onDestroy() } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/SettingsListener.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/SettingsListener.kt index 039b293d69..d996c432ad 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/SettingsListener.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/SettingsListener.kt @@ -4,7 +4,6 @@ import android.os.Messenger import net.mullvad.mullvadvpn.lib.ipc.Event import net.mullvad.mullvadvpn.lib.ipc.EventDispatcher import net.mullvad.mullvadvpn.lib.ipc.Request -import net.mullvad.mullvadvpn.model.DnsOptions import net.mullvad.mullvadvpn.model.ObfuscationSettings import net.mullvad.mullvadvpn.model.QuantumResistantState import net.mullvad.mullvadvpn.model.RelaySettings @@ -12,7 +11,6 @@ import net.mullvad.mullvadvpn.model.Settings import net.mullvad.talpid.util.EventNotifier class SettingsListener(private val connection: Messenger, eventDispatcher: EventDispatcher) { - val dnsOptionsNotifier = EventNotifier<DnsOptions?>(null) val relaySettingsNotifier = EventNotifier<RelaySettings?>(null) val settingsNotifier = EventNotifier<Settings?>(null) @@ -55,7 +53,6 @@ class SettingsListener(private val connection: Messenger, eventDispatcher: Event } fun onDestroy() { - dnsOptionsNotifier.unsubscribeAll() relaySettingsNotifier.unsubscribeAll() settingsNotifier.unsubscribeAll() } @@ -65,10 +62,6 @@ class SettingsListener(private val connection: Messenger, eventDispatcher: Event } private fun handleNewSettings(newSettings: Settings) { - if (settings?.tunnelOptions?.dnsOptions != newSettings.tunnelOptions.dnsOptions) { - dnsOptionsNotifier.notify(newSettings.tunnelOptions.dnsOptions) - } - if (settings?.relaySettings != newSettings.relaySettings) { relaySettingsNotifier.notify(newSettings.relaySettings) } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountInput.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountInput.kt index 32e81a25e4..11759d469e 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountInput.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountInput.kt @@ -120,8 +120,8 @@ class AccountInput : LinearLayout { private fun initialState() { input.apply { setTextColor(enabledTextColor) - setEnabled(true) - setFocusableInTouchMode(true) + isEnabled = true + isFocusableInTouchMode = true visibility = View.VISIBLE } @@ -132,8 +132,8 @@ class AccountInput : LinearLayout { private fun loggingInState() { input.apply { setTextColor(disabledTextColor) - setEnabled(false) - setFocusable(false) + isEnabled = false + isFocusable = false visibility = View.VISIBLE } @@ -144,8 +144,8 @@ class AccountInput : LinearLayout { private fun successState() { input.apply { setTextColor(disabledTextColor) - setEnabled(false) - setFocusable(false) + isEnabled = false + isFocusable = false visibility = View.VISIBLE } @@ -159,8 +159,8 @@ class AccountInput : LinearLayout { input.apply { setTextColor(errorTextColor) - setEnabled(true) - setFocusableInTouchMode(true) + isEnabled = true + isFocusableInTouchMode = true visibility = View.VISIBLE requestFocus() } @@ -168,10 +168,10 @@ class AccountInput : LinearLayout { private fun setButtonEnabled(enabled: Boolean) { button.apply { - if (enabled != isEnabled()) { - setEnabled(enabled) - setClickable(enabled) - setFocusable(enabled) + if (enabled != isEnabled) { + isEnabled = enabled + isClickable = enabled + isFocusable = enabled } } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/BackButton.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/BackButton.kt index 7cb3626084..efa2d6f5a6 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/BackButton.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/BackButton.kt @@ -19,7 +19,7 @@ class BackButton : LinearLayout { private val label = container.findViewById<TextView>(R.id.label) - constructor(context: Context) : super(context) {} + constructor(context: Context) : super(context) constructor(context: Context, attributes: AttributeSet) : super(context, attributes) { loadAttributes(attributes) @@ -43,7 +43,7 @@ class BackButton : LinearLayout { } init { - setFocusable(true) + isFocusable = true isClickable = true gravity = Gravity.CENTER_VERTICAL or Gravity.START orientation = HORIZONTAL diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Button.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Button.kt index c2a5f3510b..e6c266683b 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Button.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Button.kt @@ -80,7 +80,7 @@ open class Button : FrameLayout { var showSpinner = false - constructor(context: Context) : super(context) {} + constructor(context: Context) : super(context) constructor(context: Context, attributes: AttributeSet) : super(context, attributes) { loadAttributes(attributes) @@ -105,7 +105,7 @@ open class Button : FrameLayout { override fun setEnabled(enabled: Boolean) { super.setEnabled(enabled) - button.setEnabled(enabled) + button.isEnabled = enabled if (enabled) { alpha = 1.0f @@ -117,7 +117,7 @@ open class Button : FrameLayout { init { button.setOnClickListener { jobTracker?.newUiJob(clickJobName!!) { - setEnabled(false) + isEnabled = false if (showSpinner) { image.visibility = GONE @@ -132,7 +132,7 @@ open class Button : FrameLayout { image.visibility = VISIBLE } - setEnabled(true) + isEnabled = true } } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/WidgetState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/WidgetState.kt deleted file mode 100644 index e92265b2df..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/WidgetState.kt +++ /dev/null @@ -1,9 +0,0 @@ -package net.mullvad.mullvadvpn.ui.widget - -import androidx.annotation.DrawableRes - -sealed class WidgetState { - data class ImageState(@DrawableRes val imageRes: Int) : WidgetState() - - data class SwitchState(val isChecked: Boolean) : WidgetState() -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/AdapterWithHeader.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/AdapterWithHeader.kt deleted file mode 100644 index 89b0057f63..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/AdapterWithHeader.kt +++ /dev/null @@ -1,125 +0,0 @@ -package net.mullvad.mullvadvpn.util - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.recyclerview.widget.RecyclerView -import androidx.recyclerview.widget.RecyclerView.ViewHolder -import kotlin.properties.Delegates.observable - -class AdapterWithHeader<H : ViewHolder>( - val adapter: RecyclerView.Adapter<H>, - val headerLayoutId: Int -) : RecyclerView.Adapter<HeaderOrHolder<H>>() { - private val observer = - object : RecyclerView.AdapterDataObserver() { - override fun onChanged() { - notifyDataSetChanged() - } - - override fun onItemRangeChanged(start: Int, count: Int) { - notifyItemRangeChanged(start + 1, count) - } - - override fun onItemRangeChanged(start: Int, count: Int, payload: Any?) { - notifyItemRangeChanged(start + 1, count, payload) - } - - override fun onItemRangeInserted(start: Int, count: Int) { - notifyItemRangeInserted(start + 1, count) - } - - override fun onItemRangeMoved(from: Int, to: Int, count: Int) { - if (from == to) { - notifyItemRangeChanged(from + 1, count) - } else { - val sourceStart = from + 1 - val sourceEnd = sourceStart + count - val destinationStart = to + 1 - val destinationEnd = destinationStart + count - - val ascendingIndices = - (sourceStart..sourceEnd).zip(destinationStart..destinationEnd) - - val indices = - if (from < to) { - ascendingIndices.asReversed() - } else { - ascendingIndices - } - - for ((source, destination) in indices) { - notifyItemMoved(source, destination) - } - } - } - - override fun onItemRangeRemoved(start: Int, count: Int) { - notifyItemRangeRemoved(start + 1, count) - } - } - - private var headerView: View? by - observable<View?>(null) { _, _, newView -> - newView?.let { view -> onHeaderAvailable?.invoke(view) } - } - - var onHeaderAvailable by - observable<((View) -> Unit)?>(null) { _, _, listener -> - headerView?.let { header -> listener?.invoke(header) } - } - - init { - adapter.registerAdapterDataObserver(observer) - } - - override fun getItemCount() = adapter.itemCount + 1 - - override fun getItemId(position: Int): Long { - if (position == 0) { - return 0L - } else { - return adapter.getItemId(position - 1) + 1 - } - } - - override fun getItemViewType(position: Int): Int { - if (position == 0) { - return 0 - } else { - return adapter.getItemViewType(position - 1) + 1 - } - } - - override fun onBindViewHolder(holder: HeaderOrHolder<H>, position: Int) { - when (holder) { - is HeaderOrHolder.Header -> { - if (position != 0) { - throw IllegalArgumentException("Adapter position is not for the header") - } - } - is HeaderOrHolder.Holder -> { - if (position > 0) { - adapter.onBindViewHolder(holder.holder, position - 1) - } else { - throw IllegalArgumentException("Adapter position is for the header") - } - } - } - } - - override fun onCreateViewHolder(parentView: ViewGroup, viewType: Int): HeaderOrHolder<H> { - if (viewType == 0) { - val inflater = LayoutInflater.from(parentView.context) - val view = inflater.inflate(headerLayoutId, parentView, false) - - headerView = view - - return HeaderOrHolder.Header(view) - } else { - val holder = adapter.onCreateViewHolder(parentView, viewType - 1) - - return HeaderOrHolder.Holder(holder) - } - } -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ChangeMonitor.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ChangeMonitor.kt deleted file mode 100644 index c8361a36c4..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ChangeMonitor.kt +++ /dev/null @@ -1,19 +0,0 @@ -package net.mullvad.mullvadvpn.util - -import kotlin.properties.Delegates.observable - -class ChangeMonitor { - var changed = false - private set - - fun <T> monitor(initialValue: T) = - observable(initialValue) { _, oldValue, newValue -> - if (oldValue != newValue) { - changed = true - } - } - - fun reset() { - changed = false - } -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ChangelogDataProvider.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ChangelogDataProvider.kt index 8ce36fd717..c1dc72ebfe 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ChangelogDataProvider.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ChangelogDataProvider.kt @@ -7,7 +7,7 @@ import java.io.IOException private const val CHANGELOG_FILE = "en-US/default.txt" private const val EMPTY_DEFAULT_STRING_WHEN_UNABLE_TO_READ_CHANGELOG = "" -class ChangelogDataProvider(var assets: AssetManager) : IChangelogDataProvider { +class ChangelogDataProvider(private var assets: AssetManager) : IChangelogDataProvider { override fun getChangelog(): String { return try { assets.open(CHANGELOG_FILE).bufferedReader().use { it.readText() } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ExponentialBackoff.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ExponentialBackoff.kt deleted file mode 100644 index 1117b0b749..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ExponentialBackoff.kt +++ /dev/null @@ -1,52 +0,0 @@ -package net.mullvad.mullvadvpn.util - -// Calculates a series of delays that increase exponentially. -// -// The delays follow the formula: -// -// (base ^ retryAttempt) * scale -// -// but it is never larger than the specified cap value. -class ExponentialBackoff : Iterator<Long> { - private var unscaledValue = 1L - private var current = 1L - - var iteration = 1 - private set - - var base = 2L - var scale = 1000L - var cap = Long.MAX_VALUE - var count: Int? = null - - override fun hasNext(): Boolean { - val maxIterations = count - - if (maxIterations != null) { - return iteration < maxIterations - } else { - return true - } - } - - override fun next(): Long { - iteration += 1 - - if (current >= cap) { - return cap - } else { - val value = current - - unscaledValue *= base - current = Math.min(cap, scale * unscaledValue) - - return value - } - } - - fun reset() { - unscaledValue = 1L - current = 1L - iteration = 1 - } -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/FlowUtils.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/FlowUtils.kt index 77caddec85..d18e4f8fc9 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/FlowUtils.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/FlowUtils.kt @@ -13,7 +13,7 @@ import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionState import net.mullvad.talpid.util.EventNotifier fun Animation.transitionFinished(): Flow<Unit> = - callbackFlow<Unit> { + callbackFlow { val transitionAnimationListener = object : Animation.AnimationListener { override fun onAnimationStart(animation: Animation?) {} @@ -44,12 +44,11 @@ fun <R> Flow<ServiceConnectionState>.flatMapReadyConnectionOrDefault( } } -fun <T> callbackFlowFromNotifier(notifier: EventNotifier<T>) = - callbackFlow<T> { - val handler: (T) -> Unit = { value -> trySend(value) } - notifier.subscribe(this, handler) - awaitClose { notifier.unsubscribe(this) } - } +fun <T> callbackFlowFromNotifier(notifier: EventNotifier<T>) = callbackFlow { + val handler: (T) -> Unit = { value -> trySend(value) } + notifier.subscribe(this, handler) + awaitClose { notifier.unsubscribe(this) } +} inline fun <T1, T2, T3, T4, T5, T6, R> combine( flow: Flow<T1>, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/GenericExtensions.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/GenericExtensions.kt deleted file mode 100644 index 0ab0485c79..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/GenericExtensions.kt +++ /dev/null @@ -1,5 +0,0 @@ -package net.mullvad.mullvadvpn.util - -inline fun <T1 : Any, T2 : Any, R : Any> safeLet(p1: T1?, p2: T2?, block: (T1, T2) -> R?): R? { - return if (p1 != null && p2 != null) block(p1, p2) else null -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/HeaderOrHolder.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/HeaderOrHolder.kt deleted file mode 100644 index a1b50c6efb..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/HeaderOrHolder.kt +++ /dev/null @@ -1,10 +0,0 @@ -package net.mullvad.mullvadvpn.util - -import android.view.View -import androidx.recyclerview.widget.RecyclerView.ViewHolder - -sealed class HeaderOrHolder<H : ViewHolder>(itemView: View) : ViewHolder(itemView) { - class Header<H : ViewHolder>(headerView: View) : HeaderOrHolder<H>(headerView) - - class Holder<H : ViewHolder>(val holder: H) : HeaderOrHolder<H>(holder.itemView) -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/LinearInterpolation.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/LinearInterpolation.kt index 750780aa6a..ff03844e91 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/LinearInterpolation.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/LinearInterpolation.kt @@ -22,11 +22,11 @@ class LinearInterpolation { var updated = true get() { - if (field == true) { + return if (field) { field = false - return true + true } else { - return false + false } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SegmentedInputFormatter.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SegmentedInputFormatter.kt index 4dd6b7bc1b..6d3a3e5cc8 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SegmentedInputFormatter.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SegmentedInputFormatter.kt @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.util import android.text.Editable import android.text.TextWatcher import android.widget.EditText +import java.util.Locale class SegmentedInputFormatter(val input: EditText, var separator: Char) : TextWatcher { private var editing = false @@ -114,7 +115,11 @@ class SegmentedInputFormatter(val input: EditText, var separator: Char) : TextWa val character = input[index] if (allCaps && character >= 'a' && character <= 'z') { - input.replace(index, index + 1, character.toString().toUpperCase()) + input.replace( + index, + index + 1, + character.toString().uppercase(Locale.getDefault()) + ) } else if (!isValidInputCharacter(character)) { input.delete(index, index + 1) } else { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SmartDeferred.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SmartDeferred.kt deleted file mode 100644 index 45ee4a2a17..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SmartDeferred.kt +++ /dev/null @@ -1,32 +0,0 @@ -package net.mullvad.mullvadvpn.util - -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.launch -import net.mullvad.mullvadvpn.lib.common.util.JobTracker - -class SmartDeferred<T>(private val deferred: Deferred<T>) { - private val jobTracker = JobTracker() - - private var active = true - - fun awaitThen(action: T.() -> Unit): Long? { - if (active) { - return jobTracker.newJob( - GlobalScope.launch(Dispatchers.Default) { deferred.await().action() } - ) - } else { - return null - } - } - - fun cancelJob(jobId: Long) { - jobTracker.cancelJob(jobId) - } - - fun cancel() { - active = false - jobTracker.cancelAllJobs() - } -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/TimeAgoFormatter.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/TimeAgoFormatter.kt deleted file mode 100644 index 3ae5f499cd..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/TimeAgoFormatter.kt +++ /dev/null @@ -1,34 +0,0 @@ -package net.mullvad.mullvadvpn.util - -import android.content.res.Resources -import net.mullvad.mullvadvpn.R -import org.joda.time.DateTime -import org.joda.time.Duration -import org.joda.time.PeriodType - -class TimeAgoFormatter(val resources: Resources) { - private val periodType = PeriodType.standard().withMillisRemoved().withSecondsRemoved() - - fun format(instant: DateTime): String { - val elapsedTime = Duration(instant, DateTime.now()) - val elapsedTimeInfo = elapsedTime.toPeriodTo(instant, periodType) - - if (elapsedTimeInfo.years > 0) { - return getRemainingText(R.plurals.years_ago, elapsedTimeInfo.years) - } else if (elapsedTimeInfo.months > 0) { - return getRemainingText(R.plurals.months_ago, elapsedTimeInfo.months) - } else if (elapsedTimeInfo.days > 0) { - return getRemainingText(R.plurals.days_ago, elapsedTimeInfo.days) - } else if (elapsedTimeInfo.hours > 0) { - return getRemainingText(R.plurals.hours_ago, elapsedTimeInfo.hours) - } else if (elapsedTimeInfo.minutes > 0) { - return getRemainingText(R.plurals.minutes_ago, elapsedTimeInfo.minutes) - } else { - return resources.getString(R.string.less_than_a_minute_ago) - } - } - - private fun getRemainingText(pluralId: Int, quantity: Int): String { - return resources.getQuantityString(pluralId, quantity, quantity) - } -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ViewKtx.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ViewKtx.kt deleted file mode 100644 index fb4a4c65b6..0000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ViewKtx.kt +++ /dev/null @@ -1,15 +0,0 @@ -package net.mullvad.mullvadvpn.util - -import android.util.Log -import android.view.View -import android.view.ViewGroup.MarginLayoutParams - -fun View.setMargins(l: Int? = null, t: Int? = null, r: Int? = null, b: Int? = null) { - if (this.layoutParams is MarginLayoutParams) { - val p = this.layoutParams as MarginLayoutParams - p.setMargins(l ?: p.leftMargin, t ?: p.topMargin, r ?: p.rightMargin, b ?: p.bottomMargin) - this.requestLayout() - } else { - Log.w("mullvad", "setMargins is not supported") - } -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ChangelogViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ChangelogViewModel.kt index bbfac3e024..1c541944d2 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ChangelogViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ChangelogViewModel.kt @@ -40,5 +40,5 @@ class ChangelogViewModel( sealed class ChangelogDialogUiState { data class Show(val changes: List<String>) : ChangelogDialogUiState() - object Hide : ChangelogDialogUiState() + data object Hide : ChangelogDialogUiState() } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt index 6fb00b1922..07e8f48705 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt @@ -26,23 +26,23 @@ class LoginViewModel( val accountHistory = accountRepository.accountHistoryEvents sealed class LoginUiState { - object Default : LoginUiState() + data object Default : LoginUiState() - object Loading : LoginUiState() + data object Loading : LoginUiState() data class Success(val isOutOfTime: Boolean) : LoginUiState() - object CreatingAccount : LoginUiState() + data object CreatingAccount : LoginUiState() - object AccountCreated : LoginUiState() + data object AccountCreated : LoginUiState() - object UnableToCreateAccountError : LoginUiState() + data object UnableToCreateAccountError : LoginUiState() - object InvalidAccountError : LoginUiState() + data object InvalidAccountError : LoginUiState() data class TooManyDevicesError(val accountToken: String) : LoginUiState() - object TooManyDevicesMissingListError : LoginUiState() + data object TooManyDevicesMissingListError : LoginUiState() data class OtherError(val errorMessage: String) : LoginUiState() diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelState.kt index fbcc60258a..aba6dd7e36 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelState.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelState.kt @@ -199,27 +199,27 @@ data class VpnSettingsViewModelState( } sealed class VpnSettingsDialogState { - object NoDialog : VpnSettingsDialogState() + data object NoDialog : VpnSettingsDialogState() data class MtuDialog(val mtuEditValue: String) : VpnSettingsDialogState() data class DnsDialog(val stagedDns: StagedDns) : VpnSettingsDialogState() - object LocalNetworkSharingInfoDialog : VpnSettingsDialogState() + data object LocalNetworkSharingInfoDialog : VpnSettingsDialogState() - object ContentBlockersInfoDialog : VpnSettingsDialogState() + data object ContentBlockersInfoDialog : VpnSettingsDialogState() - object CustomDnsInfoDialog : VpnSettingsDialogState() + data object CustomDnsInfoDialog : VpnSettingsDialogState() - object MalwareInfoDialog : VpnSettingsDialogState() + data object MalwareInfoDialog : VpnSettingsDialogState() - object ObfuscationInfoDialog : VpnSettingsDialogState() + data object ObfuscationInfoDialog : VpnSettingsDialogState() - object QuantumResistanceInfoDialog : VpnSettingsDialogState() + data object QuantumResistanceInfoDialog : VpnSettingsDialogState() - object WireguardPortInfoDialog : VpnSettingsDialogState() + data object WireguardPortInfoDialog : VpnSettingsDialogState() - object CustomPortDialog : VpnSettingsDialogState() + data object CustomPortDialog : VpnSettingsDialogState() } sealed interface StagedDns { @@ -238,11 +238,11 @@ sealed interface StagedDns { ) : StagedDns sealed class ValidationResult { - object Success : ValidationResult() + data object Success : ValidationResult() - object InvalidAddress : ValidationResult() + data object InvalidAddress : ValidationResult() - object DuplicateAddress : ValidationResult() + data object DuplicateAddress : ValidationResult() } fun isValid() = (validationResult is ValidationResult.Success) |
