This commit is contained in:
2026-05-31 06:48:21 +03:00
parent 96ee5ea45e
commit 66deae6fc3
20 changed files with 210 additions and 150 deletions
@@ -0,0 +1,23 @@
package dev.meloda.fast.common
import dev.meloda.fast.common.model.NetworkState
import dev.meloda.fast.common.model.NetworkStatus
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
class NetworkStateListener {
private val networkStatus = MutableStateFlow(NetworkStatus.UNAVAILABLE)
val networkStatusFlow = networkStatus.asStateFlow()
private val networkState = MutableStateFlow(NetworkState.DISCONNECTED)
val networkStateFlow = networkState.asStateFlow()
fun updateNetworkState(state: NetworkState) {
networkState.value = state
networkStatus.value = when (state) {
NetworkState.CONNECTED -> NetworkStatus.AVAILABLE
NetworkState.DISCONNECTED -> NetworkStatus.UNAVAILABLE
}
}
}
@@ -0,0 +1,3 @@
package dev.meloda.fast.common.model
enum class NetworkState { CONNECTED, DISCONNECTED }
@@ -0,0 +1,10 @@
package dev.meloda.fast.common.model
enum class NetworkStatus {
AVAILABLE, UNAVAILABLE, LOST, BLOCKED, UNBLOCKED;
fun isOk(): Boolean = when (this) {
AVAILABLE, UNBLOCKED -> true
UNAVAILABLE, LOST, BLOCKED -> false
}
}
@@ -0,0 +1,5 @@
package dev.meloda.fast.common.model
enum class NetworkType {
CELLULAR, WIFI, UNKNOWN
}
@@ -3,9 +3,7 @@ package dev.meloda.fast.common.provider
import android.content.res.Resources
interface ResourceProvider {
val resources: Resources
fun getString(resId: Int): String
}
@@ -0,0 +1,24 @@
package dev.meloda.fast.model
import dev.meloda.fast.model.database.AccountEntity
data class AccountDto(
val userId: Long,
val accessToken: String,
val fastToken: String?,
val trustedHash: String?,
val exchangeToken: String?
) {
fun mapToEntity(): AccountEntity = AccountEntity(
userId = userId,
accessToken = accessToken,
fastToken = fastToken,
trustedHash = trustedHash,
exchangeToken = exchangeToken
)
override fun toString(): String {
return super.toString()
}
}
@@ -2,6 +2,7 @@ package dev.meloda.fast.model.database
import androidx.room.Entity
import androidx.room.PrimaryKey
import dev.meloda.fast.model.AccountDto
@Entity(tableName = "accounts")
data class AccountEntity(
@@ -11,4 +12,12 @@ data class AccountEntity(
val fastToken: String?,
val trustedHash: String?,
val exchangeToken: String?
)
) {
fun mapToDto(): AccountDto = AccountDto(
userId = userId,
accessToken = accessToken,
fastToken = fastToken,
trustedHash = trustedHash,
exchangeToken = exchangeToken
)
}
@@ -0,0 +1,6 @@
package dev.meloda.fast.ui.common
import androidx.compose.runtime.compositionLocalOf
import dev.meloda.fast.common.model.NetworkState
val LocalNetworkState = compositionLocalOf { NetworkState.DISCONNECTED }
+1
View File
@@ -189,6 +189,7 @@
<string name="title_application_language">Application language</string>
<string name="action_refresh">Refresh</string>
<string name="title_loading">Loading&#8230;</string>
<string name="title_no_network">No network&#8230;</string>
<string name="title_convos">Conversations</string>
<string name="title_archive">Archive</string>
<string name="title_friends">Friends</string>