mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 10:54:36 -06:00
[UI/Timetable] Fix syncing a week not refreshing the current page.
This commit is contained in:
parent
1bf0679e92
commit
6c50a80b42
@ -62,6 +62,8 @@ class TimetableDayFragment : LazyFragment(), CoroutineScope {
|
||||
private var firstEventMinute = 24 * 60
|
||||
private var paddingTop = 0
|
||||
|
||||
private var viewsRemoved = false
|
||||
|
||||
private val manager
|
||||
get() = app.timetableManager
|
||||
private val attendanceManager
|
||||
@ -127,6 +129,7 @@ class TimetableDayFragment : LazyFragment(), CoroutineScope {
|
||||
inflater.inflate(R.layout.timetable_no_timetable, b.root) { view, _, _ ->
|
||||
b.root.removeAllViews()
|
||||
b.root.addView(view)
|
||||
viewsRemoved = true
|
||||
|
||||
val b = TimetableNoTimetableBinding.bind(view)
|
||||
val weekStart = date.weekStart.stringY_m_d
|
||||
@ -151,6 +154,7 @@ class TimetableDayFragment : LazyFragment(), CoroutineScope {
|
||||
inflater.inflate(R.layout.timetable_no_lessons, b.root) { view, _, _ ->
|
||||
b.root.removeAllViews()
|
||||
b.root.addView(view)
|
||||
viewsRemoved = true
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -162,6 +166,13 @@ class TimetableDayFragment : LazyFragment(), CoroutineScope {
|
||||
return
|
||||
}
|
||||
|
||||
// the timetable was not synced (the day layout views are removed) and is now available
|
||||
if (viewsRemoved) {
|
||||
viewsRemoved = false
|
||||
activity.sendBroadcast(Intent(TimetableFragment.ACTION_RELOAD_PAGES))
|
||||
return
|
||||
}
|
||||
|
||||
b.scrollView.isVisible = true
|
||||
b.dayFrame.removeView(dayView)
|
||||
b.dayFrame.addView(dayView, 0)
|
||||
|
@ -36,6 +36,7 @@ class TimetableFragment : Fragment(), CoroutineScope {
|
||||
companion object {
|
||||
private const val TAG = "TimetableFragment"
|
||||
const val ACTION_SCROLL_TO_DATE = "pl.szczodrzynski.edziennik.timetable.SCROLL_TO_DATE"
|
||||
const val ACTION_RELOAD_PAGES = "pl.szczodrzynski.edziennik.timetable.RELOAD_PAGES"
|
||||
const val DEFAULT_START_HOUR = 6
|
||||
const val DEFAULT_END_HOUR = 19
|
||||
var pageSelection: Date? = null
|
||||
@ -66,14 +67,22 @@ class TimetableFragment : Fragment(), CoroutineScope {
|
||||
override fun onReceive(context: Context, i: Intent) {
|
||||
if (!isAdded)
|
||||
return
|
||||
val dateStr = i.extras?.getString("timetableDate", null) ?: return
|
||||
val date = Date.fromY_m_d(dateStr)
|
||||
b.viewPager.setCurrentItem(items.indexOf(date), true)
|
||||
when (i.action) {
|
||||
ACTION_SCROLL_TO_DATE -> {
|
||||
val dateStr = i.extras?.getString("timetableDate", null) ?: return
|
||||
val date = Date.fromY_m_d(dateStr)
|
||||
b.viewPager.setCurrentItem(items.indexOf(date), true)
|
||||
}
|
||||
ACTION_RELOAD_PAGES -> {
|
||||
b.viewPager.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
activity.registerReceiver(broadcastReceiver, IntentFilter(ACTION_SCROLL_TO_DATE))
|
||||
activity.registerReceiver(broadcastReceiver, IntentFilter(ACTION_RELOAD_PAGES))
|
||||
}
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
|
@ -47,4 +47,8 @@ class TimetablePagerAdapter(
|
||||
}
|
||||
return pageTitle
|
||||
}
|
||||
|
||||
override fun getItemPosition(`object`: Any): Int {
|
||||
return POSITION_NONE
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user