Skip to content

Commit 0d97fc2

Browse files
committed
refactor: refactoring
1 parent 8d6841a commit 0d97fc2

File tree

87 files changed

+841
-808
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+841
-808
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Breaking Bad - Jetpack Compose
22
<a href='https://developer.android.com'><img src='http://img.shields.io/badge/platform-android-green.svg'/></a>
3-
<a href="https://kotlinlang.org/docs/whatsnew1720.html"><img src = "https://shields.io/badge/kotlin-1.7.20-blue" /></a>
4-
<a href="https://developer.android.com/jetpack/androidx/releases/compose#versions"><img src = "https://img.shields.io/badge/jetpack%20compose-1.2.1-brightgreen" /></a>
3+
<a href="https://kotlinlang.org/docs/whatsnew1920.html"><img src = "https://shields.io/badge/kotlin-1.9.20-blue" /></a>
4+
<a href="https://developer.android.com/jetpack/compose/bom"><img src = "https://img.shields.io/badge/jetpack%20compose-2023.10.01-brightgreen" /></a>
55
<a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/license-Apache%202.0-blue.svg"/></a>
66
[![ktlint](https://img.shields.io/badge/code%20style-%E2%9D%A4-FF4081.svg)](https://ktlint.github.io/)
77

@@ -24,11 +24,10 @@
2424
- Clean Architecture (nowinandroid)
2525
- MVVM pattern
2626
- Kotlin Coroutines & Flows
27-
- Material Design
27+
- Material Design3
2828
- Single Activity
2929
- StaggeredVerticalGrid
3030
- [Gradle Version Catalog](https://docs.gradle.org/7.4/userguide/platforms.html)
31-
- [Accompanist](https://google.github.io/accompanist)
3231
- [Retrofit2](https://github.com/square/retrofit)
3332
- [Coil-Compose](https://coil-kt.github.io/coil/compose)
3433
- [Timber](https://github.com/JakeWharton/timber)

app/build.gradle.kts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,29 @@ android {
1111
versionName = "1.0"
1212
}
1313

14+
signingConfigs {
15+
getByName("debug") {
16+
storeFile = rootProject.file("debug.keystore")
17+
storePassword = "android"
18+
keyAlias = "androiddebugkey"
19+
keyPassword = "android"
20+
}
21+
}
22+
1423
buildTypes {
24+
getByName("debug") {
25+
isDebuggable = false
26+
}
27+
1528
getByName("release") {
16-
isMinifyEnabled = false
29+
isDebuggable = false
30+
isShrinkResources = true
31+
isMinifyEnabled = true
1732
proguardFiles(
1833
getDefaultProguardFile("proguard-android-optimize.txt"),
1934
"proguard-rules.pro"
2035
)
36+
signingConfig = signingConfigs.getByName("debug")
2137
}
2238
}
2339

@@ -28,15 +44,21 @@ android {
2844

2945
dependencies {
3046

47+
implementation(project(":core:data"))
3148
implementation(project(":core:designsystem"))
3249

33-
implementation(project(":feature:main"))
50+
implementation(project(":feature:list"))
51+
implementation(project(":feature:favorite"))
3452
implementation(project(":feature:detail"))
3553

36-
implementation(libs.material)
3754
implementation(libs.androidx.startup)
55+
implementation(libs.androidx.appcompat)
3856
implementation(libs.androidx.activity.compose)
57+
58+
implementation(libs.androidx.navigation.compose)
3959
implementation(libs.androidx.hilt.navigation.compose)
4060

61+
implementation(libs.androidx.compose.material3)
62+
4163
implementation(libs.timber)
4264
}

app/proguard-rules.pro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@
1818

1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
21+
#-renamesourcefileattribute SourceFile
22+
23+
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
24+
-keep,allowobfuscation,allowshrinking class retrofit2.Response
25+
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
android:label="@string/app_name"
1313
android:largeHeap="true"
1414
android:supportsRtl="true"
15+
android:enableOnBackInvokedCallback="true"
1516
android:theme="@style/Theme.BrBaCompose">
1617
<activity
1718
android:name=".app.MainActivity"

app/src/main/java/io/github/shinhyo/brba/app/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class MainActivity : AppCompatActivity() {
2828

2929
override fun onCreate(savedInstanceState: Bundle?) {
3030
super.onCreate(savedInstanceState)
31+
3132
WindowCompat.setDecorFitsSystemWindows(window, false)
3233

3334
setContent {

app/src/main/java/io/github/shinhyo/brba/app/di/CoroutinesModule.kt

Lines changed: 0 additions & 40 deletions
This file was deleted.

app/src/main/java/io/github/shinhyo/brba/app/navigation/BrbaNavHost.kt

Lines changed: 0 additions & 39 deletions
This file was deleted.

app/src/main/java/io/github/shinhyo/brba/app/ui/BrbaApp.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,25 @@
1515
*/
1616
package io.github.shinhyo.brba.app.ui
1717

18+
import androidx.compose.foundation.layout.fillMaxSize
1819
import androidx.compose.runtime.Composable
19-
import io.github.shinhyo.brba.app.navigation.BrbaNavHost
20+
import androidx.compose.ui.Modifier
21+
import androidx.navigation.compose.NavHost
22+
import io.github.shinhyo.brba.app.ui.main.navigation.ROUTE_MAIN
23+
import io.github.shinhyo.brba.app.ui.main.navigation.mainScreen
24+
import io.github.shinhyo.brba.feature.detail.navigaion.detailScreen
2025

2126
@Composable
22-
fun BrbaApp() {
23-
BrbaNavHost()
27+
fun BrbaApp(
28+
appState: BrbaAppState = rememberAppState()
29+
) {
30+
// root
31+
NavHost(
32+
navController = appState.navController,
33+
startDestination = ROUTE_MAIN,
34+
modifier = Modifier.fillMaxSize()
35+
) {
36+
mainScreen(appState = appState)
37+
detailScreen()
38+
}
2439
}

app/src/main/java/io/github/shinhyo/brba/app/ui/BrbaAppState.kt

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,45 @@ import androidx.compose.runtime.Composable
1919
import androidx.compose.runtime.Stable
2020
import androidx.compose.runtime.remember
2121
import androidx.compose.runtime.rememberCoroutineScope
22+
import androidx.navigation.NavDestination
2223
import androidx.navigation.NavHostController
24+
import androidx.navigation.compose.currentBackStackEntryAsState
2325
import androidx.navigation.compose.rememberNavController
26+
import io.github.shinhyo.brba.app.ui.main.Tab
27+
import io.github.shinhyo.brba.feature.favorate.navigation.navigateFavorite
28+
import io.github.shinhyo.brba.feature.main.navigation.navigateList
2429
import kotlinx.coroutines.CoroutineScope
2530

2631
@Composable
2732
fun rememberAppState(
2833
coroutineScope: CoroutineScope = rememberCoroutineScope(),
29-
navController: NavHostController = rememberNavController()
30-
) = remember(navController, coroutineScope) {
31-
BrbaAppState(navController, coroutineScope)
34+
navController: NavHostController = rememberNavController(),
35+
navTabController: NavHostController = rememberNavController()
36+
): BrbaAppState = remember(
37+
navController,
38+
navTabController,
39+
coroutineScope
40+
) {
41+
BrbaAppState(coroutineScope, navController, navTabController)
3242
}
3343

3444
@Stable
3545
class BrbaAppState(
36-
private val navController: NavHostController,
37-
val coroutineScope: CoroutineScope
46+
val coroutineScope: CoroutineScope,
47+
val navController: NavHostController,
48+
val navTabController: NavHostController
3849
) {
3950

40-
fun onBackClick() {
41-
navController.popBackStack()
51+
val currentDestination: NavDestination?
52+
@Composable get() = navController.currentBackStackEntryAsState().value?.destination
53+
54+
val currentTabDestination: NavDestination?
55+
@Composable get() = navTabController.currentBackStackEntryAsState().value?.destination
56+
57+
fun navigateTopDestination(destination: Tab) {
58+
when (destination) {
59+
Tab.LIST -> navTabController.navigateList()
60+
Tab.FAVORITE -> navTabController.navigateFavorite()
61+
}
4262
}
4363
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright 2021 shinhyo
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.github.shinhyo.brba.app.ui.main
17+
18+
import androidx.compose.foundation.layout.WindowInsets
19+
import androidx.compose.foundation.layout.navigationBarsPadding
20+
import androidx.compose.foundation.layout.padding
21+
import androidx.compose.material3.Icon
22+
import androidx.compose.material3.MaterialTheme
23+
import androidx.compose.material3.NavigationBar
24+
import androidx.compose.material3.NavigationBarItem
25+
import androidx.compose.material3.NavigationBarItemDefaults
26+
import androidx.compose.material3.Scaffold
27+
import androidx.compose.runtime.Composable
28+
import androidx.compose.ui.Modifier
29+
import androidx.compose.ui.graphics.Color
30+
import androidx.compose.ui.res.painterResource
31+
import androidx.compose.ui.unit.dp
32+
import androidx.navigation.NavHostController
33+
import androidx.navigation.compose.NavHost
34+
import io.github.shinhyo.brba.app.ui.BrbaAppState
35+
import io.github.shinhyo.brba.feature.detail.navigaion.navigateToDetail
36+
import io.github.shinhyo.brba.feature.favorate.navigation.favoriteScreen
37+
import io.github.shinhyo.brba.feature.main.navigation.LIST_ROUTE
38+
import io.github.shinhyo.brba.feature.main.navigation.listScreen
39+
40+
@Composable
41+
fun MainScreen(appState: BrbaAppState) {
42+
Scaffold(
43+
contentWindowInsets = WindowInsets(0.dp),
44+
bottomBar = { BrBaNavigationBar(appState) }
45+
) { paddingValues ->
46+
val navController: NavHostController = appState.navController
47+
val navTabController: NavHostController = appState.navTabController
48+
NavHost(
49+
navController = navTabController,
50+
startDestination = LIST_ROUTE,
51+
modifier = Modifier.padding(paddingValues)
52+
) {
53+
listScreen(navController::navigateToDetail)
54+
favoriteScreen(navController::navigateToDetail)
55+
}
56+
}
57+
}
58+
59+
@Composable
60+
fun BrBaNavigationBar(appState: BrbaAppState) {
61+
val currentTabRoute = appState.currentTabDestination?.route
62+
NavigationBar(
63+
containerColor = MaterialTheme.colorScheme.background,
64+
modifier = Modifier
65+
.navigationBarsPadding()
66+
) {
67+
for (tab in Tab.entries) {
68+
NavigationBarItem(
69+
selected = currentTabRoute == tab.route,
70+
onClick = { appState.navigateTopDestination(tab) },
71+
icon = {
72+
Icon(
73+
painterResource(id = tab.icon),
74+
contentDescription = tab.label
75+
)
76+
},
77+
colors = NavigationBarItemDefaults.colors(
78+
indicatorColor = Color.Transparent,
79+
selectedIconColor = MaterialTheme.colorScheme.onPrimary,
80+
unselectedIconColor = Color.LightGray
81+
)
82+
)
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)