From a7b515450da73920b86e7d1361759e7b086fc1de Mon Sep 17 00:00:00 2001 From: Goofyz Leung Date: Tue, 4 Jun 2024 09:32:52 +0800 Subject: [PATCH] feat: restore selected files only --- .../trime/ui/fragments/ProfileFragment.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/osfans/trime/ui/fragments/ProfileFragment.kt b/app/src/main/java/com/osfans/trime/ui/fragments/ProfileFragment.kt index ae7f813e8b..42f755f6a3 100644 --- a/app/src/main/java/com/osfans/trime/ui/fragments/ProfileFragment.kt +++ b/app/src/main/java/com/osfans/trime/ui/fragments/ProfileFragment.kt @@ -209,18 +209,20 @@ class ProfileFragment : lifecycleScope.withLoadingDialog(context) { withContext(Dispatchers.IO) { res = - items.fold(true) { acc, asset -> - ResourceUtils.copyFiles("$rimeFolder/$asset", DataManager.sharedDataDir, "$rimeFolder/").fold({ - acc and true // on success - }, { - acc and false // on failure - }) - } + items.filterIndexed { index, _ -> checkedItems[index] } + .fold(true) { acc, asset -> + ResourceUtils.copyFiles( + "$rimeFolder/$asset", + DataManager.sharedDataDir, + "$rimeFolder/", + ) + .fold({ acc and true }, { acc and false }) + } } + ToastUtils.showShort( + if (res) R.string.reset_success else R.string.reset_failure, + ) } - ToastUtils.showShort( - if (res) R.string.reset_success else R.string.reset_failure, - ) }.show() true }