generated from AdamMc331/AndroidAppTemplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Adding feed feature files. #581
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a63802c
Adding feed feature files.
AdamMc331 d9db554
Merge branch 'development' into arm-feed-setup
AdamMc331 310b166
Adding all the components for feed content.
AdamMc331 4c17118
Some reorg.
AdamMc331 98f122e
Adding docs.
AdamMc331 f5d811b
Moving mapping into use cases.
AdamMc331 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...otlin/com/adammcneilly/pocketleague/shared/app/domain/usecases/GetOngoingEventsUseCase.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.adammcneilly.pocketleague.shared.app.domain.usecases | ||
|
||
import com.adammcneilly.pocketleague.shared.app.core.datetime.TimeProvider | ||
import com.adammcneilly.pocketleague.shared.app.core.models.Event | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
/** | ||
* Return an observable type of events that are currently happening on today's date. | ||
*/ | ||
class GetOngoingEventsUseCase( | ||
private val eventRepository: EventRepository, | ||
private val timeProvider: TimeProvider, | ||
) { | ||
/** | ||
* @see [GetOngoingEventsUseCase] | ||
*/ | ||
fun invoke(): Flow<List<Event>> { | ||
val request = EventListRequest.OnDate( | ||
dateUtc = timeProvider.now(), | ||
) | ||
|
||
return eventRepository.stream(request) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...in/com/adammcneilly/pocketleague/shared/app/domain/usecases/GetPastWeeksMatchesUseCase.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.adammcneilly.pocketleague.shared.app.domain.usecases | ||
|
||
import com.adammcneilly.pocketleague.shared.app.core.datetime.TimeProvider | ||
import com.adammcneilly.pocketleague.shared.app.core.models.Match | ||
import com.adammcneilly.pocketleague.shared.app.feature.feed.usecases.DAYS_PER_WEEK | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
/** | ||
* Return an observable type of matches for the past week. | ||
*/ | ||
class GetPastWeeksMatchesUseCase( | ||
private val timeProvider: TimeProvider, | ||
private val matchRepository: MatchRepository, | ||
) { | ||
/** | ||
* @see [GetPastWeeksMatchesUseCase]. | ||
*/ | ||
fun invoke(): Flow<List<Match>> { | ||
val request = MatchListRequest.DateRange( | ||
startDateUTC = timeProvider.daysAgo(DAYS_PER_WEEK), | ||
endDateUTC = timeProvider.now(), | ||
) | ||
|
||
return matchRepository.stream(request) | ||
} | ||
|
||
companion object { | ||
private const val DAYS_PER_WEEK = 7 | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...tlin/com/adammcneilly/pocketleague/shared/app/domain/usecases/GetUpcomingEventsUseCase.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.adammcneilly.pocketleague.shared.app.domain.usecases | ||
|
||
import com.adammcneilly.pocketleague.shared.app.core.datetime.TimeProvider | ||
import com.adammcneilly.pocketleague.shared.app.core.models.Event | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
/** | ||
* Return an observable type of events that are upcoming from today's date. | ||
*/ | ||
class GetUpcomingEventsUseCase( | ||
private val eventRepository: EventRepository, | ||
private val timeProvider: TimeProvider, | ||
) { | ||
/** | ||
* @see [GetUpcomingEventsUseCase] | ||
*/ | ||
fun invoke(): Flow<List<Event>> { | ||
val request = EventListRequest.AfterDate( | ||
dateUtc = timeProvider.now(), | ||
) | ||
|
||
return eventRepository.stream(request) | ||
} | ||
} |
144 changes: 144 additions & 0 deletions
144
...rc/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/feature/feed/FeedContent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package com.adammcneilly.pocketleague.shared.app.feature.feed | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.LazyListScope | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.adammcneilly.pocketleague.shared.app.core.displaymodels.EventGroupDisplayModel | ||
import com.adammcneilly.pocketleague.shared.app.core.displaymodels.MatchDetailDisplayModel | ||
|
||
/** | ||
* The main list of events and matches to show within the feed screen | ||
* that is the landing page when opening the app. | ||
*/ | ||
@Composable | ||
fun FeedContent( | ||
recentMatches: List<MatchDetailDisplayModel>, | ||
ongoingEvents: List<EventGroupDisplayModel>, | ||
upcomingEvents: List<EventGroupDisplayModel>, | ||
onMatchClicked: (String) -> Unit, | ||
onEventClicked: (String) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
LazyColumn( | ||
modifier = modifier, | ||
contentPadding = PaddingValues( | ||
vertical = PocketLeagueTheme.sizes.screenPadding, | ||
), | ||
verticalArrangement = Arrangement.spacedBy(PocketLeagueTheme.sizes.listItemSpacing), | ||
) { | ||
recentMatchesHeader() | ||
|
||
recentMatchesCarousel(recentMatches, onMatchClicked) | ||
|
||
happeningNowHeader() | ||
|
||
eventGroupList(ongoingEvents, onEventClicked) | ||
|
||
upcomingHeader() | ||
|
||
eventGroupList(upcomingEvents, onEventClicked) | ||
} | ||
} | ||
|
||
private fun LazyListScope.upcomingHeader() { | ||
item { | ||
FeedSectionHeader( | ||
text = "Upcoming", | ||
) | ||
} | ||
} | ||
|
||
private fun LazyListScope.eventGroupList( | ||
events: List<EventGroupDisplayModel>, | ||
onEventClicked: (String) -> Unit, | ||
) { | ||
events.forEach { group -> | ||
item { | ||
FeedEventGroup( | ||
group, | ||
onEventClicked, | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun LazyListScope.happeningNowHeader() { | ||
item { | ||
FeedSectionHeader( | ||
text = "Happening Now", | ||
) | ||
} | ||
} | ||
|
||
private fun LazyListScope.recentMatchesCarousel( | ||
recentMatches: List<MatchDetailDisplayModel>, | ||
onMatchClicked: (Match.Id) -> Unit, | ||
) { | ||
item { | ||
MatchCarousel( | ||
matches = recentMatches, | ||
contentPadding = PaddingValues( | ||
horizontal = PocketLeagueTheme.sizes.screenPadding, | ||
), | ||
onMatchClicked = onMatchClicked, | ||
) | ||
} | ||
} | ||
|
||
private fun LazyListScope.recentMatchesHeader() { | ||
item { | ||
FeedSectionHeader( | ||
text = "Recent Matches", | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun FeedSectionHeader( | ||
text: String, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Text( | ||
text = text, | ||
style = MaterialTheme.typography.headlineSmall, | ||
modifier = modifier | ||
.screenHorizontalPadding(), | ||
) | ||
} | ||
|
||
/** | ||
* For a given [displayModel], determine how to render | ||
* that collection for our [FeedContent]. | ||
*/ | ||
@Composable | ||
private fun FeedEventGroup( | ||
displayModel: EventGroupDisplayModel, | ||
onEventClicked: (String) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val groupModifier = modifier | ||
.screenHorizontalPadding() | ||
|
||
when (displayModel) { | ||
is EventGroupDisplayModel.Regionals -> { | ||
EventSummaryListCard( | ||
events = displayModel.events, | ||
onEventClicked = onEventClicked, | ||
modifier = groupModifier, | ||
) | ||
} | ||
|
||
is EventGroupDisplayModel.Major -> { | ||
LanEventSummaryCard( | ||
event = displayModel.event, | ||
onEventClicked = onEventClicked, | ||
modifier = groupModifier, | ||
) | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/feature/feed/FeedScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.adammcneilly.pocketleague.shared.app.feature.feed | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.ui.Modifier | ||
import org.koin.compose.viewmodel.koinViewModel | ||
|
||
@Composable | ||
fun FeedScreen( | ||
modifier: Modifier = Modifier, | ||
viewModel: FeedViewModel = koinViewModel(), | ||
) { | ||
val state = viewModel.state.collectAsState() | ||
|
||
FeedContent( | ||
recentMatches = state.value.recentMatches, | ||
ongoingEvents = state.value.ongoingEvents, | ||
upcomingEvents = state.value.upcomingEvents, | ||
onMatchClicked = { /*TODO*/ }, | ||
onEventClicked = { /*TODO*/ }, | ||
modifier = modifier, | ||
) | ||
} |
110 changes: 110 additions & 0 deletions
110
.../commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/feature/feed/FeedViewModel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.adammcneilly.pocketleague.shared.app.feature.feed | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.adammcneilly.pocketleague.shared.app.core.datetime.DateTimeFormatter | ||
import com.adammcneilly.pocketleague.shared.app.core.datetime.TimeProvider | ||
import com.adammcneilly.pocketleague.shared.app.core.displaymodels.EventGroupDisplayModel | ||
import com.adammcneilly.pocketleague.shared.app.core.displaymodels.EventSummaryDisplayModel | ||
import com.adammcneilly.pocketleague.shared.app.core.displaymodels.MatchDetailDisplayModel | ||
import com.adammcneilly.pocketleague.shared.app.core.locale.LocaleHelper | ||
import com.adammcneilly.pocketleague.shared.app.domain.usecases.GetOngoingEventsUseCase | ||
import com.adammcneilly.pocketleague.shared.app.domain.usecases.GetPastWeeksMatchesUseCase | ||
import com.adammcneilly.pocketleague.shared.app.domain.usecases.GetUpcomingEventsUseCase | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.coroutines.launch | ||
|
||
class FeedViewModel( | ||
private val dateTimeFormatter: DateTimeFormatter, | ||
private val getPastWeeksMatchesUseCase: GetPastWeeksMatchesUseCase, | ||
private val getOngoingEventsUseCase: GetOngoingEventsUseCase, | ||
private val getUpcomingEventsUseCase: GetUpcomingEventsUseCase, | ||
private val localeHelper: LocaleHelper, | ||
private val timeProvider: TimeProvider, | ||
) : ViewModel() { | ||
private val mutableState = MutableStateFlow(FeedViewState.placeholderState()) | ||
val state = mutableState.asStateFlow() | ||
|
||
init { | ||
observePastWeeksMatches() | ||
observeOngoingEvents() | ||
observeUpcomingEvents() | ||
} | ||
|
||
private fun observePastWeeksMatches() { | ||
val matchFlow = getPastWeeksMatchesUseCase | ||
.invoke() | ||
.map { matchList -> | ||
matchList.map { match -> | ||
MatchDetailDisplayModel( | ||
match = match, | ||
dateTimeFormatter = dateTimeFormatter, | ||
timeProvider = timeProvider, | ||
) | ||
} | ||
} | ||
|
||
viewModelScope.launch { | ||
matchFlow.collect { matchList -> | ||
mutableState.update { currentState -> | ||
currentState.copy( | ||
recentMatches = matchList, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun observeOngoingEvents() { | ||
val eventFlow = getOngoingEventsUseCase | ||
.invoke() | ||
.map { eventList -> | ||
eventList.map { event -> | ||
EventSummaryDisplayModel( | ||
event = event, | ||
dateTimeFormatter = dateTimeFormatter, | ||
localeHelper = localeHelper, | ||
) | ||
} | ||
} | ||
.map(EventGroupDisplayModel.Companion::mapFromEventList) | ||
|
||
viewModelScope.launch { | ||
eventFlow.collect { eventList -> | ||
mutableState.update { currentState -> | ||
currentState.copy( | ||
ongoingEvents = eventList, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun observeUpcomingEvents() { | ||
val eventFlow = getUpcomingEventsUseCase | ||
.invoke() | ||
.map { eventList -> | ||
eventList.map { event -> | ||
EventSummaryDisplayModel( | ||
event = event, | ||
dateTimeFormatter = dateTimeFormatter, | ||
localeHelper = localeHelper, | ||
) | ||
} | ||
} | ||
.map(EventGroupDisplayModel.Companion::mapFromEventList) | ||
|
||
viewModelScope.launch { | ||
eventFlow.collect { eventList -> | ||
mutableState.update { currentState -> | ||
currentState.copy( | ||
ongoingEvents = eventList, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.