Revoke a single license by product key (v1.0.2).

Send license.key to the admin revoke API and track revoking state per key.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ivan Fontosh
2026-07-01 16:44:18 +08:00
parent bf6f347a44
commit 9799bca5e3
5 changed files with 13 additions and 13 deletions
+2 -2
View File
@@ -12,8 +12,8 @@ android {
applicationId = "ru.mailib.ttrpg.licensemanager"
minSdk = 26
targetSdk = 35
versionCode = 2
versionName = "1.0.1"
versionCode = 3
versionName = "1.0.2"
}
buildTypes {
@@ -32,7 +32,7 @@ data class ProductKeyResponse(
)
data class RevokeLicenseRequest(
val sub: String,
val key: String,
)
data class RevokeLicenseResponse(
@@ -59,8 +59,8 @@ class LicenseRepository(
createApi(settings).createProductKey(request)
}
suspend fun revokeLicense(settings: AppSettings, sub: String): Result<Unit> = runCatching {
createApi(settings).revokeLicense(RevokeLicenseRequest(sub))
suspend fun revokeLicense(settings: AppSettings, key: String): Result<Unit> = runCatching {
createApi(settings).revokeLicense(RevokeLicenseRequest(key))
}
private fun createApi(settings: AppSettings): LicenseApi {
@@ -22,7 +22,7 @@ import java.time.ZoneOffset
data class LicenseListUiState(
val licenses: List<LicenseEntry> = emptyList(),
val isLoading: Boolean = false,
val revokingSub: String? = null,
val revokingKey: String? = null,
val error: String? = null,
)
@@ -76,18 +76,18 @@ class LicenseViewModel(application: Application) : AndroidViewModel(application)
}
}
fun revokeLicense(sub: String) {
fun revokeLicense(key: String) {
viewModelScope.launch {
_listState.update { it.copy(revokingSub = sub, error = null) }
licenseRepository.revokeLicense(currentSettings(), sub)
_listState.update { it.copy(revokingKey = key, error = null) }
licenseRepository.revokeLicense(currentSettings(), key)
.onSuccess {
loadLicenses()
_listState.update { it.copy(revokingSub = null) }
_listState.update { it.copy(revokingKey = null) }
}
.onFailure { e ->
_listState.update {
it.copy(
revokingSub = null,
revokingKey = null,
error = e.message ?: "Не удалось отозвать лицензию",
)
}
@@ -63,7 +63,7 @@ fun LicenseListScreen(viewModel: LicenseViewModel) {
confirmButton = {
TextButton(
onClick = {
viewModel.revokeLicense(license.sub)
viewModel.revokeLicense(license.key)
confirmRevoke = null
},
) {
@@ -116,7 +116,7 @@ fun LicenseListScreen(viewModel: LicenseViewModel) {
items(state.licenses, key = { it.key }) { license ->
LicenseCard(
license = license,
isRevoking = state.revokingSub == license.sub,
isRevoking = state.revokingKey == license.key,
onRevoke = { confirmRevoke = license },
)
}