Skip to content

Commit

Permalink
feat(partners-feature): create an adapted experience for Partners in …
Browse files Browse the repository at this point in the history
…landscape.
  • Loading branch information
GerardPaligot committed Nov 8, 2023
1 parent 2e70429 commit febdc10
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 126 deletions.
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ include(":theme-m3:infos:infos-feature")
include(":theme-m3:event-list:event-list-ui")
include(":theme-m3:event-list:event-list-feature")
include(":theme-m3:navigation")
include(":theme-m3:style:partners")
include(":theme-m3:style:schedules")
include(":theme-m3:style:speakers")
include(":theme-m3:style:theme")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ class PartnerDao(private val db: Conferences4HallDatabase, private val platform:
db.partnerQueries.selectPartners(eventId, type.name, partnerMapper)
.asFlow()
.mapToList(Dispatchers.IO)
.map { type.name to it.chunked(3).toImmutableList() }
.map { type.name to it }
},
transform = { results ->
PartnerGroupsUi(
groups = types.map { type ->
PartnerGroupUi(
type = type.name,
partners = results.find { it.first == type.name }!!.second
.map { it.toImmutableList() }
.toImmutableList()
)
}.toImmutableList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import kotlinx.collections.immutable.persistentListOf

data class PartnerGroupUi(
val type: String,
val partners: ImmutableList<ImmutableList<PartnerItemUi>>
val partners: ImmutableList<PartnerItemUi>
) {
companion object {
val fake = PartnerGroupUi(
type = "Gold",
partners = persistentListOf(
persistentListOf(
PartnerItemUi.fake,
PartnerItemUi.fake,
PartnerItemUi.fake
)
PartnerItemUi.fake.copy(id = "1"),
PartnerItemUi.fake.copy(id = "2"),
PartnerItemUi.fake.copy(id = "3")
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,25 @@ data class PartnerGroupsUi(
PartnerGroupUi(
type = "Gold",
partners = persistentListOf(
persistentListOf(
PartnerItemUi.fake,
PartnerItemUi.fake,
PartnerItemUi.fake
)
PartnerItemUi.fake.copy(id = "1"),
PartnerItemUi.fake.copy(id = "2"),
PartnerItemUi.fake.copy(id = "3")
)
),
PartnerGroupUi(
type = "Silver",
partners = persistentListOf(
persistentListOf(
PartnerItemUi.fake,
PartnerItemUi.fake,
PartnerItemUi.fake
)
PartnerItemUi.fake.copy(id = "4"),
PartnerItemUi.fake.copy(id = "5"),
PartnerItemUi.fake.copy(id = "6")
)
),
PartnerGroupUi(
type = "Bronze",
partners = persistentListOf(
persistentListOf(
PartnerItemUi.fake,
PartnerItemUi.fake,
PartnerItemUi.fake
)
PartnerItemUi.fake.copy(id = "7"),
PartnerItemUi.fake.copy(id = "8"),
PartnerItemUi.fake.copy(id = "9")
)
)
)
Expand Down
1 change: 1 addition & 0 deletions theme-m3/partners/partners-feature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation(projects.shared.core)
implementation(projects.themeM3.partners.partnersUi)
implementation(projects.themeM3.navigation)
implementation(projects.themeM3.style.partners)
implementation(projects.themeM3.style.theme)

implementation(libs.kotlinx.collections)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,73 @@
package org.gdglille.devfest.android.theme.m3.partners.feature

import android.annotation.SuppressLint
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.gdglille.devfest.android.theme.m3.partners.ui.partners.PartnerDivider
import org.gdglille.devfest.android.theme.m3.partners.ui.partners.PartnerRow
import org.gdglille.devfest.android.theme.m3.style.Conferences4HallTheme
import org.gdglille.devfest.android.theme.m3.style.partners.PartnerItem
import org.gdglille.devfest.android.theme.m3.style.placeholder
import org.gdglille.devfest.models.ui.PartnerGroupsUi

@ExperimentalMaterial3Api
@Composable
fun Partners(
partners: PartnerGroupsUi,
modifier: Modifier = Modifier,
state: LazyGridState = rememberLazyGridState(),
isLoading: Boolean = false,
columnCount: Int = 3,
onPartnerClick: (id: String) -> Unit
) {
LazyColumn(
modifier = modifier.padding(horizontal = 8.dp),
contentPadding = PaddingValues(vertical = 4.dp),
LazyVerticalGrid(
columns = GridCells.Fixed(columnCount),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(vertical = 16.dp),
state = state,
modifier = modifier
) {
partners.groups.forEach {
item { PartnerDivider(title = it.type) }
item(span = { GridItemSpan(currentLineSpan = columnCount) }) {
PartnerDivider(title = it.type)
}
items(it.partners) {
PartnerRow(partners = it, onPartnerClick = onPartnerClick, isLoading = isLoading)
PartnerItem(
url = it.logoUrl,
contentDescription = it.name,
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f)
.placeholder(visible = isLoading),
onClick = { onPartnerClick(it.id) }
)
}
}
}
}

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@Preview
@Composable
fun PartnersPreview() {
Conferences4HallTheme {
Scaffold {
Partners(
partners = PartnerGroupsUi.fake,
onPartnerClick = {}
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.gdglille.devfest.android.theme.m3.partners.feature

import android.content.res.Configuration
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import org.gdglille.devfest.models.ui.PartnerGroupsUi

@Composable
fun PartnersOrientable(
partners: PartnerGroupsUi,
modifier: Modifier = Modifier,
isLoading: Boolean = false,
onPartnerClick: (id: String) -> Unit
) {
val orientation = LocalConfiguration.current
val state = rememberLazyGridState()
if (orientation.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Partners(
partners = partners,
modifier = modifier,
columnCount = 6,
state = state,
isLoading = isLoading,
onPartnerClick = onPartnerClick
)
} else {
Partners(
partners = partners,
modifier = modifier,
columnCount = 3,
state = state,
isLoading = isLoading,
onPartnerClick = onPartnerClick
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import org.gdglille.devfest.android.theme.m3.style.R
import org.gdglille.devfest.repositories.AgendaRepository

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun PartnersVM(
agendaRepository: AgendaRepository,
Expand All @@ -22,15 +21,15 @@ fun PartnersVM(
) {
val uiState = viewModel.uiState.collectAsState()
when (uiState.value) {
is PartnersUiState.Loading -> Partners(
is PartnersUiState.Loading -> PartnersOrientable(
partners = (uiState.value as PartnersUiState.Loading).partners,
modifier = modifier,
isLoading = true,
onPartnerClick = {}
)

is PartnersUiState.Failure -> Text(text = stringResource(id = R.string.text_error))
is PartnersUiState.Success -> Partners(
is PartnersUiState.Success -> PartnersOrientable(
partners = (uiState.value as PartnersUiState.Success).partners,
modifier = modifier,
onPartnerClick = onPartnerClick
Expand Down
1 change: 1 addition & 0 deletions theme-m3/partners/partners-ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ android {
dependencies {
implementation(projects.shared.uiModels)
implementation(projects.themeM3.navigation)
implementation(projects.themeM3.style.partners)
implementation(projects.themeM3.style.theme)

implementation(libs.kotlinx.collections)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.gdglille.devfest.android.theme.m3.style.socials.SocialsSection
import org.gdglille.devfest.android.theme.m3.style.Conferences4HallTheme
import org.gdglille.devfest.android.theme.m3.style.partners.PartnerItem
import org.gdglille.devfest.models.ui.PartnerItemUi

@ExperimentalMaterial3Api
Expand All @@ -33,14 +34,14 @@ fun PartnerDetailSection(
.padding(horizontal = 16.dp)
) {
Spacer(modifier = Modifier.height(24.dp))
Conferences4HallTheme(useDarkTheme = false) {
PartnerItem(
partnerUi = partnerItemUi,
isLoading = isLoading,
modifier = Modifier.size(128.dp).clearAndSetSemantics { },
onClick = {}
)
}
PartnerItem(
url = partnerItemUi.logoUrl,
contentDescription = partnerItemUi.name,
onClick = {},
modifier = Modifier
.size(128.dp)
.clearAndSetSemantics { },
)
Spacer(modifier = Modifier.height(16.dp))
SocialsSection(
title = partnerItemUi.name,
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions theme-m3/style/partners/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
20 changes: 20 additions & 0 deletions theme-m3/style/partners/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
id("conferences4hall.android.library")
id("conferences4hall.android.library.compose")
id("conferences4hall.quality")
}

android {
namespace = "org.gdglille.devfest.android.theme.m3.style.partners"
}

dependencies {
implementation(projects.themeM3.style.theme)

implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.tooling)
implementation(libs.androidx.compose.icons)

implementation(libs.coil.compose)
}
Loading

0 comments on commit febdc10

Please sign in to comment.