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

Add support standalone app #10

Merged
merged 1 commit into from
Dec 11, 2024
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_envi

# Build

## Build debug

- `./gradlew clean assembleDevDebug`

## Deploy debug to Firebase App Distribution

- `./gradlew clean bundleDevDebug`
Expand All @@ -78,6 +82,8 @@ https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_envi

## Code integration

* Switch the `isProductFlavorFilterEnabled` property to `false` in the
[BuildTypeAndroidApplicationPlugin.kt](build-logic/convention/src/main/kotlin/com/yugyd/buildlogic/convention/buildtype/BuildTypeAndroidApplicationPlugin.kt)
* Switch the `IS_BASED_ON_PLATFORM_APP` property to `true` in the [build.gradle](app/build.gradle)
file.
* Add the path to the [google-services.json](app/src/dev/google-services.json) file to
Expand Down
2 changes: 2 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/build
# Hide sensitive information for production ads ids
/src/**/res/values/ad-ids.xml
!src/main/res/values/ad-ids.xml
!src/dev/res/values/ad-ids.xml
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ dependencies {
// Work Manager
implementation libs.work.manager.ktx

// Serialization
implementation libs.kotlinx.serialization

// Logging
implementation libs.timber
}
11 changes: 10 additions & 1 deletion app/src/main/java/com/yugyd/quiz/ContentProviderImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.yugyd.quiz.core.ResIdProvider
import com.yugyd.quiz.featuretoggle.domain.RemoteConfigRepository
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import javax.inject.Singleton

internal class ContentProviderImpl @Inject constructor(
@ApplicationContext private val context: Context,
Expand All @@ -40,4 +39,14 @@ internal class ContentProviderImpl @Inject constructor(
}
?.link ?: context.getString(resIdProvider.appTelegramChat())
}

override suspend fun getUpdateLink(): String? {
val config = remoteConfigRepository.fetchUpdateConfig()
return config
?.links
?.firstOrNull {
GlobalConfig.APPLICATION_ID.contains(it.packageX)
}
?.link
}
}
38 changes: 34 additions & 4 deletions app/src/main/java/com/yugyd/quiz/YandexAdProviderImpl.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
package com.yugyd.quiz

import com.yugyd.quiz.core.AdIdProvider
import com.yugyd.quiz.core.GlobalConfig
import com.yugyd.quiz.core.TextModel
import javax.inject.Inject

internal class YandexAdProviderImpl @Inject constructor() : AdIdProvider {
override fun idAdBannerGame() = R.string.id_yandex_ad_banner_game
override fun idAdRewardedGame() = R.string.id_yandex_ad_rewarded_game
override fun idAdInterstitialGameEnd() = R.string.id_yandex_ad_interstitial_game_end
override fun idAdRewardedTheme() = R.string.id_yandex_ad_rewarded_theme

override fun idAdBannerGame(): Int {
return if (GlobalConfig.DEBUG) {
R.string.test_id_yandex_ad_banner_game
} else {
R.string.id_yandex_ad_banner_game
}
}

override fun idAdRewardedGame(): Int {
return if (GlobalConfig.DEBUG) {
R.string.test_id_yandex_ad_rewarded_game
} else {
R.string.id_yandex_ad_rewarded_game
}
}

override fun idAdInterstitialGameEnd(): Int {
return if (GlobalConfig.DEBUG) {
R.string.test_id_yandex_ad_interstitial_game_end
} else {
R.string.id_yandex_ad_interstitial_game_end
}
}

override fun idAdRewardedTheme(): Int {
return if (GlobalConfig.DEBUG) {
R.string.test_id_yandex_ad_rewarded_theme
} else {
R.string.id_yandex_ad_rewarded_theme
}
}

override fun gameBannerAdId() = TextModel.ResTextModel(res = idAdBannerGame())
override fun gameRewardedAdId() = TextModel.ResTextModel(res = idAdRewardedGame())
override fun themeRewardedAdId() = TextModel.ResTextModel(res = idAdRewardedTheme())
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/java/com/yugyd/quiz/di/SerializationModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2023 Roman Likhachev
*
* 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 com.yugyd.quiz.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.serialization.json.Json
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object SerializationModule {

@Singleton
@Provides
fun providesJson(): Json = Json {
ignoreUnknownKeys = true
isLenient = true
}
}
23 changes: 23 additions & 0 deletions app/src/main/res/values/ad-ids.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2023 Roman Likhachev
~
~ 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.
-->

<resources>
<!-- Yandex AD -->
<string name="test_id_yandex_ad_banner_game" translatable="false">demo-banner-yandex</string>
<string name="test_id_yandex_ad_interstitial_game_end" translatable="false">demo-interstitial-yandex</string>
<string name="test_id_yandex_ad_rewarded_theme" translatable="false">demo-rewarded-yandex</string>
<string name="test_id_yandex_ad_rewarded_game" translatable="false">demo-rewarded-yandex</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class BuildTypeAndroidApplicationPlugin : Plugin<Project> {
private val ACTIVE_PRODUCT_FLAVOR_VARIANTS = arrayOf("devDebug", "devStaging", "devRelease")
}

private val isProductFlavorFilterEnabled = true

override fun apply(target: Project) {
with(target) {
checkPlugin(ANDROID_APPLICATION_ALIAS)
Expand All @@ -46,7 +48,10 @@ class BuildTypeAndroidApplicationPlugin : Plugin<Project> {
// https://developer.android.com/build/build-variants#filter-variants
extensions.configure<ApplicationAndroidComponentsExtension> {
beforeVariants { variantBuilder ->
if (!ACTIVE_PRODUCT_FLAVOR_VARIANTS.contains(variantBuilder.name)) {
if (
isProductFlavorFilterEnabled &&
!ACTIVE_PRODUCT_FLAVOR_VARIANTS.contains(variantBuilder.name)
) {
variantBuilder.enable = false
}
}
Expand Down
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ kotlin = '2.0.21'
# UI
appcompat = '1.7.0'
material = '1.12.0'
compose-bom = '2024.10.01'
compose-bom = '2024.11.00'
# DI
hilt = '2.52'
# Annotation processor
Expand All @@ -21,13 +21,13 @@ androidxTest = '1.6.1'
core-ktx = '1.15.0'
roomVersion = '2.6.1'
workManagerVersion = '2.10.0'
firebaseVersion = '33.5.1'
firebaseVersion = '33.6.0'
accompanistVersion = '0.36.0'
versionsUpdates = '0.51.0'
# Build logic
compile-sdk = '35'
target-sdk = '35'
min-sdk = '24'
min-sdk = '26'
convention = "1.0.0"

[libraries]
Expand Down Expand Up @@ -74,8 +74,8 @@ compose-activity = { module = 'androidx.activity:activity-compose', version = '1
compose-viewmodel = { module = 'androidx.lifecycle:lifecycle-viewmodel-compose', version = '2.8.7' }
compose-lifecycle = { module = 'androidx.lifecycle:lifecycle-runtime-compose', version = '2.8.7' }
# Navigation
navigation-runtime = { module = 'androidx.navigation:navigation-runtime-ktx', version = '2.8.3' }
compose-navigation = { module = 'androidx.navigation:navigation-compose', version = '2.8.3' }
navigation-runtime = { module = 'androidx.navigation:navigation-runtime-ktx', version = '2.8.4' }
compose-navigation = { module = 'androidx.navigation:navigation-compose', version = '2.8.4' }
compose-hilt-navigation = { module = 'androidx.hilt:hilt-navigation-compose', version = '1.2.0' }
# Accompanist
accompanist-drawablepainter = { module = 'com.google.accompanist:accompanist-drawablepainter', version.ref = 'accompanistVersion' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ package com.yugyd.quiz.featuretoggle.data

import android.content.Context
import com.yugyd.quiz.featuretoggle.data.mapper.TelegramConfigMapper
import com.yugyd.quiz.featuretoggle.data.mapper.UpdateConfigMapper
import com.yugyd.quiz.featuretoggle.data.model.TelegramConfigDto
import com.yugyd.quiz.featuretoggle.data.model.UpdateConfigDto
import com.yugyd.quiz.featuretoggle.domain.RemoteConfigRepository
import com.yugyd.quiz.featuretoggle.domain.model.FeatureToggle
import com.yugyd.quiz.featuretoggle.domain.model.telegram.TelegramConfig
import com.yugyd.quiz.featuretoggle.domain.model.update.UpdateConfig
import com.yugyd.quiz.remoteconfig.api.RemoteConfig
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.serialization.json.Json
Expand All @@ -33,6 +36,8 @@ internal class RemoteConfigRepositoryImpl @Inject internal constructor(
@ApplicationContext private val context: Context,
private val remoteConfig: RemoteConfig,
private val telegramConfigMapper: TelegramConfigMapper,
private val updateConfigMapper: UpdateConfigMapper,
private val json: Json,
) : RemoteConfigRepository {

override suspend fun fetchFeatureToggle(
Expand All @@ -45,7 +50,7 @@ internal class RemoteConfigRepositoryImpl @Inject internal constructor(
override suspend fun fetchTelegramConfig(): TelegramConfig? {
return try {
val dtoList = remoteConfig.fetchStringValue(CONFIG_TELEGRAM_KEY).run {
Json.decodeFromString<List<TelegramConfigDto>>(this)
json.decodeFromString<List<TelegramConfigDto>>(this)
}

val mappedDtoList = dtoList.map(telegramConfigMapper::map)
Expand All @@ -63,8 +68,30 @@ internal class RemoteConfigRepositoryImpl @Inject internal constructor(
}
}

override suspend fun fetchUpdateConfig(): UpdateConfig? {
return try {
val dtoList = remoteConfig.fetchStringValue(CONFIG_UPDATE_KEY).run {
json.decodeFromString<List<UpdateConfigDto>>(this)
}

val mappedDtoList = dtoList.map(updateConfigMapper::map)

val currentLocale = context.resources.configuration.locales.get(0)

mappedDtoList.firstOrNull {
it.locale == currentLocale
} ?: mappedDtoList.firstOrNull {
it.locale == Locale.ENGLISH
}
} catch (expected: Throwable) {
Timber.e(expected)
null
}
}

companion object {
private const val FORCE_UPDATE_KEY = "force_update_version"
private const val CONFIG_TELEGRAM_KEY = "config_telegram"
private const val CONFIG_UPDATE_KEY = "config_update"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2023 Roman Likhachev
*
* 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 com.yugyd.quiz.featuretoggle.data.mapper

import com.yugyd.quiz.featuretoggle.data.model.LinkDto
import com.yugyd.quiz.featuretoggle.domain.model.telegram.Link
import javax.inject.Inject

internal class LinkMapper @Inject constructor() {

fun mapToLinks(links: List<LinkDto>): List<Link> {
return links.map { Link(link = it.link, packageX = it.packageX) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2023 Roman Likhachev
*
* 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 com.yugyd.quiz.featuretoggle.data.mapper

import java.util.Locale
import javax.inject.Inject

internal class LocaleMapper @Inject constructor() {

fun mapValueToLocale(value: String): Locale {
val language = if (value.contains(LOCALE_VALUE_SEPARATOR)) {
value.substringBefore(LOCALE_VALUE_SEPARATOR)
} else {
value
}
return Locale(language)
}

companion object {
private const val LOCALE_VALUE_SEPARATOR = "-"
}
}
Loading