forked from github/szkolny
[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 firstEventMinute = 24 * 60
|
||||||
private var paddingTop = 0
|
private var paddingTop = 0
|
||||||
|
|
||||||
|
private var viewsRemoved = false
|
||||||
|
|
||||||
private val manager
|
private val manager
|
||||||
get() = app.timetableManager
|
get() = app.timetableManager
|
||||||
private val attendanceManager
|
private val attendanceManager
|
||||||
@ -127,6 +129,7 @@ class TimetableDayFragment : LazyFragment(), CoroutineScope {
|
|||||||
inflater.inflate(R.layout.timetable_no_timetable, b.root) { view, _, _ ->
|
inflater.inflate(R.layout.timetable_no_timetable, b.root) { view, _, _ ->
|
||||||
b.root.removeAllViews()
|
b.root.removeAllViews()
|
||||||
b.root.addView(view)
|
b.root.addView(view)
|
||||||
|
viewsRemoved = true
|
||||||
|
|
||||||
val b = TimetableNoTimetableBinding.bind(view)
|
val b = TimetableNoTimetableBinding.bind(view)
|
||||||
val weekStart = date.weekStart.stringY_m_d
|
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, _, _ ->
|
inflater.inflate(R.layout.timetable_no_lessons, b.root) { view, _, _ ->
|
||||||
b.root.removeAllViews()
|
b.root.removeAllViews()
|
||||||
b.root.addView(view)
|
b.root.addView(view)
|
||||||
|
viewsRemoved = true
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -162,6 +166,13 @@ class TimetableDayFragment : LazyFragment(), CoroutineScope {
|
|||||||
return
|
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.scrollView.isVisible = true
|
||||||
b.dayFrame.removeView(dayView)
|
b.dayFrame.removeView(dayView)
|
||||||
b.dayFrame.addView(dayView, 0)
|
b.dayFrame.addView(dayView, 0)
|
||||||
|
@ -36,6 +36,7 @@ class TimetableFragment : Fragment(), CoroutineScope {
|
|||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "TimetableFragment"
|
private const val TAG = "TimetableFragment"
|
||||||
const val ACTION_SCROLL_TO_DATE = "pl.szczodrzynski.edziennik.timetable.SCROLL_TO_DATE"
|
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_START_HOUR = 6
|
||||||
const val DEFAULT_END_HOUR = 19
|
const val DEFAULT_END_HOUR = 19
|
||||||
var pageSelection: Date? = null
|
var pageSelection: Date? = null
|
||||||
@ -66,14 +67,22 @@ class TimetableFragment : Fragment(), CoroutineScope {
|
|||||||
override fun onReceive(context: Context, i: Intent) {
|
override fun onReceive(context: Context, i: Intent) {
|
||||||
if (!isAdded)
|
if (!isAdded)
|
||||||
return
|
return
|
||||||
|
when (i.action) {
|
||||||
|
ACTION_SCROLL_TO_DATE -> {
|
||||||
val dateStr = i.extras?.getString("timetableDate", null) ?: return
|
val dateStr = i.extras?.getString("timetableDate", null) ?: return
|
||||||
val date = Date.fromY_m_d(dateStr)
|
val date = Date.fromY_m_d(dateStr)
|
||||||
b.viewPager.setCurrentItem(items.indexOf(date), true)
|
b.viewPager.setCurrentItem(items.indexOf(date), true)
|
||||||
}
|
}
|
||||||
|
ACTION_RELOAD_PAGES -> {
|
||||||
|
b.viewPager.adapter?.notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
activity.registerReceiver(broadcastReceiver, IntentFilter(ACTION_SCROLL_TO_DATE))
|
activity.registerReceiver(broadcastReceiver, IntentFilter(ACTION_SCROLL_TO_DATE))
|
||||||
|
activity.registerReceiver(broadcastReceiver, IntentFilter(ACTION_RELOAD_PAGES))
|
||||||
}
|
}
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
|
@ -47,4 +47,8 @@ class TimetablePagerAdapter(
|
|||||||
}
|
}
|
||||||
return pageTitle
|
return pageTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getItemPosition(`object`: Any): Int {
|
||||||
|
return POSITION_NONE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user