Compare commits
3 Commits
v0.2.6
...
6bb4ef2805
| Author | SHA1 | Date | |
|---|---|---|---|
| 6bb4ef2805 | |||
| e4e73da229 | |||
| 255c840847 |
@@ -69,7 +69,7 @@ android {
|
||||
minSdk = libs.versions.android.minSdk.get().toInt()
|
||||
targetSdk = libs.versions.android.targetSdk.get().toInt()
|
||||
versionCode = 1
|
||||
versionName = "0.2.6"
|
||||
versionName = "0.2.5"
|
||||
}
|
||||
packaging {
|
||||
resources {
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
android:required="false" />
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package su.reya.coop
|
||||
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Network
|
||||
import android.net.NetworkCapabilities
|
||||
import android.net.NetworkRequest
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
class AndroidConnectivityMonitor(context: Context) : ConnectivityMonitor {
|
||||
private val manager =
|
||||
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
|
||||
private val _isMobileData = MutableStateFlow(checkIsMobileData())
|
||||
override val isMobileData: StateFlow<Boolean> = _isMobileData.asStateFlow()
|
||||
|
||||
init {
|
||||
val networkRequest = NetworkRequest.Builder()
|
||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||
.build()
|
||||
|
||||
manager.registerNetworkCallback(
|
||||
networkRequest,
|
||||
object : ConnectivityManager.NetworkCallback() {
|
||||
override fun onAvailable(network: Network) {
|
||||
_isMobileData.value = checkIsMobileData()
|
||||
}
|
||||
|
||||
override fun onLost(network: Network) {
|
||||
_isMobileData.value = checkIsMobileData()
|
||||
}
|
||||
|
||||
override fun onCapabilitiesChanged(
|
||||
network: Network,
|
||||
networkCapabilities: NetworkCapabilities
|
||||
) {
|
||||
_isMobileData.value = checkIsMobileData()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun checkIsMobileData(): Boolean {
|
||||
val activeNetwork = manager.activeNetwork ?: return false
|
||||
val capabilities = manager.getNetworkCapabilities(activeNetwork) ?: return false
|
||||
return capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,6 @@ import su.reya.coop.screens.ProfileScreen
|
||||
import su.reya.coop.screens.RelayScreen
|
||||
import su.reya.coop.screens.RequestListScreen
|
||||
import su.reya.coop.screens.ScanScreen
|
||||
import su.reya.coop.screens.SettingsScreen
|
||||
import su.reya.coop.screens.UpdateProfileScreen
|
||||
import su.reya.coop.screens.chat.ChatScreen
|
||||
import su.reya.coop.viewmodel.AccountViewModel
|
||||
@@ -68,10 +67,6 @@ val LocalSettings = staticCompositionLocalOf<Settings> {
|
||||
error("No Settings provided")
|
||||
}
|
||||
|
||||
val LocalConnectivity = staticCompositionLocalOf<Boolean> {
|
||||
false
|
||||
}
|
||||
|
||||
val LocalSnackbarHostState = staticCompositionLocalOf<SnackbarHostState> {
|
||||
error("No SnackbarHostState provided")
|
||||
}
|
||||
@@ -91,7 +86,6 @@ fun App(
|
||||
accountRepository: AccountRepository,
|
||||
chatRepository: ChatRepository,
|
||||
settingsRepository: SettingsRepository,
|
||||
connectivityMonitor: ConnectivityMonitor,
|
||||
) {
|
||||
val viewModelFactory = remember {
|
||||
object : ViewModelProvider.Factory {
|
||||
@@ -134,9 +128,6 @@ fun App(
|
||||
// Get the settings
|
||||
val settings by settingsViewModel.settings.collectAsStateWithLifecycle()
|
||||
|
||||
// Get connectivity status
|
||||
val isMobileData by connectivityMonitor.isMobileData.collectAsStateWithLifecycle()
|
||||
|
||||
// Snackbar
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
|
||||
@@ -217,7 +208,6 @@ fun App(
|
||||
CompositionLocalProvider(
|
||||
LocalProfileCache provides profileCache,
|
||||
LocalSettings provides settings,
|
||||
LocalConnectivity provides isMobileData,
|
||||
LocalSnackbarHostState provides snackbarHostState,
|
||||
LocalNavigator provides navigator,
|
||||
LocalScanResult provides qrScanResult,
|
||||
@@ -294,9 +284,6 @@ fun App(
|
||||
entry<Screen.Relay> {
|
||||
RelayScreen(accountViewModel)
|
||||
}
|
||||
entry<Screen.Settings> {
|
||||
SettingsScreen(settingsViewModel)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@ class MainActivity : ComponentActivity() {
|
||||
private val profileCache by lazy { ProfileCache(NostrManager.instance) }
|
||||
private val scope = MainScope()
|
||||
|
||||
private val connectivityMonitor by lazy { AndroidConnectivityMonitor(this@MainActivity) }
|
||||
|
||||
private val settingsRepository by lazy {
|
||||
val storage = AppStore(this@MainActivity)
|
||||
SettingsRepository(storage, scope)
|
||||
@@ -98,7 +96,6 @@ class MainActivity : ComponentActivity() {
|
||||
accountRepository = accountRepository,
|
||||
chatRepository = chatRepository,
|
||||
settingsRepository = settingsRepository,
|
||||
connectivityMonitor = connectivityMonitor,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,4 @@ sealed interface Screen : NavKey {
|
||||
|
||||
@Serializable
|
||||
data object Relay : Screen
|
||||
|
||||
@Serializable
|
||||
data object Settings : Screen
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -28,6 +28,8 @@ private const val GROUP_KEY_MESSAGES = "su.reya.coop.MESSAGES"
|
||||
|
||||
class NostrForegroundService : Service() {
|
||||
private val serviceScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
|
||||
var ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||
private val nostr by lazy { NostrManager.instance }
|
||||
private var notificationJob: Job? = null
|
||||
|
||||
@@ -189,13 +191,4 @@ class NostrForegroundService : Service() {
|
||||
super.onDestroy()
|
||||
serviceScope.cancel()
|
||||
}
|
||||
|
||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
super.onTaskRemoved(rootIntent)
|
||||
if (!NotificationManagerCompat.from(this).areNotificationsEnabled()) {
|
||||
Log.d("Coop", "Stopping service on task removed because notifications are disabled")
|
||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Badge
|
||||
import androidx.compose.material3.BadgedBox
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
@@ -657,39 +655,27 @@ fun NewRequests(requests: List<Room>) {
|
||||
else -> ""
|
||||
}
|
||||
|
||||
val totalUnread = requests.sumOf { it.unreadCount }
|
||||
|
||||
ListItem(
|
||||
modifier = Modifier.clickable {
|
||||
navigator.navigate(Screen.RequestList)
|
||||
},
|
||||
leadingContent = {
|
||||
BadgedBox(
|
||||
badge = {
|
||||
if (totalUnread > 0) {
|
||||
Badge {
|
||||
Text(totalUnread.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(48.dp)
|
||||
.clip(MaterialShapes.Clover4Leaf.toShape()),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(48.dp)
|
||||
.clip(MaterialShapes.Clover4Leaf.toShape()),
|
||||
contentAlignment = Alignment.Center
|
||||
Surface(
|
||||
modifier = Modifier.size(48.dp),
|
||||
color = MaterialTheme.colorScheme.tertiaryContainer,
|
||||
) {
|
||||
Surface(
|
||||
modifier = Modifier.size(48.dp),
|
||||
color = MaterialTheme.colorScheme.tertiaryContainer,
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Icon(
|
||||
painter = painterResource(Res.drawable.ic_request),
|
||||
contentDescription = "Requests",
|
||||
tint = MaterialTheme.colorScheme.onTertiaryFixed
|
||||
)
|
||||
}
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Icon(
|
||||
painter = painterResource(Res.drawable.ic_request),
|
||||
contentDescription = "Requests",
|
||||
tint = MaterialTheme.colorScheme.onTertiaryFixed
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -697,19 +683,14 @@ fun NewRequests(requests: List<Room>) {
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = "Requests",
|
||||
style = MaterialTheme.typography.titleMediumEmphasized.copy(
|
||||
fontWeight = if (totalUnread > 0) FontWeight.SemiBold else FontWeight.Normal
|
||||
)
|
||||
style = MaterialTheme.typography.titleMediumEmphasized
|
||||
)
|
||||
},
|
||||
supportingContent = {
|
||||
if (supportingText.isNotEmpty()) {
|
||||
Text(
|
||||
text = supportingText,
|
||||
style = MaterialTheme.typography.bodyMedium.copy(
|
||||
fontWeight = if (totalUnread > 0) FontWeight.SemiBold else FontWeight.Normal,
|
||||
color = if (totalUnread > 0) MaterialTheme.colorScheme.onSurface else MaterialTheme.colorScheme.outline
|
||||
),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
@@ -731,35 +712,22 @@ fun ChatRoom(room: Room, onClick: () -> Unit) {
|
||||
ListItem(
|
||||
modifier = Modifier.clickable(onClick = onClick),
|
||||
leadingContent = {
|
||||
BadgedBox(
|
||||
badge = {
|
||||
if (room.unreadCount > 0) {
|
||||
Badge {
|
||||
Text(room.unreadCount.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
Avatar(picture = roomState.picture, description = roomState.picture)
|
||||
}
|
||||
Avatar(picture = roomState.picture, description = roomState.picture)
|
||||
},
|
||||
headlineContent = {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = roomState.name,
|
||||
style = MaterialTheme.typography.titleMediumEmphasized.copy(
|
||||
fontWeight = if (room.unreadCount > 0) FontWeight.SemiBold else FontWeight.Normal
|
||||
),
|
||||
style = MaterialTheme.typography.titleMediumEmphasized,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
Text(
|
||||
text = room.createdAt.ago(),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
textAlign = TextAlign.End,
|
||||
color = MaterialTheme.colorScheme.outline
|
||||
)
|
||||
}
|
||||
},
|
||||
@@ -767,10 +735,7 @@ fun ChatRoom(room: Room, onClick: () -> Unit) {
|
||||
if (!room.lastMessage.isNullOrBlank()) {
|
||||
Text(
|
||||
text = room.lastMessage ?: "",
|
||||
style = MaterialTheme.typography.bodyMedium.copy(
|
||||
fontWeight = if (room.unreadCount > 0) FontWeight.SemiBold else FontWeight.Normal,
|
||||
color = if (room.unreadCount > 0) MaterialTheme.colorScheme.onSurface else MaterialTheme.colorScheme.outline
|
||||
),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
)
|
||||
@@ -795,7 +760,7 @@ fun BottomMenuList(
|
||||
"Update Profile" to { navigator.navigate(Screen.UpdateProfile) },
|
||||
"Contact List" to { navigator.navigate(Screen.ContactList) },
|
||||
"Relay Management" to { navigator.navigate(Screen.Relay) },
|
||||
"Settings" to { navigator.navigate(Screen.Settings) }
|
||||
"Settings" to { }
|
||||
)
|
||||
|
||||
Column(
|
||||
|
||||
@@ -95,15 +95,15 @@ fun RelayScreen(viewModel: AccountViewModel) {
|
||||
var openAddRelayDialog by remember { mutableStateOf(false) }
|
||||
var relayToDelete by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
val accountState by viewModel.state.collectAsStateWithLifecycle()
|
||||
val loadedRelayList = accountState.userRelayList
|
||||
val loadedMsgRelayList = accountState.userMsgRelayList
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.loadCurrentUserRelayList()
|
||||
viewModel.loadCurrentUserMsgRelayList()
|
||||
}
|
||||
|
||||
val accountState by viewModel.state.collectAsStateWithLifecycle()
|
||||
val loadedRelayList = accountState.userRelayList
|
||||
val loadedMsgRelayList = accountState.userMsgRelayList
|
||||
|
||||
LaunchedEffect(loadedRelayList) {
|
||||
if (loadedRelayList.isNotEmpty()) {
|
||||
relayList.clear()
|
||||
|
||||
@@ -1,291 +0,0 @@
|
||||
package su.reya.coop.screens
|
||||
|
||||
import android.content.Intent
|
||||
import android.provider.Settings as AndroidSettings
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.selection.selectableGroup
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.ListItemDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SegmentedListItem
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.unit.dp
|
||||
import coop.composeapp.generated.resources.Res
|
||||
import coop.composeapp.generated.resources.ic_arrow_back
|
||||
import org.jetbrains.compose.resources.painterResource
|
||||
import su.reya.coop.LocalNavigator
|
||||
import su.reya.coop.LocalSnackbarHostState
|
||||
import su.reya.coop.MediaConfig
|
||||
import su.reya.coop.Theme
|
||||
import su.reya.coop.viewmodel.SettingsViewModel
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun SettingsScreen(viewModel: SettingsViewModel) {
|
||||
val navigator = LocalNavigator.current
|
||||
val context = LocalContext.current
|
||||
val snackbarHostState = LocalSnackbarHostState.current
|
||||
val settings by viewModel.settings.collectAsState()
|
||||
|
||||
var showThemeDialog by remember { mutableStateOf(false) }
|
||||
var showMediaDialog by remember { mutableStateOf(false) }
|
||||
var showBlossomDialog by remember { mutableStateOf(false) }
|
||||
|
||||
Scaffold(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
text = "Settings",
|
||||
style = MaterialTheme.typography.titleMediumEmphasized
|
||||
)
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||
),
|
||||
navigationIcon = {
|
||||
IconButton(onClick = { navigator.goBack() }) {
|
||||
Icon(
|
||||
painter = painterResource(Res.drawable.ic_arrow_back),
|
||||
contentDescription = "Back"
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
) { innerPadding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(innerPadding)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(horizontal = 16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(24.dp)
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "General",
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(horizontal = 8.dp)
|
||||
)
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(ListItemDefaults.SegmentedGap)
|
||||
) {
|
||||
SegmentedListItem(
|
||||
onClick = { viewModel.update { it.copy(screening = !it.screening) } },
|
||||
shapes = ListItemDefaults.segmentedShapes(index = 0, count = 4),
|
||||
content = { Text("Screening") },
|
||||
supportingContent = { Text("Filter unknown contacts") },
|
||||
trailingContent = {
|
||||
Switch(
|
||||
checked = settings.screening,
|
||||
onCheckedChange = { viewModel.update { s -> s.copy(screening = it) } }
|
||||
)
|
||||
}
|
||||
)
|
||||
SegmentedListItem(
|
||||
onClick = { showMediaDialog = true },
|
||||
shapes = ListItemDefaults.segmentedShapes(index = 1, count = 4),
|
||||
content = { Text("Media Preview") },
|
||||
supportingContent = {
|
||||
Text(
|
||||
when (settings.media) {
|
||||
MediaConfig.Disabled -> "Disabled"
|
||||
MediaConfig.DisabledForMobileData -> "Disabled for Mobile Data"
|
||||
MediaConfig.AlwaysEnabled -> "Always Enabled"
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
SegmentedListItem(
|
||||
onClick = { showBlossomDialog = true },
|
||||
shapes = ListItemDefaults.segmentedShapes(index = 2, count = 4),
|
||||
content = { Text("Blossom Server") },
|
||||
supportingContent = { Text(settings.blossomServer ?: "Default") }
|
||||
)
|
||||
SegmentedListItem(
|
||||
onClick = {
|
||||
val intent = Intent(AndroidSettings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
|
||||
putExtra(AndroidSettings.EXTRA_APP_PACKAGE, context.packageName)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
},
|
||||
shapes = ListItemDefaults.segmentedShapes(index = 3, count = 4),
|
||||
content = { Text("Notifications") },
|
||||
supportingContent = { Text("System notification settings") }
|
||||
)
|
||||
}
|
||||
}
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Appearance",
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(horizontal = 8.dp)
|
||||
)
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(ListItemDefaults.SegmentedGap)
|
||||
) {
|
||||
SegmentedListItem(
|
||||
onClick = { showThemeDialog = true },
|
||||
shapes = ListItemDefaults.segmentedShapes(index = 0, count = 2),
|
||||
content = { Text("Theme") },
|
||||
supportingContent = { Text(settings.theme.name) }
|
||||
)
|
||||
SegmentedListItem(
|
||||
onClick = { viewModel.update { it.copy(dynamicColor = !it.dynamicColor) } },
|
||||
shapes = ListItemDefaults.segmentedShapes(index = 1, count = 2),
|
||||
content = { Text("Dynamic Color") },
|
||||
trailingContent = {
|
||||
Switch(
|
||||
checked = settings.dynamicColor,
|
||||
onCheckedChange = {
|
||||
viewModel.update { s -> s.copy(dynamicColor = it) }
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showThemeDialog) {
|
||||
OptionDialog(
|
||||
title = "Select Theme",
|
||||
options = Theme.entries.map { it.name },
|
||||
selected = settings.theme.name,
|
||||
onSelected = { name ->
|
||||
viewModel.update { it.copy(theme = Theme.valueOf(name)) }
|
||||
showThemeDialog = false
|
||||
},
|
||||
onDismiss = { showThemeDialog = false }
|
||||
)
|
||||
}
|
||||
|
||||
if (showMediaDialog) {
|
||||
OptionDialog(
|
||||
title = "Media Preview",
|
||||
options = listOf("Disabled", "Disabled for Mobile Data", "Always Enabled"),
|
||||
selected = when (settings.media) {
|
||||
MediaConfig.Disabled -> "Disabled"
|
||||
MediaConfig.DisabledForMobileData -> "Disabled for Mobile Data"
|
||||
MediaConfig.AlwaysEnabled -> "Always Enabled"
|
||||
},
|
||||
onSelected = { choice ->
|
||||
val newConfig = when (choice) {
|
||||
"Disabled" -> MediaConfig.Disabled
|
||||
"Disabled for Mobile Data" -> MediaConfig.DisabledForMobileData
|
||||
else -> MediaConfig.AlwaysEnabled
|
||||
}
|
||||
viewModel.update { it.copy(media = newConfig) }
|
||||
showMediaDialog = false
|
||||
},
|
||||
onDismiss = { showMediaDialog = false }
|
||||
)
|
||||
}
|
||||
|
||||
if (showBlossomDialog) {
|
||||
var text by remember { mutableStateOf(settings.blossomServer ?: "") }
|
||||
AlertDialog(
|
||||
onDismissRequest = { showBlossomDialog = false },
|
||||
title = { Text("Blossom Server URL") },
|
||||
text = {
|
||||
OutlinedTextField(
|
||||
value = text,
|
||||
onValueChange = { text = it },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
placeholder = { Text("https://...") },
|
||||
singleLine = true
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
viewModel.update { it.copy(blossomServer = text.ifBlank { null }) }
|
||||
showBlossomDialog = false
|
||||
}) {
|
||||
Text("Save")
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showBlossomDialog = false }) {
|
||||
Text("Cancel")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun OptionDialog(
|
||||
title: String,
|
||||
options: List<String>,
|
||||
selected: String,
|
||||
onSelected: (String) -> Unit,
|
||||
onDismiss: () -> Unit
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(title) },
|
||||
text = {
|
||||
Column(modifier = Modifier.selectableGroup()) {
|
||||
options.forEach { text ->
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.selectable(
|
||||
selected = (text == selected),
|
||||
onClick = { onSelected(text) },
|
||||
role = Role.RadioButton
|
||||
)
|
||||
.padding(vertical = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
RadioButton(selected = (text == selected), onClick = null)
|
||||
Spacer(Modifier.size(16.dp))
|
||||
Text(text = text, style = MaterialTheme.typography.bodyLarge)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {}
|
||||
)
|
||||
}
|
||||
@@ -38,9 +38,6 @@ import coil3.compose.AsyncImage
|
||||
import rust.nostr.sdk.EventId
|
||||
import rust.nostr.sdk.PublicKey
|
||||
import rust.nostr.sdk.UnsignedEvent
|
||||
import su.reya.coop.LocalConnectivity
|
||||
import su.reya.coop.LocalSettings
|
||||
import su.reya.coop.MediaConfig
|
||||
import su.reya.coop.URL_REGEX
|
||||
import su.reya.coop.formatAsTime
|
||||
import su.reya.coop.isImageUrl
|
||||
@@ -59,27 +56,14 @@ data class MessageModel(
|
||||
|
||||
@Composable
|
||||
fun rememberMessageModel(event: UnsignedEvent, currentUser: PublicKey? = null): MessageModel {
|
||||
val settings = LocalSettings.current
|
||||
val isMobileData = LocalConnectivity.current
|
||||
|
||||
return remember(event, currentUser, settings, isMobileData) {
|
||||
return remember(event, currentUser) {
|
||||
val id = event.ensureId().id()!!
|
||||
val isMine = currentUser == event.author()
|
||||
val content = event.content()
|
||||
val replyEventIds = event.tags().eventIds()
|
||||
|
||||
val showMedia = when (settings.media) {
|
||||
MediaConfig.AlwaysEnabled -> true
|
||||
MediaConfig.Disabled -> false
|
||||
MediaConfig.DisabledForMobileData -> !isMobileData
|
||||
}
|
||||
|
||||
val images = if (showMedia) {
|
||||
URL_REGEX.findAll(content).map { it.value }.filter { it.isImageUrl() }.toList()
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
val cleanedContent = if (showMedia) content.removeImageUrls() else content
|
||||
val images = URL_REGEX.findAll(content).map { it.value }.filter { it.isImageUrl() }.toList()
|
||||
val cleanedContent = content.removeImageUrls()
|
||||
|
||||
val annotatedString = buildAnnotatedString {
|
||||
var lastIndex = 0
|
||||
|
||||
@@ -93,7 +93,6 @@ import org.jetbrains.compose.resources.painterResource
|
||||
import rust.nostr.sdk.UnsignedEvent
|
||||
import su.reya.coop.LocalNavigator
|
||||
import su.reya.coop.LocalProfileCache
|
||||
import su.reya.coop.LocalSettings
|
||||
import su.reya.coop.LocalSnackbarHostState
|
||||
import su.reya.coop.Room
|
||||
import su.reya.coop.RoomUiState
|
||||
@@ -116,7 +115,6 @@ fun ChatScreen(
|
||||
val clipboardManager = LocalClipboard.current
|
||||
val navigator = LocalNavigator.current
|
||||
val profileCache = LocalProfileCache.current
|
||||
val settings = LocalSettings.current
|
||||
val scope = rememberCoroutineScope()
|
||||
val listState = rememberLazyListState()
|
||||
|
||||
@@ -267,7 +265,7 @@ fun ChatScreen(
|
||||
.fillMaxSize()
|
||||
.padding(bottom = innerPadding.calculateBottomPadding())
|
||||
) {
|
||||
if (requireScreening && settings.screening) {
|
||||
if (requireScreening) {
|
||||
room?.let { ScreenerCard(accountViewModel, it) }
|
||||
}
|
||||
|
||||
@@ -351,7 +349,7 @@ fun ChatScreen(
|
||||
}
|
||||
}
|
||||
|
||||
when (requireScreening && settings.screening) {
|
||||
when (requireScreening) {
|
||||
true -> {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package su.reya.coop.shared
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -14,9 +13,6 @@ import coil3.compose.AsyncImage
|
||||
import coop.composeapp.generated.resources.Res
|
||||
import coop.composeapp.generated.resources.avatar
|
||||
import org.jetbrains.compose.resources.painterResource
|
||||
import su.reya.coop.LocalConnectivity
|
||||
import su.reya.coop.LocalSettings
|
||||
import su.reya.coop.MediaConfig
|
||||
|
||||
@Composable
|
||||
fun Avatar(
|
||||
@@ -26,36 +22,17 @@ fun Avatar(
|
||||
size: Dp = 48.dp,
|
||||
shape: Shape = CircleShape
|
||||
) {
|
||||
val settings = LocalSettings.current
|
||||
val isMobileData = LocalConnectivity.current
|
||||
val placeholder = painterResource(Res.drawable.avatar)
|
||||
|
||||
val showMedia = when (settings.media) {
|
||||
MediaConfig.AlwaysEnabled -> true
|
||||
MediaConfig.Disabled -> false
|
||||
MediaConfig.DisabledForMobileData -> !isMobileData
|
||||
}
|
||||
|
||||
if (showMedia) {
|
||||
AsyncImage(
|
||||
model = picture,
|
||||
contentDescription = description,
|
||||
modifier = modifier
|
||||
.size(size)
|
||||
.clip(shape),
|
||||
contentScale = ContentScale.Crop,
|
||||
fallback = placeholder,
|
||||
error = placeholder,
|
||||
placeholder = placeholder
|
||||
)
|
||||
} else {
|
||||
Image(
|
||||
painter = placeholder,
|
||||
contentDescription = description,
|
||||
modifier = modifier
|
||||
.size(size)
|
||||
.clip(shape),
|
||||
contentScale = ContentScale.Crop
|
||||
)
|
||||
}
|
||||
AsyncImage(
|
||||
model = picture,
|
||||
contentDescription = description,
|
||||
modifier = modifier
|
||||
.size(size)
|
||||
.clip(shape),
|
||||
contentScale = ContentScale.Crop,
|
||||
fallback = placeholder,
|
||||
error = placeholder,
|
||||
placeholder = placeholder
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package su.reya.coop
|
||||
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
interface ConnectivityMonitor {
|
||||
val isMobileData: StateFlow<Boolean>
|
||||
}
|
||||
@@ -30,8 +30,7 @@ data class Room(
|
||||
val subject: String?,
|
||||
val members: Set<PublicKey>,
|
||||
val kind: RoomKind = RoomKind.default(),
|
||||
val lastMessage: String? = null,
|
||||
val unreadCount: Int = 0
|
||||
val lastMessage: String? = null
|
||||
) : Comparable<Room> {
|
||||
override fun compareTo(other: Room): Int {
|
||||
return this.createdAt.asSecs().compareTo(other.createdAt.asSecs())
|
||||
|
||||
@@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable
|
||||
data class Settings(
|
||||
val theme: Theme = Theme.System,
|
||||
val dynamicColor: Boolean = true,
|
||||
val media: MediaConfig = MediaConfig.AlwaysEnabled,
|
||||
val media: Media = Media.AlwaysEnabled,
|
||||
val screening: Boolean = true,
|
||||
val blossomServer: String? = "https://blossom.band",
|
||||
)
|
||||
@@ -17,6 +17,6 @@ enum class Theme {
|
||||
}
|
||||
|
||||
@Serializable
|
||||
enum class MediaConfig {
|
||||
enum class Media {
|
||||
Disabled, DisabledForMobileData, AlwaysEnabled
|
||||
}
|
||||
|
||||
@@ -154,10 +154,7 @@ class Nostr(
|
||||
|
||||
// Trigger new message notification
|
||||
if (rumor != null) {
|
||||
val isSelfMessage = rumor.author() == signer.publicKeyFlow.value
|
||||
val isNew = rumor.createdAt().asSecs() >= now.asSecs()
|
||||
|
||||
if (isNew && !isSelfMessage) {
|
||||
if (rumor.createdAt().asSecs() >= now.asSecs()) {
|
||||
onNewMessage(rumor)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,19 +130,6 @@ class ChatRepository(
|
||||
return _state.value.rooms[id]
|
||||
}
|
||||
|
||||
fun markAsRead(roomId: Long) {
|
||||
_state.update { currentState ->
|
||||
val rooms = currentState.rooms.toMutableMap()
|
||||
val room = rooms[roomId]
|
||||
if (room != null && room.unreadCount > 0) {
|
||||
rooms[roomId] = room.copy(unreadCount = 0)
|
||||
currentState.copy(rooms = rooms)
|
||||
} else {
|
||||
currentState
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun refreshChatRooms() {
|
||||
scope.launch(defaultDispatcher) {
|
||||
try {
|
||||
@@ -153,14 +140,10 @@ class ChatRepository(
|
||||
val existing = newMap[dbRoom.id]
|
||||
// Only update if the database version is newer or equal
|
||||
if (existing == null || dbRoom.createdAt.asSecs() >= existing.createdAt.asSecs()) {
|
||||
// Preserve Ongoing kind and unreadCount status if already marked as such in memory
|
||||
// Preserve Ongoing kind if already marked as such in memory
|
||||
val mergedKind =
|
||||
if (existing?.kind == RoomKind.Ongoing) RoomKind.Ongoing else dbRoom.kind
|
||||
val mergedUnreadCount = existing?.unreadCount ?: 0
|
||||
newMap[dbRoom.id] = dbRoom.copy(
|
||||
kind = mergedKind,
|
||||
unreadCount = mergedUnreadCount
|
||||
)
|
||||
newMap[dbRoom.id] = dbRoom.copy(kind = mergedKind)
|
||||
}
|
||||
}
|
||||
currentState.copy(rooms = newMap)
|
||||
@@ -254,18 +237,14 @@ class ChatRepository(
|
||||
|
||||
if (existingRoom == null) {
|
||||
// New room discovery
|
||||
val newRoom = Room.new(event, currentUser, roomId).copy(
|
||||
kind = newKind,
|
||||
unreadCount = if (isFromMe) 0 else 1
|
||||
)
|
||||
val newRoom = Room.new(event, currentUser, roomId).copy(kind = newKind)
|
||||
rooms[newRoom.id] = newRoom
|
||||
} else if (event.createdAt().asSecs() >= existingRoom.createdAt.asSecs()) {
|
||||
// Only update preview if message is newer (handles sync/late arrivals)
|
||||
rooms[roomId] = existingRoom.copy(
|
||||
lastMessage = event.content(),
|
||||
createdAt = event.createdAt(),
|
||||
kind = newKind,
|
||||
unreadCount = if (isFromMe) existingRoom.unreadCount else existingRoom.unreadCount + 1
|
||||
kind = newKind
|
||||
)
|
||||
} else if (isFromMe && existingRoom.kind != RoomKind.Ongoing) {
|
||||
// Even if it's an older message, if it's from me, the room is ongoing
|
||||
|
||||
@@ -42,8 +42,6 @@ class ChatScreenViewModel(
|
||||
messages.clear()
|
||||
messages.addAll(initialMessages.distinctBy { it.id() })
|
||||
loading = false
|
||||
// Mark the room as read once messages are loaded
|
||||
chatRepository.markAsRead(id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +55,6 @@ class ChatScreenViewModel(
|
||||
if (event.roomId() == id) {
|
||||
if (messages.none { it.id() == event.id() }) {
|
||||
messages.add(0, event)
|
||||
chatRepository.markAsRead(id)
|
||||
}
|
||||
} else {
|
||||
newOtherMessages++
|
||||
|
||||
Reference in New Issue
Block a user