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

Refactor/add di mobile app #1

Merged
merged 20 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
76583b2
Updated version catalog, added koin for di and guava dependencies
marlonlom Mar 4, 2024
60938fb
feat(mobile-app): Configured koin modules
marlonlom Mar 4, 2024
dcdca21
feat(mobile-app): Renamed old files
marlonlom Mar 4, 2024
4050fda
feat(mobile-app): Updated welcome screen composables
marlonlom Mar 4, 2024
1309710
feat(mobile-app): UPdated main activity
marlonlom Mar 4, 2024
97d03fc
feat(feat-core-catalog-src): Added catalog data in english for fetching
marlonlom Mar 4, 2024
87253b4
feat(mobile-app): Updated catalog data service dependency for depende…
marlonlom Mar 4, 2024
752fd91
feat(mobile-app): Updated string resource values
marlonlom Mar 4, 2024
5b21edc
feat(mobile-app): Updated unit tests
marlonlom Mar 4, 2024
dd9becd
feat(mobile-app): Renamed old files
marlonlom Mar 5, 2024
4c3a782
feat(mobile-app): Removed viewmodel factory for usage in koin di module
marlonlom Mar 5, 2024
6bf2a5c
feat(mobile-app): Updated catalog favorites route composable ui
marlonlom Mar 5, 2024
9258729
feat(mobile-app): Updated catalog settings route composable ui and vi…
marlonlom Mar 5, 2024
3db0f9a
feat(mobile-app): Updated scaffold and navigation type
marlonlom Mar 5, 2024
4c19e36
feat(mobile-app): Updated device posture ui feature
marlonlom Mar 5, 2024
8be6e61
feat(mobile-app): Updated catalog search route composable ui
marlonlom Mar 5, 2024
695885b
feat(mobile-app): Updated catalog list route composable ui
marlonlom Mar 5, 2024
e349c91
feat(mobile-app): Updated welcome route composable ui
marlonlom Mar 5, 2024
32a81b2
feat(mobile-app): Updated app ui state
marlonlom Mar 5, 2024
fba1e75
feat(mobile-app): Updated app scaffold content type classifier
marlonlom Mar 5, 2024
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
10 changes: 8 additions & 2 deletions apps/mobile-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ dependencies {
implementation(composeBom)
androidTestImplementation(composeBom)

val koinBom = platform(libs.koin.bom)
implementation(koinBom)

implementation(libs.androidx.activity.compose)
implementation(libs.androidx.browser)
implementation(libs.androidx.compose.ui)
Expand All @@ -88,10 +91,13 @@ dependencies {
implementation(libs.androidx.navigation.runtime.ktx)
implementation(libs.androidx.window)
implementation(libs.coil.compose)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.google.guava)
implementation(libs.google.oss.licenses)
implementation(libs.jakewharton.timber)
implementation(libs.koin.androidx.compose)
implementation(libs.koin.androidx.compose.navigation)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.bundles.database.room)

testImplementation(libs.junit)
Expand Down
5 changes: 3 additions & 2 deletions apps/mobile-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name="dev.marlonlom.apps.cappajv.CappajvApp"
android:name=".CappajvApp"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -22,8 +22,9 @@
android:enableOnBackInvokedCallback="true"
android:theme="@style/Theme.Cappajv.Starting"
tools:targetApi="tiramisu">

<activity
android:name="dev.marlonlom.apps.cappajv.ui.main.MainActivity"
android:name=".ui.main.MainActivity"
android:exported="true"
android:theme="@style/Theme.Cappajv.Starting">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import coil.disk.DiskCache
import coil.memory.MemoryCache
import coil.request.CachePolicy
import coil.util.DebugLogger
import dev.marlonlom.apps.cappajv.di.appModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import org.koin.core.logger.Level
import timber.log.Timber

/**
Expand All @@ -30,9 +35,11 @@ val Context.dataStore by preferencesDataStore("cappajv-preferences")
* @author marlonlom
*/
class CappajvApp : Application(), ImageLoaderFactory {

override fun onCreate() {
super.onCreate()
setupTimber()
initializeKoinConfig()
}

override fun newImageLoader(): ImageLoader = ImageLoader(this)
Expand Down Expand Up @@ -60,4 +67,12 @@ class CappajvApp : Application(), ImageLoaderFactory {
}
}

private fun initializeKoinConfig() {
startKoin {
androidContext(this@CappajvApp)
androidLogger(Level.DEBUG)
modules(appModule)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2024 Marlonlom
* SPDX-License-Identifier: Apache-2.0
*/

package dev.marlonlom.apps.cappajv.di

import dev.marlonlom.apps.cappajv.ui.main.MainActivityViewModel
import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.dsl.module

val mainActivityModule = module {
viewModelOf(::MainActivityViewModel)
}

val appModule = module {
includes(viewModelsModule)
includes(mainActivityModule)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 Marlonlom
* SPDX-License-Identifier: Apache-2.0
*/

package dev.marlonlom.apps.cappajv.di

import dev.marlonlom.apps.cappajv.core.catalog_source.CatalogDataService
import dev.marlonlom.apps.cappajv.core.database.CappaDatabase
import dev.marlonlom.apps.cappajv.core.database.datasource.LocalDataSource
import dev.marlonlom.apps.cappajv.core.database.datasource.LocalDataSourceImpl
import dev.marlonlom.apps.cappajv.core.preferences.UserPreferencesRepository
import dev.marlonlom.apps.cappajv.dataStore
import dev.marlonlom.apps.cappajv.features.catalog_list.CatalogListRepository
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module
import java.util.Locale

val dataModule = module {
single<LocalDataSource> {
CappaDatabase.getInstance(androidContext()).let { db ->
LocalDataSourceImpl(
catalogItemsDao = db.catalogProductsDao(),
catalogPunctuationsDao = db.catalogPunctuationsDao(),
catalogFavoriteItemsDao = db.catalogFavoriteItemsDao()
)
}
}
single<CatalogDataService> {
CatalogDataService(Locale.getDefault().language)
}
single<CatalogListRepository> {
CatalogListRepository(
localDataSource = get(),
catalogDataService = get(),
)
}
single {
UserPreferencesRepository(androidContext().dataStore)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2024 Marlonlom
* SPDX-License-Identifier: Apache-2.0
*/

package dev.marlonlom.apps.cappajv.di

import dev.marlonlom.apps.cappajv.features.catalog_detail.CatalogDetailViewModel
import dev.marlonlom.apps.cappajv.features.catalog_list.CatalogListViewModel
import dev.marlonlom.apps.cappajv.features.settings.SettingsViewModel
import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.dsl.module

val viewModelsModule = module {
includes(dataModule)
viewModelOf(::CatalogListViewModel)
viewModelOf(::CatalogDetailViewModel)
viewModelOf(::SettingsViewModel)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package dev.marlonlom.apps.cappajv.features.catalog_detail
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch

Expand All @@ -34,15 +33,4 @@ class CatalogDetailViewModel(
}
}

companion object {

fun factory(
repository: CatalogDetailRepository
): ViewModelProvider.Factory = object : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return CatalogDetailViewModel(repository) as T
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ fun FavoriteProductsRoute(
appState: CappajvAppState,
) {
val contentHorizontalPadding = when {
appState.isLandscapeOrientation.not().and(appState.is7InTabletWidth) -> 40.dp
appState.isLandscapeOrientation.not().and(appState.is10InTabletWidth) -> 80.dp
appState.isLandscape.not().and(appState.isMediumWidth) -> 40.dp
appState.isLandscape.not().and(appState.isExpandedWidth) -> 80.dp
else -> 20.dp
}
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -38,11 +39,13 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import coil.compose.AsyncImage
import coil.request.ImageRequest
import dev.marlonlom.apps.cappajv.R
import dev.marlonlom.apps.cappajv.core.database.entities.CatalogItemTuple
import dev.marlonlom.apps.cappajv.ui.main.CappajvAppState
import org.koin.androidx.compose.koinViewModel
import timber.log.Timber

@ExperimentalFoundationApi
Expand All @@ -51,10 +54,14 @@ import timber.log.Timber
@Composable
fun CatalogListRoute(
appState: CappajvAppState,
viewModel: CatalogListViewModel = koinViewModel(),
) {

val catalogListState: CatalogListState by viewModel.uiState.collectAsStateWithLifecycle()

val contentHorizontalPadding = when {
appState.isLandscapeOrientation.not().and(appState.is7InTabletWidth) -> 40.dp
appState.isLandscapeOrientation.not().and(appState.is10InTabletWidth) -> 80.dp
appState.isLandscape.not().and(appState.isMediumWidth) -> 40.dp
appState.isLandscape.not().and(appState.isExpandedWidth) -> 80.dp
else -> 20.dp
}

Expand All @@ -76,7 +83,7 @@ fun CatalogListRoute(
)
}

when (val catalogListState = appState.catalogListState) {
when (catalogListState) {
CatalogListState.Empty -> {
item {
Text(" :( ")
Expand All @@ -88,8 +95,9 @@ fun CatalogListRoute(
}

is CatalogListState.Listing -> {
val listingsData = catalogListState as CatalogListState.Listing

catalogListState.map.keys.sorted().forEach { category ->
listingsData.map.keys.sorted().forEach { category ->
item {
Row(
modifier = Modifier
Expand All @@ -110,7 +118,7 @@ fun CatalogListRoute(
}

item {
val tuples: List<CatalogItemTuple> = catalogListState.map[category]
val tuples: List<CatalogItemTuple> = listingsData.map[category]
.orEmpty().shuffled().subList(0, 5)
LazyRow(
horizontalArrangement = Arrangement.spacedBy(20.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ fun SearchProductsRoute(
appState: CappajvAppState,
) {
val contentHorizontalPadding = when {
appState.isLandscapeOrientation.not().and(appState.is7InTabletWidth) -> 40.dp
appState.isLandscapeOrientation.not().and(appState.is10InTabletWidth) -> 80.dp
appState.isLandscape.not().and(appState.isMediumWidth) -> 40.dp
appState.isLandscape.not().and(appState.isExpandedWidth) -> 80.dp
else -> 20.dp
}
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -25,6 +25,7 @@ import androidx.compose.ui.window.DialogProperties
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dev.marlonlom.apps.cappajv.R
import dev.marlonlom.apps.cappajv.ui.main.CappajvAppState
import org.koin.androidx.compose.koinViewModel

/**
* Settings dialog route composable ui.
Expand All @@ -41,10 +42,10 @@ import dev.marlonlom.apps.cappajv.ui.main.CappajvAppState
@Composable
fun SettingsDialog(
appState: CappajvAppState,
viewModel: SettingsViewModel,
onDialogDismissed: () -> Unit,
openOssLicencesInfo: () -> Unit,
openExternalUrl: (String) -> Unit
openExternalUrl: (String) -> Unit,
viewModel: SettingsViewModel = koinViewModel()
) {
val settingsUiState by viewModel.uiState.collectAsStateWithLifecycle()
when (settingsUiState) {
Expand Down Expand Up @@ -104,15 +105,15 @@ internal fun SettingsDialogContent(
},
text = {
Column {
Divider()
HorizontalDivider()
BooleanSettingsContent(
appState,
editableSettings,
onBooleanSettingUpdated
)
SectionDivider()
LinksPanelContent(openExternalUrl, openOssLicencesInfo)
Divider()
HorizontalDivider()
}
},
confirmButton = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
Expand Down Expand Up @@ -46,7 +46,7 @@ internal fun LinksPanelContent(
FlowRow(
horizontalArrangement = Arrangement.spacedBy(
space = 16.dp,
alignment = Alignment.Start,
alignment = Alignment.CenterHorizontally,
),
modifier = Modifier.fillMaxWidth(),
) {
Expand Down Expand Up @@ -82,7 +82,7 @@ internal fun LinksPanelContent(
*/
@Composable
fun SectionDivider() {
Divider(Modifier.padding(top = 8.dp))
HorizontalDivider(Modifier.padding(top = 8.dp))
}

/**
Expand All @@ -100,7 +100,7 @@ internal fun BooleanSettingsContent(
editableSettings: UserEditableSettings,
onBooleanSettingUpdated: (String, Boolean) -> Unit
) {
if (appState.is7InTabletWidth) {
if (appState.isMediumWidth) {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
Expand Down
Loading
Loading