Skip to content

Commit

Permalink
Merge pull request #29 from vipulyaara/develop
Browse files Browse the repository at this point in the history
Release 0.37.0
  • Loading branch information
vipulyaara authored Aug 22, 2024
2 parents badc22a + 2155b67 commit b96c808
Show file tree
Hide file tree
Showing 89 changed files with 3,313 additions and 537 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ android {
"PIPELESS_AUTH_TOKEN",
properties["PIPELESS_AUTH_TOKEN"]?.toString() ?: System.getenv("PIPELESS_AUTH_TOKEN")
)
buildConfigField(
"String",
"OPEN_AI_API_KEY",
properties["OPEN_AI_API_KEY"]?.toString() ?: System.getenv("OPEN_AI_API_KEY")
)
}

compileOptions {
Expand Down Expand Up @@ -128,6 +133,7 @@ dependencies {
implementation(projects.core.play)
implementation(projects.corePlayback)
implementation(projects.core.remoteConfig)
implementation(projects.data.prefs)
implementation(projects.data.repo)
implementation(projects.domain)
implementation(projects.navigation)
Expand All @@ -142,6 +148,7 @@ dependencies {
implementation(projects.ui.profile)
implementation(projects.ui.reader)
implementation(projects.ui.search)
implementation(projects.ui.summary)
implementation(projects.ui.theme)
implementation(projects.ui.webview)

Expand Down Expand Up @@ -184,8 +191,6 @@ dependencies {
implementation(libs.okhttp.okhttp)
implementation(libs.retrofit.serialization)
implementation(libs.threeTenAbp)
implementation(libs.timber)
implementation(libs.tracing)
implementation(libs.profileinstaller)

debugImplementation(libs.leakCanary)
Expand Down
1 change: 1 addition & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,4 @@
-keep public class androidx.compose.ui.platform.AndroidCompositionLocals_androidKt {
public static *** getLocalLifecycleOwner();
}
-dontwarn org.slf4j.impl.StaticLoggerBinder
49 changes: 44 additions & 5 deletions app/src/main/java/com/kafka/user/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
package com.kafka.user

import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.core.view.WindowCompat
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.kafka.data.prefs.PreferencesStore
import com.kafka.data.prefs.Theme
import com.kafka.data.prefs.observeTheme
import com.kafka.remote.config.RemoteConfig
import com.kafka.remote.config.isTrueContrastEnabled
import com.kafka.user.home.MainScreen
import com.sarahang.playback.ui.color.ColorExtractor
import dagger.hilt.android.AndroidEntryPoint
import org.kafka.base.errorLog
import org.kafka.navigation.rememberBottomSheetNavigator
import ui.common.theme.theme.AppTheme
import ui.common.theme.theme.shouldUseDarkColors
import ui.common.theme.theme.shouldUseTrueContrast
import javax.inject.Inject

@AndroidEntryPoint
Expand All @@ -30,20 +34,29 @@ class MainActivity : ComponentActivity() {
@Inject
internal lateinit var colorExtractor: ColorExtractor

@Inject
internal lateinit var remoteConfig: RemoteConfig

private lateinit var navController: NavHostController

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
enableEdgeToEdge()

setContent {
val theme by preferencesStore.observeTheme().collectAsStateWithLifecycle(Theme.SYSTEM)
val isDarkTheme = preferencesStore.shouldUseDarkColors()
val bottomSheetNavigator = rememberBottomSheetNavigator()
navController = rememberNavController(bottomSheetNavigator)

DisposableEffect(isDarkTheme) {
enableEdgeToEdge(isDarkTheme)
onDispose {}
}

AppTheme(
isDarkTheme = preferencesStore.shouldUseDarkColors(),
isTrueContrast = preferencesStore.shouldUseTrueContrast()
isTrueContrast = remoteConfig.isTrueContrastEnabled()
) {
MainScreen(
navController = navController,
Expand All @@ -55,12 +68,38 @@ class MainActivity : ComponentActivity() {
}
}

private fun enableEdgeToEdge(isDarkTheme: Boolean) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(
Color.TRANSPARENT,
Color.TRANSPARENT,
) { isDarkTheme },
navigationBarStyle = SystemBarStyle.auto(
lightScrim,
darkScrim,
) { isDarkTheme },
)
}

@Suppress("SENSELESS_COMPARISON") // intent is somehow null
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
if (::navController.isInitialized && intent != null) { // intent is somehow null
if (::navController.isInitialized && intent != null) {
navController.handleDeepLink(intent)
} else {
errorLog(Error("navController is not initialized or intent is null. isFinishing = $isFinishing, intent = $intent"))
}
}
}

/**
* The default light scrim, as defined by androidx and the platform:
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=35-38;drc=27e7d52e8604a080133e8b842db10c89b4482598
*/
private val lightScrim = Color.argb(0xe6, 0xFF, 0xFF, 0xFF)

/**
* The default dark scrim, as defined by androidx and the platform:
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=40-44;drc=27e7d52e8604a080133e8b842db10c89b4482598
*/
private val darkScrim = Color.argb(0x80, 0x1b, 0x1b, 0x1b)
10 changes: 10 additions & 0 deletions app/src/main/java/com/kafka/user/home/AppNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import org.kafka.navigation.RootScreen
import org.kafka.navigation.Screen
import org.kafka.navigation.Screen.Reader
import org.kafka.navigation.deeplink.Config
import org.kafka.summary.SummaryScreen
import org.kafka.webview.WebView
import org.rekhta.ui.auth.LoginScreen
import org.rekhta.ui.profile.ProfileScreen
Expand Down Expand Up @@ -118,6 +119,7 @@ private fun NavGraphBuilder.addHomeRoot(navController: NavController) {
addWebView(RootScreen.Home)
addOnlineReader(RootScreen.Home, navController)
addRecentItems(RootScreen.Home)
addSummary(RootScreen.Home)
}
}

Expand All @@ -134,6 +136,7 @@ private fun NavGraphBuilder.addSearchRoot(navController: NavController) {
addPlayer(RootScreen.Search)
addWebView(RootScreen.Search)
addOnlineReader(RootScreen.Search, navController)
addSummary(RootScreen.Search)
}
}

Expand All @@ -153,6 +156,7 @@ private fun NavGraphBuilder.addLibraryRoot(navController: NavController) {
addOnlineReader(RootScreen.Library, navController)
addLogin(RootScreen.Library)
addProfile(RootScreen.Library)
addSummary(RootScreen.Library)
}
}

Expand Down Expand Up @@ -264,6 +268,12 @@ private fun NavGraphBuilder.addRecentItems(root: RootScreen) {
}
}

private fun NavGraphBuilder.addSummary(root: RootScreen) {
composable(route = Screen.Summary.createRoute(root)) {
SummaryScreen()
}
}

private fun NavGraphBuilder.addWebView(root: RootScreen) {
composable(
route = Screen.Web.createRoute(root),
Expand Down
58 changes: 29 additions & 29 deletions app/src/main/java/com/kafka/user/home/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun MainScreen(
navController: NavHostController,
bottomSheetNavigator: BottomSheetNavigator,
colorExtractor: ColorExtractor,
theme: Theme
theme: Theme,
) {
val mainViewModel = hiltViewModel<MainViewModel>()
val context = LocalContext.current
Expand All @@ -55,29 +55,25 @@ fun MainScreen(

RequestNotificationPermission()

val snackbarHostState = remember { SnackbarHostState() }
CompositionLocalProvider(LocalSnackbarHostState provides snackbarHostState) {
CompositionLocalProvider(LocalColorExtractor provides colorExtractor) {
CompositionLocalProvider(LocalTheme provides theme) {
SnackbarMessagesHost()
CompositionHosts {
ModalBottomSheetLayout(
bottomSheetNavigator = bottomSheetNavigator,
sheetShape = MaterialTheme.shapes.large.copy(
bottomStart = CornerSize(0.dp),
bottomEnd = CornerSize(0.dp),
),
sheetBackgroundColor = MaterialTheme.colorScheme.surface,
sheetContentColor = MaterialTheme.colorScheme.onSurface,
scrimColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.32f),
) {
Home(
navController = navController,
analytics = mainViewModel.analytics,
modifier = Modifier.semantics { testTagsAsResourceId = true },
playerTheme = mainViewModel.playerTheme,
)
}
CompositionLocalProvider(LocalColorExtractor provides colorExtractor) {
CompositionLocalProvider(LocalTheme provides theme) {
CompositionHosts {
ModalBottomSheetLayout(
bottomSheetNavigator = bottomSheetNavigator,
sheetShape = MaterialTheme.shapes.large.copy(
bottomStart = CornerSize(0.dp),
bottomEnd = CornerSize(0.dp),
),
sheetBackgroundColor = MaterialTheme.colorScheme.surface,
sheetContentColor = MaterialTheme.colorScheme.onSurface,
scrimColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.32f),
) {
Home(
navController = navController,
analytics = mainViewModel.analytics,
modifier = Modifier.semantics { testTagsAsResourceId = true },
playerTheme = mainViewModel.playerTheme,
)
}
}
}
Expand All @@ -86,11 +82,15 @@ fun MainScreen(

@Composable
private fun CompositionHosts(content: @Composable () -> Unit) {
NavigatorHost {
DownloaderHost {
PlaybackHost {
AudioActionHost {
content()
val snackbarHostState = remember { SnackbarHostState() }
CompositionLocalProvider(LocalSnackbarHostState provides snackbarHostState) {
NavigatorHost {
DownloaderHost {
PlaybackHost {
AudioActionHost {
SnackbarMessagesHost()
content()
}
}
}
}
Expand Down
29 changes: 15 additions & 14 deletions app/src/main/java/com/kafka/user/injection/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package com.kafka.user.injection

import android.app.Application
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.preferencesDataStoreFile
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.messaging.FirebaseMessaging
import com.kafka.data.prefs.PreferencesStore
import com.kafka.user.BuildConfig
import com.kafka.user.initializer.AudioProgressInitializer
import com.kafka.user.initializer.FirebaseInitializer
Expand All @@ -27,24 +27,18 @@ import dagger.hilt.components.SingletonComponent
import dagger.multibindings.IntoSet
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import org.kafka.analytics.logger.Analytics
import org.kafka.analytics.logger.AnalyticsImpl
import org.kafka.base.AppInitializer
import org.kafka.base.CoroutineDispatchers
import org.kafka.base.ProcessLifetime
import org.kafka.base.SecretsProvider
import org.kafka.common.image.CoilAppInitializer
import org.kafka.play.AppReviewManager
import org.kafka.play.AppReviewManagerImpl
import org.kafka.analytics.logger.Analytics
import org.kafka.analytics.logger.AnalyticsImpl
import tm.alashow.datmusic.downloader.DownloadInitializer
import javax.inject.Named
import javax.inject.Singleton

/**
* DI module that provides objects which will live during the application lifecycle.
*/
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "app")

@InstallIn(SingletonComponent::class)
@Module
class AppModule {
Expand All @@ -68,10 +62,16 @@ class AppModule {
return FirebaseMessaging.getInstance()
}

@Named("app")
@Provides
private val dataStoreFileName = "app_preferences.preferences_pb"

@Singleton
fun provideDataStorePreferences(@ApplicationContext context: Context) = context.dataStore
@Provides
fun providePreferenceStore(
@ApplicationContext context: Context,
): PreferencesStore = PreferencesStore(
PreferenceDataStoreFactory.create(
produceFile = { context.preferencesDataStoreFile(dataStoreFileName) }
))

@Singleton
@Provides
Expand Down Expand Up @@ -99,6 +99,7 @@ class AppModule {
fun provideSecretsProvider() = object : SecretsProvider {
override val googleServerClientId: String = BuildConfig.GOOGLE_SERVER_CLIENT_ID
override val pipelessAuthToken: String = BuildConfig.PIPELESS_AUTH_TOKEN
override val openAiApiKey: String = BuildConfig.OPEN_AI_API_KEY
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package org.kafka.base
interface SecretsProvider {
val googleServerClientId: String?
val pipelessAuthToken: String?
val openAiApiKey: String?
}
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.android.lint) apply false
alias(libs.plugins.cacheFixPlugin) apply false
alias(libs.plugins.composeMultiplatform) apply false
alias(libs.plugins.android.lint) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.compose.compiler) apply false
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.gms.googleServices) apply false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@ class EventRepository @Inject constructor() {
fun showAppReviewDialog() = "show_review_dialog" to mapOf<String, String>()

fun openNotificationsSettings() = "open_notifications_settings" to mapOf<String, String>()

fun openCreator(source: String = "") = "open_creator" to mapOf("source" to source)

fun openSummary(itemId: String) = "open_summary" to mapOf(
"item_id" to itemId
)
}
1 change: 1 addition & 0 deletions core/downloader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
implementation projects.data.repo
implementation projects.ui.common

implementation libs.androidx.documentfile
implementation libs.hilt.android

implementation libs.fetch
Expand Down
Loading

0 comments on commit b96c808

Please sign in to comment.