Refactor: Require active server connection for sharing and joining lists
- ListDetailScreen: hide Share action icon when not connected to a server (isLoggedIn == false)
- ListsScreen: show informative prompt dialog if user attempts to join a list without active server connection
- ListDetailViewModel: expose sessionManager to check auth state cleanly
- ADB reinstall & launch verified ✅
This commit is contained in:
parent
69591df12a
commit
97583340a4
3 changed files with 50 additions and 3 deletions
|
|
@ -45,6 +45,7 @@ fun ListDetailScreen(
|
|||
val query by viewModel.query.collectAsStateWithLifecycle()
|
||||
val suggestions by viewModel.suggestions.collectAsStateWithLifecycle()
|
||||
val inviteCode by viewModel.inviteCode.collectAsStateWithLifecycle()
|
||||
val isLoggedIn by viewModel.sessionManager.isLoggedIn.collectAsStateWithLifecycle()
|
||||
|
||||
val context = LocalContext.current
|
||||
var showShareDialog by remember { mutableStateOf(false) }
|
||||
|
|
@ -68,7 +69,8 @@ fun ListDetailScreen(
|
|||
}
|
||||
},
|
||||
actions = {
|
||||
if (!inviteCode.isNullOrBlank()) {
|
||||
// Only allow sharing if the user is connected to a sync server
|
||||
if (isLoggedIn && !inviteCode.isNullOrBlank()) {
|
||||
IconButton(onClick = { showShareDialog = true }) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Share,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.example.mitbringsl.ui.detail
|
|||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.example.mitbringsl.data.auth.SessionManager
|
||||
import com.example.mitbringsl.data.local.entity.ItemEntity
|
||||
import com.example.mitbringsl.data.remote.api.MitbringslApi
|
||||
import com.example.mitbringsl.data.repository.ShoppingRepository
|
||||
|
|
@ -17,6 +18,7 @@ import javax.inject.Inject
|
|||
class ListDetailViewModel @Inject constructor(
|
||||
private val repository: ShoppingRepository,
|
||||
private val api: MitbringslApi,
|
||||
val sessionManager: SessionManager,
|
||||
) : ViewModel() {
|
||||
|
||||
private val _listId = MutableStateFlow<String?>(null)
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ fun ListsScreen(
|
|||
|
||||
var showAddDialog by remember { mutableStateOf(false) }
|
||||
var showJoinDialog by remember { mutableStateOf(false) }
|
||||
var showNeedSyncDialog by remember { mutableStateOf(false) }
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
|
|
@ -55,7 +56,13 @@ fun ListsScreen(
|
|||
)
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = { showJoinDialog = true }) {
|
||||
IconButton(onClick = {
|
||||
if (isLoggedIn) {
|
||||
showJoinDialog = true
|
||||
} else {
|
||||
showNeedSyncDialog = true
|
||||
}
|
||||
}) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.GroupAdd,
|
||||
contentDescription = "Liste beitreten"
|
||||
|
|
@ -170,7 +177,13 @@ fun ListsScreen(
|
|||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
OutlinedButton(
|
||||
onClick = { showJoinDialog = true },
|
||||
onClick = {
|
||||
if (isLoggedIn) {
|
||||
showJoinDialog = true
|
||||
} else {
|
||||
showNeedSyncDialog = true
|
||||
}
|
||||
},
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
) {
|
||||
Icon(imageVector = Icons.Default.GroupAdd, contentDescription = null)
|
||||
|
|
@ -221,6 +234,36 @@ fun ListsScreen(
|
|||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (showNeedSyncDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showNeedSyncDialog = false },
|
||||
title = { Text("Server-Verbindung erforderlich") },
|
||||
text = {
|
||||
Text(
|
||||
text = "Um einer geteilten Einkaufsliste beizutreten oder eigene Listen zu teilen, verbinde dich bitte zuerst mit deinem Mitbringsl Sync-Server.",
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = {
|
||||
showNeedSyncDialog = false
|
||||
onOpenSync()
|
||||
},
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
) {
|
||||
Text("Jetzt verbinden")
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showNeedSyncDialog = false }) {
|
||||
Text("Abbrechen")
|
||||
}
|
||||
},
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue