Skip to content

Commit

Permalink
Merge remote-tracking branch 'paug/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed Apr 23, 2022
2 parents df1209b + 1c9e076 commit 15ef16d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,12 @@ import android.util.SparseArray
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.Checkbox
import androidx.compose.material.DrawerState
import androidx.compose.material.DrawerValue
import androidx.compose.material.ModalDrawer
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
Expand All @@ -43,16 +27,14 @@ import fr.paug.androidmakers.R
import fr.paug.androidmakers.ui.adapter.DaySchedule
import fr.paug.androidmakers.ui.adapter.RoomSchedule
import fr.paug.androidmakers.ui.adapter.ScheduleSession
import fr.paug.androidmakers.util.SessionFilter
import fr.paug.androidmakers.ui.viewmodel.LceViewModel
import fr.paug.androidmakers.util.EmojiUtils
import fr.paug.androidmakers.util.SessionFilter
import fr.paug.androidmakers.util.TimeUtils
import kotlinx.coroutines.flow.Flow
import surfaceColor2
import java.text.DateFormat
import java.time.Instant
import java.time.ZoneOffset
import java.util.Arrays
import java.util.Calendar
import java.util.*

@Composable
fun AgendaLayout(
Expand Down Expand Up @@ -202,7 +184,7 @@ private fun FilterItem(
modifier = Modifier
.fillMaxWidth()
.clickable {
onCheck(!checked)
onCheck(!checked)
},
verticalAlignment = Alignment.CenterVertically,
) {
Expand Down Expand Up @@ -238,7 +220,7 @@ private fun HeaderItem(text: Int) {
Text(
modifier = Modifier
.fillMaxWidth()
.background(color = colorResource(R.color.light_grey))
.background(color = surfaceColor2())
.padding(12.dp),
fontSize = 16.sp,
text = stringResource(text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import com.google.accompanist.pager.rememberPagerState
import fr.paug.androidmakers.ui.adapter.DaySchedule
import fr.paug.androidmakers.ui.adapter.ScheduleSession
import fr.paug.androidmakers.ui.model.UISession
import fr.paug.androidmakers.util.SessionFilter
import fr.paug.androidmakers.util.BookmarksStore
import fr.paug.androidmakers.util.SessionFilter
import fr.paug.androidmakers.util.TimeUtils
import kotlinx.coroutines.launch
import java.time.OffsetDateTime
Expand Down Expand Up @@ -87,11 +87,14 @@ fun AgendaPager(
},
)
}

AgendaColumn(
sessionsPerStartTime = addSeparators(LocalContext.current, items),
onSessionClicked = onSessionClicked
)
if (items.isEmpty()) {
EmptyLayout()
} else {
AgendaColumn(
sessionsPerStartTime = addSeparators(LocalContext.current, items),
onSessionClicked = onSessionClicked
)
}
}
}
}
Expand All @@ -108,37 +111,50 @@ private fun addSeparators(context: Context, sessions: List<UISession>): Map<Stri
}
}


// algorithm to filter sessions by applying filters, if the filters is same category we keep
// the combined logic (OR) otherwise it's AND with category filters
// example: Language English && (Rooms Moebius || Rooms A...)
// the algorithm is inspired by Inverted index
// time complexity is O(n * m) where n is the number of sessions and m is the number of filters
private fun List<ScheduleSession>.filterSessions(
filterList: List<SessionFilter>
): List<ScheduleSession> {
val filteredSessions = mutableListOf<ScheduleSession>()

if (filterList.isEmpty()) {
filteredSessions.addAll(this)
} else {
for (item in this) {
for (sessionFilter in filterList) {
val matched = when (sessionFilter.type) {
SessionFilter.FilterType.BOOKMARK -> {
BookmarksStore.isBookmarked(item.sessionId)
}
SessionFilter.FilterType.LANGUAGE -> {
sessionFilter.value == item.language
}
SessionFilter.FilterType.ROOM -> {
sessionFilter.value == item.roomId
}
): Set<ScheduleSession> {
val filteredSessions = hashSetOf<ScheduleSession>()
if (filterList.isEmpty()) {
filteredSessions.addAll(this)
return filteredSessions
}
val sessionsByFilterType = mutableMapOf<SessionFilter.FilterType, MutableList<ScheduleSession>>()
for (filter in filterList) {
if (!sessionsByFilterType.containsKey(filter.type)) {
sessionsByFilterType[filter.type] = mutableListOf()
}

if (matched) {
filteredSessions.add(item)
}
for (session in this) {
for (filter in filterList) {
when (filter.type) {
SessionFilter.FilterType.BOOKMARK -> {
if (BookmarksStore.isBookmarked(session.sessionId)) {
sessionsByFilterType[filter.type]?.add(session)
}
}
SessionFilter.FilterType.LANGUAGE -> {
if (filter.value == session.language) {
sessionsByFilterType[filter.type]?.add(session)
}
}
SessionFilter.FilterType.ROOM -> {
if (filter.value == session.roomId) {
sessionsByFilterType[filter.type]?.add(session)
}
}
}
}
}
}
}

return filteredSessions
//get union join of all ScheduleSessions
val origin = sessionsByFilterType.values.flatten().toMutableSet()
sessionsByFilterType.values.forEach { origin.retainAll(it) }
return origin
}

private fun getRoomTitle(scheduleSession: ScheduleSession, daySchedule: DaySchedule): String {
Expand Down
18 changes: 16 additions & 2 deletions app/src/main/java/fr/paug/androidmakers/ui/components/LceLayout.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.paug.androidmakers.ui.components

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Button
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Text
Expand All @@ -14,7 +13,6 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.google.android.datatransport.runtime.retries.Retries.retry
import fr.paug.androidmakers.R
import fr.paug.androidmakers.ui.viewmodel.Lce
import fr.paug.androidmakers.ui.viewmodel.LceViewModel
Expand Down Expand Up @@ -111,4 +109,20 @@ fun ErrorLayout(
}
}
}
}

@Composable
fun EmptyLayout(modifier: Modifier = Modifier) {
Box(
modifier = modifier
.fillMaxWidth()
.fillMaxHeight()
.padding(16.dp),
contentAlignment = Alignment.Center
) {
Text(
text = stringResource(id = R.string.empty_events),
textAlign = TextAlign.Center
)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<string name="language">Langue</string>
<string name="room">Salle</string>
<string name="rooms">Salles</string>
<string name="empty_events">Désolé, aucune conférence n\'est disponible pour les filtres actuellement sélectionnés.</string>

<!--Venue-->
<string name="locate_on_map">Localiser sur la carte</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<string name="language">Language</string>
<string name="room">Room</string>
<string name="rooms">Rooms</string>
<string name="empty_events">Sorry, there is nothing conference available for currently selected filters.</string>

<!--Venue-->
<string name="locate_on_map">Locate on map</string>
Expand Down

0 comments on commit 15ef16d

Please sign in to comment.