From 24ca5e6181cd6365cf1d86b98ac5a2fa3c3dba70 Mon Sep 17 00:00:00 2001 From: lunaticbum Date: Mon, 16 Nov 2026 14:25:14 +0900 Subject: [PATCH] =?UTF-8?q?RecyclerView=20=EC=A0=84=EC=B2=B4=20=EA=B0=B1?= =?UTF-8?q?=EC=8B=A0(notifyDataSetChanged)=EC=9D=84=20DiffUtil=20=EB=B0=8F?= =?UTF-8?q?=20=EB=B6=80=EB=B6=84=20=EA=B0=B1=EC=8B=A0=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CompletedFilesAdapter: submitList()에 DiffUtil 적용 및 updateSelection() 시 선택 상태가 바뀐 항목만 notifyItemChanged() 호출 - TorrentListAdapter: submitList()에 DiffUtil 적용하여 진행률/상태 변경 시 불필요한 전체 뷰 재바인딩 방지 --- .../launcher/home/CompletedFilesActivity.kt | 24 +++++++++++++++++-- .../home/adapters/TorrentListAdapter.kt | 15 +++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/CompletedFilesActivity.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/CompletedFilesActivity.kt index c600c526..9ee9188e 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/CompletedFilesActivity.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/CompletedFilesActivity.kt @@ -33,6 +33,7 @@ import androidx.activity.OnBackPressedCallback import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.core.content.FileProvider +import androidx.recyclerview.widget.DiffUtil import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager @@ -1335,8 +1336,22 @@ class CompletedFilesAdapter( fun getAll() = fileList fun submitList(files: List) { + val oldList = fileList + val diffResult = DiffUtil.calculateDiff(object : DiffUtil.Callback() { + override fun getOldListSize() = oldList.size + override fun getNewListSize() = files.size + override fun areItemsTheSame(oldPos: Int, newPos: Int): Boolean = + oldList[oldPos].absolutePath == files[newPos].absolutePath + override fun areContentsTheSame(oldPos: Int, newPos: Int): Boolean { + val o = oldList[oldPos] + val n = files[newPos] + return o.absolutePath == n.absolutePath && + o.lastModified() == n.lastModified() && + o.length() == n.length() + } + }) fileList = files - notifyDataSetChanged() + diffResult.dispatchUpdatesTo(this) } fun setViewMode(mode: FileViewMode) { @@ -1345,8 +1360,13 @@ class CompletedFilesAdapter( } fun updateSelection(selection: Set) { + val oldSelection = selectedFiles selectedFiles = selection - notifyDataSetChanged() + fileList.forEachIndexed { index, file -> + if ((file in oldSelection) != (file in selection)) { + notifyItemChanged(index) + } + } } override fun getItemViewType(position: Int) = viewMode.ordinal diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/TorrentListAdapter.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/TorrentListAdapter.kt index 84e1b24c..7c246f81 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/TorrentListAdapter.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/TorrentListAdapter.kt @@ -7,6 +7,7 @@ import android.view.ViewGroup import android.widget.ImageButton import android.widget.ProgressBar import android.widget.TextView +import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import bums.lunatic.launcher.R import bums.lunatic.launcher.workers.TorrentTask @@ -20,8 +21,20 @@ class TorrentListAdapter( private var tasks = listOf() fun submitList(newTasks: List) { + val oldTasks = tasks + val diffResult = DiffUtil.calculateDiff(object : DiffUtil.Callback() { + override fun getOldListSize() = oldTasks.size + override fun getNewListSize() = newTasks.size + override fun areItemsTheSame(oldPos: Int, newPos: Int) = + oldTasks[oldPos].name == newTasks[newPos].name + override fun areContentsTheSame(oldPos: Int, newPos: Int): Boolean { + val o = oldTasks[oldPos] + val n = newTasks[newPos] + return o.name == n.name && o.stateText == n.stateText && o.progress == n.progress + } + }) tasks = newTasks - notifyDataSetChanged() + diffResult.dispatchUpdatesTo(this) } class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {