Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.kotlinxSerialization)
alias(libs.plugins.kapt)
alias(libs.plugins.compose.compiler)
}

android {
Expand Down Expand Up @@ -34,16 +35,38 @@ android {
}
buildFeatures {
viewBinding true
compose true
}
}

composeCompiler {
enableStrongSkippingMode = true
reportsDestination = layout.buildDirectory.dir("compose_compiler")
metricsDestination = layout.buildDirectory.dir("compose_compiler")
}

dependencies {
implementation project(":common:di")
implementation project(":common:formatters")
implementation project(":common:ui")
implementation project(":common:data:products")
implementation project(":common:data:promo")

def composeBom = platform(libs.compose.bom)
implementation composeBom
androidTestImplementation composeBom

implementation libs.compose.ui
implementation libs.compose.ui.graphics
implementation libs.compose.ui.tooling.preview
implementation libs.compose.material3
implementation libs.compose.activity
implementation libs.compose.viewmodel
implementation libs.compose.navigation
implementation libs.coil.compose
debugImplementation libs.compose.ui.tooling


implementation libs.core.ktx
implementation libs.appcompat
implementation libs.material
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:enableOnBackInvokedCallback="true"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.MarketSample"
tools:targetApi="31">

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 5 additions & 14 deletions app/src/main/java/ru/otus/marketsample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
package ru.otus.marketsample

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import ru.otus.marketsample.databinding.ActivityMainBinding
import androidx.activity.ComponentActivity

class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding
class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

ViewCompat.setOnApplyWindowInsetsListener(binding.container) { view, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
view.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
setContent {
MainScreen()
}
}
}
49 changes: 0 additions & 49 deletions app/src/main/java/ru/otus/marketsample/MainFragment.kt

This file was deleted.

127 changes: 127 additions & 0 deletions app/src/main/java/ru/otus/marketsample/MainScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package ru.otus.marketsample
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import ru.otus.marketsample.details.feature.DetailsScreen
import ru.otus.marketsample.details.feature.DetailsViewModel
import ru.otus.marketsample.details.feature.di.DaggerDetailsComponent
import ru.otus.marketsample.details.feature.di.DetailsComponentDependencies
import ru.otus.marketsample.products.feature.ProductListScreen
import ru.otus.marketsample.products.feature.ProductListViewModel
import ru.otus.marketsample.products.feature.di.DaggerProductListComponent
import ru.otus.marketsample.products.feature.di.ProductListComponentDependencies
import ru.otus.marketsample.promo.feature.PromoListScreen
import ru.otus.marketsample.promo.feature.PromoListViewModel
import ru.otus.marketsample.promo.feature.di.DaggerPromoComponent
import ru.otus.marketsample.promo.feature.di.PromoComponentDependencies
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MainScreen() {
val navController = rememberNavController()
Scaffold(
bottomBar = {
NavigationBar {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
NavigationBarItem(
icon = { Icon(painterResource(ru.otus.common.ui.R.drawable.ic_list), tint = null, contentDescription = "Продукты") },
label = { Text("Продукты") },
selected = currentDestination?.hierarchy?.any { it.route == "products" } == true,
onClick = {
navController.navigate("products") {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
}
)
NavigationBarItem(
icon = { Icon(painterResource(ru.otus.common.ui.R.drawable.ic_discount), tint = null, contentDescription = "Акции") },
label = { Text("Акции") },
selected = currentDestination?.hierarchy?.any { it.route == "promo" } == true,
onClick = {
navController.navigate("promo") {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
}
)
}
}
) { innerPadding ->
val context = LocalContext.current
val dependencies = (context.applicationContext as MarketSampleApp).getDependencies()
NavHost(
navController = navController,
startDestination = "products",
modifier = Modifier.padding(innerPadding)
) {
composable("products") {
val component = remember {
DaggerProductListComponent.factory().create(dependencies as ProductListComponentDependencies)
}
val factory = component.getViewModelFactory()
val viewModel: ProductListViewModel = viewModel(factory = factory)
val state by viewModel.state.collectAsState()
ProductListScreen(
state = state,
onRefresh = { viewModel.refresh() },
onItemClick = { productId ->
navController.navigate("details/$productId")
}
)
}
composable("promo") {
val component = remember {
DaggerPromoComponent.factory().create(dependencies as PromoComponentDependencies)
}
val factory = component.getViewModelFactory()
val viewModel: PromoListViewModel = viewModel(factory = factory)
val state by viewModel.state.collectAsState()
PromoListScreen(
state = state,
onRefresh = { viewModel.refresh() }
)
}
composable(
route = "details/{productId}",
arguments = listOf(navArgument("productId") { type = NavType.StringType })
) { backStackEntry ->
val productId = backStackEntry.arguments?.getString("productId") ?: return@composable

val component = remember(productId) {
DaggerDetailsComponent.factory().create(dependencies as DetailsComponentDependencies, productId)
}
val factory = component.getViewModelFactory()
val viewModel: DetailsViewModel = viewModel(factory = factory)
val state by viewModel.state.collectAsState()
DetailsScreen(state = state)
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading