mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-23 17:16:02 -06:00
Add swipe refresh to grade fragment (#287)
This commit is contained in:
parent
8db73e9459
commit
575e244b3a
@ -14,6 +14,7 @@ cache:
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- 0.7.x
|
||||
|
||||
android:
|
||||
licenses:
|
||||
|
@ -77,7 +77,7 @@ play {
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
implementation('com.github.wulkanowy:api:0aea843800') { exclude module: "threetenbp" }
|
||||
implementation('com.github.wulkanowy:api:bc60169383') { exclude module: "threetenbp" }
|
||||
|
||||
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
||||
implementation "androidx.appcompat:appcompat:1.0.2"
|
||||
|
@ -29,6 +29,8 @@ class GradeFragment : BaseSessionFragment(), GradeView, MainView.MainChildView,
|
||||
@Inject
|
||||
lateinit var pagerAdapter: BaseFragmentPagerAdapter
|
||||
|
||||
private var semesterSwitchMenu: MenuItem? = null
|
||||
|
||||
companion object {
|
||||
private const val SAVED_SEMESTER_KEY = "CURRENT_SEMESTER"
|
||||
|
||||
@ -57,6 +59,8 @@ class GradeFragment : BaseSessionFragment(), GradeView, MainView.MainChildView,
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
|
||||
inflater?.inflate(R.menu.action_menu_grade, menu)
|
||||
semesterSwitchMenu = menu?.findItem(R.id.gradeMenuSemester)
|
||||
presenter.onCreateMenu()
|
||||
}
|
||||
|
||||
override fun initView() {
|
||||
@ -75,6 +79,7 @@ class GradeFragment : BaseSessionFragment(), GradeView, MainView.MainChildView,
|
||||
setOnSelectPageListener { presenter.onPageSelected(it) }
|
||||
}
|
||||
gradeTabLayout.setupWithViewPager(gradeViewPager)
|
||||
gradeSwipe.setOnRefreshListener { presenter.onSwipeRefresh() }
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||
@ -95,8 +100,20 @@ class GradeFragment : BaseSessionFragment(), GradeView, MainView.MainChildView,
|
||||
gradeProgress.visibility = if (show) VISIBLE else INVISIBLE
|
||||
}
|
||||
|
||||
override fun showEmpty() {
|
||||
gradeEmpty.visibility = VISIBLE
|
||||
override fun showEmpty(show: Boolean) {
|
||||
gradeEmpty.visibility = if (show) VISIBLE else INVISIBLE
|
||||
}
|
||||
|
||||
override fun showRefresh(show: Boolean) {
|
||||
gradeSwipe.isRefreshing = show
|
||||
}
|
||||
|
||||
override fun showSemesterSwitch(show: Boolean) {
|
||||
semesterSwitchMenu?.isVisible = show
|
||||
}
|
||||
|
||||
override fun enableSwipe(enable: Boolean) {
|
||||
gradeSwipe.isEnabled = enable
|
||||
}
|
||||
|
||||
override fun showSemesterDialog(selectedIndex: Int) {
|
||||
|
@ -33,11 +33,18 @@ class GradePresenter @Inject constructor(
|
||||
disposable.add(Completable.timer(150, MILLISECONDS, schedulers.mainThread)
|
||||
.subscribe {
|
||||
selectedIndex = savedIndex ?: 0
|
||||
view.initView()
|
||||
view.run {
|
||||
initView()
|
||||
enableSwipe(false)
|
||||
}
|
||||
loadData()
|
||||
})
|
||||
}
|
||||
|
||||
fun onCreateMenu() {
|
||||
if (semesters.isEmpty()) view?.showSemesterSwitch(false)
|
||||
}
|
||||
|
||||
fun onViewReselected() {
|
||||
Timber.i("Grade view is reselected")
|
||||
view?.run { notifyChildParentReselected(currentPageIndex) }
|
||||
@ -69,6 +76,7 @@ class GradePresenter @Inject constructor(
|
||||
view?.apply {
|
||||
showContent(true)
|
||||
showProgress(false)
|
||||
showEmpty(false)
|
||||
loadedSemesterId[currentPageIndex] = semesterId
|
||||
}
|
||||
}
|
||||
@ -77,6 +85,10 @@ class GradePresenter @Inject constructor(
|
||||
loadChild(index)
|
||||
}
|
||||
|
||||
fun onSwipeRefresh() {
|
||||
loadData()
|
||||
}
|
||||
|
||||
private fun loadData() {
|
||||
Timber.i("Loading grade data started")
|
||||
disposable.add(studentRepository.getCurrentStudent()
|
||||
@ -89,17 +101,21 @@ class GradePresenter @Inject constructor(
|
||||
}
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.observeOn(schedulers.mainThread)
|
||||
.doFinally { view?.showRefresh(false) }
|
||||
.subscribe({
|
||||
view?.run {
|
||||
Timber.i("Loading grade result: Attempt load index $currentPageIndex")
|
||||
loadChild(currentPageIndex)
|
||||
enableSwipe(false)
|
||||
showSemesterSwitch(true)
|
||||
}
|
||||
}) {
|
||||
Timber.i("Loading grade result: An exception occurred")
|
||||
errorHandler.dispatch(it)
|
||||
view?.run {
|
||||
showProgress(false)
|
||||
showEmpty()
|
||||
showEmpty(true)
|
||||
enableSwipe(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -12,10 +12,16 @@ interface GradeView : BaseSessionView {
|
||||
|
||||
fun showProgress(show: Boolean)
|
||||
|
||||
fun showEmpty()
|
||||
fun showEmpty(show: Boolean)
|
||||
|
||||
fun showRefresh(show: Boolean)
|
||||
|
||||
fun showSemesterSwitch(show: Boolean)
|
||||
|
||||
fun showSemesterDialog(selectedIndex: Int)
|
||||
|
||||
fun enableSwipe(enable: Boolean)
|
||||
|
||||
fun notifyChildLoadData(index: Int, semesterId: Int, forceRefresh: Boolean)
|
||||
|
||||
fun notifyChildParentReselected(index: Int)
|
||||
|
@ -17,13 +17,19 @@
|
||||
app:tabTextColor="@android:color/white"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/gradeViewPager"
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/gradeSwipe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="48dp"
|
||||
android:visibility="invisible"
|
||||
tools:visibility="visible" />
|
||||
android:layout_marginTop="48dp">
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/gradeViewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="invisible"
|
||||
tools:visibility="visible" />
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/gradeProgress"
|
||||
|
Loading…
Reference in New Issue
Block a user