Use actual dialog title for tracker login dialogs

This commit is contained in:
arkon 2020-03-15 17:31:36 -04:00
parent 3f88a67865
commit 3e5a48e5e4
6 changed files with 31 additions and 33 deletions

View File

@ -53,7 +53,7 @@ class SettingsTrackingController : SettingsController(),
tabsIntent.launchUrl(activity!!, AnilistApi.authUrl()) tabsIntent.launchUrl(activity!!, AnilistApi.authUrl())
} }
trackPreference(trackManager.kitsu) { trackPreference(trackManager.kitsu) {
val dialog = TrackLoginDialog(trackManager.kitsu, context.getString(R.string.email)) val dialog = TrackLoginDialog(trackManager.kitsu, R.string.email)
dialog.targetController = this@SettingsTrackingController dialog.targetController = this@SettingsTrackingController
dialog.showDialog(router) dialog.showDialog(router)
} }

View File

@ -4,6 +4,7 @@ import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.text.method.PasswordTransformationMethod import android.text.method.PasswordTransformationMethod
import android.view.View import android.view.View
import androidx.annotation.StringRes
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.ControllerChangeType
@ -19,8 +20,12 @@ import kotlinx.android.synthetic.main.pref_account_login.view.username_label
import rx.Subscription import rx.Subscription
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
abstract class LoginDialogPreference(private val usernameLabel: String? = null, bundle: Bundle? = null) : abstract class LoginDialogPreference(
DialogController(bundle) { @StringRes private val titleRes: Int? = null,
private val titleFormatArgs: Any? = null,
@StringRes private val usernameLabelRes: Int? = null,
bundle: Bundle? = null
) : DialogController(bundle) {
var v: View? = null var v: View? = null
private set private set
@ -30,10 +35,15 @@ abstract class LoginDialogPreference(private val usernameLabel: String? = null,
var requestSubscription: Subscription? = null var requestSubscription: Subscription? = null
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val dialog = MaterialDialog.Builder(activity!!) var dialogBuilder = MaterialDialog.Builder(activity!!)
.customView(R.layout.pref_account_login, false) .customView(R.layout.pref_account_login, false)
.negativeText(android.R.string.cancel) .negativeText(android.R.string.cancel)
.build()
if (titleRes != null) {
dialogBuilder = dialogBuilder.title(activity!!.getString(titleRes, titleFormatArgs))
}
val dialog = dialogBuilder.build()
onViewCreated(dialog.view) onViewCreated(dialog.view)
@ -49,8 +59,8 @@ abstract class LoginDialogPreference(private val usernameLabel: String? = null,
password.transformationMethod = PasswordTransformationMethod() password.transformationMethod = PasswordTransformationMethod()
} }
if (!usernameLabel.isNullOrEmpty()) { if (usernameLabelRes != null) {
username_label.hint = usernameLabel username_label.hint = context.getString(usernameLabelRes)
} }
login.setMode(ActionProcessButton.Mode.ENDLESS) login.setMode(ActionProcessButton.Mode.ENDLESS)

View File

@ -2,11 +2,11 @@ package eu.kanade.tachiyomi.widget.preference
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import kotlinx.android.synthetic.main.pref_account_login.view.dialog_title
import kotlinx.android.synthetic.main.pref_account_login.view.login import kotlinx.android.synthetic.main.pref_account_login.view.login
import kotlinx.android.synthetic.main.pref_account_login.view.password import kotlinx.android.synthetic.main.pref_account_login.view.password
import kotlinx.android.synthetic.main.pref_account_login.view.username import kotlinx.android.synthetic.main.pref_account_login.view.username
@ -15,18 +15,21 @@ import rx.schedulers.Schedulers
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
class TrackLoginDialog(usernameLabel: String? = null, bundle: Bundle? = null) : class TrackLoginDialog(
LoginDialogPreference(usernameLabel, bundle) { @StringRes titleRes: Int? = null,
titleFormatArgs: Any? = null,
@StringRes usernameLabelRes: Int? = null,
bundle: Bundle? = null
) : LoginDialogPreference(titleRes, titleFormatArgs, usernameLabelRes, bundle) {
private val service = Injekt.get<TrackManager>().getService(args.getInt("key"))!! private val service = Injekt.get<TrackManager>().getService(args.getInt("key"))!!
constructor(service: TrackService) : this(service, null) constructor(service: TrackService) : this(service, null)
constructor(service: TrackService, usernameLabel: String?) : constructor(service: TrackService, @StringRes usernameLabelRes: Int?) :
this(usernameLabel, Bundle().apply { putInt("key", service.id) }) this(R.string.login_title, service.name, usernameLabelRes, Bundle().apply { putInt("key", service.id) })
override fun setCredentialsOnView(view: View) = with(view) { override fun setCredentialsOnView(view: View) = with(view) {
dialog_title.text = context.getString(R.string.login_title, service.name)
username.setText(service.getUsername()) username.setText(service.getUsername())
password.setText(service.getPassword()) password.setText(service.getPassword())
} }

View File

@ -4,7 +4,7 @@ The regular version uses ?attr/colorPrimary when focused, which doesn't work wel
https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/textfield/res/color/mtrl_filled_stroke_color.xml https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/textfield/res/color/mtrl_filled_stroke_color.xml
--> -->
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorAccent" android:state_focused="true" /> <item android:color="?attr/colorSecondary" android:state_focused="true" />
<item android:alpha="0.87" android:color="?attr/colorOnSurface" android:state_hovered="true" /> <item android:alpha="0.87" android:color="?attr/colorOnSurface" android:state_hovered="true" />
<item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_enabled="false" /> <item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_enabled="false" />
<item android:alpha="0.38" android:color="?attr/colorOnSurface" /> <item android:alpha="0.38" android:color="?attr/colorOnSurface" />

View File

@ -4,23 +4,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:padding="24dp"> android:paddingStart="24dp"
android:paddingEnd="24dp">
<TextView
android:id="@+id/dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="16sp"
android:textStyle="bold" />
<View
android:id="@+id/titleDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="24dp"
android:background="?android:attr/divider" />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/username_label" android:id="@+id/username_label"

View File

@ -211,12 +211,12 @@
<style name="Theme.Widget.TextInputLayout.OutlinedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox"> <style name="Theme.Widget.TextInputLayout.OutlinedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">@color/text_input_stroke</item> <item name="boxStrokeColor">@color/text_input_stroke</item>
<item name="hintTextColor">?attr/colorAccent</item> <item name="hintTextColor">?attr/colorSecondary</item>
</style> </style>
<style name="Theme.Widget.TextInputLayout.OutlinedBox.Dense" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"> <style name="Theme.Widget.TextInputLayout.OutlinedBox.Dense" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">@color/text_input_stroke</item> <item name="boxStrokeColor">@color/text_input_stroke</item>
<item name="hintTextColor">?attr/colorAccent</item> <item name="hintTextColor">?attr/colorSecondary</item>
</style> </style>