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

Feature/multi module setup #40

Merged
merged 13 commits into from
Oct 16, 2023
Merged
2 changes: 1 addition & 1 deletion .idea/.name

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

26 changes: 26 additions & 0 deletions .idea/appInsightsSettings.xml

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

10 changes: 10 additions & 0 deletions .idea/migrations.xml

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

94 changes: 36 additions & 58 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
id("samplecomposeanroid.android.application")
id("samplecomposeanroid.android.application.compose")
id("samplecomposeanroid.android.room")
id("samplecomposeanroid.android.hilt")
id("samplecomposeanroid.kotlinter")
alias(libs.plugins.samplecomposeandroid.android.application)
alias(libs.plugins.samplecomposeandroid.android.application.compose)
alias(libs.plugins.samplecomposeandroid.android.application.flavors)
alias(libs.plugins.samplecomposeandroid.android.application.jacoco)
alias(libs.plugins.samplecomposeandroid.android.hilt)
id("jacoco")
id("samplecomposeandroid.android.room")
id("samplecomposeandroid.kotlinter")
}

android {
Expand All @@ -21,29 +25,6 @@ android {
}
}

buildTypes {
getByName("release") {
isDebuggable = false
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)

}

getByName("debug") {
isDebuggable = true
isMinifyEnabled = false
isShrinkResources = false
enableUnitTestCoverage = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

packagingOptions {
resources {
Expand All @@ -54,52 +35,49 @@ android {
namespace = "com.loodos.samplecomposeandroid"
}
dependencies {
implementation(libs.accompanist.systemuicontroller)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.android.material)
implementation(libs.compose.ui)
implementation(libs.compose.material)
implementation(libs.androidx.compose.material.iconsExtended)
implementation(libs.compose.ui.tooling)
implementation(libs.square.moshi.kotlin)
implementation(libs.square.retrofit)
implementation(libs.square.retrofit.converter.moshi)
implementation(libs.androidx.core.splashscreen)
implementation(libs.okhttp.logging.interceptor)
implementation(projects.feature.login)
implementation(projects.feature.home)
implementation(projects.feature.category)
implementation(projects.feature.profile)
implementation(projects.feature.productdetail)

implementation(projects.core.common)
implementation(projects.core.designsystem)
implementation(projects.core.data)
implementation(projects.core.domain)
implementation(projects.core.ui)

testImplementation(libs.junit4)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.core.splashscreen)
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.compose.runtime.tracing)
implementation(libs.androidx.compose.material3.windowSizeClass)
implementation(libs.androidx.lifecycle.runtimeCompose)
implementation(libs.androidx.lifecycle.livedata.ktx)
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.fragment.ktx)
implementation(libs.coil.kt)
implementation(libs.compose.state.events)

testImplementation(libs.junit4)
androidTestImplementation(libs.androidx.test.junit)
androidTestImplementation(libs.androidx.test.espresso.core)
androidTestImplementation(libs.compose.ui.test.junit)
androidTestImplementation(libs.hilt.android.testing)
implementation(libs.androidx.hilt.navigation.compose)


debugImplementation(libs.compose.ui.test.manifest)
debugImplementation(libs.compose.ui.tooling)
androidTestImplementation(libs.androidx.navigation.testing)
debugImplementation(libs.square.leakcanary)
implementation(libs.retrofit.converter.gson)

kapt(libs.square.moshi.kotlin.codegen)

debugImplementation(libs.chucker)
releaseImplementation(libs.chucker.no.op)

implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.runtimeCompose)
implementation(libs.compose.state.events)
implementation(libs.androidx.fragment.ktx)
implementation(libs.androidx.navigation.compose)

// Core functions
kaptTest(libs.hilt.compiler)
testImplementation(kotlin("test"))
testImplementation(libs.androidx.navigation.testing)

}

This file was deleted.

1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
android:name="com.loodos.MainApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:enableOnBackInvokedCallback="true"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/loodos/MainApplication.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
package com.loodos

import android.app.Application
import coil.ImageLoader
import coil.ImageLoaderFactory
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject
import javax.inject.Provider

/**
* Created by mertcantoptas on 07.03.2023
*/
@HiltAndroidApp
class MainApplication : Application()
class MainApplication : Application(), ImageLoaderFactory {

@Inject
lateinit var imageLoader: Provider<ImageLoader>

override fun newImageLoader(): ImageLoader = imageLoader.get()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.loodos.samplecomposeandroid.di

import android.app.Activity
import android.util.Log
import android.view.Window
import androidx.metrics.performance.JankStats
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityComponent

@Module
@InstallIn(ActivityComponent::class)
object JankStatsModule {
@Provides
fun providesOnFrameListener(): JankStats.OnFrameListener {
return JankStats.OnFrameListener { frameData ->
// Make sure to only log janky frames.
if (frameData.isJank) {
// We're currently logging this but would better report it to a backend.
Log.v("SampleCompose Jank", frameData.toString())
}
}
}

@Provides
fun providesWindow(activity: Activity): Window {
return activity.window
}

@Provides
fun providesJankStats(
window: Window,
frameListener: JankStats.OnFrameListener,
): JankStats {
return JankStats.createAndTrack(window, frameListener)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navOptions
import com.loodos.category.navigation.navigateToCategory
import com.loodos.data.util.NetworkMonitor
import com.loodos.samplecomposeandroid.feature.category.navigateToCategory
import com.loodos.samplecomposeandroid.feature.home.navigation.HomeNavigationRoute
import com.loodos.samplecomposeandroid.feature.home.navigation.navigateToHome
import com.loodos.samplecomposeandroid.feature.profile.navigateToProfile
import com.loodos.home.navigation.navigateToHome
import com.loodos.profile.navigation.navigateToProfile
import com.loodos.samplecomposeandroid.navigation.TopLevelDestination
import com.loodos.ui.TrackDisposableJank
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
Expand All @@ -27,10 +28,11 @@ import kotlinx.coroutines.flow.stateIn

@Composable
fun rememberMainAppState(
networkMonitor: com.loodos.data.util.NetworkMonitor,
networkMonitor: NetworkMonitor,
coroutineScope: CoroutineScope = rememberCoroutineScope(),
navController: NavHostController = rememberNavController(),
): MainAppState {
NavigationTrackingSideEffect(navController)
return remember(navController, coroutineScope, networkMonitor) {
MainAppState(navController, coroutineScope, networkMonitor)
}
Expand All @@ -40,7 +42,7 @@ fun rememberMainAppState(
class MainAppState(
val navController: NavHostController,
val coroutineScope: CoroutineScope,
networkMonitor: com.loodos.data.util.NetworkMonitor,
networkMonitor: NetworkMonitor,
) {
val currentDestination: NavDestination?
@Composable get() = navController
Expand Down Expand Up @@ -68,7 +70,7 @@ class MainAppState(
// Pop up to the start destination of the graph to
// avoid building up a large stack of destinations
// on the back stack as users select items
popUpTo(HomeNavigationRoute) {
popUpTo(com.loodos.home.navigation.HomeNavigationRoute) {
saveState = true
}
// Avoid multiple copies of the same destination when
Expand All @@ -89,3 +91,21 @@ class MainAppState(
navController.popBackStack()
}
}

/**
* Stores information about navigation events to be used with JankStats
*/
@Composable
private fun NavigationTrackingSideEffect(navController: NavHostController) {
TrackDisposableJank(navController) { metricsHolder ->
val listener = NavController.OnDestinationChangedListener { _, destination, _ ->
metricsHolder.state?.putState("Navigation", destination.route.toString())
}

navController.addOnDestinationChangedListener(listener)

onDispose {
navController.removeOnDestinationChangedListener(listener)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import androidx.core.view.WindowCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.metrics.performance.JankStats
import com.loodos.data.util.NetworkMonitor
import com.loodos.designsystems.theme.SampleComposeAndroidTheme
import com.loodos.samplecomposeandroid.feature.appstate.MainApp
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
Expand All @@ -29,7 +31,10 @@ import javax.inject.Inject
class MainActivity : ComponentActivity() {

@Inject
lateinit var networkMonitor: com.loodos.data.util.NetworkMonitor
lateinit var networkMonitor: NetworkMonitor

@Inject
lateinit var lazyStats: dagger.Lazy<JankStats>

companion object {
const val splashFadeDurationMillis = 1000L
Expand Down Expand Up @@ -83,11 +88,21 @@ class MainActivity : ComponentActivity() {

private fun setContent() {
setContent {
com.loodos.designsystems.theme.SampleComposeAndroidTheme {
SampleComposeAndroidTheme {
MainApp(networkMonitor = networkMonitor)
}
}
}

override fun onResume() {
super.onResume()
lazyStats.get().isTrackingEnabled = true
}

override fun onPause() {
super.onPause()
lazyStats.get().isTrackingEnabled = false
}
}

@Composable
Expand Down
Loading
Loading