Skip to content

Commit

Permalink
Add full and foss product flavors
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang committed Aug 7, 2023
1 parent 7c3bb2b commit f363d13
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
cache: 'gradle'

- name: Build debug APK and run jvm tests
run: ./gradlew assembleDebug lintDebug testDebugUnitTest --stacktrace -DskipFormatKtlint
run: ./gradlew assembleDebug lintFullDebug testFullDebugUnitTest --stacktrace -DskipFormatKtlint
env:
MUSIC_DEBUG_KEYSTORE_FILE: 'music-debug.jks'
MUSIC_DEBUG_SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
Expand All @@ -42,4 +42,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: app
path: app/build/outputs/apk/debug/*.apk
path: app/build/outputs/apk/full/debug/*.apk
4 changes: 2 additions & 2 deletions .github/workflows/build_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
cache: 'gradle'

- name: Build debug APK and run jvm tests
run: ./gradlew assembleDebug lintDebug testDebugUnitTest --stacktrace -DskipFormatKtlint
run: ./gradlew assembleDebug lintFullDebug testFullDebugUnitTest --stacktrace -DskipFormatKtlint
env:
PULL_REQUEST: 'true'

- name: Upload APK
uses: actions/upload-artifact@v3
with:
name: app
path: app/build/outputs/apk/debug/*.apk
path: app/build/outputs/apk/full/debug/*.apk
29 changes: 19 additions & 10 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ plugins {
kotlin("kapt")
id("com.google.dagger.hilt.android")
id("com.google.devtools.ksp")
if (System.getenv("PULL_REQUEST") == null) {
id("com.google.gms.google-services")
id("com.google.firebase.crashlytics")
id("com.google.firebase.firebase-perf")
}
}

android {
Expand All @@ -37,6 +32,20 @@ android {
resValue("string", "app_name", "InnerTune Debug")
}
}
flavorDimensions += "version"
productFlavors {
create("full") {
dimension = "version"
if (System.getenv("PULL_REQUEST") == null) {
apply(plugin = "com.google.gms.google-services")
apply(plugin = "com.google.firebase.crashlytics")
apply(plugin = "com.google.firebase.firebase-perf")
}
}
create("foss") {
dimension = "version"
}
}
signingConfigs {
getByName("debug") {
if (System.getenv("MUSIC_DEBUG_SIGNING_STORE_PASSWORD") != null) {
Expand Down Expand Up @@ -126,11 +135,11 @@ dependencies {

coreLibraryDesugaring(libs.desugaring)

implementation(platform(libs.firebase.bom))
implementation(libs.firebase.analytics)
implementation(libs.firebase.crashlytics)
implementation(libs.firebase.config)
implementation(libs.firebase.perf)
"fullImplementation"(platform(libs.firebase.bom))
"fullImplementation"(libs.firebase.analytics)
"fullImplementation"(libs.firebase.crashlytics)
"fullImplementation"(libs.firebase.config)
"fullImplementation"(libs.firebase.perf)

implementation(libs.timber)
}
5 changes: 5 additions & 0 deletions app/src/foss/java/com/zionhuang/music/utils/Utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.zionhuang.music.utils

import com.zionhuang.music.MainActivity

fun MainActivity.setupRemoteConfig() {}
31 changes: 31 additions & 0 deletions app/src/full/java/com/zionhuang/music/utils/Utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.zionhuang.music.utils

import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.ConfigUpdate
import com.google.firebase.remoteconfig.ConfigUpdateListener
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException
import com.google.firebase.remoteconfig.ktx.remoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings
import com.zionhuang.music.MainActivity
import kotlin.time.Duration.Companion.hours

fun MainActivity.setupRemoteConfig() {
val remoteConfig = Firebase.remoteConfig
remoteConfig.setConfigSettingsAsync(remoteConfigSettings {
minimumFetchIntervalInSeconds = 12.hours.inWholeSeconds
})
remoteConfig.fetchAndActivate()
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
latestVersion = remoteConfig.getLong("latest_version")
}
}
remoteConfig.addOnConfigUpdateListener(object : ConfigUpdateListener {
override fun onError(error: FirebaseRemoteConfigException) {}
override fun onUpdate(configUpdate: ConfigUpdate) {
remoteConfig.activate().addOnCompleteListener {
latestVersion = remoteConfig.getLong("latest_version")
}
}
})
}
31 changes: 2 additions & 29 deletions app/src/main/java/com/zionhuang/music/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ import androidx.navigation.navArgument
import coil.imageLoader
import coil.request.ImageRequest
import com.google.common.util.concurrent.MoreExecutors
import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.ConfigUpdate
import com.google.firebase.remoteconfig.ConfigUpdateListener
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException
import com.google.firebase.remoteconfig.ktx.remoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings
import com.valentinilk.shimmer.LocalShimmerTheme
import com.zionhuang.innertube.YouTube
import com.zionhuang.innertube.models.SongItem
Expand Down Expand Up @@ -107,6 +101,7 @@ import com.zionhuang.music.utils.dataStore
import com.zionhuang.music.utils.get
import com.zionhuang.music.utils.rememberEnumPreference
import com.zionhuang.music.utils.rememberPreference
import com.zionhuang.music.utils.setupRemoteConfig
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest
Expand All @@ -115,7 +110,6 @@ import kotlinx.coroutines.withContext
import java.net.URLDecoder
import java.net.URLEncoder
import javax.inject.Inject
import kotlin.time.Duration.Companion.hours

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
Expand All @@ -139,7 +133,7 @@ class MainActivity : ComponentActivity() {
playerConnection = null
}
}
private var latestVersion by mutableStateOf(BuildConfig.VERSION_CODE.toLong())
var latestVersion by mutableStateOf(BuildConfig.VERSION_CODE.toLong())

override fun onStart() {
super.onStart()
Expand Down Expand Up @@ -835,27 +829,6 @@ class MainActivity : ComponentActivity() {
}
}

private fun setupRemoteConfig() {
val remoteConfig = Firebase.remoteConfig
remoteConfig.setConfigSettingsAsync(remoteConfigSettings {
minimumFetchIntervalInSeconds = 12.hours.inWholeSeconds
})
remoteConfig.fetchAndActivate()
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
latestVersion = remoteConfig.getLong("latest_version")
}
}
remoteConfig.addOnConfigUpdateListener(object : ConfigUpdateListener {
override fun onError(error: FirebaseRemoteConfigException) {}
override fun onUpdate(configUpdate: ConfigUpdate) {
remoteConfig.activate().addOnCompleteListener {
latestVersion = remoteConfig.getLong("latest_version")
}
}
})
}

companion object {
const val ACTION_SEARCH = "com.zionhuang.music.action.SEARCH"
const val ACTION_SONGS = "com.zionhuang.music.action.SONGS"
Expand Down

0 comments on commit f363d13

Please sign in to comment.