Skip to content

Commit

Permalink
Fix remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Oct 11, 2023
1 parent 1b251e7 commit b40c461
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package net.mullvad.mullvadvpn.compose.component

import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.foundation.background
Expand Down Expand Up @@ -287,12 +288,17 @@ fun MullvadTopBarWithDeviceName(
start = Dimens.mediumPadding,
end = Dimens.mediumPadding
)
.fillMaxWidth(),
.fillMaxWidth()
.animateContentSize(),
horizontalArrangement = Arrangement.spacedBy(Dimens.mediumPadding)
) {
Text(
modifier = Modifier.weight(1f, fill = false),
text = stringResource(id = R.string.top_bar_device_name, deviceName ?: ""),
text =
deviceName?.let {
stringResource(id = R.string.top_bar_device_name, deviceName)
}
?: "",
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.bodySmall
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package net.mullvad.mullvadvpn.util

import java.text.DateFormat
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.DurationUnit
import org.joda.time.DateTime
import org.joda.time.format.ISODateTimeFormat

fun DateTime.formatDate(): String = ISODateTimeFormat.date().print(this)

fun DateTime.toExpiryDateString(): String =
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(this.toDate())

fun DateTime.daysFromNow() =
(toInstant().millis - DateTime.now().toInstant().millis).milliseconds.toInt(DurationUnit.DAYS)
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import net.mullvad.mullvadvpn.ui.serviceconnection.connectionProxy
import net.mullvad.mullvadvpn.util.appVersionCallbackFlow
import net.mullvad.mullvadvpn.util.callbackFlowFromNotifier
import net.mullvad.mullvadvpn.util.combine
import net.mullvad.mullvadvpn.util.daysFromNow
import net.mullvad.mullvadvpn.util.toInAddress
import net.mullvad.mullvadvpn.util.toOutAddress
import net.mullvad.talpid.tunnel.ActionAfterDisconnect
Expand Down Expand Up @@ -131,7 +132,7 @@ class ConnectViewModel(
accountExpiry = accountExpiry
),
deviceName = deviceName,
daysLeftUntilExpiry = accountExpiry.daysLeft()
daysLeftUntilExpiry = accountExpiry.date()?.daysFromNow()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
package net.mullvad.mullvadvpn.model

import android.os.Parcelable
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.DurationUnit
import kotlinx.parcelize.Parcelize
import org.joda.time.DateTime

sealed class AccountExpiry : Parcelable {
@Parcelize
data class Available(val expiryDateTime: DateTime) : AccountExpiry() {
override fun daysLeft(): Int =
(expiryDateTime.toInstant().millis - DateTime.now().toInstant().millis)
.milliseconds
.toInt(DurationUnit.DAYS)
}
@Parcelize data class Available(val expiryDateTime: DateTime) : AccountExpiry()

@Parcelize data object Missing : AccountExpiry()

fun date(): DateTime? {
return (this as? Available)?.expiryDateTime
}

open fun daysLeft(): Int? {
return (this as? Available)?.daysLeft()
}
}

0 comments on commit b40c461

Please sign in to comment.