Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions app/src/main/java/dev/scuttle/inventory/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ private object Routes {
const val SETTINGS = "settings"
const val STORAGE = "storage/{householdId}"
const val SEARCH = "search/{householdId}"
const val INVITE = "invite/{householdId}"
const val INVITE = "invite/{householdId}/{householdName}"
const val LOCATION = "location/{householdId}/{locationId}"
const val PRODUCT_DETAIL = "product-detail/{householdId}/{shelfId}/{productId}"
const val MISSING_ITEMS = "missing-items"

fun storage(householdId: Long) = "storage/$householdId"
fun search(householdId: Long) = "search/$householdId"
fun invite(householdId: Long) = "invite/$householdId"
fun invite(householdId: Long, householdName: String) = "invite/$householdId/${java.net.URLEncoder.encode(householdName, "UTF-8")}"
fun location(householdId: Long, locationId: Long) = "location/$householdId/$locationId"
fun productDetail(householdId: Long, shelfId: Long, productId: Long) = "product-detail/$householdId/$shelfId/$productId"
}
Expand Down Expand Up @@ -209,7 +209,7 @@ private fun InventoryNavHost(
composable(Routes.HOUSEHOLDS) {
HouseholdsScreen(
onBack = { navController.popBackStack() },
onOpenInvite = { navController.navigate(Routes.invite(it)) },
onOpenInvite = { id, name -> navController.navigate(Routes.invite(id, name)) },
)
}

Expand Down Expand Up @@ -237,10 +237,14 @@ private fun InventoryNavHost(

composable(
route = Routes.INVITE,
arguments = listOf(navArgument("householdId") { type = NavType.LongType }),
arguments = listOf(
navArgument("householdId") { type = NavType.LongType },
navArgument("householdName") { type = NavType.StringType },
),
) { entry ->
val householdId = entry.arguments?.getLong("householdId") ?: return@composable
InviteScreen(householdId = householdId, onBack = { navController.popBackStack() })
val householdName = entry.arguments?.getString("householdName") ?: ""
InviteScreen(householdId = householdId, storageName = householdName, onBack = { navController.popBackStack() })
}

composable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import dev.scuttle.inventory.R
fun HouseholdsScreen(
modifier: Modifier = Modifier,
onBack: () -> Unit = {},
onOpenInvite: (householdId: Long) -> Unit = {},
onOpenInvite: (householdId: Long, householdName: String) -> Unit = { _, _ -> },
viewModel: HouseholdsViewModel = hiltViewModel(),
) {
val state by viewModel.state.collectAsState()
Expand Down Expand Up @@ -134,7 +134,7 @@ fun HouseholdsScreen(
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.weight(1f),
)
IconButton(onClick = { onOpenInvite(household.id) }) {
IconButton(onClick = { onOpenInvite(household.id, household.name) }) {
Icon(Icons.Default.Share, contentDescription = stringResource(R.string.households_invite_cd, household.name))
}
TextButton(onClick = { confirmLeaveId = household.id }) {
Expand Down
58 changes: 41 additions & 17 deletions app/src/main/java/dev/scuttle/inventory/ui/invite/InviteScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ 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.graphics.asImageBitmap
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.google.zxing.BarcodeFormat
Expand All @@ -37,6 +39,7 @@ import kotlinx.coroutines.delay
@Composable
fun InviteScreen(
householdId: Long,
storageName: String = "",
modifier: Modifier = Modifier,
onBack: () -> Unit = {},
viewModel: InviteViewModel = hiltViewModel(),
Expand Down Expand Up @@ -77,26 +80,47 @@ fun InviteScreen(
}

if (state.code.isNotEmpty()) {
Text(text = stringResource(R.string.invite_join_code_label))
Text(text = state.code, fontFamily = SpaceMono)
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
if (storageName.isNotEmpty()) {
Text(
text = storageName,
style = MaterialTheme.typography.titleLarge,
textAlign = TextAlign.Center,
)
}

val qr = remember(state.link) { qrBitmap(state.link) }
if (qr != null) {
Image(
bitmap = qr.asImageBitmap(),
contentDescription = stringResource(R.string.invite_qr_cd),
modifier = Modifier.size(220.dp),
Text(
text = stringResource(R.string.invite_join_code_label),
textAlign = TextAlign.Center,
)
Text(
text = state.code,
fontFamily = SpaceMono,
textAlign = TextAlign.Center,
)
}

Button(
onClick = {
clipboard.setText(AnnotatedString(state.link))
copied = true
},
enabled = state.link.isNotEmpty(),
) {
Text(if (copied) stringResource(R.string.invite_copied) else stringResource(R.string.invite_copy_link))
val qr = remember(state.link) { qrBitmap(state.link) }
if (qr != null) {
Image(
bitmap = qr.asImageBitmap(),
contentDescription = stringResource(R.string.invite_qr_cd),
modifier = Modifier.size(220.dp),
)
}

Button(
onClick = {
clipboard.setText(AnnotatedString(state.link))
copied = true
},
enabled = state.link.isNotEmpty(),
) {
Text(if (copied) stringResource(R.string.invite_copied) else stringResource(R.string.invite_copy_link))
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
<string name="drawer_settings">Settings</string>

<!-- Invite -->
<string name="invite_title">Invite to household</string>
<string name="invite_title">Invite to storage</string>
<string name="invite_join_code_label">Join code</string>
<string name="invite_qr_cd">Invite QR code</string>
<string name="invite_copy_link">Copy link</string>
Expand Down
Loading