1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-31 20:52:46 +01:00

Fix login button state in student select login fragment (#863)

This commit is contained in:
Mikołaj Pich 2020-06-02 15:50:32 +02:00 committed by GitHub
parent ff5a47b0df
commit 792e44a9d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 14 deletions

View File

@ -12,7 +12,13 @@ import javax.inject.Inject
class LoginStudentSelectAdapter @Inject constructor() : class LoginStudentSelectAdapter @Inject constructor() :
RecyclerView.Adapter<LoginStudentSelectAdapter.ItemViewHolder>() { RecyclerView.Adapter<LoginStudentSelectAdapter.ItemViewHolder>() {
private val checkedList = mutableMapOf<Int, Boolean>()
var items = emptyList<Pair<Student, Boolean>>() var items = emptyList<Pair<Student, Boolean>>()
set(value) {
field = value
checkedList.clear()
}
var onClickListener: (Student, alreadySaved: Boolean) -> Unit = { _, _ -> } var onClickListener: (Student, alreadySaved: Boolean) -> Unit = { _, _ -> }
@ -36,7 +42,7 @@ class LoginStudentSelectAdapter @Inject constructor() :
with(loginItemCheck) { with(loginItemCheck) {
isEnabled = !alreadySaved isEnabled = !alreadySaved
keyListener = null keyListener = null
isChecked = false isChecked = checkedList[position] ?: false
} }
root.setOnClickListener { root.setOnClickListener {
@ -45,6 +51,7 @@ class LoginStudentSelectAdapter @Inject constructor() :
with(loginItemCheck) { with(loginItemCheck) {
if (isEnabled) { if (isEnabled) {
isChecked = !isChecked isChecked = !isChecked
checkedList[position] = isChecked
} }
} }
} }

View File

@ -22,7 +22,7 @@ class LoginStudentSelectPresenter @Inject constructor(
var students = emptyList<Student>() var students = emptyList<Student>()
private var selectedStudents = mutableListOf<Student>() private val selectedStudents = mutableListOf<Student>()
fun onAttachView(view: LoginStudentSelectView, students: Serializable?) { fun onAttachView(view: LoginStudentSelectView, students: Serializable?) {
super.onAttachView(view) super.onAttachView(view)
@ -69,6 +69,7 @@ class LoginStudentSelectPresenter @Inject constructor(
} }
private fun loadData(students: List<Student>) { private fun loadData(students: List<Student>) {
resetSelectedState()
this.students = students this.students = students
disposable.add(studentRepository.getSavedStudents() disposable.add(studentRepository.getSavedStudents()
.map { savedStudents -> .map { savedStudents ->
@ -88,6 +89,11 @@ class LoginStudentSelectPresenter @Inject constructor(
) )
} }
private fun resetSelectedState() {
selectedStudents.clear()
view?.enableSignIn(false)
}
private fun registerStudents(students: List<Student>) { private fun registerStudents(students: List<Student>) {
disposable.add(studentRepository.saveStudents(students) disposable.add(studentRepository.saveStudents(students)
.map { students.first().apply { id = it.first() } } .map { students.first().apply { id = it.first() } }

View File

@ -24,10 +24,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
android:visibility="gone"
tools:visibility="visible"> tools:visibility="visible">
<View <View
@ -42,9 +42,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="32dp" android:layout_marginStart="32dp"
android:layout_marginLeft="32dp" android:layout_marginLeft="32dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="32dp" android:layout_marginEnd="32dp"
android:layout_marginRight="32dp" android:layout_marginRight="32dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:text="@string/login_contact_header" android:text="@string/login_contact_header"
@ -55,28 +55,29 @@
android:id="@+id/loginStudentSelectContactButtons" android:id="@+id/loginStudentSelectContactButtons"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"> android:layout_marginRight="16dp"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:id="@+id/loginStudentSelectContactEmail" android:id="@+id/loginStudentSelectContactEmail"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:text="@string/login_contact_email" android:text="@string/login_contact_email"
app:icon="@drawable/ic_more_messages" /> app:icon="@drawable/ic_more_messages" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:id="@+id/loginStudentSelectContactDiscord" android:id="@+id/loginStudentSelectContactDiscord"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:text="@string/login_contact_discord" android:text="@string/login_contact_discord"
app:icon="@drawable/ic_about_discord" /> app:icon="@drawable/ic_about_discord" />
</LinearLayout> </LinearLayout>
@ -95,9 +96,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="32dp" android:layout_marginStart="32dp"
android:layout_marginLeft="32dp" android:layout_marginLeft="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp" android:layout_marginEnd="32dp"
android:layout_marginRight="32dp" android:layout_marginRight="32dp"
android:layout_marginTop="32dp"
android:layout_marginBottom="32dp" android:layout_marginBottom="32dp"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:text="@string/login_select_student" android:text="@string/login_select_student"
@ -129,8 +130,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="32dp" android:layout_marginTop="32dp"
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:layout_marginBottom="32dp" android:layout_marginBottom="32dp"
android:enabled="false"
android:text="@string/login_sign_in" android:text="@string/login_sign_in"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"