From a41070b7d74b2e8c3788b36a55289d15cddd87cd Mon Sep 17 00:00:00 2001 From: HystericalDragon Date: Fri, 15 Mar 2024 18:00:50 +0800 Subject: [PATCH] fix(database): not save empty list Signed-off-by: HystericalDragon --- .../nekohasekai/sagernet/database/ListConverter.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/nekohasekai/sagernet/database/ListConverter.kt b/app/src/main/java/io/nekohasekai/sagernet/database/ListConverter.kt index 9d59f019..c144f00e 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/database/ListConverter.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/database/ListConverter.kt @@ -7,13 +7,21 @@ class ListConverter { @TypeConverter @JvmStatic fun fromList(list: List): String { - return list.joinToString(",") + return if (list.isEmpty()) { + "" + } else { + list.joinToString(",") + } } @TypeConverter @JvmStatic - fun toList(string: String): List { - return string.split(",") + fun toList(str: String): List { + return if (str.isBlank()) { + listOf() + } else { + str.split(",") + } } } }