Change login progress bars (#272)

This commit is contained in:
Mikołaj Pich 2019-03-10 11:57:11 +01:00 committed by Rafał Borcz
parent f773310cdb
commit feb38b97e4
17 changed files with 44 additions and 110 deletions

View File

@ -37,4 +37,3 @@ class SemesterRepository @Inject constructor(
return getSemesters(student, forceRefresh).map { item -> item.single { it.isCurrent } } return getSemesters(student, forceRefresh).map { item -> item.single { it.isCurrent } }
} }
} }

View File

@ -75,6 +75,7 @@ class AttendanceSummaryPresenter @Inject constructor(
view?.run { view?.run {
hideRefresh() hideRefresh()
showProgress(false) showProgress(false)
enableSwipe(true)
} }
} }
.subscribe({ .subscribe({

View File

@ -115,7 +115,7 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
} }
override fun showProgress(show: Boolean) { override fun showProgress(show: Boolean) {
loginFormProgressContainer.visibility = if (show) VISIBLE else GONE loginFormProgress.visibility = if (show) VISIBLE else GONE
} }
override fun showContent(show: Boolean) { override fun showContent(show: Boolean) {

View File

@ -47,7 +47,7 @@ class LoginStudentSelectFragment : BaseFragment(), LoginStudentSelectView {
override fun initView() { override fun initView() {
loginAdapter.apply { setOnItemClickListener { presenter.onItemSelected(it) } } loginAdapter.apply { setOnItemClickListener { presenter.onItemSelected(it) } }
loginOptionsRecycler.apply { loginStudentSelectRecycler.apply {
adapter = loginAdapter adapter = loginAdapter
layoutManager = SmoothScrollLinearLayoutManager(context) layoutManager = SmoothScrollLinearLayoutManager(context)
} }
@ -65,11 +65,11 @@ class LoginStudentSelectFragment : BaseFragment(), LoginStudentSelectView {
} }
override fun showProgress(show: Boolean) { override fun showProgress(show: Boolean) {
loginOptionsProgressContainer.visibility = if (show) VISIBLE else GONE loginStudentSelectProgress.visibility = if (show) VISIBLE else GONE
} }
override fun showContent(show: Boolean) { override fun showContent(show: Boolean) {
loginOptionsRecycler.visibility = if (show) VISIBLE else GONE loginStudentSelectRecycler.visibility = if (show) VISIBLE else GONE
} }
override fun showActionBar(show: Boolean) { override fun showActionBar(show: Boolean) {

View File

@ -8,11 +8,11 @@ import eu.davidea.viewholders.FlexibleViewHolder
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.Student
import kotlinx.android.extensions.LayoutContainer import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.item_login_options.view.* import kotlinx.android.synthetic.main.item_login_student_select.view.*
class LoginStudentSelectItem(val student: Student) : AbstractFlexibleItem<LoginStudentSelectItem.ItemViewHolder>() { class LoginStudentSelectItem(val student: Student) : AbstractFlexibleItem<LoginStudentSelectItem.ItemViewHolder>() {
override fun getLayoutRes(): Int = R.layout.item_login_options override fun getLayoutRes(): Int = R.layout.item_login_student_select
override fun createViewHolder(view: View?, adapter: FlexibleAdapter<IFlexible<*>>?): ItemViewHolder { override fun createViewHolder(view: View?, adapter: FlexibleAdapter<IFlexible<*>>?): ItemViewHolder {
return ItemViewHolder(view, adapter) return ItemViewHolder(view, adapter)

View File

@ -3,7 +3,6 @@ package io.github.wulkanowy.ui.modules.login.studentselect
import com.google.firebase.analytics.FirebaseAnalytics.Param.SUCCESS import com.google.firebase.analytics.FirebaseAnalytics.Param.SUCCESS
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.repositories.semester.SemesterRepository
import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.data.repositories.student.StudentRepository
import io.github.wulkanowy.ui.base.BasePresenter import io.github.wulkanowy.ui.base.BasePresenter
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
@ -17,7 +16,6 @@ import javax.inject.Inject
class LoginStudentSelectPresenter @Inject constructor( class LoginStudentSelectPresenter @Inject constructor(
private val errorHandler: LoginErrorHandler, private val errorHandler: LoginErrorHandler,
private val studentRepository: StudentRepository, private val studentRepository: StudentRepository,
private val semesterRepository: SemesterRepository,
private val schedulers: SchedulersProvider, private val schedulers: SchedulersProvider,
private val analytics: FirebaseAnalyticsHelper private val analytics: FirebaseAnalyticsHelper
) : BasePresenter<LoginStudentSelectView>(errorHandler) { ) : BasePresenter<LoginStudentSelectView>(errorHandler) {
@ -59,7 +57,6 @@ class LoginStudentSelectPresenter @Inject constructor(
private fun registerStudent(student: Student) { private fun registerStudent(student: Student) {
disposable.add(studentRepository.saveStudent(student) disposable.add(studentRepository.saveStudent(student)
.map { student.apply { id = it } } .map { student.apply { id = it } }
.flatMap { semesterRepository.getSemesters(student, true) }
.onErrorResumeNext { studentRepository.logoutStudent(student).andThen(Single.error(it)) } .onErrorResumeNext { studentRepository.logoutStudent(student).andThen(Single.error(it)) }
.flatMapCompletable { studentRepository.switchStudent(student) } .flatMapCompletable { studentRepository.switchStudent(student) }
.subscribeOn(schedulers.backgroundThread) .subscribeOn(schedulers.backgroundThread)

View File

@ -93,7 +93,7 @@ class LoginSymbolFragment : BaseFragment(), LoginSymbolView {
} }
override fun showProgress(show: Boolean) { override fun showProgress(show: Boolean) {
loginSymbolProgressContainer.visibility = if (show) VISIBLE else GONE loginSymbolProgress.visibility = if (show) VISIBLE else GONE
} }
override fun showContent(show: Boolean) { override fun showContent(show: Boolean) {

View File

@ -33,8 +33,6 @@ class LuckyNumberFragment : BaseSessionFragment(), LuckyNumberView, MainView.Tit
} }
override fun initView() { override fun initView() {
showContent(false)
showProgress(true)
luckyNumberSwipe.setOnRefreshListener { presenter.onSwipeRefresh() } luckyNumberSwipe.setOnRefreshListener { presenter.onSwipeRefresh() }
} }

View File

@ -35,6 +35,12 @@ class LuckyNumberPresenter @Inject constructor(
.flatMapMaybe { luckyNumberRepository.getLuckyNumber(it, forceRefresh) } .flatMapMaybe { luckyNumberRepository.getLuckyNumber(it, forceRefresh) }
.subscribeOn(schedulers.backgroundThread) .subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread) .observeOn(schedulers.mainThread)
.doOnSubscribe {
view?.run {
showContent(false)
enableSwipe(false)
}
}
.doFinally { .doFinally {
view?.run { view?.run {
hideRefresh() hideRefresh()

View File

@ -4,31 +4,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<RelativeLayout <ProgressBar
android:id="@+id/loginFormProgressContainer" android:id="@+id/loginFormProgress"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:gravity="center" android:layout_gravity="center"
android:visibility="gone"> android:indeterminate="true"
android:visibility="gone" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/loginFormProgressTitle"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:minWidth="220dp"
android:minHeight="30dp" />
<TextView
android:id="@+id/loginFormProgressTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:text="@string/login_progress" />
</RelativeLayout>
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollView" android:id="@+id/nestedScrollView"

View File

@ -1,40 +1,21 @@
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<RelativeLayout <ProgressBar
android:id="@+id/loginOptionsProgressContainer" android:id="@+id/loginStudentSelectProgress"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:gravity="center" android:layout_gravity="center"
android:visibility="gone"> android:indeterminate="true"
android:visibility="gone" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/loginOptionsProgressText"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:minWidth="220dp"
android:minHeight="30dp" />
<TextView
android:id="@+id/loginOptionsProgressText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:text="@string/login_sync" />
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/loginOptionsRecycler" android:id="@+id/loginStudentSelectRecycler"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:itemCount="5" tools:itemCount="5"
tools:listitem="@layout/item_login_options" /> tools:listitem="@layout/item_login_student_select" />
</LinearLayout> </FrameLayout>

View File

@ -4,31 +4,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<RelativeLayout <ProgressBar
android:id="@+id/loginSymbolProgressContainer" android:id="@+id/loginSymbolProgress"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:gravity="center" android:layout_gravity="center"
android:visibility="gone"> android:indeterminate="true"
android:visibility="gone" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/loginSymbolProgressText"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:minWidth="220dp"
android:minHeight="30dp" />
<TextView
android:id="@+id/loginSymbolProgressText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:text="@string/login_progress" />
</RelativeLayout>
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -11,7 +11,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:indeterminate="true" android:indeterminate="true"
android:visibility="gone" /> tools:visibility="invisible" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/luckyNumberSwipe" android:id="@+id/luckyNumberSwipe"
@ -36,8 +36,8 @@
android:id="@+id/luckyNumberText" android:id="@+id/luckyNumberText"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
tools:text="14" android:textSize="52sp"
android:textSize="52sp" /> tools:text="14" />
</LinearLayout> </LinearLayout>

View File

@ -26,11 +26,9 @@
<string name="login_host_hint">Dziennik</string> <string name="login_host_hint">Dziennik</string>
<string name="login_symbol_hint">Symbol</string> <string name="login_symbol_hint">Symbol</string>
<string name="login_sign_in">Zaloguj</string> <string name="login_sign_in">Zaloguj</string>
<string name="login_progress">Logowanie&#8230;</string>
<string name="login_sync">Synchronizacja</string>
<string name="login_invalid_password">To hasło jest za krótkie</string> <string name="login_invalid_password">To hasło jest za krótkie</string>
<string name="login_incorrect_password">Dane logowania są niepoprawne</string> <string name="login_incorrect_password">Dane logowania są niepoprawne</string>
<string name="login_incorrect_symbol">Nie znaleziono ucznia. Sprwadź symbol</string> <string name="login_incorrect_symbol">Nie znaleziono ucznia. Sprawdź symbol</string>
<string name="login_field_required">To pole jest wymagane</string> <string name="login_field_required">To pole jest wymagane</string>
<string name="login_duplicate_student">Ten student jest już zalogowany</string> <string name="login_duplicate_student">Ten student jest już zalogowany</string>
<string name="login_symbol_helper">Symbol znajduje się na stronie dziennika w zakładce Dostęp Mobilny</string> <string name="login_symbol_helper">Symbol znajduje się na stronie dziennika w zakładce Dostęp Mobilny</string>

View File

@ -26,8 +26,6 @@
<string name="login_host_hint">Register</string> <string name="login_host_hint">Register</string>
<string name="login_symbol_hint">Symbol</string> <string name="login_symbol_hint">Symbol</string>
<string name="login_sign_in">Sign in</string> <string name="login_sign_in">Sign in</string>
<string name="login_progress">Logging in&#8230;</string>
<string name="login_sync">Synchronization&#8230;</string>
<string name="login_invalid_password">This password is too short</string> <string name="login_invalid_password">This password is too short</string>
<string name="login_incorrect_password">Login details are incorrect</string> <string name="login_incorrect_password">Login details are incorrect</string>
<string name="login_incorrect_symbol">Student not found. Check the symbol</string> <string name="login_incorrect_symbol">Student not found. Check the symbol</string>

View File

@ -1,9 +1,7 @@
package io.github.wulkanowy.ui.modules.login.studentselect package io.github.wulkanowy.ui.modules.login.studentselect
import io.github.wulkanowy.TestSchedulersProvider import io.github.wulkanowy.TestSchedulersProvider
import io.github.wulkanowy.data.db.entities.Semester
import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.repositories.semester.SemesterRepository
import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.data.repositories.student.StudentRepository
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
@ -29,9 +27,6 @@ class LoginStudentSelectPresenterTest {
@Mock @Mock
lateinit var studentRepository: StudentRepository lateinit var studentRepository: StudentRepository
@Mock
lateinit var semesterRepository: SemesterRepository
@Mock @Mock
lateinit var analytics: FirebaseAnalyticsHelper lateinit var analytics: FirebaseAnalyticsHelper
@ -45,8 +40,7 @@ class LoginStudentSelectPresenterTest {
fun initPresenter() { fun initPresenter() {
MockitoAnnotations.initMocks(this) MockitoAnnotations.initMocks(this)
clearInvocations(studentRepository, loginStudentSelectView) clearInvocations(studentRepository, loginStudentSelectView)
clearInvocations(semesterRepository, loginStudentSelectView) presenter = LoginStudentSelectPresenter(errorHandler, studentRepository, TestSchedulersProvider(), analytics)
presenter = LoginStudentSelectPresenter(errorHandler, studentRepository, semesterRepository, TestSchedulersProvider(), analytics)
presenter.onAttachView(loginStudentSelectView, null) presenter.onAttachView(loginStudentSelectView, null)
} }
@ -58,7 +52,6 @@ class LoginStudentSelectPresenterTest {
@Test @Test
fun onSelectedStudentTest() { fun onSelectedStudentTest() {
doReturn(Single.just(1L)).`when`(studentRepository).saveStudent(testStudent) doReturn(Single.just(1L)).`when`(studentRepository).saveStudent(testStudent)
doReturn(Single.just(emptyList<Semester>())).`when`(semesterRepository).getSemesters(testStudent, true)
doReturn(Completable.complete()).`when`(studentRepository).switchStudent(testStudent) doReturn(Completable.complete()).`when`(studentRepository).switchStudent(testStudent)
presenter.onItemSelected(LoginStudentSelectItem(testStudent)) presenter.onItemSelected(LoginStudentSelectItem(testStudent))
verify(loginStudentSelectView).showContent(false) verify(loginStudentSelectView).showContent(false)
@ -69,7 +62,6 @@ class LoginStudentSelectPresenterTest {
@Test @Test
fun onSelectedStudentErrorTest() { fun onSelectedStudentErrorTest() {
doReturn(Single.error<Student>(testException)).`when`(studentRepository).saveStudent(testStudent) doReturn(Single.error<Student>(testException)).`when`(studentRepository).saveStudent(testStudent)
doReturn(Single.just(emptyList<Semester>())).`when`(semesterRepository).getSemesters(testStudent, true)
doReturn(Completable.complete()).`when`(studentRepository).logoutStudent(testStudent) doReturn(Completable.complete()).`when`(studentRepository).logoutStudent(testStudent)
presenter.onItemSelected(LoginStudentSelectItem(testStudent)) presenter.onItemSelected(LoginStudentSelectItem(testStudent))
verify(loginStudentSelectView).showContent(false) verify(loginStudentSelectView).showContent(false)