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

Favorite Screen #7

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions .idea/deploymentTargetDropDown.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/encodings.xml

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

8 changes: 8 additions & 0 deletions .idea/misc.xml

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

84 changes: 78 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'

id 'com.google.devtools.ksp' version '1.6.10-1.0.4'
id 'kotlin-parcelize'
}

android {
compileSdkVersion 32
compileSdk 32
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.example.mensfashion"
minSdkVersion 23
targetSdkVersion 32
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
versionName "1.0.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}

buildTypes {
Expand All @@ -34,12 +39,36 @@ android {
jvmTarget = '1.8'
}
buildFeatures {
compose true
dataBinding true
viewBinding true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}

applicationVariants.all { variant ->
kotlin.sourceSets {
getByName(variant.name) {
kotlin.srcDir("build/generated/ksp/${variant.name}/kotlin")
}
}
}
}

dependencies {
// Kotlin extensions
implementation 'androidx.core:core-ktx:1.8.0'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

// Testing
testImplementation 'junit:junit:4.13.2'

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.8.0'
Expand All @@ -48,9 +77,52 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.security:security-crypto-ktx:1.1.0-alpha03'
testImplementation 'junit:junit:'

androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"

// Compose
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.compose.ui:ui:$compose_version"
implementation 'androidx.activity:activity-compose:1.4.0'
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.activity:activity-compose:1.6.0-alpha03"
implementation "androidx.compose.material:material-icons-extended:$compose_version"
implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"
implementation "androidx.navigation:navigation-compose:2.5.0-rc01"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"

// Material
implementation "androidx.compose.material:material:$compose_version"
implementation 'com.google.android.material:material:1.4.0'

// Hilt for DI
implementation "com.google.dagger:hilt-android:2.38.1"
kapt "com.google.dagger:hilt-compiler:2.38.1"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt 'androidx.hilt:hilt-compiler:1.0.0'
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-beta01'
// Navigation made easier
implementation 'io.github.raamcosta.compose-destinations:core:1.5.9-beta'
ksp 'io.github.raamcosta.compose-destinations:ksp:1.5.9-beta'

// Coil for loading images
implementation("io.coil-kt:coil-compose:2.1.0")

// System UI Controller for Jetpack Compose
implementation "com.google.accompanist:accompanist-systemuicontroller:0.24.10-beta"

// Timber for logging
implementation 'com.jakewharton.timber:timber:5.0.1'

// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1'


implementation "androidx.security:security-crypto:1.1.0-alpha01"
implementation "com.google.code.gson:gson:2.9.0"

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mensfashion">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".App"
android:allowBackup="true"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/example/mensfashion/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class App : Application() , ViewModelStoreOwner, Configuration.Provider {
override fun onCreate() {
super.onCreate()
instance = this
initTimber()
pref = SecureSharedPreferences.initPreferences(this)
if (BuildConfig.DEBUG) {
// to just log when app is debug
Expand All @@ -36,6 +37,9 @@ class App : Application() , ViewModelStoreOwner, Configuration.Provider {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) // prevent dark mode
}

private fun initTimber() {
Timber.plant(Timber.DebugTree())
}

companion object {
private val appViewModelStore: ViewModelStore by lazy {
Expand Down
40 changes: 40 additions & 0 deletions app/src/main/java/com/example/mensfashion/core/ComposeExtension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.mensfashion.core

import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.flowWithLifecycle
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

@Composable
fun <T> rememberFlow(
flow: Flow<T>,
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current
): Flow<T> {
return remember(
key1 = flow,
key2 = lifecycleOwner
) { flow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED) }
}

@Composable
fun <T : R, R> Flow<T>.collectAsStateLifecycleAware(
initial: R,
context: CoroutineContext = EmptyCoroutineContext
): State<R> {
val lifecycleAwareFlow = rememberFlow(flow = this)
return lifecycleAwareFlow.collectAsState(initial = initial, context = context)
}

@Suppress("StateFlowValueCalledInComposition")
@Composable
fun <T> StateFlow<T>.collectAsStateLifecycleAware(
context: CoroutineContext = EmptyCoroutineContext
): State<T> = collectAsStateLifecycleAware(initial = value, context = context)
5 changes: 5 additions & 0 deletions app/src/main/java/com/example/mensfashion/core/UiEvents.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.mensfashion.core

sealed class UiEvents {
data class SnackbarEvent(val message: String) : UiEvents()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.mensfashion.core.ui.theme


import androidx.compose.ui.graphics.Color

val YellowMain = Color(0xFFF0B428)
val DarkBlue = Color(0xFF181B37)
val MainWhiteColor = Color(0xFFF4F4F4)
val GrayColor = Color(0xFFBBB2A7)
11 changes: 11 additions & 0 deletions app/src/main/java/com/example/mensfashion/core/ui/theme/Shape.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.mensfashion.core.ui.theme

import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Shapes
import androidx.compose.ui.unit.dp

val Shapes = Shapes(
small = RoundedCornerShape(4.dp),
medium = RoundedCornerShape(4.dp),
large = RoundedCornerShape(0.dp)
)
48 changes: 48 additions & 0 deletions app/src/main/java/com/example/mensfashion/core/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.mensfashion.core.ui.theme


import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import com.google.accompanist.systemuicontroller.rememberSystemUiController

private val DarkColorPalette = darkColors(
primary = YellowMain,
primaryVariant = MainWhiteColor,
secondary = GrayColor.copy(alpha = 0.3f),
onSecondary = MainWhiteColor
)

private val LightColorPalette = lightColors(
primary = DarkBlue,
primaryVariant = MainWhiteColor,
secondary = GrayColor
)

@Composable
fun MenFashionTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
val colors = if (darkTheme) {
DarkColorPalette
} else {
LightColorPalette
}

val systemUiController = rememberSystemUiController()

SideEffect {
systemUiController.setSystemBarsColor(
color = if (darkTheme) DarkBlue else MainWhiteColor
)
}

MaterialTheme(
colors = colors,
typography = Typography,
shapes = Shapes,
content = content
)
}
40 changes: 40 additions & 0 deletions app/src/main/java/com/example/mensfashion/core/ui/theme/Type.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.mensfashion.core.ui.theme

import androidx.compose.material.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import com.example.mensfashion.R

val poppins = FontFamily(
Font(R.font.poppins_light, FontWeight.Light),
Font(R.font.poppins_regular, FontWeight.Normal),
Font(R.font.poppins_medium, FontWeight.Medium),
Font(R.font.poppins_semibold, FontWeight.SemiBold),
Font(R.font.poppin_bold, FontWeight.Bold)
)

val Typography = Typography(
body1 = TextStyle(
fontFamily = poppins,
fontWeight = FontWeight.Normal,
fontSize = 16.sp
),
body2 = TextStyle(
fontFamily = poppins,
fontWeight = FontWeight.Normal,
fontSize = 12.sp
),
h1 = TextStyle(
fontFamily = poppins,
fontWeight = FontWeight.Bold,
fontSize = 30.sp
),
h2 = TextStyle(
fontFamily = poppins,
fontWeight = FontWeight.Medium,
fontSize = 24.sp
)
)
27 changes: 27 additions & 0 deletions app/src/main/java/com/example/mensfashion/di/FavoriteModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.mensfashion.di

import com.example.mensfashion.favorite.data.remote.FavoriteService
import com.example.mensfashion.favorite.data.repository.FavoriteRepositoryImpl
import com.example.mensfashion.favorite.domain.repository.FavoriteRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton


@Module
@InstallIn(SingletonComponent::class)
object FavoriteModule {

@Provides
@Singleton
fun provideFavoriteService(
) = FavoriteService()

@Provides
@Singleton
fun provideFavoriteRepository(favoriteService: FavoriteService): FavoriteRepository {
return FavoriteRepositoryImpl(favoriteService)
}
}
Loading