Skip to content

Commit

Permalink
Merge pull request #541 from 5altNaCl/feature/525
Browse files Browse the repository at this point in the history
Apply stamps initial screen
  • Loading branch information
takahirom authored Aug 17, 2023
2 parents c27309e + ae995d2 commit efc6880
Show file tree
Hide file tree
Showing 56 changed files with 200 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.droidkaigi.confsched2023.model

data class Stamp(
val hasDrawableResId: Int,
val notHasDrawableResId: Int,
val hasStamp: Boolean = false,
val contentDescription: String,
) {
fun getDrawableResId() = if (hasStamp) hasDrawableResId else notHasDrawableResId
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package io.github.droidkaigi.confsched2023.stamps

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.testTag
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import io.github.droidkaigi.confsched2023.model.Stamp
import io.github.droidkaigi.confsched2023.stamps.section.StampsList
import io.github.droidkaigi.confsched2023.ui.SnackbarMessageEffect
import kotlinx.collections.immutable.ImmutableList

Expand Down Expand Up @@ -59,7 +61,7 @@ fun StampsScreen(
}

data class StampsScreenUiState(
val stamps: ImmutableList<String>,
val stamps: ImmutableList<Stamp>,
)

@Composable
Expand All @@ -72,15 +74,17 @@ private fun StampsScreen(
modifier = Modifier.testTag(StampsScreenTestTag),
snackbarHost = { SnackbarHost(snackbarHostState) },
content = { padding ->
Column(
Modifier
.padding(padding),
) {
Text(
text = "Please implement StampsScreen!!!",
style = MaterialTheme.typography.titleLarge,
)
}
val layoutDirection = LocalLayoutDirection.current

StampsList(
stamps = uiState.stamps,
onStampsClick = onStampsClick,
modifier = Modifier.padding(
top = padding.calculateTopPadding(),
start = padding.calculateStartPadding(layoutDirection),
end = padding.calculateEndPadding(layoutDirection),
),
)
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package io.github.droidkaigi.confsched2023.stamps

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import io.github.droidkaigi.confsched2023.feature.stamps.R
import io.github.droidkaigi.confsched2023.model.Stamp
import io.github.droidkaigi.confsched2023.ui.UserMessageStateHolder
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -15,7 +17,33 @@ class StampsScreenViewModel @Inject constructor(

val uiState = MutableStateFlow(
StampsScreenUiState(
stamps = persistentListOf(),
stamps = persistentListOf(
Stamp(
hasDrawableResId = R.drawable.img_stamp_a_on,
notHasDrawableResId = R.drawable.img_stamp_a_off,
contentDescription = "StampA image",
),
Stamp(
hasDrawableResId = R.drawable.img_stamp_b_on,
notHasDrawableResId = R.drawable.img_stamp_b_off,
contentDescription = "StampB image",
),
Stamp(
hasDrawableResId = R.drawable.img_stamp_c_on,
notHasDrawableResId = R.drawable.img_stamp_c_off,
contentDescription = "StampC image",
),
Stamp(
hasDrawableResId = R.drawable.img_stamp_d_on,
notHasDrawableResId = R.drawable.img_stamp_d_off,
contentDescription = "StampD image",
),
Stamp(
hasDrawableResId = R.drawable.img_stamp_e_on,
notHasDrawableResId = R.drawable.img_stamp_e_off,
contentDescription = "StampE image",
),
),
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@ import io.github.droidkaigi.confsched2023.designsystem.strings.StringsBindings

sealed class StampsStrings : Strings<StampsStrings>(Bindings) {

data object Title : StampsStrings()

data object Description : StampsStrings()

data object DescriptionNotes : StampsStrings()

private object Bindings : StringsBindings<StampsStrings>(
Lang.Japanese to { item, _ ->
TODO()
when (item) {
Title -> "Stamps"
Description -> "会場の各部屋に設置されたNFCタグにスマホをかざしてスタンプを集めてみましょう。"
DescriptionNotes -> "※ この企画は変更または中止になる可能性があります"
}
},
Lang.English to { item, bindings ->
TODO()
Lang.English to { item, _ ->
when (item) {
Title -> "Stamps"
Description -> "Let's collect stamps by holding your smartphone over the NFC tags placed in each room of the venue."
DescriptionNotes -> "※ This program is subject to change or cancellation."
}
},
default = Lang.Japanese,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.droidkaigi.confsched2023.stamps.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import io.github.droidkaigi.confsched2023.model.Stamp

@Composable
fun StampImage(
stamp: Stamp,
onStampClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Image(
painter = painterResource(id = stamp.getDrawableResId()),
contentDescription = stamp.contentDescription,
modifier = modifier
.clickable { onStampClick() }
.padding(horizontal = 21.dp),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.github.droidkaigi.confsched2023.stamps.component

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.github.droidkaigi.confsched2023.stamps.StampsStrings

@Composable
fun StampsDetail(
modifier: Modifier = Modifier,
) {
Column(modifier = modifier) {
Text(
text = StampsStrings.Title.asString(),
style = MaterialTheme.typography.headlineLarge,
modifier = Modifier.fillMaxWidth(),
)

Spacer(modifier = Modifier.height(16.dp))

Text(
text = StampsStrings.Description.asString(),
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.fillMaxWidth(),
)

Spacer(modifier = Modifier.height(12.dp))

Text(
text = StampsStrings.DescriptionNotes.asString(),
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.fillMaxWidth(),
)

Spacer(modifier = Modifier.height(24.dp))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.github.droidkaigi.confsched2023.stamps.section

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.grid.GridCells.Fixed
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.github.droidkaigi.confsched2023.model.Stamp
import io.github.droidkaigi.confsched2023.stamps.component.StampImage
import io.github.droidkaigi.confsched2023.stamps.component.StampsDetail
import kotlinx.collections.immutable.ImmutableList

private const val STAMP_LIST_COLUMNS = 2
private const val SINGLE_ITEM_SPAN_COUNT = 2
private const val DOUBLE_ITEM_SPAN_COUNT = 2 / 2

@Composable
fun StampsList(
stamps: ImmutableList<Stamp>,
onStampsClick: () -> Unit,
modifier: Modifier = Modifier,
) {
LazyVerticalGrid(
columns = Fixed(STAMP_LIST_COLUMNS),
modifier = modifier,
contentPadding = PaddingValues(
horizontal = 16.dp,
vertical = 20.dp,
),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
item(
key = "stamps_header",
span = { GridItemSpan(SINGLE_ITEM_SPAN_COUNT) },
) {
StampsDetail()
}
items(
items = stamps,
key = { stamp -> stamp.hasDrawableResId },
span = { stamp ->
GridItemSpan(
if (stamp == stamps.last() && stamps.size % STAMP_LIST_COLUMNS != 0) {
SINGLE_ITEM_SPAN_COUNT
} else {
DOUBLE_ITEM_SPAN_COUNT
},
)
},
) { stamp ->
StampImage(stamp = stamp, onStampClick = onStampsClick)
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit efc6880

Please sign in to comment.