Add Konsist test Class with 'ContributeBinding' annotation should have allowed prefix and fix exissting issues.

Also remove annotation `DefaultPreferences`, we only have one implementation.
This commit is contained in:
Benoit Marty 2024-05-31 10:18:08 +02:00
parent f886eab582
commit 3fa508f1fe
12 changed files with 54 additions and 52 deletions

View file

@ -1,21 +0,0 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.di
import javax.inject.Qualifier
@Qualifier annotation class DefaultPreferences

View file

@ -20,7 +20,6 @@ import android.content.SharedPreferences
import androidx.core.content.edit
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.libraries.di.AppScope
import io.element.android.libraries.di.DefaultPreferences
import javax.inject.Inject
/**
@ -32,15 +31,15 @@ interface FirebaseStore {
}
@ContributesBinding(AppScope::class)
class DefaultFirebaseStore @Inject constructor(
@DefaultPreferences private val sharedPrefs: SharedPreferences,
class SharedPreferencesFirebaseStore @Inject constructor(
private val sharedPreferences: SharedPreferences,
) : FirebaseStore {
override fun getFcmToken(): String? {
return sharedPrefs.getString(PREFS_KEY_FCM_TOKEN, null)
return sharedPreferences.getString(PREFS_KEY_FCM_TOKEN, null)
}
override fun storeFcmToken(token: String?) {
sharedPrefs.edit {
sharedPreferences.edit {
putString(PREFS_KEY_FCM_TOKEN, token)
}
}

View file

@ -22,7 +22,6 @@ import androidx.core.content.edit
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.libraries.di.AppScope
import io.element.android.libraries.di.ApplicationContext
import io.element.android.libraries.di.DefaultPreferences
import io.element.android.libraries.matrix.api.core.UserId
import javax.inject.Inject
@ -36,9 +35,9 @@ interface UnifiedPushStore {
}
@ContributesBinding(AppScope::class)
class DefaultUnifiedPushStore @Inject constructor(
class SharedPreferencesUnifiedPushStore @Inject constructor(
@ApplicationContext val context: Context,
@DefaultPreferences private val defaultPrefs: SharedPreferences,
private val sharedPreferences: SharedPreferences,
) : UnifiedPushStore {
/**
* Retrieves the UnifiedPush Endpoint.
@ -47,7 +46,7 @@ class DefaultUnifiedPushStore @Inject constructor(
* @return the UnifiedPush Endpoint or null if not received
*/
override fun getEndpoint(clientSecret: String): String? {
return defaultPrefs.getString(PREFS_ENDPOINT_OR_TOKEN + clientSecret, null)
return sharedPreferences.getString(PREFS_ENDPOINT_OR_TOKEN + clientSecret, null)
}
/**
@ -57,7 +56,7 @@ class DefaultUnifiedPushStore @Inject constructor(
* @param endpoint the endpoint to store
*/
override fun storeUpEndpoint(clientSecret: String, endpoint: String?) {
defaultPrefs.edit {
sharedPreferences.edit {
putString(PREFS_ENDPOINT_OR_TOKEN + clientSecret, endpoint)
}
}
@ -69,7 +68,7 @@ class DefaultUnifiedPushStore @Inject constructor(
* @return the Push Gateway or null if not defined
*/
override fun getPushGateway(clientSecret: String): String? {
return defaultPrefs.getString(PREFS_PUSH_GATEWAY + clientSecret, null)
return sharedPreferences.getString(PREFS_PUSH_GATEWAY + clientSecret, null)
}
/**
@ -79,17 +78,17 @@ class DefaultUnifiedPushStore @Inject constructor(
* @param gateway the push gateway to store
*/
override fun storePushGateway(clientSecret: String, gateway: String?) {
defaultPrefs.edit {
sharedPreferences.edit {
putString(PREFS_PUSH_GATEWAY + clientSecret, gateway)
}
}
override fun getDistributorValue(userId: UserId): String? {
return defaultPrefs.getString(PREFS_DISTRIBUTOR + userId, null)
return sharedPreferences.getString(PREFS_DISTRIBUTOR + userId, null)
}
override fun setDistributorValue(userId: UserId, value: String) {
defaultPrefs.edit {
sharedPreferences.edit {
putString(PREFS_DISTRIBUTOR + userId, value)
}
}

View file

@ -33,7 +33,7 @@ import javax.inject.Inject
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "push_client_secret_store")
@ContributesBinding(AppScope::class)
class PushClientSecretStoreDataStore @Inject constructor(
class DataStorePushClientSecretStore @Inject constructor(
@ApplicationContext private val context: Context,
) : PushClientSecretStore {
override suspend fun storeSecret(userId: SessionId, clientSecret: String) {