Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import androidx.glance.action.actionParametersOf
import androidx.glance.appwidget.action.ActionCallback
import com.twofasapp.designsystem.ktx.copyToClipboard

internal class CopyToClipboardAction : ActionCallback {
internal class CopyAndToggleAction : ActionCallback {

companion object {
private val paramCode = ActionParameters.Key<String>("code")
private val paramAppWidgetId = ActionParameters.Key<Int>("appWidgetId")
private val paramServiceId = ActionParameters.Key<Long>("serviceId")

fun params(code: String): ActionParameters {
return actionParametersOf(paramCode to code)
fun params(code: String, appWidgetId: Int, serviceId: Long): ActionParameters {
return actionParametersOf(
paramCode to code,
paramAppWidgetId to appWidgetId,
paramServiceId to serviceId
)
}
}

Expand All @@ -21,10 +28,15 @@ internal class CopyToClipboardAction : ActionCallback {
glanceId: GlanceId,
parameters: ActionParameters
) {
// Copy to clipboard
context.copyToClipboard(
text = parameters[paramCode].orEmpty(),
isSensitive = true,
showToast = false,
showToast = false
)

// Call ToggleServiceAction to avoid duplicate code
ToggleServiceAction().onAction(context, glanceId, parameters)

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ internal fun WidgetContent(
) {
val context = LocalContext.current
val isNight by remember { mutableStateOf(context.resources.getBoolean(R.bool.isNight)) }
val widget by widgetsRepository.observeWidget(appWidgetId).collectAsState(initial = Widget(appWidgetId = appWidgetId))
val widget by widgetsRepository.observeWidget(appWidgetId)
.collectAsState(initial = Widget(appWidgetId = appWidgetId))

Column(
modifier = GlanceModifier
Expand All @@ -65,7 +66,8 @@ internal fun WidgetContent(
horizontalAlignment = Alignment.CenterHorizontally
) {
Row(
modifier = GlanceModifier.fillMaxWidth().padding(start = 8.dp, end = 6.dp, top = 8.dp, bottom = 2.dp),
modifier = GlanceModifier.fillMaxWidth()
.padding(start = 8.dp, end = 6.dp, top = 8.dp, bottom = 2.dp),
verticalAlignment = Alignment.Vertical.CenterVertically,
) {
Image(
Expand Down Expand Up @@ -141,12 +143,17 @@ private fun ServiceItem(
.fillMaxWidth()
.height(52.dp)
.clickable(
actionRunCallback<ToggleServiceAction>(
ToggleServiceAction.params(
appWidgetId = appWidgetId,
serviceId = service.id
// toggle-on when it's hidden, copy to clipboard and toggle-off when it's revealed
if (!revealed) {
actionRunCallback<ToggleServiceAction>(
ToggleServiceAction.params(appWidgetId, service.id)
)
)
} else {
actionRunCallback<CopyAndToggleAction>(
CopyAndToggleAction.params(code.current, appWidgetId, service.id)
)
}

)
.padding(
start = if (revealed) 0.dp else 8.dp,
Expand Down Expand Up @@ -188,7 +195,11 @@ private fun ServiceItem(
)
Text(
text = "${code.timer}" + context.getString(com.twofasapp.locale.R.string.time_unit_seconds_short),
style = TextStyle(fontSize = 13.sp, fontWeight = FontWeight.Bold, color = textColor)
style = TextStyle(
fontSize = 13.sp,
fontWeight = FontWeight.Bold,
color = textColor
)
)
}
}
Expand All @@ -212,15 +223,6 @@ private fun ServiceItem(

Spacer(GlanceModifier.width(8.dp))

Icon(
resId = com.twofasapp.designsystem.R.drawable.ic_copy,
modifier = GlanceModifier
.size(26.dp)
.clickable(actionRunCallback<CopyToClipboardAction>(CopyToClipboardAction.params(code.current)))
.padding(2.dp)
.cornerRadius(24.dp),
)

} else {
Text(
text = service.name,
Expand Down Expand Up @@ -264,7 +266,11 @@ private fun ServiceImage(
) {
Text(
text = service.labelText.orEmpty(),
style = TextStyle(fontSize = 12.sp, fontWeight = FontWeight.Bold, color = ColorProvider(Color.White)),
style = TextStyle(
fontSize = 12.sp,
fontWeight = FontWeight.Bold,
color = ColorProvider(Color.White)
),
)
}
}
Expand Down