From a65f56fa263c34a1a203553dbe4fc8f8b7b3a30e Mon Sep 17 00:00:00 2001 From: armv9 <48624112+arm64v8a@users.noreply.github.com> Date: Wed, 11 Dec 2024 20:29:23 +0900 Subject: [PATCH] feat: prepend & append --- app/src/main/java/moe/matsuri/nb4a/utils/Util.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/moe/matsuri/nb4a/utils/Util.kt b/app/src/main/java/moe/matsuri/nb4a/utils/Util.kt index 1f8f1073..ef695f7c 100644 --- a/app/src/main/java/moe/matsuri/nb4a/utils/Util.kt +++ b/app/src/main/java/moe/matsuri/nb4a/utils/Util.kt @@ -122,6 +122,20 @@ object Util { val currentMap = (to[k] as Map<*, *>).toMutableMap() currentMap += v to[k] = currentMap + } else if (v is List<*>) { + if (k.startsWith("+")) { // prepend + val dstKey = k.removePrefix("+") + var currentList = (to[dstKey] as List<*>).toMutableList() + currentList = (v + currentList).toMutableList() + to[dstKey] = currentList + } else if (k.endsWith("+")) { // append + val dstKey = k.removeSuffix("+") + var currentList = (to[dstKey] as List<*>).toMutableList() + currentList = (currentList + v).toMutableList() + to[dstKey] = currentList + } else { + to[k] = v + } } else { to[k] = v }