Skip to content
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

bug fix : Seasonview - prev next buttons. goes 2 year back to 2023. + current season matches to mal app #268

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ enum class SeasonType : Localizable {

val season
get() = when (this) {
PREVIOUS -> SeasonCalendar.prevStartSeason
CURRENT -> SeasonCalendar.currentStartSeason
NEXT -> SeasonCalendar.nextStartSeason
PREVIOUS -> SeasonCalendar.prevStartSeason()
CURRENT -> SeasonCalendar.currentStartSeason()
NEXT -> SeasonCalendar.nextStartSeason()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class HomeViewModel(
}

private suspend fun getSeasonAnimes() {
val currentStartSeason = SeasonCalendar.currentStartSeason
val currentStartSeason = SeasonCalendar.currentStartSeason()
val result = animeRepository.getSeasonalAnimes(
sort = MediaSort.ANIME_START_DATE,
year = currentStartSeason.year,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.axiel7.moelist.utils.SeasonCalendar

@Stable
data class SeasonChartUiState(
val season: StartSeason = SeasonCalendar.currentStartSeason,
val season: StartSeason = SeasonCalendar.currentStartSeason(),
val sort: MediaSort = MediaSort.ANIME_NUM_USERS,
val isNew: Boolean = true,
val seasonType: SeasonType? = SeasonType.CURRENT,
Expand All @@ -26,7 +26,7 @@ data class SeasonChartUiState(
override fun setMessage(value: String?) = copy(message = value)

companion object {
private const val BASE_YEAR = 1917
private const val BASE_YEAR = 1950
val years = ((SeasonCalendar.currentYear + 1) downTo BASE_YEAR).toList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.axiel7.moelist.ui.season.SeasonChartEvent
import com.axiel7.moelist.ui.season.SeasonChartUiState
import com.axiel7.moelist.ui.theme.MoeListTheme
import com.axiel7.moelist.ui.userlist.composables.SortChip
import com.axiel7.moelist.utils.SeasonCalendar

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -92,7 +93,10 @@ fun SeasonChartFilterSheet(
SeasonType.entries.forEach {
SegmentedButton(
selected = it == uiState.seasonType,
onClick = { event?.setSeason(it) },
onClick =
{
event?.setSeason(it)
},
shape = SegmentedButtonDefaults.itemShape(
index = it.ordinal,
count = SeasonType.entries.size
Expand Down
104 changes: 74 additions & 30 deletions app/src/main/java/com/axiel7/moelist/utils/SeasonCalendar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,87 @@ object SeasonCalendar {

val currentYear = calendar[Calendar.YEAR]

val currentSeason = when (month) {
0, 1, 11 -> Season.WINTER
2, 3, 4 -> Season.SPRING
5, 6, 7 -> Season.SUMMER
8, 9, 10 -> Season.FALL
val currentSeason = when (month)
{
0, 1, -> Season.WINTER
2, 3, 4 -> Season.SPRING
5, 6, 7 -> Season.SUMMER
8, 9, 10,11 -> Season.FALL /*according to mal, "12 december 2024" should show -> Fall in SeasonChart */
else -> Season.SPRING
}

private val nextSeason = when (currentSeason) {
Season.WINTER -> Season.SPRING
Season.SPRING -> Season.SUMMER
Season.SUMMER -> Season.FALL
Season.FALL -> Season.WINTER
/*
--- MAL APP --button values --- expecting the same from moelist.
---- tested on 12.12.2024

previous: summer 2024
current : fall 2024
next: winter 2025
*/

private fun nextSeason (seasonx : Season): Season
{
var ret = when (seasonx)
{
Season.SPRING -> Season.SUMMER
Season.SUMMER -> Season.FALL
Season.FALL -> Season.WINTER
Season.WINTER -> Season.SPRING
}

return ret;
}
private fun prevSeason (seasonx : Season ):Season
{
var ret = when (seasonx)
{
Season.SPRING -> Season.WINTER
Season.SUMMER -> Season.SPRING
Season.FALL -> Season.SUMMER
Season.WINTER -> Season.FALL
}
return ret;
}

fun currentStartSeason() :StartSeason
{
var curYear = currentYear;
var curSeason = currentSeason;

val ss = StartSeason(
year = curYear,
season = curSeason
)
return ss;
}

fun nextStartSeason() :StartSeason
{
var curSS = currentStartSeason();

val year = if (curSS.season == Season.FALL) currentYear + 1 else currentYear;
val season = nextSeason(curSS.season);

val ss = StartSeason(
year = year,
season = season
)
return ss;
}
fun prevStartSeason() :StartSeason
{
var curSS = currentStartSeason();

val year = if (curSS.season == Season.WINTER) currentYear -1 else currentYear;
val season = prevSeason(curSS.season);

private val prevSeason = when (currentSeason) {
Season.WINTER -> Season.FALL
Season.SPRING -> Season.WINTER
Season.SUMMER -> Season.SPRING
Season.FALL -> Season.SUMMER
val ss = StartSeason(
year = year,
season = season
)
return ss;
}

val currentStartSeason = StartSeason(
// if december, the season is next year winter
year = if (month == 11) currentYear + 1 else currentYear,
season = currentSeason
)

val nextStartSeason = StartSeason(
year = if (nextSeason == Season.WINTER) currentYear + 1 else currentYear,
season = nextSeason
)

val prevStartSeason = StartSeason(
year = if (prevSeason == Season.FALL) currentYear - 1 else currentYear,
season = prevSeason
)

val currentWeekday = when (weekDay) {
2 -> WeekDay.MONDAY
Expand Down