Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(channelgroups): update values on confirm #4782

Merged
merged 1 commit into from
Sep 16, 2023
Merged
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 @@ -2,7 +2,6 @@ package com.github.libretube.ui.sheets

import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -48,6 +47,12 @@ class ChannelGroupsSheet : ExpandedBottomSheet() {
}

binding.confirm.setOnClickListener {
channelGroupsModel.groups.value = adapter.groups
channelGroupsModel.groups.value?.forEachIndexed { index, group -> group.index = index }
CoroutineScope(Dispatchers.IO).launch {
DatabaseHolder.Database.subscriptionGroupsDao()
.updateAll(channelGroupsModel.groups.value.orEmpty())
}
dismiss()
}

Expand All @@ -62,20 +67,8 @@ class ChannelGroupsSheet : ExpandedBottomSheet() {
): Boolean {
val from = viewHolder.absoluteAdapterPosition
val to = target.absoluteAdapterPosition

Log.e("move", "move")

channelGroupsModel.groups.value = channelGroupsModel.groups.value.orEmpty()
.toMutableList()
.also { it.move(from, to) }
adapter.groups.move(from, to)
adapter.notifyItemMoved(from, to)

channelGroupsModel.groups.value?.forEachIndexed { index, group -> group.index = index }
CoroutineScope(Dispatchers.IO).launch {
DatabaseHolder.Database.subscriptionGroupsDao()
.updateAll(channelGroupsModel.groups.value.orEmpty())
}

return true
}

Expand Down
Loading