Skip to content

Commit f237058

Browse files
committed
add compose
1 parent 05e637b commit f237058

File tree

8 files changed

+198
-7
lines changed

8 files changed

+198
-7
lines changed

app/build.gradle.kts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ android {
6969
}
7070
signingConfig = signingConfigs.getByName("debug-key")
7171
}
72-
create("staging") {
72+
create("beta") {
7373
isDebuggable = true
7474
isMinifyEnabled = true
7575
isShrinkResources = true
@@ -131,6 +131,14 @@ android {
131131
// https://developer.android.com/topic/libraries/data-binding
132132
buildFeatures {
133133
dataBinding = true
134+
compose = true
135+
}
136+
composeOptions {
137+
kotlinCompilerExtensionVersion = "1.3.0"
138+
}
139+
lint {
140+
checkReleaseBuilds = false
141+
abortOnError = false
134142
}
135143
}
136144

@@ -145,6 +153,33 @@ dependencies {
145153
implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.10")
146154
implementation("androidx.multidex:multidex:2.0.1")
147155

156+
// compose
157+
// https://developer.android.com/jetpack/compose/interop/adding
158+
// Integration with activities
159+
implementation("androidx.activity:activity-compose:1.6.0")
160+
// Animations
161+
implementation("androidx.compose.animation:animation:1.2.1")
162+
// Integration with ViewModels
163+
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1")
164+
// https://developer.android.com/jetpack/compose/setup
165+
implementation("androidx.compose.ui:ui:1.2.1")
166+
// Tooling support (Previews, etc.)
167+
implementation("androidx.compose.ui:ui-tooling:1.2.1")
168+
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
169+
implementation("androidx.compose.foundation:foundation:1.2.1")
170+
// Material Design
171+
implementation("androidx.compose.material:material:1.2.1")
172+
implementation("androidx.compose.material3:material3:1.0.0-beta03")
173+
// Material design icons
174+
implementation("androidx.compose.material:material-icons-core:1.2.1")
175+
implementation("androidx.compose.material:material-icons-extended:1.2.1")
176+
// Integration with observables
177+
implementation("androidx.compose.runtime:runtime-livedata:1.2.1")
178+
implementation("androidx.compose.runtime:runtime-rxjava2:1.2.1")
179+
// UI Tests
180+
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.2.1")
181+
debugImplementation("androidx.compose.ui:ui-test-manifest:1.2.1")
182+
148183
// List of KTX extensions
149184
// https://developer.android.com/kotlin/ktx/extensions-list
150185
implementation("androidx.core:core-ktx:1.9.0")

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
android:usesCleartextTraffic="true">
2626

2727
<activity
28-
android:name="com.example.moviedb.ui.screen.main.MainActivity"
28+
android:name="com.example.moviedb.compose.main.ComposeActivity"
2929
android:configChanges="orientation|screenSize"
3030
android:exported="true"
3131
android:theme="@style/Theme.MyApplication.NoActionBar">
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.example.moviedb.compose.main
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.compose.foundation.layout.fillMaxSize
7+
import androidx.compose.material3.MaterialTheme
8+
import androidx.compose.material3.Surface
9+
import androidx.compose.material3.Text
10+
import androidx.compose.runtime.Composable
11+
import androidx.compose.ui.Modifier
12+
import androidx.compose.ui.tooling.preview.Preview
13+
import com.example.moviedb.compose.theme.ComposeAppTheme
14+
15+
class ComposeActivity : ComponentActivity() {
16+
override fun onCreate(savedInstanceState: Bundle?) {
17+
super.onCreate(savedInstanceState)
18+
setContent {
19+
ComposeAppTheme {
20+
// A surface container using the 'background' color from the theme
21+
Surface(
22+
modifier = Modifier.fillMaxSize(),
23+
color = MaterialTheme.colorScheme.background
24+
) {
25+
Greeting("Android")
26+
}
27+
}
28+
}
29+
}
30+
}
31+
32+
@Composable
33+
fun Greeting(name: String) {
34+
Text(text = "Hello $name!")
35+
}
36+
37+
@Preview(showBackground = true)
38+
@Composable
39+
fun DefaultPreview() {
40+
ComposeAppTheme {
41+
Greeting("Android")
42+
}
43+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.example.moviedb.compose.theme
2+
3+
import androidx.compose.ui.graphics.Color
4+
5+
val Purple80 = Color(0xFFD0BCFF)
6+
val PurpleGrey80 = Color(0xFFCCC2DC)
7+
val Pink80 = Color(0xFFEFB8C8)
8+
9+
val Purple40 = Color(0xFF6650a4)
10+
val PurpleGrey40 = Color(0xFF625b71)
11+
val Pink40 = Color(0xFF7D5260)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.example.moviedb.compose.theme
2+
3+
import android.app.Activity
4+
import android.os.Build
5+
import androidx.compose.foundation.isSystemInDarkTheme
6+
import androidx.compose.material3.MaterialTheme
7+
import androidx.compose.material3.darkColorScheme
8+
import androidx.compose.material3.dynamicDarkColorScheme
9+
import androidx.compose.material3.dynamicLightColorScheme
10+
import androidx.compose.material3.lightColorScheme
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.runtime.SideEffect
13+
import androidx.compose.ui.graphics.toArgb
14+
import androidx.compose.ui.platform.LocalContext
15+
import androidx.compose.ui.platform.LocalView
16+
import androidx.core.view.ViewCompat
17+
18+
private val DarkColorScheme = darkColorScheme(
19+
primary = Purple80,
20+
secondary = PurpleGrey80,
21+
tertiary = Pink80
22+
)
23+
24+
private val LightColorScheme = lightColorScheme(
25+
primary = Purple40,
26+
secondary = PurpleGrey40,
27+
tertiary = Pink40
28+
29+
/* Other default colors to override
30+
background = Color(0xFFFFFBFE),
31+
surface = Color(0xFFFFFBFE),
32+
onPrimary = Color.White,
33+
onSecondary = Color.White,
34+
onTertiary = Color.White,
35+
onBackground = Color(0xFF1C1B1F),
36+
onSurface = Color(0xFF1C1B1F),
37+
*/
38+
)
39+
40+
@Composable
41+
fun ComposeAppTheme(
42+
darkTheme: Boolean = isSystemInDarkTheme(),
43+
// Dynamic color is available on Android 12+
44+
dynamicColor: Boolean = true,
45+
content: @Composable () -> Unit
46+
) {
47+
val colorScheme = when {
48+
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
49+
val context = LocalContext.current
50+
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
51+
}
52+
darkTheme -> DarkColorScheme
53+
else -> LightColorScheme
54+
}
55+
val view = LocalView.current
56+
if (!view.isInEditMode) {
57+
SideEffect {
58+
(view.context as Activity).window.statusBarColor = colorScheme.primary.toArgb()
59+
ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme
60+
}
61+
}
62+
63+
MaterialTheme(
64+
colorScheme = colorScheme,
65+
typography = Typography,
66+
content = content
67+
)
68+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.example.moviedb.compose.theme
2+
3+
import androidx.compose.material3.Typography
4+
import androidx.compose.ui.text.TextStyle
5+
import androidx.compose.ui.text.font.FontFamily
6+
import androidx.compose.ui.text.font.FontWeight
7+
import androidx.compose.ui.unit.sp
8+
9+
// Set of Material typography styles to start with
10+
val Typography = Typography(
11+
bodyLarge = TextStyle(
12+
fontFamily = FontFamily.Default,
13+
fontWeight = FontWeight.Normal,
14+
fontSize = 16.sp,
15+
lineHeight = 24.sp,
16+
letterSpacing = 0.5.sp
17+
)
18+
/* Other default text styles to override
19+
titleLarge = TextStyle(
20+
fontFamily = FontFamily.Default,
21+
fontWeight = FontWeight.Normal,
22+
fontSize = 22.sp,
23+
lineHeight = 28.sp,
24+
letterSpacing = 0.sp
25+
),
26+
labelSmall = TextStyle(
27+
fontFamily = FontFamily.Default,
28+
fontWeight = FontWeight.Medium,
29+
fontSize = 11.sp,
30+
lineHeight = 16.sp,
31+
letterSpacing = 0.5.sp
32+
)
33+
*/
34+
)

app/src/main/java/com/example/moviedb/ui/screen/moviedetail/MovieDetailViewModel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class MovieDetailViewModel @Inject constructor(
1919
private val userRepository: UserRepository
2020
) : BaseViewModel() {
2121

22-
val movie = SingleLiveData<Movie>()
22+
val movie = SingleLiveData<Movie?>()
2323
private val _castList = MutableStateFlow<List<Cast>>(emptyList())
2424
val castList = _castList.asStateFlow()
2525

@@ -29,9 +29,9 @@ class MovieDetailViewModel @Inject constructor(
2929
val favoriteMovie = userRepository.getMovieLocal(id)
3030
withContext(Dispatchers.Main) {
3131
if (favoriteMovie?.isFavorite == true) {
32-
val newMoview = movie.value
33-
newMoview?.isFavorite = true
34-
movie.value = newMoview
32+
val newMovie = movie.value
33+
newMovie?.isFavorite = true
34+
movie.value = newMovie
3535
} else {
3636
movie.value?.isFavorite = false
3737
}

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66
dependencies {
77
classpath("com.android.tools.build:gradle:7.3.0")
8-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
8+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10")
99
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.5.2")
1010
classpath("com.google.dagger:hilt-android-gradle-plugin:2.42")
1111
// classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Libs.kotlinVersion}")

0 commit comments

Comments
 (0)