-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from DimensionDev/feature/bluesky_status_action
[WIP][Android][Bluesky] Add status action
- Loading branch information
Showing
20 changed files
with
884 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
app/src/main/java/dev/dimension/flare/ui/screen/status/action/BlueskyReportStatusDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package dev.dimension.flare.ui.screen.status.action | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.material3.AlertDialog | ||
import androidx.compose.material3.ListItem | ||
import androidx.compose.material3.RadioButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import com.ramcosta.composedestinations.annotation.DeepLink | ||
import com.ramcosta.composedestinations.annotation.Destination | ||
import com.ramcosta.composedestinations.annotation.FULL_ROUTE_PLACEHOLDER | ||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator | ||
import dev.dimension.flare.R | ||
import dev.dimension.flare.model.MicroBlogKey | ||
import dev.dimension.flare.molecule.producePresenter | ||
import dev.dimension.flare.ui.model.onSuccess | ||
import dev.dimension.flare.ui.presenter.status.action.BlueskyReportStatusPresenter | ||
import dev.dimension.flare.ui.presenter.status.action.BlueskyReportStatusState | ||
|
||
@Composable | ||
@Destination( | ||
deepLinks = [ | ||
DeepLink( | ||
uriPattern = "flare://$FULL_ROUTE_PLACEHOLDER", | ||
), | ||
], | ||
) | ||
fun BlueskyReportStatusRoute( | ||
navigator: DestinationsNavigator, | ||
statusKey: MicroBlogKey, | ||
) { | ||
BlueskyReportStatusDialog( | ||
statusKey = statusKey, | ||
onBack = { | ||
navigator.navigateUp() | ||
}, | ||
) | ||
} | ||
|
||
@Composable | ||
internal fun BlueskyReportStatusDialog( | ||
statusKey: MicroBlogKey, | ||
onBack: () -> Unit, | ||
) { | ||
val state by producePresenter(key = statusKey.toString()) { | ||
blueskyReportStatusPresenter(statusKey) | ||
} | ||
|
||
AlertDialog( | ||
onDismissRequest = onBack, | ||
confirmButton = { | ||
TextButton( | ||
enabled = state.reason != null, | ||
onClick = { | ||
state.status.onSuccess { status -> | ||
state.reason?.let { | ||
state.report(it, status) | ||
onBack.invoke() | ||
} | ||
} | ||
}, | ||
) { | ||
Text(text = stringResource(id = R.string.confirm)) | ||
} | ||
}, | ||
dismissButton = { | ||
TextButton(onClick = onBack) { | ||
Text(text = stringResource(id = R.string.cancel)) | ||
} | ||
}, | ||
title = { | ||
Text(text = stringResource(id = R.string.report_title)) | ||
}, | ||
text = { | ||
Column { | ||
Text(text = stringResource(id = R.string.report_description)) | ||
state.allReasons.forEach { | ||
val interactionSource = | ||
remember(it) { | ||
MutableInteractionSource() | ||
} | ||
ListItem( | ||
modifier = | ||
Modifier.clickable( | ||
interactionSource = interactionSource, | ||
indication = null, | ||
onClick = { | ||
state.selectReason(it) | ||
}, | ||
), | ||
headlineContent = { | ||
Text(text = stringResource(id = it.stringRes)) | ||
}, | ||
supportingContent = { | ||
Text(text = stringResource(id = it.descriptionRes)) | ||
}, | ||
leadingContent = { | ||
RadioButton( | ||
selected = state.reason == it, | ||
interactionSource = interactionSource, | ||
onClick = { | ||
state.selectReason(it) | ||
}, | ||
) | ||
}, | ||
) | ||
} | ||
} | ||
}, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun blueskyReportStatusPresenter(statusKey: MicroBlogKey) = | ||
run { | ||
val state = | ||
remember(statusKey) { | ||
BlueskyReportStatusPresenter(statusKey) | ||
}.invoke() | ||
|
||
object : BlueskyReportStatusState by state { | ||
} | ||
} | ||
|
||
private val BlueskyReportStatusState.ReportReason.stringRes: Int | ||
get() = | ||
when (this) { | ||
BlueskyReportStatusState.ReportReason.Spam -> R.string.report_reason_spam_title | ||
BlueskyReportStatusState.ReportReason.Violation -> R.string.report_reason_violation_title | ||
BlueskyReportStatusState.ReportReason.Misleading -> R.string.report_reason_misleading_title | ||
BlueskyReportStatusState.ReportReason.Sexual -> R.string.report_reason_sexual_title | ||
BlueskyReportStatusState.ReportReason.Rude -> R.string.report_reason_rude_title | ||
BlueskyReportStatusState.ReportReason.Other -> R.string.report_reason_other_title | ||
} | ||
|
||
private val BlueskyReportStatusState.ReportReason.descriptionRes: Int | ||
get() = | ||
when (this) { | ||
BlueskyReportStatusState.ReportReason.Spam -> R.string.report_reason_spam_description | ||
BlueskyReportStatusState.ReportReason.Violation -> R.string.report_reason_violation_description | ||
BlueskyReportStatusState.ReportReason.Misleading -> R.string.report_reason_misleading_description | ||
BlueskyReportStatusState.ReportReason.Sexual -> R.string.report_reason_sexual_description | ||
BlueskyReportStatusState.ReportReason.Rude -> R.string.report_reason_rude_description | ||
BlueskyReportStatusState.ReportReason.Other -> R.string.report_reason_other_description | ||
} |
Oops, something went wrong.