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:
@@ -34,7 +34,6 @@ import io.element.android.libraries.designsystem.utils.snackbar.SnackbarDispatch
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.di.ApplicationContext
|
||||
import io.element.android.libraries.di.CacheDirectory
|
||||
import io.element.android.libraries.di.DefaultPreferences
|
||||
import io.element.android.libraries.di.SingleIn
|
||||
import io.element.android.x.BuildConfig
|
||||
import io.element.android.x.R
|
||||
@@ -97,8 +96,7 @@ object AppModule {
|
||||
|
||||
@Provides
|
||||
@SingleIn(AppScope::class)
|
||||
@DefaultPreferences
|
||||
fun providesDefaultSharedPreferences(@ApplicationContext context: Context): SharedPreferences {
|
||||
fun providesSharedPreferences(@ApplicationContext context: Context): SharedPreferences {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import android.content.Context
|
||||
import android.system.Os
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.startup.Initializer
|
||||
import io.element.android.features.preferences.impl.developer.tracing.SharedPrefTracingConfigurationStore
|
||||
import io.element.android.features.preferences.impl.developer.tracing.SharedPreferencesTracingConfigurationStore
|
||||
import io.element.android.features.preferences.impl.developer.tracing.TargetLogLevelMapBuilder
|
||||
import io.element.android.libraries.architecture.bindings
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingConfiguration
|
||||
@@ -38,7 +38,7 @@ class TracingInitializer : Initializer<Unit> {
|
||||
Timber.plant(tracingService.createTimberTree())
|
||||
val tracingConfiguration = if (BuildConfig.DEBUG) {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val store = SharedPrefTracingConfigurationStore(prefs)
|
||||
val store = SharedPreferencesTracingConfigurationStore(prefs)
|
||||
val builder = TargetLogLevelMapBuilder(store)
|
||||
TracingConfiguration(
|
||||
filterConfiguration = TracingFilterConfigurations.custom(builder.getCurrentMap()),
|
||||
|
||||
@@ -20,14 +20,13 @@ 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 io.element.android.libraries.di.SingleIn
|
||||
import javax.inject.Inject
|
||||
|
||||
@ContributesBinding(AppScope::class)
|
||||
@SingleIn(AppScope::class)
|
||||
class AndroidWelcomeScreenState @Inject constructor(
|
||||
@DefaultPreferences private val sharedPreferences: SharedPreferences,
|
||||
private val sharedPreferences: SharedPreferences,
|
||||
) : WelcomeScreenState {
|
||||
companion object {
|
||||
private const val IS_WELCOME_SCREEN_SHOWN = "is_welcome_screen_shown"
|
||||
|
||||
@@ -26,7 +26,7 @@ import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import javax.inject.Inject
|
||||
|
||||
@ContributesBinding(SessionScope::class)
|
||||
class AcceptDeclineInviteViewWrapper @Inject constructor() : AcceptDeclineInviteView {
|
||||
class DefaultAcceptDeclineInviteView @Inject constructor() : AcceptDeclineInviteView {
|
||||
@Composable
|
||||
override fun Render(
|
||||
state: AcceptDeclineInviteState,
|
||||
@@ -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 io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import io.element.android.libraries.matrix.api.tracing.Target
|
||||
import javax.inject.Inject
|
||||
@@ -32,8 +31,8 @@ interface TracingConfigurationStore {
|
||||
}
|
||||
|
||||
@ContributesBinding(AppScope::class)
|
||||
class SharedPrefTracingConfigurationStore @Inject constructor(
|
||||
@DefaultPreferences private val sharedPreferences: SharedPreferences
|
||||
class SharedPreferencesTracingConfigurationStore @Inject constructor(
|
||||
private val sharedPreferences: SharedPreferences
|
||||
) : TracingConfigurationStore {
|
||||
override fun getLogLevel(target: Target): LogLevel? {
|
||||
return sharedPreferences.getString("$KEY_PREFIX${target.name}", null)
|
||||
|
||||
@@ -22,13 +22,12 @@ import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.features.roomlist.api.migration.MigrationScreenStore
|
||||
import io.element.android.libraries.androidutils.hash.hash
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.di.DefaultPreferences
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import javax.inject.Inject
|
||||
|
||||
@ContributesBinding(AppScope::class)
|
||||
class SharedPrefsMigrationScreenStore @Inject constructor(
|
||||
@DefaultPreferences private val sharedPreferences: SharedPreferences,
|
||||
class SharedPreferencesMigrationScreenStore @Inject constructor(
|
||||
private val sharedPreferences: SharedPreferences,
|
||||
) : MigrationScreenStore {
|
||||
override fun isMigrationScreenNeeded(sessionId: SessionId): Boolean {
|
||||
return sharedPreferences.getBoolean(sessionId.toKey(), false).not()
|
||||
@@ -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
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
@@ -31,7 +31,7 @@ import io.element.android.features.roomlist.impl.datasource.RoomListRoomSummaryF
|
||||
import io.element.android.features.roomlist.impl.filters.RoomListFiltersPresenter
|
||||
import io.element.android.features.roomlist.impl.filters.selection.DefaultFilterSelectionStrategy
|
||||
import io.element.android.features.roomlist.impl.migration.MigrationScreenPresenter
|
||||
import io.element.android.features.roomlist.impl.migration.SharedPrefsMigrationScreenStore
|
||||
import io.element.android.features.roomlist.impl.migration.SharedPreferencesMigrationScreenStore
|
||||
import io.element.android.features.roomlist.impl.search.RoomListSearchDataSource
|
||||
import io.element.android.features.roomlist.impl.search.RoomListSearchPresenter
|
||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
@@ -114,7 +114,7 @@ class RoomListScreen(
|
||||
featureFlagService = featureFlagService,
|
||||
migrationScreenPresenter = MigrationScreenPresenter(
|
||||
matrixClient = matrixClient,
|
||||
migrationScreenStore = SharedPrefsMigrationScreenStore(context.getSharedPreferences("migration", Context.MODE_PRIVATE))
|
||||
migrationScreenStore = SharedPreferencesMigrationScreenStore(context.getSharedPreferences("migration", Context.MODE_PRIVATE))
|
||||
),
|
||||
searchPresenter = RoomListSearchPresenter(
|
||||
RoomListSearchDataSource(
|
||||
|
||||
@@ -20,9 +20,11 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import com.lemonappdev.konsist.api.Konsist
|
||||
import com.lemonappdev.konsist.api.ext.list.withAllParentsOf
|
||||
import com.lemonappdev.konsist.api.ext.list.withAnnotationNamed
|
||||
import com.lemonappdev.konsist.api.ext.list.withNameContaining
|
||||
import com.lemonappdev.konsist.api.ext.list.withNameEndingWith
|
||||
import com.lemonappdev.konsist.api.ext.list.withoutName
|
||||
import com.lemonappdev.konsist.api.ext.list.withoutNameStartingWith
|
||||
import com.lemonappdev.konsist.api.verify.assertEmpty
|
||||
import com.lemonappdev.konsist.api.verify.assertTrue
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
@@ -92,4 +94,32 @@ class KonsistClassNameTest {
|
||||
.withoutName("MediaUploadHandlerImpl")
|
||||
.assertEmpty(additionalMessage = "Class implementing interface should have name not end with 'Impl' but start with 'Default'")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Class with 'ContributeBinding' annotation should have allowed prefix`() {
|
||||
Konsist.scopeFromProject()
|
||||
.classes()
|
||||
.withAnnotationNamed("ContributesBinding")
|
||||
.withoutName(
|
||||
"Factory",
|
||||
"TimelineController",
|
||||
)
|
||||
.withoutNameStartingWith(
|
||||
"Accompanist",
|
||||
"AES",
|
||||
"Android",
|
||||
"Database",
|
||||
"DBov",
|
||||
"Default",
|
||||
"DataStore",
|
||||
"FileExtensionExtractor",
|
||||
"KeyStore",
|
||||
"Matrix",
|
||||
"Noop",
|
||||
"Preferences",
|
||||
"Rust",
|
||||
"SharedPreferences",
|
||||
)
|
||||
.assertEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user