Skip to content

Commit

Permalink
Merge pull request #4782 from FineFindus/fix/reorder-channel-groups
Browse files Browse the repository at this point in the history
fix(channelgroups): update values on confirm
  • Loading branch information
Bnyro authored Sep 16, 2023
2 parents 1af0709 + e48e1d7 commit 2350b57
Showing 1 changed file with 7 additions and 14 deletions.
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

0 comments on commit 2350b57

Please sign in to comment.