Fix pre-migration resetting the order

This commit is contained in:
Jobobby04 2023-12-24 15:49:48 -05:00
parent cbb743f995
commit 66a14d99c5
2 changed files with 15 additions and 10 deletions

View File

@ -12,6 +12,7 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@ -55,6 +56,12 @@ class PreMigrationScreen(val mangaIds: List<Long>) : Screen() {
val navigator = LocalNavigator.currentOrThrow
var fabExpanded by remember { mutableStateOf(true) }
val items by screenModel.state.collectAsState()
val adapter by screenModel.adapter.collectAsState()
LaunchedEffect(items.isNotEmpty(), adapter != null) {
if (adapter != null && items.isNotEmpty()) {
adapter?.updateDataSet(items)
}
}
val nestedScrollConnection = remember {
// All this lines just for fab state :/
@ -136,9 +143,9 @@ class PreMigrationScreen(val mangaIds: List<Long>) : Screen() {
modifier = Modifier.fillMaxWidth(),
factory = { context ->
screenModel.controllerBinding = PreMigrationListBinding.inflate(LayoutInflater.from(context))
screenModel.adapter = MigrationSourceAdapter(screenModel.clickListener)
screenModel.controllerBinding.root.adapter = screenModel.adapter
screenModel.adapter?.isHandleDragEnabled = true
screenModel.adapter.value = MigrationSourceAdapter(screenModel.clickListener)
screenModel.controllerBinding.root.adapter = screenModel.adapter.value
screenModel.adapter.value?.isHandleDragEnabled = true
screenModel.controllerBinding.root.layoutManager = LinearLayoutManager(context)
ViewCompat.setNestedScrollingEnabled(screenModel.controllerBinding.root, true)
@ -153,8 +160,6 @@ class PreMigrationScreen(val mangaIds: List<Long>) : Screen() {
right = right,
bottom = bottom,
)
screenModel.adapter?.updateDataSet(items)
},
)
}

View File

@ -28,10 +28,10 @@ class PreMigrationScreenModel(
val migrationSheetOpen = _migrationSheetOpen.asStateFlow()
lateinit var controllerBinding: PreMigrationListBinding
var adapter: MigrationSourceAdapter? = null
var adapter: MutableStateFlow<MigrationSourceAdapter?> = MutableStateFlow(null)
val clickListener = FlexibleAdapter.OnItemClickListener { _, position ->
val adapter = adapter ?: return@OnItemClickListener false
val adapter = adapter.value ?: return@OnItemClickListener false
adapter.getItem(position)?.let {
it.sourceEnabled = !it.sourceEnabled
}
@ -95,7 +95,7 @@ class PreMigrationScreenModel(
}
fun massSelect(selectAll: Boolean) {
val adapter = adapter ?: return
val adapter = adapter.value ?: return
adapter.currentItems.forEach {
it.sourceEnabled = selectAll
}
@ -103,7 +103,7 @@ class PreMigrationScreenModel(
}
fun matchSelection(matchEnabled: Boolean) {
val adapter = adapter ?: return
val adapter = adapter.value ?: return
val enabledSources = if (matchEnabled) {
sourcePreferences.disabledSources().get().mapNotNull { it.toLongOrNull() }
} else {
@ -126,7 +126,7 @@ class PreMigrationScreenModel(
}
fun saveEnabledSources() {
val listOfSources = adapter?.currentItems
val listOfSources = adapter.value?.currentItems
?.filterIsInstance<MigrationSourceItem>()
?.filter {
it.sourceEnabled