From 792e44a9d0b263832e5cf70d15cbaf21e723f820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Tue, 2 Jun 2020 15:50:32 +0200 Subject: [PATCH] Fix login button state in student select login fragment (#863) --- .../LoginStudentSelectAdapter.kt | 9 ++++++- .../LoginStudentSelectPresenter.kt | 8 +++++- .../layout/fragment_login_student_select.xml | 25 ++++++++++--------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/studentselect/LoginStudentSelectAdapter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/studentselect/LoginStudentSelectAdapter.kt index f59260b43..3332f2be8 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/studentselect/LoginStudentSelectAdapter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/studentselect/LoginStudentSelectAdapter.kt @@ -12,7 +12,13 @@ import javax.inject.Inject class LoginStudentSelectAdapter @Inject constructor() : RecyclerView.Adapter() { + private val checkedList = mutableMapOf() + var items = emptyList>() + set(value) { + field = value + checkedList.clear() + } var onClickListener: (Student, alreadySaved: Boolean) -> Unit = { _, _ -> } @@ -36,7 +42,7 @@ class LoginStudentSelectAdapter @Inject constructor() : with(loginItemCheck) { isEnabled = !alreadySaved keyListener = null - isChecked = false + isChecked = checkedList[position] ?: false } root.setOnClickListener { @@ -45,6 +51,7 @@ class LoginStudentSelectAdapter @Inject constructor() : with(loginItemCheck) { if (isEnabled) { isChecked = !isChecked + checkedList[position] = isChecked } } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/studentselect/LoginStudentSelectPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/studentselect/LoginStudentSelectPresenter.kt index b2d0aed91..db25c0da3 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/studentselect/LoginStudentSelectPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/studentselect/LoginStudentSelectPresenter.kt @@ -22,7 +22,7 @@ class LoginStudentSelectPresenter @Inject constructor( var students = emptyList() - private var selectedStudents = mutableListOf() + private val selectedStudents = mutableListOf() fun onAttachView(view: LoginStudentSelectView, students: Serializable?) { super.onAttachView(view) @@ -69,6 +69,7 @@ class LoginStudentSelectPresenter @Inject constructor( } private fun loadData(students: List) { + resetSelectedState() this.students = students disposable.add(studentRepository.getSavedStudents() .map { savedStudents -> @@ -88,6 +89,11 @@ class LoginStudentSelectPresenter @Inject constructor( ) } + private fun resetSelectedState() { + selectedStudents.clear() + view?.enableSignIn(false) + } + private fun registerStudents(students: List) { disposable.add(studentRepository.saveStudents(students) .map { students.first().apply { id = it.first() } } diff --git a/app/src/main/res/layout/fragment_login_student_select.xml b/app/src/main/res/layout/fragment_login_student_select.xml index 64e06cbd5..f9c6c1572 100644 --- a/app/src/main/res/layout/fragment_login_student_select.xml +++ b/app/src/main/res/layout/fragment_login_student_select.xml @@ -24,10 +24,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" + android:visibility="gone" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - android:visibility="gone" tools:visibility="visible"> + android:layout_marginRight="16dp" + android:orientation="horizontal"> + @@ -95,9 +96,9 @@ android:layout_height="wrap_content" android:layout_marginStart="32dp" android:layout_marginLeft="32dp" + android:layout_marginTop="32dp" android:layout_marginEnd="32dp" android:layout_marginRight="32dp" - android:layout_marginTop="32dp" android:layout_marginBottom="32dp" android:gravity="center_horizontal" android:text="@string/login_select_student" @@ -129,8 +130,8 @@ android:layout_height="wrap_content" android:layout_marginTop="32dp" android:layout_marginEnd="24dp" - android:layout_marginRight="24dp" android:layout_marginBottom="32dp" + android:enabled="false" android:text="@string/login_sign_in" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"