Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use explicit API for core/data module #1257

Merged
merged 3 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ plugins {
android.namespace = "io.github.droidkaigi.confsched2023.core.data"

kotlin {
explicitApi()

sourceSets {
commonMain {
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
class AchievementsDataStoreModule {
public class AchievementsDataStoreModule {

@Provides
@Singleton
fun provideAchievementsDataStore(
public fun provideAchievementsDataStore(
@AchievementsDataStoreQualifier
dataStore: DataStore<Preferences>,
): AchievementsDataStore {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import io.github.droidkaigi.confsched2023.data.NetworkService

@Module
@InstallIn(SingletonComponent::class)
class ContributorsApiModule {
public class ContributorsApiModule {
@Provides
fun provideContributorsApi(
public fun provideContributorsApi(
networkService: NetworkService,
ktorfit: Ktorfit,
): ContributorsApiClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class ContributorsRepositoryModule {
public class ContributorsRepositoryModule {
@Provides
@Singleton
fun provideContributorsRepository(
public fun provideContributorsRepository(
contributorsApi: ContributorsApiClient,
): ContributorsRepository {
return DefaultContributorsRepository(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class ApiModule {

@Provides
@Singleton
fun provideKtorJsonSettings(): Json {
public fun provideKtorJsonSettings(): Json {
return defaultJson()
}

Expand Down Expand Up @@ -105,10 +105,10 @@ public class KtorfitModule {

@InstallIn(SingletonComponent::class)
@Module
class AuthApiModule {
public class AuthApiModule {
@Provides
@Singleton
fun provideAuthApi(
public fun provideAuthApi(
httpClient: HttpClient,
userDataStore: UserDataStore,
authenticator: Authenticator,
Expand All @@ -119,39 +119,39 @@ class AuthApiModule {

@InstallIn(SingletonComponent::class)
@Module
class AuthenticatorModule {
public class AuthenticatorModule {
@Provides
@Singleton
fun provideAuthenticator(): Authenticator {
public fun provideAuthenticator(): Authenticator {
return AndroidAuthenticator()
}
}

@InstallIn(SingletonComponent::class)
@Module
class RemoteConfigModule {
public class RemoteConfigModule {

@Provides
@Singleton
fun provideRemoteConfigApi(): RemoteConfigApi {
public fun provideRemoteConfigApi(): RemoteConfigApi {
return DefaultRemoteConfigApi(ProcessLifecycleOwner.get().lifecycle)
}
}

@InstallIn(SingletonComponent::class)
@Module
class ServerEnvironmentModule {
class ServerEnvironment(
val baseUrl: String,
public class ServerEnvironmentModule {
public class ServerEnvironment(
internal val baseUrl: String,
)

interface HasServerEnvironment {
val serverEnvironment: ServerEnvironment
public interface HasServerEnvironment {
public val serverEnvironment: ServerEnvironment
}

@Provides
@Singleton
fun provideServerEnvironment(application: Application): ServerEnvironment {
public fun provideServerEnvironment(application: Application): ServerEnvironment {
return (application as HasServerEnvironment).serverEnvironment
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import javax.inject.Qualifier
import javax.inject.Singleton

@Qualifier
annotation class AppAndroidBuildConfig
public annotation class AppAndroidBuildConfig

@Module
@InstallIn(SingletonComponent::class)
class BuildConfigProviderModule {
public class BuildConfigProviderModule {
@Provides
@Singleton
fun provideBuildConfigProvider(
public fun provideBuildConfigProvider(
@AppAndroidBuildConfig buildConfigOverride: Optional<BuildConfigProvider>,
): BuildConfigProvider = if (buildConfigOverride.isPresent) {
buildConfigOverride.get()
Expand All @@ -29,10 +29,10 @@ class BuildConfigProviderModule {

@InstallIn(SingletonComponent::class)
@Module
abstract class AppAndroidBuildConfigModule {
public abstract class AppAndroidBuildConfigModule {
@BindsOptionalOf
@AppAndroidBuildConfig
abstract fun bindBuildConfigProvider(): BuildConfigProvider
public abstract fun bindBuildConfigProvider(): BuildConfigProvider
}

private object EmptyBuildConfigProvider : BuildConfigProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import dev.gitlive.firebase.Firebase
import dev.gitlive.firebase.remoteconfig.get
import dev.gitlive.firebase.remoteconfig.remoteConfig

class DefaultRemoteConfigApi(lifecycle: Lifecycle) : RemoteConfigApi {
public class DefaultRemoteConfigApi(lifecycle: Lifecycle) : RemoteConfigApi {

private val firebaseRemoteConfig = Firebase.remoteConfig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class RemoteConfigRepositoryModule {
public class RemoteConfigRepositoryModule {
@Provides
@Singleton
fun provideRemoteConfigRepository(
public fun provideRemoteConfigRepository(
remoteConfigApi: RemoteConfigApi,
achievementsDataStore: AchievementsDataStore,
): AchievementRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class SessionCacheDatastoreModule {
public class SessionCacheDatastoreModule {
@Provides
@Singleton
internal fun provideSessionCacheDataStore(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class SessionsApiModule {
public class SessionsApiModule {
@Provides
@Singleton
internal fun provideSessionsApi(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class SessionsRepositoryModule {
public class SessionsRepositoryModule {
@Provides
@Singleton
fun provideSessionsRepository(
public fun provideSessionsRepository(
sessionsApi: SessionsApiClient,
userDataStore: UserDataStore,
sessionCacheDataStore: SessionCacheDataStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import io.github.droidkaigi.confsched2023.data.NetworkService

@Module
@InstallIn(SingletonComponent::class)
class SponsorsApiModule {
public class SponsorsApiModule {
@Provides
fun provideSponsorsApi(
public fun provideSponsorsApi(
networkService: NetworkService,
ktorfit: Ktorfit,
): SponsorsApiClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class SponsorsRepositoryModule {
public class SponsorsRepositoryModule {
@Provides
@Singleton
fun provideSponsorsRepository(
public fun provideSponsorsRepository(
sponsorsApi: SponsorsApiClient,
): SponsorsRepository {
return DefaultSponsorsRepository(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import io.github.droidkaigi.confsched2023.data.NetworkService

@Module
@InstallIn(SingletonComponent::class)
class StaffApiModule {
public class StaffApiModule {

@Provides
fun providesStaffApiClient(
public fun providesStaffApiClient(
networkService: NetworkService,
ktorfit: Ktorfit,
): StaffApiClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class StaffRepositoryModule {
public class StaffRepositoryModule {

@Provides
@Singleton
fun provideStaffRepository(
public fun provideStaffRepository(
staffApi: StaffApiClient,
): StaffRepository {
return DefaultStaffRepository(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ import javax.inject.Qualifier
import javax.inject.Singleton

@Qualifier
annotation class UserDataStoreQualifier
public annotation class UserDataStoreQualifier

@Qualifier
annotation class SessionCacheDataStoreQualifier
public annotation class SessionCacheDataStoreQualifier

@Qualifier
annotation class AchievementsDataStoreQualifier
public annotation class AchievementsDataStoreQualifier

@InstallIn(SingletonComponent::class)
@Module
class DataStoreModule {
public class DataStoreModule {

@UserDataStoreQualifier
@Provides
@Singleton
fun provideDataStore(
public fun provideDataStore(
@ApplicationContext context: Context,
): DataStore<Preferences> = createDataStore(
coroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()),
Expand All @@ -41,7 +41,7 @@ class DataStoreModule {
@SessionCacheDataStoreQualifier
@Provides
@Singleton
fun provideSessionCacheDataStore(
public fun provideSessionCacheDataStore(
@ApplicationContext context: Context,
): DataStore<Preferences> = createDataStore(
coroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()),
Expand All @@ -51,14 +51,14 @@ class DataStoreModule {
@AchievementsDataStoreQualifier
@Provides
@Singleton
fun provideAchievementsDataStore(
public fun provideAchievementsDataStore(
@ApplicationContext context: Context,
): DataStore<Preferences> = createDataStore(
coroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()),
producePath = { context.filesDir.resolve(DATA_STORE_ACHIEVEMENTS_FILE_NAME).path },
)

companion object {
public companion object {
private const val DATA_STORE_PREFERENCE_FILE_NAME = "confsched2023.preferences_pb"
private const val DATA_STORE_CACHE_PREFERENCE_FILE_NAME =
"confsched2023.cache.preferences_pb"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
class UserDataStoreModule {
public class UserDataStoreModule {

@Provides
@Singleton
fun provideUserDataStore(
public fun provideUserDataStore(
@UserDataStoreQualifier
dataStore: DataStore<Preferences>,
): UserDataStore {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.datastore.preferences.core.Preferences
import kotlinx.coroutines.CoroutineScope
import okio.Path.Companion.toPath

fun createDataStore(
public fun createDataStore(
coroutineScope: CoroutineScope,
producePath: () -> String,
): DataStore<Preferences> = PreferenceDataStoreFactory.createWithPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map

class AchievementsDataStore(private val dataStore: DataStore<Preferences>) {
public class AchievementsDataStore(private val dataStore: DataStore<Preferences>) {

fun getAchievementsStream(): Flow<PersistentSet<Achievement>> {
public fun getAchievementsStream(): Flow<PersistentSet<Achievement>> {
return dataStore.data
.catch {
emit(emptyPreferences())
Expand All @@ -28,7 +28,7 @@ class AchievementsDataStore(private val dataStore: DataStore<Preferences>) {
}
}

suspend fun saveAchievements(achievement: Achievement) {
public suspend fun saveAchievements(achievement: Achievement) {
val updatedAchievements = getAchievementsStream().first().toMutableSet()

updatedAchievements.add(achievement)
Expand All @@ -39,7 +39,7 @@ class AchievementsDataStore(private val dataStore: DataStore<Preferences>) {
}
}

suspend fun resetAchievements() {
public suspend fun resetAchievements() {
dataStore.edit { preferences ->
preferences[KEY_ACHIEVEMENTS] = ""
}
Expand Down Expand Up @@ -67,7 +67,7 @@ class AchievementsDataStore(private val dataStore: DataStore<Preferences>) {
}
}

companion object {
private companion object {
private val KEY_ACHIEVEMENTS = stringPreferencesKey("KEY_ACHIEVEMENTS")
private val KEY_ACHIEVEMENTS_INITIAL_DIALOG_DISPLAY =
stringPreferencesKey("KEY_ACHIEVEMENTS_INITIAL_DIALOG_DISPLAY")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.onStart

class DefaultAchievementRepository(
public class DefaultAchievementRepository(
private val remoteConfigApi: RemoteConfigApi,
private val achievementsDataStore: AchievementsDataStore,
) : AchievementRepository {
Expand Down Expand Up @@ -60,9 +60,9 @@ class DefaultAchievementRepository(
achievementsDataStore.saveInitialDialogDisplayState(true)
}

companion object {
const val IS_ACHIEVEMENTS_ENABLED_KEY = "is_achievements_enable"
const val ACHIEVEMENT_DETAIL_DESCRIPTION_KEY = "achievements_detail_description"
const val IS_RESET_ACHIEVEMENTS_ENABLED_KEY = "is_reset_achievements_enable"
private companion object {
private const val IS_ACHIEVEMENTS_ENABLED_KEY = "is_achievements_enable"
private const val ACHIEVEMENT_DETAIL_DESCRIPTION_KEY = "achievements_detail_description"
private const val IS_RESET_ACHIEVEMENTS_ENABLED_KEY = "is_reset_achievements_enable"
}
}
Loading
Loading