mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-02-20 21:34:45 +01:00
Disable signed in students in login (#677)
This commit is contained in:
parent
2f56f7e4a4
commit
720a530a6c
@ -2,6 +2,8 @@ package io.github.wulkanowy.ui.modules.login.studentselect
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.View
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
@ -10,12 +12,16 @@ import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import kotlinx.android.extensions.LayoutContainer
|
||||
import kotlinx.android.synthetic.main.item_login_student_select.*
|
||||
import timber.log.Timber
|
||||
|
||||
class LoginStudentSelectItem(val student: Student) : AbstractFlexibleItem<LoginStudentSelectItem.ItemViewHolder>() {
|
||||
class LoginStudentSelectItem(val student: Student, val alreadySaved: Boolean) :
|
||||
AbstractFlexibleItem<LoginStudentSelectItem.ItemViewHolder>() {
|
||||
|
||||
override fun getLayoutRes() = R.layout.item_login_student_select
|
||||
|
||||
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<*>>): ItemViewHolder {
|
||||
Timber.i("createViewHolder()")
|
||||
Timber.i(alreadySaved.toString())
|
||||
return ItemViewHolder(view, adapter)
|
||||
}
|
||||
|
||||
@ -24,6 +30,10 @@ class LoginStudentSelectItem(val student: Student) : AbstractFlexibleItem<LoginS
|
||||
holder.apply {
|
||||
loginItemName.text = "${student.studentName} ${student.className}"
|
||||
loginItemSchool.text = student.schoolName
|
||||
loginItemName.isEnabled = !alreadySaved
|
||||
loginItemSchool.isEnabled = !alreadySaved
|
||||
loginItemCheck.isEnabled = !alreadySaved
|
||||
loginItemSignedIn.visibility = if (alreadySaved) VISIBLE else GONE
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +44,7 @@ class LoginStudentSelectItem(val student: Student) : AbstractFlexibleItem<LoginS
|
||||
other as LoginStudentSelectItem
|
||||
|
||||
if (student != other.student) return false
|
||||
if (alreadySaved != other.alreadySaved) return false
|
||||
|
||||
return true
|
||||
}
|
||||
@ -42,7 +53,8 @@ class LoginStudentSelectItem(val student: Student) : AbstractFlexibleItem<LoginS
|
||||
return student.hashCode()
|
||||
}
|
||||
|
||||
class ItemViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer {
|
||||
class ItemViewHolder(view: View, val adapter: FlexibleAdapter<*>) :
|
||||
FlexibleViewHolder(view, adapter), LayoutContainer {
|
||||
|
||||
override val containerView: View
|
||||
get() = itemView
|
||||
@ -53,7 +65,10 @@ class LoginStudentSelectItem(val student: Student) : AbstractFlexibleItem<LoginS
|
||||
|
||||
override fun onClick(view: View?) {
|
||||
super.onClick(view)
|
||||
loginItemCheck.apply { isChecked = !isChecked }
|
||||
|
||||
if (loginItemCheck.isEnabled) {
|
||||
loginItemCheck.apply { isChecked = !isChecked }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
|
||||
import io.github.wulkanowy.utils.SchedulersProvider
|
||||
import io.github.wulkanowy.utils.ifNullOrBlank
|
||||
import io.reactivex.Single
|
||||
import timber.log.Timber
|
||||
import java.io.Serializable
|
||||
import javax.inject.Inject
|
||||
@ -50,7 +51,7 @@ class LoginStudentSelectPresenter @Inject constructor(
|
||||
}
|
||||
|
||||
fun onItemSelected(item: AbstractFlexibleItem<*>?) {
|
||||
if (item is LoginStudentSelectItem) {
|
||||
if (item is LoginStudentSelectItem && !item.alreadySaved) {
|
||||
selectedStudents.removeAll { it == item.student }
|
||||
.let { if (!it) selectedStudents.add(item.student) }
|
||||
|
||||
@ -58,11 +59,33 @@ class LoginStudentSelectPresenter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun compareStudents(a: Student, b: Student): Boolean {
|
||||
return a.email == b.email
|
||||
&& a.symbol == b.symbol
|
||||
&& a.studentId == b.studentId
|
||||
&& a.schoolSymbol == b.schoolSymbol
|
||||
&& a.classId == b.classId
|
||||
}
|
||||
|
||||
private fun loadData(students: List<Student>) {
|
||||
this.students = students
|
||||
view?.apply {
|
||||
updateData(students.map { LoginStudentSelectItem(it) })
|
||||
}
|
||||
disposable.add(studentRepository.getSavedStudents()
|
||||
.map { savedStudents ->
|
||||
students.map { student ->
|
||||
Pair(student, savedStudents.any { compareStudents(student, it) })
|
||||
}
|
||||
}
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.observeOn(schedulers.mainThread)
|
||||
.subscribe({
|
||||
view?.updateData(it.map { studentPair ->
|
||||
LoginStudentSelectItem(studentPair.first, studentPair.second)
|
||||
})
|
||||
}, {
|
||||
errorHandler.dispatch(it)
|
||||
view?.updateData(students.map { student -> LoginStudentSelectItem(student, false) })
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
private fun registerStudents(students: List<Student>) {
|
||||
|
@ -2,8 +2,11 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/loginItemContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
android:background="?selectableItemBackground">
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="72dp"
|
||||
android:background="?selectableItemBackground"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingTop="8dp">
|
||||
|
||||
<com.google.android.material.checkbox.MaterialCheckBox
|
||||
android:id="@+id/loginItemCheck"
|
||||
@ -11,16 +14,16 @@
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginEnd="28dp"
|
||||
android:layout_marginRight="28dp"
|
||||
android:background="@android:color/transparent"
|
||||
android:layout_centerVertical="true"
|
||||
tools:text=" " />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loginItemName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="32dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_toEndOf="@id/loginItemCheck"
|
||||
@ -34,7 +37,7 @@
|
||||
<TextView
|
||||
android:id="@+id/loginItemSchool"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="20dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/loginItemName"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
@ -42,8 +45,27 @@
|
||||
android:layout_toRightOf="@id/loginItemCheck"
|
||||
android:ellipsize="end"
|
||||
android:gravity="bottom"
|
||||
android:maxLines="2"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="14sp"
|
||||
tools:text="@tools:sample/lorem/random" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loginItemSignedIn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="20dp"
|
||||
android:layout_below="@id/loginItemSchool"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_toEndOf="@id/loginItemCheck"
|
||||
android:layout_toRightOf="@id/loginItemCheck"
|
||||
android:ellipsize="end"
|
||||
android:gravity="bottom"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="14sp"
|
||||
tools:text="@tools:sample/lorem/random" />
|
||||
android:text="@string/login_signed_in"
|
||||
android:enabled="false"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
</RelativeLayout>
|
||||
|
@ -52,6 +52,7 @@
|
||||
<string name="login_contact_email">Email</string>
|
||||
<string name="login_contact_discord">Discord</string>
|
||||
<string name="login_email_intent_title">Wyślij email</string>
|
||||
<string name="login_signed_in">Uczeń jest już zalogowany</string>
|
||||
|
||||
|
||||
<!--Main-->
|
||||
|
@ -53,6 +53,7 @@
|
||||
<string name="login_contact_email">Электронная почта</string>
|
||||
<string name="login_contact_discord">Discord</string>
|
||||
<string name="login_email_intent_title">Отправить письмо</string>
|
||||
<string name="login_signed_in">Студент уже вошел в систему</string>
|
||||
|
||||
|
||||
<!--Main-->
|
||||
|
@ -54,6 +54,7 @@
|
||||
<string name="login_email_intent_title">Send email</string>
|
||||
<string name="login_email_subject" translatable="false">Zgłoszenie: Problemy z logowaniem</string>
|
||||
<string name="login_email_text" translatable="false">Informacje o aplikacji:\n\nUrządzenie: %1$s\nWersja SDK: %2$s\nWersja aplikacji: %3$s\n\nOpis problemu:</string>
|
||||
<string name="login_signed_in">Student is already signed in</string>
|
||||
|
||||
|
||||
<!--Main-->
|
||||
|
@ -53,7 +53,7 @@ class LoginStudentSelectPresenterTest {
|
||||
fun onSelectedStudentTest() {
|
||||
doReturn(Single.just(listOf(1L))).`when`(studentRepository).saveStudents(listOf(testStudent))
|
||||
doReturn(Completable.complete()).`when`(studentRepository).switchStudent(testStudent)
|
||||
presenter.onItemSelected(LoginStudentSelectItem(testStudent))
|
||||
presenter.onItemSelected(LoginStudentSelectItem(testStudent, false))
|
||||
presenter.onSignIn()
|
||||
verify(loginStudentSelectView).showContent(false)
|
||||
verify(loginStudentSelectView).showProgress(true)
|
||||
@ -64,7 +64,7 @@ class LoginStudentSelectPresenterTest {
|
||||
fun onSelectedStudentErrorTest() {
|
||||
doReturn(Single.error<Student>(testException)).`when`(studentRepository).saveStudents(listOf(testStudent))
|
||||
doReturn(Completable.complete()).`when`(studentRepository).logoutStudent(testStudent)
|
||||
presenter.onItemSelected(LoginStudentSelectItem(testStudent))
|
||||
presenter.onItemSelected(LoginStudentSelectItem(testStudent, false))
|
||||
presenter.onSignIn()
|
||||
verify(loginStudentSelectView).showContent(false)
|
||||
verify(loginStudentSelectView).showProgress(true)
|
||||
|
Loading…
x
Reference in New Issue
Block a user