From 206ba79ef8f3a7344f2b1f557c40581f85d44a0a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 28 Mar 2024 15:49:30 +0100 Subject: [PATCH] fix: channel groups duplicated after updating name --- .../libretube/ui/sheets/EditChannelGroupSheet.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/sheets/EditChannelGroupSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/EditChannelGroupSheet.kt index 32324c70c..0294390c8 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/EditChannelGroupSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/EditChannelGroupSheet.kt @@ -64,9 +64,11 @@ class EditChannelGroupSheet : ExpandedBottomSheet() { updateConfirmStatus() binding.confirm.setOnClickListener { - channelGroupsModel.groupToEdit?.name = binding.groupName.text.toString() - if (channelGroupsModel.groupToEdit?.name.isNullOrBlank()) return@setOnClickListener - saveGroup(channelGroupsModel.groupToEdit!!, oldGroupName) + val updatedGroup = channelGroupsModel.groupToEdit?.copy( + name = binding.groupName.text.toString().ifEmpty { return@setOnClickListener } + ) ?: return@setOnClickListener + saveGroup(updatedGroup, oldGroupName) + dismiss() } } @@ -78,10 +80,9 @@ class EditChannelGroupSheet : ExpandedBottomSheet() { ?.plus(group) CoroutineScope(Dispatchers.IO).launch { - runCatching { - // delete the old one as it might have a different name - DatabaseHolder.Database.subscriptionGroupsDao().deleteGroup(oldGroupName) - } + // delete the old version of the group first before updating it, as the name is the + // primary key + DatabaseHolder.Database.subscriptionGroupsDao().deleteGroup(oldGroupName) DatabaseHolder.Database.subscriptionGroupsDao().createGroup(group) } }