From bfbf805adc07825d29832998abc1f5108e12fcdc Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Sun, 15 Jan 2023 20:32:46 -0700 Subject: [PATCH] list: remove synclistdiffer Forgot to remove this now useless class. --- .../auxio/list/recycler/DiffAdapter.kt | 2 +- .../auxio/list/recycler/SyncListDiffer.kt | 141 ------------------ 2 files changed, 1 insertion(+), 142 deletions(-) delete mode 100644 app/src/main/java/org/oxycblt/auxio/list/recycler/SyncListDiffer.kt diff --git a/app/src/main/java/org/oxycblt/auxio/list/recycler/DiffAdapter.kt b/app/src/main/java/org/oxycblt/auxio/list/recycler/DiffAdapter.kt index aff5e4d2c..e6595b325 100644 --- a/app/src/main/java/org/oxycblt/auxio/list/recycler/DiffAdapter.kt +++ b/app/src/main/java/org/oxycblt/auxio/list/recycler/DiffAdapter.kt @@ -54,7 +54,7 @@ abstract class DiffAdapter(differFactory: ListD } /** - * Update this list using [DiffUtil]. This can simplify the work of updating the list, but can + * Update this list using DiffUtil. This can simplify the work of updating the list, but can * also cause erratic behavior. * @param newList The new list of [T] items to show. * @param onDone Callback that will be invoked when the update is completed, allowing means to diff --git a/app/src/main/java/org/oxycblt/auxio/list/recycler/SyncListDiffer.kt b/app/src/main/java/org/oxycblt/auxio/list/recycler/SyncListDiffer.kt deleted file mode 100644 index 4b47c22c3..000000000 --- a/app/src/main/java/org/oxycblt/auxio/list/recycler/SyncListDiffer.kt +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2022 Auxio Project - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.oxycblt.auxio.list.recycler - -import androidx.recyclerview.widget.AdapterListUpdateCallback -import androidx.recyclerview.widget.DiffUtil -import androidx.recyclerview.widget.RecyclerView - -/** - * A list differ that operates synchronously. This can help resolve some shortcomings with - * AsyncListDiffer, at the cost of performance. Derived from Material Files: - * https://github.com/zhanghai/MaterialFiles - * @author Hai Zhang, Alexander Capehart (OxygenCobalt) - */ -class SyncListDiffer( - adapter: RecyclerView.Adapter<*>, - private val diffCallback: DiffUtil.ItemCallback -) { - private val updateCallback = AdapterListUpdateCallback(adapter) - - var currentList: List = emptyList() - private set(newList) { - if (newList === currentList || newList.isEmpty() && currentList.isEmpty()) { - return - } - - if (newList.isEmpty()) { - val oldListSize = currentList.size - field = emptyList() - updateCallback.onRemoved(0, oldListSize) - return - } - - if (currentList.isEmpty()) { - field = newList - updateCallback.onInserted(0, newList.size) - return - } - - val oldList = currentList - val result = - DiffUtil.calculateDiff( - object : DiffUtil.Callback() { - override fun getOldListSize(): Int { - return oldList.size - } - - override fun getNewListSize(): Int { - return newList.size - } - - override fun areItemsTheSame( - oldItemPosition: Int, - newItemPosition: Int - ): Boolean { - val oldItem: T? = oldList[oldItemPosition] - val newItem: T? = newList[newItemPosition] - return if (oldItem != null && newItem != null) { - diffCallback.areItemsTheSame(oldItem, newItem) - } else { - oldItem == null && newItem == null - } - } - - override fun areContentsTheSame( - oldItemPosition: Int, - newItemPosition: Int - ): Boolean { - val oldItem: T? = oldList[oldItemPosition] - val newItem: T? = newList[newItemPosition] - return if (oldItem != null && newItem != null) { - diffCallback.areContentsTheSame(oldItem, newItem) - } else if (oldItem == null && newItem == null) { - true - } else { - throw AssertionError() - } - } - - override fun getChangePayload( - oldItemPosition: Int, - newItemPosition: Int - ): Any? { - val oldItem: T? = oldList[oldItemPosition] - val newItem: T? = newList[newItemPosition] - return if (oldItem != null && newItem != null) { - diffCallback.getChangePayload(oldItem, newItem) - } else { - throw AssertionError() - } - } - }) - - field = newList - result.dispatchUpdatesTo(updateCallback) - } - - /** - * Submit a list like AsyncListDiffer. This is exceedingly slow for large diffs, so only use it - * if the changes are trivial. - * @param newList The list to update to. - */ - fun submitList(newList: List) { - if (newList == currentList) { - // Nothing to do. - return - } - - currentList = newList - } - - /** - * Replace this list with a new list. This is good for large diffs that are too slow to update - * synchronously, but too chaotic to update asynchronously. - * @param newList The list to update to. - */ - fun replaceList(newList: List) { - if (newList == currentList) { - // Nothing to do. - return - } - - currentList = emptyList() - currentList = newList - } -}