Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Develop #16

Open
wants to merge 22 commits into
base: main
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
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<activity
android:name=".app.MainActivity"
android:exported="true"
android:label="@string/title_activity_main"
android:theme="@style/Theme.MixDrinksTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
71 changes: 43 additions & 28 deletions app/src/main/java/org/mixdrinks/mixdrinks/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,59 @@ import org.koin.core.context.GlobalContext.startKoin
import org.koin.dsl.module
import org.mixdrinks.mixdrinks.app.RetrofitClient
import org.mixdrinks.mixdrinks.database.AppDatabase
import org.mixdrinks.mixdrinks.features.data.CocktailProvider
import org.mixdrinks.mixdrinks.features.data.GoodType
import org.mixdrinks.mixdrinks.features.data.MixDrinkService
import org.mixdrinks.mixdrinks.features.detail.ui.cocktail.DetailScreenCocktailViewModel
import org.mixdrinks.mixdrinks.features.detail.ui.good.DetailScreenGoodViewModel
import org.mixdrinks.mixdrinks.features.detail.ui.tool.DetailScreenToolViewModel
import org.mixdrinks.mixdrinks.features.detail.ui.goods.DetailScreenGoodsViewModel
import org.mixdrinks.mixdrinks.features.fetcher.Fetcher
import org.mixdrinks.mixdrinks.features.filter.ui.FilterScreenViewModel
import org.mixdrinks.mixdrinks.features.start.ui.StartScreenViewModel
import org.mixdrinks.mixdrinks.features.start.StartRepository
import org.mixdrinks.mixdrinks.features.start.filter.ui.main.FilterScreenViewModel
import org.mixdrinks.mixdrinks.features.start.filter.SelectedFilterStorage
import org.mixdrinks.mixdrinks.features.start.main.ui.StartScreenViewModel
import org.mixdrinks.mixdrinks.features.start.filter.FilterRepository
import org.mixdrinks.mixdrinks.features.start.filter.ui.search.FilterSearchScreenViewModel

class App : Application() {
override fun onCreate() {
super.onCreate()
override fun onCreate() {
super.onCreate()

val appModule = module {
val appModule = module {
single {
Room.databaseBuilder(
androidContext(),
AppDatabase::class.java,
"mix-drinks-database"
).build()
}
single<MixDrinkService> { RetrofitClient.retrofit.create(MixDrinkService::class.java) }

single {
Room.databaseBuilder(
androidContext(),
AppDatabase::class.java,
"mix-drinks-database"
).build()
}
single { Fetcher(get(), get()) }

single<CocktailProvider> { RetrofitClient.retrofit.create(CocktailProvider::class.java) }
viewModel { StartScreenViewModel(get()) }
viewModel { (id: Int) -> DetailScreenCocktailViewModel(cocktailId = id, get()) }
viewModel { (id: Int) -> DetailScreenGoodViewModel(goodId = id, get())}
viewModel { (id: Int) -> DetailScreenToolViewModel(toolId = id, get()) }
// Repository
single { StartRepository(get(), get()) }
single { FilterRepository(get(), get()) }

viewModel { FilterScreenViewModel(get()) }
single { SelectedFilterStorage() }

single { Fetcher(get(), get()) }
}
viewModel { StartScreenViewModel(get(), get()) }
viewModel { (id: Int) -> DetailScreenCocktailViewModel(cocktailId = id, get(), get()) }
viewModel { (goodType: GoodType) -> DetailScreenGoodsViewModel(goodType = goodType, get()) }

viewModel { FilterScreenViewModel(get(), get()) }
viewModel { (groupId: Int) ->
FilterSearchScreenViewModel(
groupId = groupId,
get(),
get()
)
}
}

startKoin {
androidLogger()
androidContext(applicationContext)
modules(appModule)
startKoin {
androidLogger()
androidContext(applicationContext)
modules(appModule)
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ class MainActivity : ComponentActivity() {
}



86 changes: 39 additions & 47 deletions app/src/main/java/org/mixdrinks/mixdrinks/app/MixDrinksApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,70 @@ import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import org.koin.androidx.compose.get
import org.mixdrinks.mixdrinks.features.fetcher.Fetcher
import org.mixdrinks.mixdrinks.app.ui.theme.MixDrinksTheme
import org.mixdrinks.mixdrinks.features.common.ui.NotFoundScreen
import org.mixdrinks.mixdrinks.features.data.GoodType
import org.mixdrinks.mixdrinks.features.detail.ui.cocktail.DetailScreen
import org.mixdrinks.mixdrinks.features.detail.ui.good.DetailScreenGood
import org.mixdrinks.mixdrinks.features.detail.ui.tool.DetailScreenTool
import org.mixdrinks.mixdrinks.features.filter.ui.FilterScreen
import org.mixdrinks.mixdrinks.features.start.ui.StartScreen
import org.mixdrinks.mixdrinks.features.detail.ui.goods.DetailScreenGoods
import org.mixdrinks.mixdrinks.features.start.filter.ui.main.FilterScreen
import org.mixdrinks.mixdrinks.features.start.filter.ui.search.FilterSearchScreen
import org.mixdrinks.mixdrinks.features.start.main.ui.StartScreen

@Suppress("LongMethod")
@Composable
fun MixDrinksApp(modifier: Modifier = Modifier) {
Fetcher(get(), get())

MixDrinksTheme {
val navController = rememberNavController()
NavHost(
navController = navController,
startDestination = Routes.start
navController = navController, startDestination = Routes.start
) {
composable(Routes.start) {
StartScreen(
modifier = modifier,
StartScreen(modifier = modifier,
onNavigateToDetail = { navController.navigate("${Routes.cocktail}/$it") },
onNavigateToFilter = { navController.navigate(Routes.filter) },
)
onNavigateToStart = { navController.navigate(Routes.start) })
}
composable("${Routes.cocktail}/{${Routes.cocktailId}}") {
backStackEntry ->
composable("${Routes.cocktail}/{${Routes.cocktailId}}") { backStackEntry ->
val cocktailId = backStackEntry.arguments?.getString(Routes.cocktailId)
cocktailId?.toInt()?.let {
DetailScreen(
modifier = modifier,
cocktailId = it,
onNavigateToDetailGood = { navController.navigate("${Routes.good}/$it")},
onNavigateToDetailTool = { navController.navigate("${Routes.tool}/$it")},
onBack = { navController.popBackStack() }
)
cocktailId?.toInt()?.let { id ->
DetailScreen(modifier = modifier,
cocktailId = id,
onNavigateToStart = { navController.navigate(Routes.start) },
onNavigateToDetailGood = { goodType ->
navController.navigate("${Routes.good}/${goodType.id}/${goodType.type}")
},
onBack = { navController.popBackStack() })
}
}
composable("${Routes.good}/{${Routes.goodId}}") {
backStackEntry ->
composable("${Routes.good}/{${Routes.goodId}}/{${Routes.goodType}}") { backStackEntry ->
val goodId = backStackEntry.arguments?.getString(Routes.goodId)
goodId?.toInt()?.let {
DetailScreenGood(
val goodType = backStackEntry.arguments?.getString(Routes.goodType)

if (goodId != null && goodType != null)
DetailScreenGoods(
modifier = modifier,
goodId = it,
onBack = { navController.popBackStack() }
)
}
goodType = GoodType(id = goodId.toInt(), GoodType.Type.fromString(goodType)),
onBack = { navController.popBackStack() })
}
composable("${Routes.tool}/{${Routes.toolId}}") {
backStackEntry ->
val toolId = backStackEntry.arguments?.getString(Routes.toolId)
toolId?.toInt()?.let {
DetailScreenTool(
composable(Routes.filter) {
FilterScreen(modifier = modifier,
onNavigateToStart = { navController.navigate(Routes.start) },
onNavigateToFilterSearch = { navController.navigate("${Routes.filterSearch}/${it}") }
)
}
composable("${Routes.filterSearch}/{${Routes.groupFilterId}}") { backStackEntry ->
val groupId = backStackEntry.arguments?.getString(Routes.groupFilterId)
groupId?.toInt()?.let {
FilterSearchScreen(
modifier = modifier,
toolId = it,
onBack = { navController.popBackStack() }
groupId = it,
onNavigateToFilter = { navController.navigate(Routes.filter) },
)
}
}
composable(Routes.filter) {
FilterScreen(
modifier = modifier,
)
}
composable(Routes.notFound) {
NotFoundScreen(
modifier = modifier,
onNavigateToStart = { navController.navigate(Routes.start) }
)
NotFoundScreen(modifier = modifier,
onNavigateToStart = { navController.navigate(Routes.start) })
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import retrofit2.Retrofit
import java.util.concurrent.TimeUnit

object RetrofitClient {
private const val BASE_URL = "https://api.mixdrinks.org/v2/"
private const val BASE_URL = "https://api.mixdrinks.org/"
private const val TIME_OUT: Long = 60

private val logging = HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/org/mixdrinks/mixdrinks/app/Routes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ object Routes {
const val notFound = "not_found"

const val cocktail = "cocktail"
const val cocktailId = "cocktailId"

const val tool = "tool"
const val toolId = "toolId"
const val cocktailId = "cocktail_id"

const val good = "good"
const val goodId = "goodId"
const val goodId = "good_id"
const val goodType = "good_type"

const val filterSearch = "filter_search"
const val groupFilterId = "group_filter_id"

}

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ import androidx.compose.ui.graphics.Color
val Green700 = Color(0XFF2B4718)
val Green = Color(0XFF4E6640)
val Black = Color(0XFF181818)
val GreenAlfa = Color(0x322B4718)

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private val DarkColorPalette = darkColors(
private val LightColorPalette = lightColors(
primary = Green700,
primaryVariant = Green,
secondary = Black
secondary = Black,

/* Other default colors to override
background = Color.White,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ val Typography = Typography(
fontSize = 14.sp,
color = Green700
),
h5 = TextStyle(
fontSize = 12.sp,
fontWeight = FontWeight.W400,
lineHeight = 18.sp,
// letterSpacing =
),
button = TextStyle(
fontSize = 14.sp,
color = Color.White,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.mixdrinks.mixdrinks.database.dao


import android.util.Log
import androidx.room.ColumnInfo
import androidx.room.Dao
import androidx.room.Embedded
Expand All @@ -22,12 +21,14 @@ import org.mixdrinks.mixdrinks.database.entities.CocktailToGoodRelation
import org.mixdrinks.mixdrinks.database.entities.CocktailToTag
import org.mixdrinks.mixdrinks.database.entities.CocktailToTaste
import org.mixdrinks.mixdrinks.database.entities.CocktailToTool
import org.mixdrinks.mixdrinks.database.entities.FilterWithCocktailIds
import org.mixdrinks.mixdrinks.database.entities.Glassware
import org.mixdrinks.mixdrinks.database.entities.Good
import org.mixdrinks.mixdrinks.database.entities.Tag
import org.mixdrinks.mixdrinks.database.entities.Taste
import org.mixdrinks.mixdrinks.database.entities.Tool
import org.mixdrinks.mixdrinks.features.data.CocktailFull
import org.mixdrinks.mixdrinks.features.data.SelectedFilter

@Dao
interface CocktailDao {
Expand Down Expand Up @@ -59,7 +60,8 @@ interface CocktailDao {
suspend fun getById(id: Int): CocktailSnapshotDatabase

@Query("SELECT cocktail_id, name FROM cocktails")
suspend fun getAllShortCocktail(): List<CocktailShort>
suspend fun getAllCocktailShort(): List<Cocktails>

}

data class CocktailSnapshotDatabase(
Expand Down Expand Up @@ -111,7 +113,6 @@ data class CocktailSnapshotDatabase(
}

fun toCocktailFull(): CocktailFull {
Log.d("good", goods.size.toString() + goods.toString())
return CocktailFull(
id = CocktailId(cocktail.cocktailId),
name = cocktail.name,
Expand All @@ -122,9 +123,11 @@ data class CocktailSnapshotDatabase(
id = GoodId(good.goodId),
name = good.name,
amount = goodsUnit.filter {
it.goodId == good.goodId }.first().amount,
it.goodId == good.goodId
}.first().amount,
unit = goodsUnit.filter {
it.goodId == good.goodId }.first().unit,
it.goodId == good.goodId
}.first().unit,
)
},
tools = tools.map { tool ->
Expand All @@ -145,13 +148,35 @@ data class CocktailSnapshotDatabase(
name = taste.name
)
},
glassware = CocktailFull.Glassware(id = GlasswareId(glassware.glasswareId), name = glassware.name)
glassware = CocktailFull.Glassware(
id = GlasswareId(glassware.glasswareId),
name = glassware.name
)
)
}
}

data class CocktailShort(
data class Cocktails(
@ColumnInfo(name = "cocktail_id")
val cocktailId: Int,
val name: String,
@Relation(
parentColumn = "cocktail_id",
entityColumn = "cocktail_id",
)
val filters: List<FilterWithCocktailIds>
) {
fun toCocktailsWithFilters(): CocktailsWithFilters {
return CocktailsWithFilters(
cocktailId = cocktailId,
name = name,
filters = filters.map { SelectedFilter(it.filterId, it.filterGroupId) }
)
}
}

data class CocktailsWithFilters(
val cocktailId: Int,
val name: String,
val filters: List<SelectedFilter>
)
Loading