Skip to content

Commit

Permalink
Merge pull request #91 from eshc123/dev
Browse files Browse the repository at this point in the history
[RELEASE]
  • Loading branch information
eshc123 authored Jun 6, 2024
2 parents 0812473 + dd8f11d commit 60d7331
Show file tree
Hide file tree
Showing 13 changed files with 646 additions and 461 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,21 @@ fun GnrElevatedCard(
modifier = modifier,
content = content
)
}

@Composable
fun GnrElevatedCard(
colors: CardColors,
radius: Dp,
elevation: Dp,
modifier: Modifier = Modifier,
content: @Composable ColumnScope.() -> Unit
) {
GnrElevatedCard(
shape = RoundedCornerShape(radius),
colors = colors,
elevation = CardDefaults.elevatedCardElevation(elevation),
modifier = modifier,
content = content
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fun MatchLeagueInfo(
Text(
text = competitionName,
color = ColorFF181818,
style = GnrTypography.descriptionSemiBold
style = GnrTypography.descriptionMedium
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ data class Rank(
val teamId: Int,
val teamName: String,
val shortCode: String
)
) {
fun getTotalGames(): Int = wins + draw + loss
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class GetPreviewRankListByTeamAndSeasonUseCase @Inject constructor(
private val seasonRepository: SeasonRepository
) {
operator fun invoke(
teamId: Int,
seasonId: Int
seasonId: Int,
teamId: Int = 19
): Flow<DataResult<List<Rank>>> = seasonRepository.getPreviewRankListByTeamAndSeason(
teamId = teamId,
seasonId = seasonId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package com.eshc.goonersapp.core.network.di
import com.eshc.goonersapp.core.network.ChatNetworkDataSource
import com.eshc.goonersapp.core.network.MatchNetworkDataSource
import com.eshc.goonersapp.core.network.PlayerNetworkDataSource
import com.eshc.goonersapp.core.network.SeasonNetworkDataSource
import com.eshc.goonersapp.core.network.TeamNetworkDataSource
import com.eshc.goonersapp.core.network.UserNetworkDataSource
import com.eshc.goonersapp.core.network.remote.ChatNetworkDataSourceImpl
import com.eshc.goonersapp.core.network.remote.MatchNetworkDataSourceImpl
import com.eshc.goonersapp.core.network.remote.PlayerNetworkDataSourceImpl
import com.eshc.goonersapp.core.network.remote.SeasonNetworkDataSourceImpl
import com.eshc.goonersapp.core.network.remote.TeamNetworkDataSourceImpl
import com.eshc.goonersapp.core.network.remote.UserNetworkDataSourceImpl
import dagger.Binds
Expand Down Expand Up @@ -43,4 +45,9 @@ abstract class NetworkDataSourceModule {
abstract fun bindUserNetworkDataSource(
gnrRemoteDataSource: UserNetworkDataSourceImpl
): UserNetworkDataSource

@Binds
abstract fun bindSeasonNetworkDataSource(
gnrRemoteSeason: SeasonNetworkDataSourceImpl
): SeasonNetworkDataSource
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.eshc.goonersapp.core.network.di
import com.eshc.goonersapp.core.network.BuildConfig
import com.eshc.goonersapp.core.network.api.MatchNetworkService
import com.eshc.goonersapp.core.network.api.PlayerNetworkService
import com.eshc.goonersapp.core.network.api.SeasonNetworkService
import com.eshc.goonersapp.core.network.api.TeamNetworkService
import com.eshc.goonersapp.core.network.api.UserNetworkService
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
Expand Down Expand Up @@ -82,6 +83,13 @@ object NetworkModule {
UserNetworkService::class.java
)

@Singleton
@Provides
fun provideSeasonNetworkService(retrofit: Retrofit): SeasonNetworkService =
retrofit.create(
SeasonNetworkService::class.java
)

@Singleton
@Provides
fun provideChatSocket(): Socket = IO.socket(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.eshc.goonersapp.feature.home
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand All @@ -27,6 +28,7 @@ import com.eshc.goonersapp.core.designsystem.theme.GnrTypography
import com.eshc.goonersapp.feature.home.component.DashboardCard
import com.eshc.goonersapp.feature.home.component.RecentlyMatchCard
import com.eshc.goonersapp.feature.home.component.UpcomingMatchCard
import com.eshc.goonersapp.feature.home.state.DashBoardUiState
import com.eshc.goonersapp.feature.home.state.RecentlyResultUiState
import com.eshc.goonersapp.feature.home.state.UpcomingMatchesUiState

Expand All @@ -37,6 +39,7 @@ fun HomeRoute(
viewModel: HomeViewModel = hiltViewModel(),
onShowSnackbar : (String) -> Unit
) {
val dashBoardUiState by viewModel.teamDashBoardUiStateFlow.collectAsStateWithLifecycle()
val upcomingMatchesUiState by viewModel.upcomingMatchesUiStateFlow.collectAsStateWithLifecycle()
val recentlyResultUiState by viewModel.recentlyResultUiStateFlow.collectAsStateWithLifecycle()

Expand All @@ -46,6 +49,7 @@ fun HomeRoute(
) { padding ->
HomeScreen(
modifier = Modifier.padding(padding),
dashBoardUiState = dashBoardUiState,
upcomingMatchesUiState = upcomingMatchesUiState,
recentlyResultUiState = recentlyResultUiState
)
Expand All @@ -54,28 +58,71 @@ fun HomeRoute(

@Composable
fun HomeScreen(
modifier: Modifier = Modifier,
dashBoardUiState: DashBoardUiState,
upcomingMatchesUiState: UpcomingMatchesUiState,
recentlyResultUiState: RecentlyResultUiState
recentlyResultUiState: RecentlyResultUiState,
modifier: Modifier = Modifier,
) {
LazyColumn(
modifier = modifier,
modifier = modifier.fillMaxSize(),
contentPadding = PaddingValues(top = 30.dp)
) {
item {
Text(
text = "Team Dashboard",
modifier = Modifier.padding(start = 8.dp),
modifier = Modifier.padding(start = 15.dp),
color = ColorFF181818,
style = GnrTypography.subtitleMedium
)
DashboardCard()
when (dashBoardUiState) {
is DashBoardUiState.Loading -> {
Box(
modifier = Modifier
.fillMaxWidth()
.height(208.dp),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator()
}
}
is DashBoardUiState.Success -> {
DashboardCard(dashBoardUiState.data)
}
is DashBoardUiState.Failed -> {
Box(
modifier = Modifier
.fillMaxWidth()
.height(208.dp),
contentAlignment = Alignment.Center
) {
Text(
text = "Rank List cannot be loaded.",
style = MaterialTheme.typography.titleSmall,
color = Color.LightGray,
)
}
}
is DashBoardUiState.Error -> {
Box(
modifier = Modifier
.fillMaxWidth()
.height(208.dp),
contentAlignment = Alignment.Center
) {
Text(
text = "Error! ${dashBoardUiState.throwable}",
style = MaterialTheme.typography.titleSmall,
color = Color.LightGray,
)
}
}
}
}

item {
Text(
text = "Upcoming Matches",
modifier = Modifier.padding(start = 8.dp),
modifier = Modifier.padding(start = 15.dp, top = 55.dp),
color = ColorFF181818,
style = GnrTypography.subtitleMedium,
)
Expand All @@ -92,7 +139,7 @@ fun HomeScreen(
}
is UpcomingMatchesUiState.Success -> {
LazyRow(
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 12.dp),
contentPadding = PaddingValues(horizontal = 15.dp, vertical = 15.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
items(
Expand All @@ -104,7 +151,7 @@ fun HomeScreen(
homeShortName = matches.homeTeamNickname,
awayUrl = matches.awayTeamImageUrl,
awayShortName = matches.awayTeamNickname,
time = DateUtil.getYearAndMonthAndDateAndTimeString(matches.matchDate),
time = DateUtil.getYearAndMonthAndDateAndDayAndTimeString(matches.matchDate),
location = if (matches.stadiumName == "null") "" else matches.stadiumName,
competitionUrl = matches.leagueImageUrl,
competitionName = "Premier League"
Expand Down Expand Up @@ -145,7 +192,7 @@ fun HomeScreen(

item {
Text(
modifier = Modifier.padding(start = 8.dp),
modifier = Modifier.padding(start = 15.dp, top = 55.dp),
text = "Recently Result",
style = GnrTypography.subtitleMedium,
color = Color.Black,
Expand All @@ -166,7 +213,7 @@ fun HomeScreen(
RecentlyMatchCard(
competitionUrl = match.match.leagueImageUrl,
competitionName = "Premier league",
time = DateUtil.getYearAndMonthAndDateAndTimeString(match.match.matchDate),
time = DateUtil.getYearAndMonthAndDateAndDayAndTimeString(match.match.matchDate),
location = match.match.stadiumName,
homeId = match.match.homeTeamId,
homeUrl = match.match.homeTeamImageUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import androidx.lifecycle.viewModelScope
import com.eshc.goonersapp.core.domain.model.DataResult
import com.eshc.goonersapp.core.domain.usecase.match.GetRecentlyMatchUseCase
import com.eshc.goonersapp.core.domain.usecase.match.GetUpcomingMatchesUseCase
import com.eshc.goonersapp.core.domain.usecase.season.GetPreviewRankListByTeamAndSeasonUseCase
import com.eshc.goonersapp.feature.home.state.DashBoardUiState
import com.eshc.goonersapp.feature.home.state.RecentlyResultUiState
import com.eshc.goonersapp.feature.home.state.UpcomingMatchesUiState
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -17,9 +19,27 @@ import javax.inject.Inject

@HiltViewModel
class HomeViewModel @Inject constructor(
getPreviewRankListByTeamAndSeasonUseCase: GetPreviewRankListByTeamAndSeasonUseCase,
getUpcomingMatchesUseCase: GetUpcomingMatchesUseCase,
getRecentlyMatchUseCase: GetRecentlyMatchUseCase
) : ViewModel() {
val teamDashBoardUiStateFlow: StateFlow<DashBoardUiState> =
getPreviewRankListByTeamAndSeasonUseCase(
seasonId = 21646
).catch { exception ->
DashBoardUiState.Error(exception.message)
}.map { result ->
when (result) {
is DataResult.Success -> DashBoardUiState.Success(result.data)
is DataResult.Failure -> DashBoardUiState.Failed(result.message)
}
}.stateIn(
scope = viewModelScope,
initialValue = DashBoardUiState.Loading,
started = SharingStarted.Eagerly
)


val upcomingMatchesUiStateFlow: StateFlow<UpcomingMatchesUiState> =
getUpcomingMatchesUseCase()
.catch { exception ->
Expand Down
Loading

0 comments on commit 60d7331

Please sign in to comment.