-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from toquete/ads
Adding ads banner
- Loading branch information
Showing
29 changed files
with
392 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.toquete.boxbox.di | ||
|
||
import com.google.firebase.analytics.FirebaseAnalytics | ||
import com.google.firebase.analytics.ktx.analytics | ||
import com.google.firebase.crashlytics.FirebaseCrashlytics | ||
import com.google.firebase.crashlytics.ktx.crashlytics | ||
import com.google.firebase.ktx.Firebase | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig | ||
import com.google.firebase.remoteconfig.ktx.remoteConfig | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal object FirebaseModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun providesFirebaseAnalytics(): FirebaseAnalytics = Firebase.analytics | ||
|
||
@Provides | ||
@Singleton | ||
fun providesFirebaseCrashlytics(): FirebaseCrashlytics = Firebase.crashlytics | ||
|
||
@Provides | ||
@Singleton | ||
fun providesFirebaseRemoteConfig(): FirebaseRemoteConfig = Firebase.remoteConfig | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/toquete/boxbox/di/FirebaseRemoteConfigRepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.toquete.boxbox.di | ||
|
||
import com.toquete.boxbox.domain.repository.RemoteConfigRepository | ||
import com.toquete.boxbox.util.remoteconfig.FirebaseRemoteConfigRepository | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
fun interface FirebaseRemoteConfigRepositoryModule { | ||
|
||
@Binds | ||
fun bindRemoteConfigRepository( | ||
firebaseRemoteConfigRepository: FirebaseRemoteConfigRepository | ||
): RemoteConfigRepository | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/toquete/boxbox/util/remoteconfig/FirebaseRemoteConfigRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.toquete.boxbox.util.remoteconfig | ||
|
||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig | ||
import com.google.firebase.remoteconfig.get | ||
import com.toquete.boxbox.core.common.annotation.Generated | ||
import com.toquete.boxbox.core.common.annotation.IoDispatcher | ||
import com.toquete.boxbox.core.model.RemoteConfigs | ||
import com.toquete.boxbox.domain.repository.RemoteConfigRepository | ||
import com.toquete.boxbox.util.remoteconfig.RemoteConfigKeys.IS_AD_BANNER_VISIBLE | ||
import jakarta.inject.Inject | ||
import kotlinx.coroutines.channels.awaitClose | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.callbackFlow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOn | ||
import timber.log.Timber | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
@Generated | ||
class FirebaseRemoteConfigRepository @Inject constructor( | ||
private val firebaseRemoteConfig: FirebaseRemoteConfig, | ||
@IoDispatcher private val dispatcher: CoroutineContext | ||
) : RemoteConfigRepository { | ||
|
||
override val remoteConfigs: Flow<RemoteConfigs> = flow { | ||
emit( | ||
RemoteConfigs(isAdBannerVisible = firebaseRemoteConfig[IS_AD_BANNER_VISIBLE].asBoolean()) | ||
) | ||
}.flowOn(dispatcher) | ||
|
||
override fun fetchAndActivate(): Flow<Boolean> = callbackFlow { | ||
firebaseRemoteConfig.fetchAndActivate() | ||
.addOnCompleteListener { task -> | ||
if (task.isSuccessful) { | ||
trySend(true) | ||
} else { | ||
Timber.e(task.exception, "Failed to fetch and activate remote config") | ||
trySend(false) | ||
} | ||
close(task.exception) | ||
} | ||
awaitClose() | ||
}.flowOn(dispatcher) | ||
} |
3 changes: 3 additions & 0 deletions
3
app/src/main/java/com/toquete/boxbox/util/remoteconfig/RemoteConfigDefaults.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.toquete.boxbox.util.remoteconfig | ||
|
||
val remoteConfigDefaults = mapOf("is_ad_banner_visible" to false) |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/toquete/boxbox/util/remoteconfig/RemoteConfigKeys.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.toquete.boxbox.util.remoteconfig | ||
|
||
object RemoteConfigKeys { | ||
const val IS_AD_BANNER_VISIBLE = "is_ad_banner_visible" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
core/common/src/main/java/com/toquete/boxbox/core/common/annotation/Generated.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
package com.toquete.boxbox.core.common.annotation | ||
|
||
@Target( | ||
AnnotationTarget.FIELD, | ||
AnnotationTarget.PROPERTY, | ||
AnnotationTarget.FUNCTION, | ||
AnnotationTarget.CLASS, | ||
AnnotationTarget.FILE | ||
) | ||
annotation class Generated |
Oops, something went wrong.