[API] Fix archiving compatibility for older app versions.

This commit is contained in:
Kuba Szczodrzyński 2020-08-25 22:25:21 +02:00
parent 6c6bc89f57
commit a02033d0f3
3 changed files with 25 additions and 21 deletions

View File

@ -617,6 +617,16 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
swipeRefreshLayout.isRefreshing = false swipeRefreshLayout.isRefreshing = false
return return
} }
if (app.profile.shouldArchive()) {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.profile_archiving_title)
.setMessage(
R.string.profile_archiving_format,
app.profile.dateYearEnd.formattedString
)
.setPositiveButton(R.string.ok, null)
.show()
}
if (app.profile.isBeforeYear()) { if (app.profile.isBeforeYear()) {
MaterialAlertDialogBuilder(this) MaterialAlertDialogBuilder(this)
.setTitle(R.string.profile_year_not_started_title) .setTitle(R.string.profile_year_not_started_title)
@ -629,21 +639,6 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
swipeRefreshLayout.isRefreshing = false swipeRefreshLayout.isRefreshing = false
return return
} }
// vulcan hotfix
if (app.profile.dateYearEnd.month > 6) {
app.profile.dateYearEnd.month = 6
app.profile.dateYearEnd.day = 30
}
if (app.profile.shouldArchive()) {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.profile_archiving_title)
.setMessage(
R.string.profile_archiving_format,
app.profile.dateYearEnd.formattedString
)
.setPositiveButton(R.string.ok, null)
.show()
}
swipeRefreshLayout.isRefreshing = true swipeRefreshLayout.isRefreshing = true
Toast.makeText(this, fragmentToSyncName(navTargetId), Toast.LENGTH_SHORT).show() Toast.makeText(this, fragmentToSyncName(navTargetId), Toast.LENGTH_SHORT).show()
val fragmentParam = when (navTargetId) { val fragmentParam = when (navTargetId) {

View File

@ -73,11 +73,6 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
internal fun run(app: App, taskCallback: EdziennikCallback) { internal fun run(app: App, taskCallback: EdziennikCallback) {
profile?.let { profile -> profile?.let { profile ->
// vulcan hotfix
if (profile.dateYearEnd.month > 6) {
profile.dateYearEnd.month = 6
profile.dateYearEnd.day = 30
}
if (profile.archived) { if (profile.archived) {
d(TAG, "The profile $profileId is archived") d(TAG, "The profile $profileId is archived")
taskCallback.onError(ApiError(TAG, ERROR_PROFILE_ARCHIVED)) taskCallback.onError(ApiError(TAG, ERROR_PROFILE_ARCHIVED))

View File

@ -91,7 +91,21 @@ open class Profile(
@delegate:Ignore @delegate:Ignore
val currentSemester by lazy { dateToSemester(Date.getToday()) } val currentSemester by lazy { dateToSemester(Date.getToday()) }
fun shouldArchive() = Date.getToday() >= dateYearEnd && Date.getToday().year > studentSchoolYearStart fun shouldArchive(): Boolean {
// vulcan hotfix
if (dateYearEnd.month > 6) {
dateYearEnd.month = 6
dateYearEnd.day = 30
}
// fix for when versions <4.3 synced 2020/2021 year dates to older profiles during 2020 Jun-Aug
if (dateSemester1Start.year > studentSchoolYearStart) {
val diff = dateSemester1Start.year - studentSchoolYearStart
dateSemester1Start.year -= diff
dateSemester2Start.year -= diff
dateYearEnd.year -= diff
}
return Date.getToday() >= dateYearEnd && Date.getToday().year > studentSchoolYearStart
}
fun isBeforeYear() = Date.getToday() < dateSemester1Start fun isBeforeYear() = Date.getToday() < dateSemester1Start
var disabledNotifications: List<Long>? = null var disabledNotifications: List<Long>? = null