forked from github/szkolny
[APIv2/Timetable] Add selecting date, marking as read and fix stepForward in Date
This commit is contained in:
parent
540afb6a28
commit
63960c5e05
@ -4,21 +4,28 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.google.android.material.datepicker.MaterialDatePicker
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||
import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont
|
||||
import kotlinx.coroutines.*
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_TYPE_LIBRUS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentTimetableV2Binding
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem
|
||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class TimetableFragment : Fragment(), CoroutineScope {
|
||||
@ -151,6 +158,35 @@ class TimetableFragment : Fragment(), CoroutineScope {
|
||||
b.tabLayout.setUpWithViewPager(b.viewPager)
|
||||
b.tabLayout.setCurrentItem(items.indexOfFirst { it.value == today }, false)
|
||||
|
||||
activity.navView.bottomSheet.prependItems(
|
||||
BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.timetable_select_day)
|
||||
.withIcon(SzkolnyFont.Icon.szf_calendar_today_outline)
|
||||
.withOnClickListener(View.OnClickListener {
|
||||
activity.bottomSheet.close()
|
||||
MaterialDatePicker.Builder
|
||||
.datePicker()
|
||||
.setSelection(Date.getToday().inMillis)
|
||||
.build()
|
||||
.apply {
|
||||
addOnPositiveButtonClickListener { dateInMillis ->
|
||||
val dateSelected = Date.fromMillis(dateInMillis)
|
||||
b.tabLayout.setCurrentItem(items.indexOfFirst { it == dateSelected }, true)
|
||||
}
|
||||
show(this@TimetableFragment.activity.supportFragmentManager, "MaterialDatePicker")
|
||||
}
|
||||
}),
|
||||
BottomSheetSeparatorItem(true),
|
||||
BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.menu_mark_as_read)
|
||||
.withIcon(CommunityMaterial.Icon.cmd_eye_check_outline)
|
||||
.withOnClickListener(View.OnClickListener {
|
||||
activity.bottomSheet.close()
|
||||
AsyncTask.execute { app.db.metadataDao().setAllSeen(App.profileId, Metadata.TYPE_LESSON_CHANGE, true) }
|
||||
Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show()
|
||||
})
|
||||
)
|
||||
|
||||
//activity.navView.bottomBar.fabEnable = true
|
||||
activity.navView.bottomBar.fabExtendedText = getString(R.string.timetable_today)
|
||||
activity.navView.bottomBar.fabIcon = SzkolnyFont.Icon.szf_calendar_today_outline
|
||||
@ -158,4 +194,4 @@ class TimetableFragment : Fragment(), CoroutineScope {
|
||||
b.tabLayout.setCurrentItem(items.indexOfFirst { it.value == today }, true)
|
||||
})
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
@ -134,11 +134,23 @@ public class Date implements Comparable<Date> {
|
||||
|
||||
public Date stepForward(int years, int months, int days) {
|
||||
this.day += days;
|
||||
if (day <= 0) {
|
||||
month--;
|
||||
if(month <= 0) {
|
||||
month += 12;
|
||||
year--;
|
||||
}
|
||||
day += daysInMonth();
|
||||
}
|
||||
if (day > daysInMonth()) {
|
||||
day -= daysInMonth();
|
||||
month++;
|
||||
}
|
||||
this.month += months;
|
||||
if(month <= 0) {
|
||||
month += 12;
|
||||
year--;
|
||||
}
|
||||
if (month > 12) {
|
||||
month -= 12;
|
||||
year++;
|
||||
@ -176,6 +188,7 @@ public class Date implements Comparable<Date> {
|
||||
public boolean isLeap() {
|
||||
return ((year & 3) == 0) && ((year % 100) != 0 || (year % 400) == 0);
|
||||
}
|
||||
|
||||
public int daysInMonth() {
|
||||
switch (month) {
|
||||
case 1:
|
||||
|
@ -1030,4 +1030,5 @@
|
||||
<string name="edziennik_progress_endpoint_grade_comments">Pobieranie komentarzy ocen...</string>
|
||||
<string name="menu_remove_notifications">Usuń wszystkie</string>
|
||||
<string name="menu_remove_notifications_success">Wyczyszczono powiadomienia</string>
|
||||
<string name="timetable_select_day">Wybierz dzień</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user