Skip to content

Commit

Permalink
refactor: Cleaning the utilities package to become standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbyESP committed Dec 18, 2024
1 parent bf3abbd commit e8479d5
Show file tree
Hide file tree
Showing 25 changed files with 353 additions and 304 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.

27 changes: 16 additions & 11 deletions app/src/main/java/com/bobbyesp/metadator/App.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
package com.bobbyesp.metadator

import android.app.Application
import android.content.ClipboardManager
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.net.ConnectivityManager
import android.os.Build
import androidx.core.content.getSystemService
import com.bobbyesp.crashhandler.CrashHandler.setupCrashHandler
import com.bobbyesp.crashhandler.ReportInfo
import com.bobbyesp.metadator.di.appCoroutinesScope
import com.bobbyesp.metadator.di.appMainViewModels
import com.bobbyesp.metadator.di.appSystemManagers
import com.bobbyesp.metadator.di.mediaplayerViewModels
import com.bobbyesp.metadator.di.utilitiesViewModels
import com.bobbyesp.metadator.features.spotify.di.spotifyMainModule
import com.bobbyesp.metadator.features.spotify.di.spotifyServicesModule
import com.bobbyesp.metadator.util.preferences.BooleanPreferenceDefaults
import com.bobbyesp.metadator.util.preferences.IntPreferenceDefaults
import com.bobbyesp.metadator.util.preferences.PreferencesKeys
import com.bobbyesp.metadator.util.preferences.StringPreferenceDefaults
import com.bobbyesp.utilities.Preferences
import com.tencent.mmkv.MMKV
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import mediaplayerInternalsModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.GlobalContext.startKoin
import org.koin.dsl.module
import kotlin.properties.Delegates

class App : Application() {
override fun onCreate() {
MMKV.initialize(this)
preferences = Preferences(
PreferencesKeys.MMKV_PREFERENCES_NAME,
IntPreferenceDefaults,
StringPreferenceDefaults,
BooleanPreferenceDefaults
)
startKoin {
androidLogger()
androidContext(this@App)
modules(appSystemManagers, appCoroutinesScope)
modules(mediaplayerInternalsModule)
modules(appMainViewModels, utilitiesViewModels, mediaplayerViewModels)
modules(spotifyMainModule, spotifyServicesModule)
Expand All @@ -39,9 +49,6 @@ class App : Application() {
) else
getPackageInfo(packageName, 0)
}
applicationScope = CoroutineScope(SupervisorJob())
clipboard = getSystemService()!!
connectivityManager = getSystemService()!!
isPlayStoreBuild = BuildConfig.FLAVOR == "playstore"
super.onCreate()

Expand All @@ -55,9 +62,7 @@ class App : Application() {
}

companion object {
lateinit var clipboard: ClipboardManager
lateinit var applicationScope: CoroutineScope
lateinit var connectivityManager: ConnectivityManager
lateinit var preferences: Preferences
lateinit var packageInfo: PackageInfo
var isPlayStoreBuild by Delegates.notNull<Boolean>()

Expand Down
20 changes: 14 additions & 6 deletions app/src/main/java/com/bobbyesp/metadator/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.bobbyesp.metadator

import android.content.ComponentName
import android.content.Intent
import android.content.ServiceConnection
import android.os.Bundle
import android.os.IBinder
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
Expand All @@ -17,12 +13,20 @@ import com.bobbyesp.mediaplayer.service.MediaplayerService
import com.bobbyesp.metadator.presentation.Navigator
import com.bobbyesp.metadator.presentation.common.AppLocalSettingsProvider
import com.bobbyesp.metadator.presentation.theme.MetadatorTheme
import com.bobbyesp.metadator.util.preferences.BooleanPreferenceDefaults
import com.bobbyesp.metadator.util.preferences.CoreSettings
import com.bobbyesp.metadator.util.preferences.IntPreferenceDefaults
import com.bobbyesp.metadator.util.preferences.PreferencesKeys
import com.bobbyesp.metadator.util.preferences.StringPreferenceDefaults
import com.bobbyesp.utilities.Preferences
import org.koin.android.ext.android.inject
import org.koin.compose.KoinContext
import org.koin.core.component.KoinComponent
import setCrashlyticsCollection
import kotlin.getValue

@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
class MainActivity : ComponentActivity() {
class MainActivity : ComponentActivity(), KoinComponent {
private var isMusicPlayerServiceStarted = false

private val connectionHandler: ConnectionHandler by inject()
Expand All @@ -36,7 +40,11 @@ class MainActivity : ComponentActivity() {
setContent {
KoinContext {
val windowSizeClass = calculateWindowSizeClass(this)
AppLocalSettingsProvider(windowSizeClass.widthSizeClass, connectionHandler) {
AppLocalSettingsProvider(
windowWidthSize = windowSizeClass.widthSizeClass,
playerConnectionHandler = connectionHandler,
coreSettings = CoreSettings(App.preferences.kv)
) {
MetadatorTheme {
Navigator()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.bobbyesp.metadator.di

import android.content.ClipboardManager
import android.content.Context.CLIPBOARD_SERVICE
import android.content.Context.CONNECTIVITY_SERVICE
import android.net.ConnectivityManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import org.koin.android.ext.koin.androidApplication
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module

val appSystemManagers = module {
single<ClipboardManager> { androidApplication().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager }
single<ConnectivityManager> { androidContext().getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager }
}

val appCoroutinesScope = module {
single { CoroutineScope(SupervisorJob()) }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bobbyesp.metadator.model
package com.bobbyesp.metadator.domain.model

import android.net.Uri
import android.os.Parcelable
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/bobbyesp/metadator/ext/Song.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bobbyesp.metadator.ext

import com.bobbyesp.metadator.model.ParcelableSong
import com.bobbyesp.metadator.domain.model.ParcelableSong
import com.bobbyesp.utilities.model.Song

fun Song.toParcelableSong(): ParcelableSong {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
Expand All @@ -42,9 +40,10 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.dialog
import androidx.navigation.compose.navigation
import androidx.navigation.toRoute
import com.bobbyesp.metadator.model.ParcelableSong
import com.bobbyesp.metadator.domain.model.ParcelableSong
import com.bobbyesp.metadator.presentation.common.LocalDrawerState
import com.bobbyesp.metadator.presentation.common.LocalNavController
import com.bobbyesp.metadator.presentation.common.LocalPlayerAwareWindowInsets
Expand Down Expand Up @@ -192,6 +191,10 @@ fun Navigator() {
mediaStoreViewModel.songs.collectAsStateWithLifecycle()
HomePage(songs = songsState, onEvent = mediaStoreViewModel::onEvent)
}

dialog<Route.MetadatorNavigator.Home.VisualSettings> {
Text("Dialog")
}
}

navigation<Route.MediaplayerNavigator>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import coil.ImageLoader
import coil.disk.DiskCache
import coil.memory.MemoryCache
import com.bobbyesp.mediaplayer.service.ConnectionHandler
import com.bobbyesp.utilities.preferences.Preferences.AppMainSettingsStateFlow
import com.bobbyesp.utilities.theme.DarkThemePreference
import com.bobbyesp.metadator.util.preferences.CoreSettings
import com.bobbyesp.metadator.util.theme.DarkThemePreference
import com.bobbyesp.utilities.ui.DEFAULT_SEED_COLOR
import com.materialkolor.DynamicMaterialThemeState
import com.materialkolor.rememberDynamicMaterialThemeState
Expand Down Expand Up @@ -53,11 +53,12 @@ val LocalPlayerAwareWindowInsets =
fun AppLocalSettingsProvider(
windowWidthSize: WindowWidthSizeClass,
playerConnectionHandler: ConnectionHandler,
coreSettings: CoreSettings,
content: @Composable () -> Unit
) {
val context = LocalContext.current

val appSettingsState = AppMainSettingsStateFlow.collectAsStateWithLifecycle().value
val appSettingsState = coreSettings.appMainSettingsStateFlow.collectAsStateWithLifecycle().value
val navController = rememberNavController()

val imageLoader = ImageLoader.Builder(context)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bobbyesp.metadator.presentation.common

import com.bobbyesp.metadator.model.ParcelableSong
import com.bobbyesp.metadator.domain.model.ParcelableSong
import kotlinx.serialization.Serializable

@Serializable
Expand All @@ -11,7 +11,11 @@ sealed interface Route {
@Serializable
data object MetadatorNavigator : Route {
@Serializable
data object Home : Route
data object Home : Route {

@Serializable
data object VisualSettings : Route
}
}

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.TextUnit
import com.bobbyesp.ui.components.text.MarqueeText
import com.bobbyesp.ui.components.text.MarqueeTextGradientOptions
import com.bobbyesp.utilities.preferences.PreferencesKeys.MARQUEE_TEXT
import com.bobbyesp.utilities.preferences.booleanState
import com.bobbyesp.metadator.util.preferences.PreferencesKeys.MARQUEE_TEXT
import com.bobbyesp.metadator.util.preferences.booleanState

@Composable
fun ConditionedMarqueeText(
Expand Down
Loading

0 comments on commit e8479d5

Please sign in to comment.