mirror of
https://github.com/lone-cloud/prism-android
synced 2026-06-03 11:03:10 -07:00
fix app deletion
This commit is contained in:
parent
b2ae8c3e0c
commit
3bf7227a55
4 changed files with 28 additions and 17 deletions
|
|
@ -39,6 +39,13 @@ object Distributor : UnifiedPushDistributor() {
|
||||||
) = backendRegisterNewChannelId(context, packageName, channelId, title, vapid, description)
|
) = backendRegisterNewChannelId(context, packageName, channelId, title, vapid, description)
|
||||||
|
|
||||||
override fun backendUnregisterChannelId(context: Context, channelId: String) {
|
override fun backendUnregisterChannelId(context: Context, channelId: String) {
|
||||||
|
val db = getDb(context)
|
||||||
|
val app = db.listApps().find { it.connectorToken == channelId }
|
||||||
|
if (app?.description?.startsWith("target:") == true) {
|
||||||
|
val appName = app.title ?: app.packageName
|
||||||
|
PrismServerClient.deleteApp(context, appName)
|
||||||
|
}
|
||||||
|
|
||||||
MessageSender.send(
|
MessageSender.send(
|
||||||
context,
|
context,
|
||||||
ClientMessage.Unregister(
|
ClientMessage.Unregister(
|
||||||
|
|
|
||||||
|
|
@ -82,15 +82,23 @@ class MainViewModel(
|
||||||
|
|
||||||
fun deleteSelection() {
|
fun deleteSelection() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val state = registrationsViewModel.state
|
Log.d(TAG, "deleteSelection called")
|
||||||
val tokenList = state.list.filter { it.selected }.map { it.token }
|
application?.let { app ->
|
||||||
messenger?.sendIMessage(InternalOpcode.REG_DELETE, "regs" to tokenList)
|
val selectedTokens = registrationsViewModel.state.list
|
||||||
registrationsViewModel.state = RegistrationListState(
|
.filter { it.selected }
|
||||||
list = state.list.filter {
|
.map { it.token }
|
||||||
!it.selected
|
|
||||||
},
|
Log.d(TAG, "Deleting ${selectedTokens.size} apps: $selectedTokens")
|
||||||
selectionCount = 0
|
|
||||||
)
|
selectedTokens.forEach { token ->
|
||||||
|
val intent = android.content.Intent("org.unifiedpush.android.distributor.UNREGISTER")
|
||||||
|
intent.setPackage(app.packageName)
|
||||||
|
intent.putExtra("token", token)
|
||||||
|
app.sendBroadcast(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
registrationsViewModel.unselectAll()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,10 @@ fun MainAppBarOrSelection(viewModel: MainViewModel, onGoToSettings: () -> Unit)
|
||||||
val registrationsState = viewModel.registrationsViewModel.state
|
val registrationsState = viewModel.registrationsViewModel.state
|
||||||
if (registrationsState.selectionCount > 0) {
|
if (registrationsState.selectionCount > 0) {
|
||||||
UnregisterBarUi(
|
UnregisterBarUi(
|
||||||
viewModel = viewModel.registrationsViewModel
|
viewModel = viewModel.registrationsViewModel,
|
||||||
|
onDelete = {
|
||||||
|
viewModel.deleteSelection()
|
||||||
|
}
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
MainAppBar(
|
MainAppBar(
|
||||||
|
|
|
||||||
|
|
@ -65,13 +65,6 @@ class PrismInternalService : InternalService() {
|
||||||
override fun registrations() = object : IRegistrations {
|
override fun registrations() = object : IRegistrations {
|
||||||
override fun delete(registrations: List<String>) {
|
override fun delete(registrations: List<String>) {
|
||||||
registrations.forEach { token ->
|
registrations.forEach { token ->
|
||||||
// Prism's custom logic: delete from Prism server if it's a "target:" app
|
|
||||||
val dbApp = db.listApps().find { it.connectorToken == token }
|
|
||||||
if (dbApp?.description?.startsWith("target:") == true) {
|
|
||||||
val appName = dbApp.title ?: dbApp.packageName
|
|
||||||
PrismServerClient.deleteApp(context, appName)
|
|
||||||
}
|
|
||||||
|
|
||||||
distributor.deleteApp(context, token)
|
distributor.deleteApp(context, token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue