forked from github/szkolny
[UI/Login] Add recommended, testing and dev only badges to login modes.
This commit is contained in:
parent
46407f9647
commit
f39d0c595d
@ -60,7 +60,8 @@ class LoginChooserAdapter(
|
||||
|
||||
private val onClickListener = View.OnClickListener { view ->
|
||||
val model = view.getTag(R.string.tag_key_model)
|
||||
if (model is LoginInfo.Register && model.loginModes.size == 1) {
|
||||
if (model is LoginInfo.Register
|
||||
&& model.loginModes.count { App.devMode || !it.isDevOnly } == 1) {
|
||||
onModeClick?.invoke(model, model.loginModes.first())
|
||||
return@OnClickListener
|
||||
}
|
||||
@ -85,7 +86,9 @@ class LoginChooserAdapter(
|
||||
|
||||
if (model.state == STATE_CLOSED) {
|
||||
|
||||
val subItems = model.items
|
||||
val subItems = model.items.filter {
|
||||
App.devMode || !it.isDevOnly
|
||||
}
|
||||
|
||||
model.state = STATE_OPENED
|
||||
items.addAll(position + 1, subItems)
|
||||
|
@ -13,6 +13,7 @@ import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.*
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
@ -50,25 +51,7 @@ class LoginChooserFragment : Fragment(), CoroutineScope {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
if (!isAdded) return
|
||||
|
||||
val adapter = LoginChooserAdapter(activity) { loginType, loginMode ->
|
||||
launch {
|
||||
if (!checkAvailability(loginType.loginType))
|
||||
return@launch
|
||||
|
||||
if (loginMode.isPlatformSelection) {
|
||||
nav.navigate(R.id.loginPlatformListFragment, Bundle(
|
||||
"loginType" to loginType.loginType,
|
||||
"loginMode" to loginMode.loginMode
|
||||
), activity.navOptions)
|
||||
return@launch
|
||||
}
|
||||
|
||||
nav.navigate(R.id.loginFormFragment, Bundle(
|
||||
"loginType" to loginType.loginType,
|
||||
"loginMode" to loginMode.loginMode
|
||||
), activity.navOptions)
|
||||
}
|
||||
}
|
||||
val adapter = LoginChooserAdapter(activity, this::onLoginModeClicked)
|
||||
|
||||
LoginInfo.chooserList = LoginInfo.chooserList
|
||||
?: LoginInfo.list.toMutableList<Any>()
|
||||
@ -106,6 +89,45 @@ class LoginChooserFragment : Fragment(), CoroutineScope {
|
||||
}
|
||||
}
|
||||
|
||||
private fun onLoginModeClicked(
|
||||
loginType: LoginInfo.Register,
|
||||
loginMode: LoginInfo.Mode
|
||||
) {
|
||||
launch {
|
||||
if (!checkAvailability(loginType.loginType))
|
||||
return@launch
|
||||
|
||||
if (loginMode.isTesting || loginMode.isDevOnly) {
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setTitle(R.string.login_chooser_testing_title)
|
||||
.setMessage(R.string.login_chooser_testing_text)
|
||||
.setPositiveButton(R.string.ok) { _, _ ->
|
||||
navigateToLoginMode(loginType, loginMode)
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show()
|
||||
return@launch
|
||||
}
|
||||
|
||||
navigateToLoginMode(loginType, loginMode)
|
||||
}
|
||||
}
|
||||
|
||||
private fun navigateToLoginMode(loginType: LoginInfo.Register, loginMode: LoginInfo.Mode) {
|
||||
if (loginMode.isPlatformSelection) {
|
||||
nav.navigate(R.id.loginPlatformListFragment, Bundle(
|
||||
"loginType" to loginType.loginType,
|
||||
"loginMode" to loginMode.loginMode
|
||||
), activity.navOptions)
|
||||
return
|
||||
}
|
||||
|
||||
nav.navigate(R.id.loginFormFragment, Bundle(
|
||||
"loginType" to loginType.loginType,
|
||||
"loginMode" to loginMode.loginMode
|
||||
), activity.navOptions)
|
||||
}
|
||||
|
||||
private suspend fun checkAvailability(loginType: Int): Boolean {
|
||||
when (loginType) {
|
||||
LOGIN_TYPE_LIBRUS -> "librus"
|
||||
|
@ -181,18 +181,18 @@ object LoginInfo {
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_VULCAN_EXPIRED_TOKEN to R.string.login_error_expired_token
|
||||
)
|
||||
)/*,
|
||||
),
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_VULCAN_WEB,
|
||||
name = R.string.login_mode_vulcan_web,
|
||||
icon = R.drawable.login_mode_vulcan_web,
|
||||
hintText = R.string.login_mode_vulcan_web_hint,
|
||||
guideText = R.string.login_mode_vulcan_web_guide,
|
||||
isTesting = true,
|
||||
isDevOnly = true,
|
||||
isPlatformSelection = true,
|
||||
credentials = listOf(
|
||||
getEmailCredential("webEmail"),
|
||||
Credential(
|
||||
FormField(
|
||||
keyName = "webUsername",
|
||||
name = R.string.login_hint_username,
|
||||
icon = CommunityMaterial.Icon.cmd_account_outline,
|
||||
@ -201,12 +201,12 @@ object LoginInfo {
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "[A-Z]{7}[0-9]+",
|
||||
caseMode = Credential.CaseMode.UPPER_CASE
|
||||
caseMode = FormField.CaseMode.UPPER_CASE
|
||||
),
|
||||
getPasswordCredential("webPassword")
|
||||
),
|
||||
errorCodes = mapOf()
|
||||
)*/
|
||||
)
|
||||
)
|
||||
),
|
||||
Register(
|
||||
@ -398,6 +398,7 @@ object LoginInfo {
|
||||
|
||||
val isRecommended: Boolean = false,
|
||||
val isTesting: Boolean = false,
|
||||
val isDevOnly: Boolean = false,
|
||||
val isPlatformSelection: Boolean = false,
|
||||
|
||||
val credentials: List<BaseCredential>,
|
||||
|
@ -10,7 +10,10 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.databinding.LoginChooserModeItemBinding
|
||||
import pl.szczodrzynski.edziennik.resolveColor
|
||||
import pl.szczodrzynski.edziennik.setTintColor
|
||||
import pl.szczodrzynski.edziennik.ui.modules.grades.viewholder.BindableViewHolder
|
||||
import pl.szczodrzynski.edziennik.ui.modules.login.LoginChooserAdapter
|
||||
import pl.szczodrzynski.edziennik.ui.modules.login.LoginInfo
|
||||
@ -34,6 +37,19 @@ class ModeViewHolder(
|
||||
b.description.isVisible = true
|
||||
b.description.setText(item.hintText)
|
||||
}
|
||||
b.hint.isVisible = false
|
||||
|
||||
b.badge.isVisible = item.isRecommended || item.isDevOnly || item.isTesting
|
||||
if (item.isRecommended) {
|
||||
b.badge.setText(R.string.login_chooser_mode_recommended)
|
||||
b.badge.background.setTintColor(R.color.md_blue_300.resolveColor(app))
|
||||
}
|
||||
if (item.isTesting) {
|
||||
b.badge.setText(R.string.login_chooser_mode_testing)
|
||||
b.badge.background.setTintColor(R.color.md_yellow_300.resolveColor(app))
|
||||
}
|
||||
if (item.isDevOnly) {
|
||||
b.badge.setText(R.string.login_chooser_mode_dev_only)
|
||||
b.badge.background.setTintColor(R.color.md_red_300.resolveColor(app))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,19 @@
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<com.mikepenz.iconics.view.IconicsTextView
|
||||
android:id="@+id/badge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_rounded_8dp"
|
||||
android:minHeight="0dp"
|
||||
android:paddingHorizontal="4dp"
|
||||
android:paddingVertical="2dp"
|
||||
android:textColor="@color/md_black_1000"
|
||||
android:textSize="12sp"
|
||||
tools:backgroundTint="@color/md_blue_300"
|
||||
tools:text="{cmd-alert-circle-outline} Zalecane" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
@ -43,13 +56,6 @@
|
||||
android:textAppearance="@style/NavView.TextView.Medium"
|
||||
tools:text="Zaloguj używając e-maila" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textStyle="bold"
|
||||
tools:text="(zalecane)" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -1380,4 +1380,9 @@
|
||||
<string name="register_unavailable_read_more">Dowiedz się więcej</string>
|
||||
<string name="settings_register_hide_sticks_from_old">Stara nie zobaczy pał</string>
|
||||
<string name="login_podlasie_logout_devices">Wyloguj z pozostałych urządzeń</string>
|
||||
<string name="login_chooser_testing_title">Wersja testowa</string>
|
||||
<string name="login_chooser_testing_text">Wybrany sposób logowania jest jeszcze w fazie testów i może nie działać poprawnie.\n\nJeśli masz problemy z aplikacją, wybierz zalecany sposób logowania.</string>
|
||||
<string name="login_chooser_mode_recommended">{cmd-information-outline} Zalecane</string>
|
||||
<string name="login_chooser_mode_testing">{cmd-alert-circle-outline} Wersja testowa</string>
|
||||
<string name="login_chooser_mode_dev_only">{cmd-android-studio} Wersja deweloperska</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user