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

Product edit #5

Merged
merged 7 commits into from
Nov 12, 2023
Merged
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: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize"
android:label="@string/app_name"
android:theme="@style/Theme.TheBeerCounter">
<intent-filter>
Expand Down
10 changes: 5 additions & 5 deletions buildSrc/src/main/java/BuildValues.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import org.gradle.api.JavaVersion
* Created by MD on 18.10.23.
*/
object BuildValues {
val minSdk = 23
val targetSdk = 33
val compileSdk = 33
const val minSdk = 23
const val targetSdk = 33
const val compileSdk = 33

val javaVersion : JavaVersion = JavaVersion.VERSION_1_8
val jvmTarget = "1.8"
val kotlinCompilerExtensionVersion = "1.2.0"
const val jvmTarget = "1.8"
const val kotlinCompilerExtensionVersion = "1.2.0"
}
53 changes: 27 additions & 26 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,55 @@
* Created by MD on 18.10.23.
*/
object Versions {
val composeVersion = "1.1.1"
val koinVersion = "3.4.0"
val roomVersion = "2.5.1"
const val composeVersion = "1.1.1"
const val koinVersion = "3.4.0"
const val roomVersion = "2.5.1"
}

object Dependencies {
val core_ktx = "androidx.core:core-ktx:1.10.0"
val activity_compose = "androidx.activity:activity-compose:1.7.1"
const val core_ktx = "androidx.core:core-ktx:1.10.0"
const val activity_compose = "androidx.activity:activity-compose:1.7.1"

val lifecycle_runtime = "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
const val lifecycle_runtime = "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
/**
* LIFECYCLE AWARE FLOW COLLECTION (for lifecycle aware viewstate collection in compose)
*/
val lifecycle_runtime_compose = "androidx.lifecycle:lifecycle-runtime-compose:2.6.1"
const val lifecycle_runtime_compose = "androidx.lifecycle:lifecycle-runtime-compose:2.6.1"

// COMPOSE
val compose_ui = "androidx.compose.ui:ui:${Versions.composeVersion}"
const val compose_ui = "androidx.compose.ui:ui:${Versions.composeVersion}"
// val compose_ui_tooling_preview = "androidx.compose.ui:ui-tooling-preview:${Versions.composeVersion}"
val compose_ui_tooling_preview = "androidx.compose.ui:ui-tooling-preview:1.4.2"
val compose_material = "androidx.compose.material:material:${Versions.composeVersion}"
val compose_ui_tooling = "androidx.compose.ui:ui-tooling:${Versions.composeVersion}"
val compose_ui_test_manifest = "androidx.compose.ui:ui-test-manifest:${Versions.composeVersion}"
val compose_navigation = "androidx.navigation:navigation-compose:2.5.3"
val compose_ui_test_junit = "androidx.compose.ui:ui-test-junit4:${Versions.composeVersion}"

const val compose_ui_tooling_preview = "androidx.compose.ui:ui-tooling-preview:1.4.2"
const val compose_material = "androidx.compose.material:material:${Versions.composeVersion}"
const val compose_ui_tooling = "androidx.compose.ui:ui-tooling:${Versions.composeVersion}"
const val compose_ui_test_manifest = "androidx.compose.ui:ui-test-manifest:${Versions.composeVersion}"
const val compose_navigation = "androidx.navigation:navigation-compose:2.5.3"
const val compose_ui_test_junit = "androidx.compose.ui:ui-test-junit4:${Versions.composeVersion}"

/**
* IMMUTABLE COLLECTIONS FOR KOTLIN (for composable methods stability)
*/
val collections_immutable = "org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5"
const val collections_immutable = "org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5"

// KOIN
val koin_core = "io.insert-koin:koin-core:${Versions.koinVersion}"
val koin_navigation = "io.insert-koin:koin-androidx-navigation:${Versions.koinVersion}"
val koin_compose = "io.insert-koin:koin-androidx-compose:${Versions.koinVersion}"
val koin_junit = "io.insert-koin:koin-test-junit4:${Versions.koinVersion}"
const val koin_core = "io.insert-koin:koin-core:${Versions.koinVersion}"
const val koin_navigation = "io.insert-koin:koin-androidx-navigation:${Versions.koinVersion}"
const val koin_compose = "io.insert-koin:koin-androidx-compose:${Versions.koinVersion}"
const val koin_junit = "io.insert-koin:koin-test-junit4:${Versions.koinVersion}"

// ROOM
val room_runtime = "androidx.room:room-runtime:${Versions.roomVersion}"
val room_compiler = "androidx.room:room-compiler:${Versions.roomVersion}"
val room_room = "androidx.room:room-ktx:${Versions.roomVersion}"
const val room_runtime = "androidx.room:room-runtime:${Versions.roomVersion}"
const val room_compiler = "androidx.room:room-compiler:${Versions.roomVersion}"
const val room_room = "androidx.room:room-ktx:${Versions.roomVersion}"

/**
* DESUGARING (e.g. for LocalDate manipulation on API < 26)
*/
val desugar = "com.android.tools:desugar_jdk_libs:1.2.2"
const val desugar = "com.android.tools:desugar_jdk_libs:1.2.2"

// TESTS
val test_junit = "junit:junit:4.13.2"
val test_ext_junit = "androidx.test.ext:junit:1.1.5"
val test_espresso = "androidx.test.espresso:espresso-core:3.5.1"
const val test_junit = "junit:junit:4.13.2"
const val test_ext_junit = "androidx.test.ext:junit:1.1.5"
const val test_espresso = "androidx.test.espresso:espresso-core:3.5.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch

/**
* Created by MD on 29.12.22.
*/
abstract class BaseViewModel<STATE : ViewState, EVENT : ViewEvent, COMMAND : ViewCommand>(val initialState: STATE) : ViewModel() {
abstract class BaseViewModel<STATE : ViewStateDTO, EVENT : ViewEvent, COMMAND : ViewCommand>(val initialState: STATE) : ViewModel() {

// todo - use explicit backing fields when project is switched to Kotlin 2.0, see https://github.com/Kotlin/KEEP/blob/explicit-backing-fields-re/proposals/explicit-backing-fields.md

Expand All @@ -29,8 +28,8 @@ abstract class BaseViewModel<STATE : ViewState, EVENT : ViewEvent, COMMAND : Vie
val eventChannel = Channel<EVENT>(Channel.UNLIMITED)

// For handling commands from VM to UI
private val _commandFlow = MutableSharedFlow<COMMAND>()
val commandFlow: Flow<COMMAND> = _commandFlow.asSharedFlow()
private val commandChannel = Channel<COMMAND>()
val commandFlow: Flow<COMMAND> = commandChannel.receiveAsFlow()

/**
* This is the job for all coroutines started by this ViewModel.
Expand Down Expand Up @@ -89,8 +88,10 @@ abstract class BaseViewModel<STATE : ViewState, EVENT : ViewEvent, COMMAND : Vie
/**
* Post a command to the UI.
*/
protected suspend fun sendCommand(command : COMMAND) {
_commandFlow.emit(command)
protected fun sendCommand(command : COMMAND) {
defaultScope.launch {
commandChannel.send(command)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cz.damat.thebeercounter.commonUI.base

import androidx.annotation.StringRes


/**
* Created by MD on 08.11.23.
*/
sealed class State {
object Loading : State()
object Content : State()
data class Error(@StringRes val message: Int) : State()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import androidx.compose.runtime.Immutable
* Created by MD on 23.04.23.
*/
@Immutable
interface ViewState
interface ViewStateDTO
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cz.damat.thebeercounter.commonUI.compose.component

import androidx.compose.foundation.layout.heightIn
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp


/**
* Created by MD on 09.11.23.
*/
@Composable
fun TBCButton(
modifier: Modifier = Modifier,
text: String,
enabled: Boolean = true,
onClick: () -> Unit,
) {
Button(
modifier = modifier
.heightIn(min = 48.dp),
enabled = enabled,
shape = MaterialTheme.shapes.medium,
onClick = onClick,
) {
Text(text = text)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.compose.ui.unit.dp
* Created by MD on 28.04.23.
*/
@Composable
fun CardThemed(
fun TBCCard(
modifier: Modifier = Modifier,
backgroundColor: Color = MaterialTheme.colors.surface,
borderColor: Color? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kotlinx.coroutines.launch
* e.g. has to be in the same box as the button opening the dropdown
*/
@Composable
fun DropdownMenu(
fun TBCDropdownMenu(
dropdownShown: MutableState<Boolean>,
scaffoldState: ScaffoldState?,
items: List<DropdownItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cz.damat.thebeercounter.commonUI.compose.component

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.size
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import cz.damat.thebeercounter.commonUI.base.State


/**
* Created by MD on 08.11.23.
*/
@Composable
fun TBCStateWrapper(
modifier: Modifier = Modifier,
state: State,
customLoading: @Composable (BoxScope.() -> Unit)? = null,
customError: @Composable (BoxScope.() -> Unit)? = null,
content: @Composable () -> Unit,
) {
Box(modifier = modifier) {
when (state) {
State.Content -> content()
is State.Error -> customError?.invoke(this) ?: Error(message = stringResource(id = state.message))
State.Loading -> customLoading?.invoke(this) ?: Loading()
}
}
}

@Composable
private fun BoxScope.Loading() {
CircularProgressIndicator(
modifier = Modifier
.align(Alignment.Center)
.size(64.dp),
)
}

@Composable
private fun BoxScope.Error(
message: String,
) {
Text(
modifier = Modifier.align(Alignment.Center),
text = message
)
}
Loading
Loading