Skip to content

Commit

Permalink
Merge pull request #75 from luongvo/release/0.4.0
Browse files Browse the repository at this point in the history
Release 0.4.0
  • Loading branch information
luongvo authored Jan 10, 2023
2 parents 4c0c737 + 93da67b commit 378ffca
Show file tree
Hide file tree
Showing 74 changed files with 5,954 additions and 160 deletions.
6 changes: 6 additions & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,10 @@ dependencies {
testImplementation(MOCKK_ANDROID)
testImplementation(ROBOLECTRIC)
}
// For test json resources parsing
with(Dependencies.Ktor) {
testImplementation(CORE)
testImplementation(JSON)
testImplementation(JSON_API)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MyApplication : Application() {
androidContext(applicationContext)
modules(loginModule)
modules(homeModule)
modules(surveyModule)
modules(helperModule)
}
setupLogging()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package vn.luongvo.kmm.survey.android.di

import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.dsl.module
import vn.luongvo.kmm.survey.android.ui.screens.survey.SurveyViewModel

val surveyModule = module {
viewModelOf(::SurveyViewModel)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package vn.luongvo.kmm.survey.android.ui.common

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import vn.luongvo.kmm.survey.android.R
import vn.luongvo.kmm.survey.android.ui.theme.AppTheme.dimensions

private const val Rotate180 = 180f

@Composable
fun BackButton(
onClick: () -> Unit,
modifier: Modifier = Modifier
) {
Image(
painter = painterResource(id = R.drawable.ic_arrow_right),
contentDescription = null,
colorFilter = ColorFilter.tint(White),
contentScale = ContentScale.FillWidth,
modifier = modifier
.wrapContentSize()
.rotate(Rotate180) // switch Right Arrow to Back button
.clickable { onClick() }
.padding(all = dimensions.paddingMedium)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package vn.luongvo.kmm.survey.android.ui.common

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import vn.luongvo.kmm.survey.android.R

@Composable
fun CloseButton(
onClick: () -> Unit,
modifier: Modifier = Modifier
) {
Image(
painter = painterResource(id = R.drawable.ic_close),
contentDescription = null,
contentScale = ContentScale.FillWidth,
modifier = modifier
.size(28.dp)
.clip(CircleShape)
.clickable { onClick() }
)
}

@Preview
@Composable
fun CloseButtonPreview() {
CloseButton(
onClick = {}
)
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,33 @@
package vn.luongvo.kmm.survey.android.ui.common

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import vn.luongvo.kmm.survey.android.R
import vn.luongvo.kmm.survey.android.ui.theme.AppTheme.dimensions

@Composable
fun NextCircleButton(
onClick: () -> Unit,
contentDescription: String = ""
modifier: Modifier = Modifier
) {
Button(
onClick = onClick,
modifier = Modifier
Image(
painter = painterResource(id = R.drawable.ic_arrow_right),
contentDescription = null,
contentScale = ContentScale.Inside,
modifier = modifier
.size(dimensions.buttonHeight)
.semantics { this.contentDescription = contentDescription },
shape = CircleShape,
contentPadding = PaddingValues(0.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = White
),
) {
Image(
painter = painterResource(id = R.drawable.ic_arrow_right),
contentDescription = null,
contentScale = ContentScale.FillWidth
)
}
.clip(CircleShape)
.background(White)
.clickable { onClick() }
)
}

@Preview
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package vn.luongvo.kmm.survey.android.ui.common

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.height
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import vn.luongvo.kmm.survey.android.ui.theme.AppTheme.dimensions
import vn.luongvo.kmm.survey.android.ui.theme.AppTheme.shapes
Expand All @@ -18,18 +16,16 @@ import vn.luongvo.kmm.survey.android.ui.theme.BlackRussian
fun PrimaryButton(
text: String,
onClick: () -> Unit,
contentDescription: String = ""
modifier: Modifier = Modifier
) {
Button(
shape = shapes.medium,
onClick = onClick,
colors = ButtonDefaults.buttonColors(
backgroundColor = White
),
modifier = Modifier
.fillMaxWidth()
.height(dimensions.buttonHeight)
.semantics { this.contentDescription = contentDescription }
contentPadding = PaddingValues(horizontal = dimensions.paddingLarge),
modifier = modifier.height(dimensions.buttonHeight)
) {
Text(
text = text,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package vn.luongvo.kmm.survey.android.ui.common

import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection

/**
* ModalDrawer from right/end side
* https://issuetracker.google.com/issues/174514369#comment18
*/
@Composable
fun RtlModalDrawer(
drawerContent: @Composable ColumnScope.() -> Unit,
modifier: Modifier = Modifier,
drawerState: DrawerState = rememberDrawerState(DrawerValue.Closed),
gesturesEnabled: Boolean = true,
drawerShape: Shape = MaterialTheme.shapes.large,
drawerElevation: Dp = DrawerDefaults.Elevation,
drawerBackgroundColor: Color = MaterialTheme.colors.surface,
drawerContentColor: Color = contentColorFor(drawerBackgroundColor),
scrimColor: Color = DrawerDefaults.scrimColor,
content: @Composable () -> Unit
) {
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
ModalDrawer(
modifier = modifier,
drawerState = drawerState,
gesturesEnabled = gesturesEnabled,
drawerShape = drawerShape,
drawerElevation = drawerElevation,
drawerBackgroundColor = drawerBackgroundColor,
drawerContentColor = drawerContentColor,
scrimColor = scrimColor,
drawerContent = {
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
drawerContent()
}
}
) {
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
content()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package vn.luongvo.kmm.survey.android.ui.navigation

import androidx.navigation.NamedNavArgument
import androidx.navigation.*

const val SurveyIdArg = "surveyId"

sealed class AppDestination(val route: String = "") {

Expand All @@ -12,6 +14,20 @@ sealed class AppDestination(val route: String = "") {

object Up : AppDestination()

object Root : AppDestination("root")

object Login : AppDestination("login")

object Home : AppDestination("home")

object Survey : AppDestination("survey/{$SurveyIdArg}") {

override val arguments = listOf(
navArgument(SurveyIdArg) { type = NavType.StringType }
)

fun buildDestination(surveyId: String) = apply {
destination = "survey/$surveyId"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import androidx.navigation.*
import androidx.navigation.compose.*
import vn.luongvo.kmm.survey.android.ui.screens.home.HomeScreen
import vn.luongvo.kmm.survey.android.ui.screens.login.LoginScreen
import vn.luongvo.kmm.survey.android.ui.screens.survey.SurveyScreen

@Composable
fun AppNavigation(
navController: NavHostController = rememberNavController(),
startDestination: String = AppDestination.Login.destination
startDestination: String = AppDestination.Login.destination,
) {
NavHost(
route = AppDestination.Root.route,
navController = navController,
startDestination = startDestination
) {
Expand All @@ -22,8 +24,13 @@ fun AppNavigation(
}
composable(AppDestination.Home) {
HomeScreen(
// TODO handle navigation later
// navigator = { destination -> navController.navigate(destination) }
navigator = { destination -> navController.navigate(destination) },
)
}
composable(AppDestination.Survey) { backStackEntry ->
SurveyScreen(
surveyId = backStackEntry.arguments?.getString(SurveyIdArg).orEmpty(),
navigator = { destination -> navController.navigate(destination) }
)
}
}
Expand All @@ -49,8 +56,18 @@ private fun NavHostController.navigate(destination: AppDestination) {
route = destination.destination,
navOptions {
popUpTo(
route = AppDestination.Login.route
) { inclusive = true }
route = AppDestination.Root.route
) { inclusive = false }
launchSingleTop = true
}
)
is AppDestination.Login -> navigate(
route = destination.destination,
navOptions {
popUpTo(
route = AppDestination.Root.route
) { inclusive = false }
launchSingleTop = true
}
)
else -> navigate(route = destination.destination)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package vn.luongvo.kmm.survey.android.ui.preview

import androidx.compose.material.DrawerValue
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import vn.luongvo.kmm.survey.android.ui.screens.home.SurveyUiModel
import vn.luongvo.kmm.survey.android.ui.screens.home.UserUiModel

class HomeParameterProvider : PreviewParameterProvider<HomeParameterProvider.Params> {

private val userUiModel = UserUiModel(
email = "[email protected]",
name = "Luong",
avatarUrl = "https://secure.gravatar.com/avatar/8fae17b9d0c4cca18a9661bcdf650f23"
)

private val surveyUiModels = listOf(
SurveyUiModel(
id = "1",
title = "Scarlett Bangkok",
description = "We'd love to hear from you!",
coverImageUrl = "https://dhdbhh0jsld0o.cloudfront.net/m/1ea51560991bcb7d00d0_"
),
SurveyUiModel(
id = "2",
title = "ibis Bangkok Riverside",
description = "We'd love to hear from you!",
coverImageUrl = "https://dhdbhh0jsld0o.cloudfront.net/m/287db81c5e4242412cc0_"
)
)

override val values = sequenceOf(
Params(
isLoading = false,
),
Params(
isLoading = true,
),
Params(
isLoading = false,
drawerState = DrawerValue.Open,
)
)

inner class Params(
val isLoading: Boolean,
val drawerState: DrawerValue = DrawerValue.Closed,
val appVersion: String = "v1.0.0",
val currentDate: String = "Monday, JUNE 15",
val user: UserUiModel = userUiModel,
val surveys: List<SurveyUiModel> = surveyUiModels
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vn.luongvo.kmm.survey.android.ui.providers
package vn.luongvo.kmm.survey.android.ui.preview

import androidx.compose.ui.tooling.preview.PreviewParameterProvider

Expand Down
Loading

0 comments on commit 378ffca

Please sign in to comment.