diff --git a/app/src/androidTest/java/com/owncloud/android/datamodel/ArbitraryDataProviderIT.kt b/app/src/androidTest/java/com/owncloud/android/datamodel/ArbitraryDataProviderIT.kt index a5c4a327bb..dad2be82ba 100644 --- a/app/src/androidTest/java/com/owncloud/android/datamodel/ArbitraryDataProviderIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/datamodel/ArbitraryDataProviderIT.kt @@ -56,11 +56,11 @@ class ArbitraryDataProviderIT : AbstractIT() { fun testBoolean() { val key = "DUMMY_KEY" var value = true - arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value.toString()) + arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value) assertEquals(value, arbitraryDataProvider.getBooleanValue(user.accountName, key)) value = false - arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value.toString()) + arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value) assertEquals(value, arbitraryDataProvider.getBooleanValue(user.accountName, key)) } diff --git a/app/src/main/java/com/nextcloud/client/database/dao/ArbitraryDataDao.kt b/app/src/main/java/com/nextcloud/client/database/dao/ArbitraryDataDao.kt index f176db83a9..bf51c0efbb 100644 --- a/app/src/main/java/com/nextcloud/client/database/dao/ArbitraryDataDao.kt +++ b/app/src/main/java/com/nextcloud/client/database/dao/ArbitraryDataDao.kt @@ -24,14 +24,15 @@ package com.nextcloud.client.database.dao import androidx.room.Dao import androidx.room.Query +import com.nextcloud.client.database.entity.ArbitraryDataEntity @Dao interface ArbitraryDataDao { @Query("INSERT INTO arbitrary_data(cloud_id, `key`, value) VALUES(:accountName, :key, :value)") fun insertValue(accountName: String, key: String, value: String?) - @Query("SELECT value FROM arbitrary_data WHERE cloud_id = :accountName AND `key` = :key LIMIT 1") - fun getValue(accountName: String, key: String): String? + @Query("SELECT * FROM arbitrary_data WHERE cloud_id = :accountName AND `key` = :key LIMIT 1") + fun getByAccountAndKey(accountName: String, key: String): ArbitraryDataEntity? @Query("UPDATE arbitrary_data SET value = :value WHERE cloud_id = :accountName AND `key` = :key ") fun updateValue(accountName: String, key: String, value: String?) diff --git a/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProviderImpl.java b/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProviderImpl.java index 74863d8065..f44c842c08 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProviderImpl.java +++ b/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProviderImpl.java @@ -25,6 +25,7 @@ import android.content.Context; import com.nextcloud.client.account.User; import com.nextcloud.client.database.NextcloudDatabase; import com.nextcloud.client.database.dao.ArbitraryDataDao; +import com.nextcloud.client.database.entity.ArbitraryDataEntity; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -71,7 +72,7 @@ public class ArbitraryDataProviderImpl implements ArbitraryDataProvider { public void storeOrUpdateKeyValue(@NonNull String accountName, @NonNull String key, @Nullable String newValue) { - final String currentValue = arbitraryDataDao.getValue(accountName, key); + final ArbitraryDataEntity currentValue = arbitraryDataDao.getByAccountAndKey(accountName, key); if (currentValue != null) { arbitraryDataDao.updateValue(accountName, key, newValue); } else { @@ -138,10 +139,10 @@ public class ArbitraryDataProviderImpl implements ArbitraryDataProvider { @Override @NonNull public String getValue(@NonNull String accountName, @NonNull String key) { - final String value = arbitraryDataDao.getValue(accountName, key); - if (value == null) { + final ArbitraryDataEntity entity = arbitraryDataDao.getByAccountAndKey(accountName, key); + if (entity == null || entity.getValue() == null) { return ""; } - return value; + return entity.getValue(); } }