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

Set up KMP compose resources #121

Merged
merged 11 commits into from
Aug 26, 2024
9 changes: 8 additions & 1 deletion appDesktop/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
alias(libs.plugins.jvm)
alias(libs.plugins.compose)
Expand All @@ -12,6 +14,11 @@ dependencies {

compose.desktop {
application {
mainClass = "NotflixApplicationKt"
mainClass = "com.vickbt.notflix.MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "Notflix"
packageVersion = "1.0.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fun main() {
koin = initKoin(enableNetworkLogs = true).koin

return application {
Thread.currentThread().contextClassLoader = this.javaClass.classLoader
MainWindow(applicationScope = this)
}
}
22 changes: 11 additions & 11 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ kotlin {
jvm("desktop")

sourceSets {
sourceSets["commonMain"].dependencies {
commonMain.dependencies {
api(compose.runtime)
api(compose.foundation)
api(compose.material3)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
api(compose.components.resources)
api(compose.materialIconsExtended)

Expand Down Expand Up @@ -65,28 +64,23 @@ kotlin {
// implementation(libs.material.windowSizeClass)
}

/*sourceSets["commonTest"].dependencies {
commonTest.dependencies {
implementation(kotlin("test"))
implementation(libs.turbine)
implementation(libs.ktor.mock)
implementation(libs.kotlinX.coroutines.test)
implementation(libs.multiplatformSettings.test)
}*/
}

sourceSets["androidMain"].dependencies {
androidMain.dependencies {
implementation(libs.ktor.android)
implementation(libs.sqlDelight.android)
}

// sourceSets["androidUnitTest"].dependencies {}

sourceSets["iosMain"].dependencies {
iosMain.dependencies {
implementation(libs.ktor.darwin)
implementation(libs.sqlDelight.native)
}

sourceSets["iosTest"].dependencies {}

sourceSets["desktopMain"].dependencies {
implementation(libs.ktor.java)
implementation(libs.sqlDelight.jvm)
Expand Down Expand Up @@ -134,3 +128,9 @@ sqldelight {
}
}
}

compose.resources {
publicResClass = true
packageOfResClass = "com.vickbt.shared.resources"
generateResClass = always
}
Binary file not shown.
64 changes: 64 additions & 0 deletions shared/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="title_home">Home</string>
<string name="title_search">Search</string>
<string name="title_favorites">Favorites</string>
<string name="title_settings">Settings</string>
<string name="title_details">Details</string>

<string name="trending_movies">Trending Movies</string>
<string name="popular_movies">Popular Movies</string>
<string name="upcoming_movies">Upcoming Movies</string>
<string name="view_all">View All</string>

<string name="share">Share</string>

<!--Preference Titles-->
<string name="title_personalisation">Personalisation</string>
<string name="title_extras">Extras</string>

<!--Preference Headers-->
<string name="change_theme">Change theme</string>
<string name="change_language">Change language</string>
<string name="change_image_quality">Change image quality</string>
<string name="report_bug">Report Bug</string>
<string name="report_bug_description">Report bug or request feature</string>
<string name="source_code">Source Code</string>
<string name="source_code_description">View app source code</string>

<string name="light_theme">Light theme</string>
<string name="dark_theme">Dark theme</string>
<string name="system_default">System default</string>

<string name="popularity">Popularity</string>
<string name="overview">Overview</string>
<string name="cast">Cast</string>
<string name="trailer">Trailer</string>
<string name="similar_movies">Similar Movies</string>

<string name="def">Default</string>
<string name="language_eg" translatable="false">No Russian</string>

<string name="cancel">Cancel</string>
<string name="movie_poster">Movie poster</string>
<string name="unknown_movie">Unknown movie</string>
<string name="rating">Rating</string>
<string name="unknown_actor">Unknown Actor</string>
<string name="unknown_character">Unknown character</string>
<string name="back">Back</string>
<string name="close_search">Close Search</string>

<string-array name="themes">
<item>Light theme</item>
<item>Dark theme</item>
<item>System default</item>
</string-array>

<string-array name="image_qualities">
<item>High Quality</item>
<item>Low Quality</item>
</string-array>



</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import com.vickbt.shared.ui.navigation.NavigationItem
import com.vickbt.shared.ui.theme.Gray
import org.jetbrains.compose.resources.stringResource

@Composable
fun BottomNavBar(
Expand All @@ -32,12 +33,19 @@ fun BottomNavBar(

NavigationBarItem(
icon = {
Icon(
imageVector = item.icon!!,
contentDescription = item.title
item.icon?.let {
Icon(
imageVector = item.icon,
contentDescription = stringResource(item.title)
)
}
},
label = {
Text(
text = stringResource(item.title),
style = MaterialTheme.typography.labelSmall
)
},
label = { Text(text = item.title) },
alwaysShowLabel = true,
colors = NavigationBarItemDefaults.colors(
selectedIconColor = MaterialTheme.colorScheme.primary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fun ExpandableText(
modifier: Modifier = Modifier,
minimizedMaxLines: Int = 1,
fontSize: TextUnit = 14.sp,
style: TextStyle = MaterialTheme.typography.bodySmall,
style: TextStyle = MaterialTheme.typography.bodyMedium,
textAlign: TextAlign = TextAlign.Start,
color: Color = Color.LightGray.copy(alpha = .85f),
) {
Expand All @@ -42,7 +42,6 @@ fun ExpandableText(
val seeMoreSizeState = remember { mutableStateOf<IntSize?>(null) }
val seeMoreOffsetState = remember { mutableStateOf<Offset?>(null) }

// getting raw values for smart cast
val textLayoutResult = textLayoutResultState.value
val seeMoreSize = seeMoreSizeState.value
val seeMoreOffset = seeMoreOffsetState.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
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 Down Expand Up @@ -123,12 +123,12 @@ fun MovieCardLandscape(
)

movie.releaseDate?.let {
Divider(
HorizontalDivider(
modifier = Modifier
.padding(horizontal = 4.dp)
.width(1.dp)
.height(13.dp),
color = dominantSubTextColor,
color = dominantSubTextColor
)

Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fun MovieCardPortraitCompact(
Text(
modifier = Modifier.width(145.dp),
text = movie.title ?: "Unknown movie",
style = MaterialTheme.typography.labelMedium,
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
fontSize = 14.sp,
maxLines = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Star
import androidx.compose.material3.Divider
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.vickbt.shared.resources.Res
import com.vickbt.shared.resources.popularity
import com.vickbt.shared.resources.rating
import com.vickbt.shared.ui.theme.Golden
import org.jetbrains.compose.resources.stringResource

@Composable
fun MovieRatingSection(popularity: String?, voteAverage: String?) {
Expand All @@ -39,21 +43,21 @@ fun MovieRatingSection(popularity: String?, voteAverage: String?) {
Text(
modifier = Modifier,
text = if (popularity.isNullOrEmpty()) "N/A" else popularity,
style = MaterialTheme.typography.titleMedium,
style = MaterialTheme.typography.titleLarge,
fontSize = 42.sp,
color = MaterialTheme.colorScheme.onSurface,
)

Text(
text = "Popularity",
text = stringResource(Res.string.popularity),
style = MaterialTheme.typography.titleMedium,
fontSize = 18.sp,
color = MaterialTheme.colorScheme.onSurface,
)
}
//endregion

Divider(
VerticalDivider(
modifier = Modifier
.fillMaxHeight()
.width(2.dp),
Expand All @@ -70,7 +74,7 @@ fun MovieRatingSection(popularity: String?, voteAverage: String?) {
modifier = Modifier.size(48.dp),
imageVector = Icons.Rounded.Star,
tint = Golden,
contentDescription = "Rating"
contentDescription = stringResource(Res.string.rating)
)

Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import com.vickbt.shared.ui.navigation.NavigationItem
import com.vickbt.shared.ui.theme.Gray
import com.vickbt.shared.ui.theme.PrimaryColor
import org.jetbrains.compose.resources.stringResource

@Composable
fun NavRailBar(
Expand All @@ -25,13 +26,6 @@ fun NavRailBar(
NavigationRail(
modifier = modifier.fillMaxHeight().alpha(0.95F),
containerColor = MaterialTheme.colorScheme.surface,
header = {
/*Icon(
modifier = Modifier.size(42.dp),
painter = painterResource("n_logo.png"),
contentDescription = "Logo"
)*/
},
contentColor = PrimaryColor
) {
navigationItems.forEach { item ->
Expand All @@ -45,11 +39,16 @@ fun NavRailBar(
item.icon?.let {
Icon(
imageVector = it,
contentDescription = item.title
contentDescription = stringResource(item.title)
)
}
},
label = { Text(text = item.title) },
label = {
Text(
text = stringResource(item.title),
style = MaterialTheme.typography.labelSmall
)
},
colors = NavigationRailItemDefaults.colors(
selectedIconColor = PrimaryColor,
unselectedIconColor = Gray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ package com.vickbt.shared.ui.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.sp
import androidx.compose.ui.unit.dp

@Composable
fun SectionSeparator(
modifier: Modifier = Modifier,
sectionTitle: String
) {
Row(
modifier = modifier,
modifier = modifier.padding(start = 16.dp, end = 16.dp, top = 16.dp, bottom = 8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
) {
Text(
modifier = Modifier,
text = sectionTitle,
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.titleMedium,
fontSize = 20.sp,
style = MaterialTheme.typography.titleLarge,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ArrowBack
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
import androidx.compose.material.icons.rounded.Favorite
import androidx.compose.material.icons.rounded.FavoriteBorder
import androidx.compose.material.icons.rounded.Share
Expand Down Expand Up @@ -124,7 +124,7 @@ fun DetailsAppBar(
modifier = Modifier,
text = movieDetails?.runtime?.getMovieDuration() ?: "",
color = dominantTextColor,
style = MaterialTheme.typography.labelMedium,
style = MaterialTheme.typography.bodyMedium,
fontSize = 14.sp
)
}
Expand All @@ -147,7 +147,7 @@ fun DetailsAppBar(
navigationIcon = {
IconButton(onClick = { onNavigationIconClick() }) {
Icon(
imageVector = Icons.Rounded.ArrowBack,
imageVector = Icons.AutoMirrored.Rounded.ArrowBack,
contentDescription = "Back",
tint = MaterialTheme.colorScheme.onSurface
)
Expand Down
Loading
Loading