forked from github/wulkanowy-mirror
Auto select students for login (#2307)
* Auto select students for login * Add sign in icon to sign in button on student select screen
This commit is contained in:
parent
1835446468
commit
26a95ecb99
@ -21,6 +21,7 @@ import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.ifNullOrBlank
|
||||
import io.github.wulkanowy.utils.isCurrent
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
@ -73,7 +74,14 @@ class LoginStudentSelectPresenter @Inject constructor(
|
||||
students = it.dataOrNull.orEmpty()
|
||||
when (it) {
|
||||
is Resource.Loading -> Timber.d("Login student select students load started")
|
||||
is Resource.Success -> refreshItems()
|
||||
is Resource.Success -> {
|
||||
getStudentsWithCurrentlyActiveSemesters()
|
||||
selectedStudents.clear()
|
||||
selectedStudents.addAll(getStudentsWithCurrentlyActiveSemesters())
|
||||
view?.enableSignIn(selectedStudents.isNotEmpty())
|
||||
refreshItems()
|
||||
}
|
||||
|
||||
is Resource.Error -> {
|
||||
errorHandler.dispatch(it.error)
|
||||
lastError = it.error
|
||||
@ -83,6 +91,21 @@ class LoginStudentSelectPresenter @Inject constructor(
|
||||
}.launch()
|
||||
}
|
||||
|
||||
private fun getStudentsWithCurrentlyActiveSemesters(): List<LoginStudentSelectItem.Student> {
|
||||
val students = registerUser.symbols.flatMap { symbol ->
|
||||
symbol.schools.flatMap { unit ->
|
||||
unit.students.map {
|
||||
createStudentItem(it, symbol, unit, students)
|
||||
}
|
||||
}
|
||||
}
|
||||
return students.filter { student ->
|
||||
student.student.semesters.any { semester ->
|
||||
semester.isCurrent()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createItems(): List<LoginStudentSelectItem> = buildList {
|
||||
val notEmptySymbols = registerUser.symbols.filter { it.schools.isNotEmpty() }
|
||||
val emptySymbols = registerUser.symbols.filter { it.schools.isEmpty() }
|
||||
|
5
app/src/main/res/drawable/ic_login.xml
Normal file
5
app/src/main/res/drawable/ic_login.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#000000" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M11,7L9.6,8.4l2.6,2.6H2v2h10.2l-2.6,2.6L11,17l5,-5L11,7zM20,19h-8v2h8c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2h-8v2h8V19z"/>
|
||||
</vector>
|
@ -56,6 +56,8 @@
|
||||
android:layout_marginBottom="32dp"
|
||||
android:enabled="false"
|
||||
android:text="@string/login_sign_in"
|
||||
app:icon="@drawable/ic_login"
|
||||
app:iconGravity="end"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/loginStudentSelectRecycler" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user