Skip to content

Commit

Permalink
Improve snackbar behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperDragonXD committed Aug 23, 2024
1 parent c974fcf commit fc2f199
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ private fun HandleTouchInteractions(
encodedRequestList: String,
snackbarHostState: SnackbarHostState,
) {
val prefs = preferenceManager()
val lastestOnExpandSheet by rememberUpdatedState(newValue = onExpandSheet)
LaunchedEffect(interactionSource) {
var isLongClick = false
Expand All @@ -206,18 +207,16 @@ private fun HandleTouchInteractions(

is PressInteraction.Release -> {
if (!isLongClick) {
if (iconRequestList.isEmpty()) {
openLink(context, Constants.ICON_REQUEST_FORM)
} else if (directLinkEnabled) {
openLink(context, encodedRequestList)
} else {
openSnackbarWarningContent(
context,
requestList,
coroutineScope,
snackbarHostState,
)
}
prefs.showFirstLaunchSnackbar.set(false)
handleRequestClick(
iconRequestList,
context,
directLinkEnabled,
encodedRequestList,
requestList,
coroutineScope,
snackbarHostState,
)
}
}

Expand Down Expand Up @@ -275,6 +274,30 @@ private fun copyTextToClipboard(context: Context, text: String) {
clipboard.setPrimaryClip(clip)
}


private fun handleRequestClick(
iconRequestList: List<IconRequest>,
context: Context,
directLinkEnabled: Boolean,
encodedRequestList: String,
requestList: String,
coroutineScope: CoroutineScope,
snackbarHostState: SnackbarHostState,
) {
if (iconRequestList.isEmpty()) {
openLink(context, Constants.ICON_REQUEST_FORM)
} else if (directLinkEnabled) {
openLink(context, encodedRequestList)
} else {
openSnackbarWarningContent(
context,
requestList,
coroutineScope,
snackbarHostState,
)
}
}

private fun openSnackbarFirstLaunchContent(
context: Context,
coroutineScope: CoroutineScope,
Expand All @@ -284,21 +307,12 @@ private fun openSnackbarFirstLaunchContent(
coroutineScope.launch {
val result = snackbarHostState
.showSnackbar(
message = context.getString(R.string.you_have_missing_icons),
actionLabel = context.getString(R.string.request_icons),
withDismissAction = true,
duration = SnackbarDuration.Indefinite,
message = context.getString(R.string.snackbar_request_icons_hint),
duration = SnackbarDuration.Long,
)
when (result) {
SnackbarResult.ActionPerformed -> {
onActionPerformed()
openLink(context, Constants.ICON_REQUEST_FORM)
}

SnackbarResult.Dismissed -> {
onActionPerformed()
snackbarHostState.currentSnackbarData?.dismiss()
}
if (result == SnackbarResult.Dismissed) {
onActionPerformed()
snackbarHostState.currentSnackbarData?.dismiss()
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
<string name="copied_text">Copied text</string>

<!-- Snackbar content -->
<string name="snackbar_request_icons_hint">Request missing icons from the bottom bar</string>

<string name="snackbar_request_too_large">Copied icon request details to clipboard. To request them, submit the details into the form.</string>
<string name="snackbar_use_fallback_link">Open form</string>
<string name="you_have_missing_icons">You have missing icons</string>
</resources>

0 comments on commit fc2f199

Please sign in to comment.