Skip to content

Commit

Permalink
Create a new flavor to publish on fdroid
Browse files Browse the repository at this point in the history
  • Loading branch information
prof18 committed Sep 12, 2024
1 parent 4447c74 commit 074d1b5
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android-alpha-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ jobs:
PLAY_CONFIG_JSON: ${{ secrets.PLAY_CONFIG }}

- name: Distribute app to Alpha track
run: ./gradlew :androidApp:bundleRelease :androidApp:publishBundle
run: ./gradlew :androidApp:bundleGooglePlayRelease :androidApp:publishGooglePlayReleaseBundle
2 changes: 1 addition & 1 deletion .github/workflows/code-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
mv androidApp/src/release/dummy-google-services.json androidApp/src/release/google-services.json
- name: Build Android Sample
run: ./gradlew :androidApp:assembleDebug
run: ./gradlew :androidApp:assembleGooglePlayDebug

build-desktop-app:
name: Build Desktop App
Expand Down
26 changes: 24 additions & 2 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import java.util.Locale
import java.util.Properties

plugins {
Expand All @@ -22,6 +23,7 @@ val dropboxAppKey: String = local.getProperty("dropbox_key").orEmpty()
if (dropboxAppKey.isEmpty()) {
println("Dropbox key not set in keystore.properties. Please add it to the file with the key 'dropbox_key'")
}

android {
namespace = "com.prof18.feedflow.android"
compileSdk = libs.versions.android.compile.sdk.get().toInt()
Expand Down Expand Up @@ -80,6 +82,18 @@ android {
buildConfigField("String", "DROPBOX_APP_KEY", "\"$dropboxAppKey\"")
}
}

flavorDimensions += "version"
productFlavors {
create("fdroid") {
dimension = "version"
}

create("googlePlay") {
dimension = "version"
isDefault = true
}
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
Expand All @@ -104,8 +118,7 @@ dependencies {

implementation(libs.bundles.compose)
implementation(libs.bundles.about.libraries)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.crashlytics)

implementation(libs.material.window.size)
implementation(libs.androidx.browser)
implementation(libs.compose.webview)
Expand All @@ -120,6 +133,9 @@ dependencies {
implementation(libs.workmanager)
implementation(libs.androidx.lifecycle.process)

"googlePlayImplementation"(platform(libs.firebase.bom))
"googlePlayImplementation"(libs.firebase.crashlytics)

debugImplementation(compose.uiTooling)

testImplementation(libs.koin.test)
Expand All @@ -145,3 +161,9 @@ fun getVersionName(): String =
.asText.get()
.trim()
.replace("-android", "")

android.applicationVariants.configureEach {
val name = name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
val googleTask = tasks.findByName("process${name}GoogleServices")
googleTask?.enabled = !name.contains("fdroid")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.prof18.feedflow.android

class CrashlyticsHelper {
fun initCrashlytics() {
// no-op
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.prof18.feedflow.android

import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import com.prof18.feedflow.shared.utils.enableKmpCrashlytics

class CrashlyticsHelper {
fun initCrashlytics() {
Firebase.crashlytics.setCrashlyticsCollectionEnabled(true)
enableKmpCrashlytics()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import android.content.Context
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import com.prof18.feedflow.android.readermode.ReaderModeViewModel
import com.prof18.feedflow.core.utils.AppConfig
import com.prof18.feedflow.core.utils.AppEnvironment
import com.prof18.feedflow.shared.di.getWith
import com.prof18.feedflow.shared.di.initKoin
import com.prof18.feedflow.shared.domain.feedsync.FeedSyncRepository
import com.prof18.feedflow.shared.ui.utils.coilImageLoader
import com.prof18.feedflow.shared.utils.enableKmpCrashlytics
import org.koin.android.ext.android.inject
import org.koin.androidx.workmanager.koin.workManagerFactory
import org.koin.core.module.dsl.viewModel
Expand All @@ -26,19 +24,28 @@ class FeedFlowApp : Application() {
override fun onCreate() {
super.onCreate()

val isGooglePlayFlavor = when (BuildConfig.FLAVOR) {
"googlePlay" -> true
else -> false
}
val appEnvironment = if (BuildConfig.DEBUG) {
AppEnvironment.Debug
} else {
AppEnvironment.Release
}
val appConfig = AppConfig(
appEnvironment = appEnvironment,
isLoggingEnabled = isGooglePlayFlavor,
isDropboxSyncEnabled = isGooglePlayFlavor,
)

if (appEnvironment.isRelease()) {
Firebase.crashlytics.setCrashlyticsCollectionEnabled(true)
enableKmpCrashlytics()
if (isGooglePlayFlavor && appEnvironment.isRelease()) {
val crashlyticsHelper = CrashlyticsHelper()
crashlyticsHelper.initCrashlytics()
}

initKoin(
appEnvironment = appEnvironment,
appConfig = appConfig,
platformSetup = {
workManagerFactory()
},
Expand All @@ -59,6 +66,7 @@ class FeedFlowApp : Application() {
debug = appEnvironment.isDebug(),
)
}
single { appConfig }
viewModel {
ReaderModeViewModel(
readerModeExtractor = get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.compose.ui.platform.testTag
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.prof18.feedflow.android.BrowserManager
import com.prof18.feedflow.android.settings.components.BrowserSelectionDialog
import com.prof18.feedflow.core.utils.AppConfig
import com.prof18.feedflow.core.utils.TestingTag
import com.prof18.feedflow.shared.domain.model.Browser
import com.prof18.feedflow.shared.presentation.SettingsViewModel
Expand Down Expand Up @@ -69,6 +70,7 @@ fun SettingsScreen(

val browserManager = koinInject<BrowserManager>()
val settingsViewModel = koinViewModel<SettingsViewModel>()
val appConfig = koinInject<AppConfig>()

val browserListState by browserManager.browserListState.collectAsStateWithLifecycle()
val settingState by settingsViewModel.settingsState.collectAsStateWithLifecycle()
Expand All @@ -85,6 +87,7 @@ fun SettingsScreen(
isShowReadItemEnabled = settingState.isShowReadItemsEnabled,
isReaderModeEnabled = settingState.isReaderModeEnabled,
isRemoveTitleFromDescriptionEnabled = settingState.isRemoveTitleFromDescriptionEnabled,
showAccounts = appConfig.isDropboxSyncEnabled,
onBrowserSelected = { browser ->
browserManager.setFavouriteBrowser(browser)
},
Expand Down Expand Up @@ -124,6 +127,7 @@ private fun SettingsScreenContent(
isShowReadItemEnabled: Boolean,
isReaderModeEnabled: Boolean,
isRemoveTitleFromDescriptionEnabled: Boolean,
showAccounts: Boolean,
onFeedListClick: () -> Unit,
onAddFeedClick: () -> Unit,
onBrowserSelected: (Browser) -> Unit,
Expand Down Expand Up @@ -181,6 +185,7 @@ private fun SettingsScreenContent(
setReaderMode = setReaderMode,
isRemoveTitleFromDescriptionEnabled = isRemoveTitleFromDescriptionEnabled,
setRemoveTitleFromDescription = setRemoveTitleFromDescription,
showAccounts = showAccounts,
)
}
}
Expand All @@ -191,6 +196,7 @@ private fun SettingsList(
isShowReadItemEnabled: Boolean,
isReaderModeEnabled: Boolean,
isRemoveTitleFromDescriptionEnabled: Boolean,
showAccounts: Boolean,
onFeedListClick: () -> Unit,
onAddFeedClick: () -> Unit,
onBrowserSelectionClick: () -> Unit,
Expand Down Expand Up @@ -242,12 +248,14 @@ private fun SettingsList(
)
}

item {
SettingItem(
title = LocalFeedFlowStrings.current.settingsAccounts,
icon = Icons.Outlined.Sync,
onClick = navigateToAccounts,
)
if (showAccounts) {
item {
SettingItem(
title = LocalFeedFlowStrings.current.settingsAccounts,
icon = Icons.Outlined.Sync,
onClick = navigateToAccounts,
)
}
}

item {
Expand Down Expand Up @@ -508,6 +516,7 @@ private fun SettingsScreenPreview() {
isShowReadItemEnabled = false,
isReaderModeEnabled = false,
isRemoveTitleFromDescriptionEnabled = false,
showAccounts = true,
onFeedListClick = {},
onAddFeedClick = {},
onBrowserSelected = {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.prof18.feedflow.core.utils

data class AppConfig(
val appEnvironment: AppEnvironment,
val isLoggingEnabled: Boolean,
val isDropboxSyncEnabled: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
import co.touchlab.kermit.Logger
import co.touchlab.kermit.StaticConfig
import co.touchlab.kermit.platformLogWriter
import com.prof18.feedflow.core.utils.AppConfig
import com.prof18.feedflow.core.utils.AppEnvironment
import com.prof18.feedflow.database.DatabaseHelper
import com.prof18.feedflow.feedsync.database.di.getFeedSyncModule
Expand Down Expand Up @@ -47,7 +48,7 @@ import org.koin.core.scope.Scope
import org.koin.dsl.module

fun initKoin(
appEnvironment: AppEnvironment,
appConfig: AppConfig,
modules: List<Module>,
platformSetup: KoinApplication.() -> Unit = {},
): KoinApplication {
Expand All @@ -56,18 +57,18 @@ fun initKoin(
modules +
coreModule +
dropboxModule +
getLoggingModule(appEnvironment) +
getPlatformModule(appEnvironment) +
getFeedSyncModule(appEnvironment),
getLoggingModule(appConfig) +
getPlatformModule(appConfig.appEnvironment) +
getFeedSyncModule(appConfig.appEnvironment),
)
platformSetup()
}
}

private fun getLoggingModule(appEnvironment: AppEnvironment): Module =
private fun getLoggingModule(appConfig: AppConfig): Module =
module {
val loggers = mutableListOf(platformLogWriter())
if (appEnvironment.isRelease()) {
if (appConfig.appEnvironment.isRelease() && appConfig.isLoggingEnabled) {
loggers.add(crashReportingLogWriter())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.prof18.feedflow.shared.di

import app.cash.sqldelight.db.SqlDriver
import co.touchlab.kermit.Logger
import com.prof18.feedflow.core.utils.AppConfig
import com.prof18.feedflow.core.utils.AppEnvironment
import com.prof18.feedflow.core.utils.DispatcherProvider
import com.prof18.feedflow.database.createDatabaseDriver
Expand Down Expand Up @@ -46,7 +47,11 @@ fun initKoinIos(
regionCode: String?,
dropboxDataSource: DropboxDataSource,
): KoinApplication = initKoin(
appEnvironment = appEnvironment,
appConfig = AppConfig(
appEnvironment = appEnvironment,
isLoggingEnabled = true,
isDropboxSyncEnabled = true,
),
modules = listOf(
module {
factory { htmlParser }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.prof18.feedflow.shared.di

import app.cash.sqldelight.db.SqlDriver
import com.prof18.feedflow.core.utils.AppConfig
import com.prof18.feedflow.core.utils.AppEnvironment
import com.prof18.feedflow.core.utils.DispatcherProvider
import com.prof18.feedflow.database.createDatabaseDriver
Expand All @@ -26,7 +27,11 @@ fun initKoinDesktop(
appEnvironment: AppEnvironment,
modules: List<Module>,
): KoinApplication = initKoin(
appEnvironment = appEnvironment,
appConfig = AppConfig(
appEnvironment = appEnvironment,
isLoggingEnabled = true,
isDropboxSyncEnabled = true,
),
modules = modules + getDatabaseModule(appEnvironment),
)

Expand Down

0 comments on commit 074d1b5

Please sign in to comment.