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())
}
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.showDialog(router)
}

View File

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

View File

@ -2,11 +2,11 @@ package eu.kanade.tachiyomi.widget.preference
import android.os.Bundle
import android.view.View
import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.track.TrackService
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.password
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.api.get
class TrackLoginDialog(usernameLabel: String? = null, bundle: Bundle? = null) :
LoginDialogPreference(usernameLabel, bundle) {
class TrackLoginDialog(
@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"))!!
constructor(service: TrackService) : this(service, null)
constructor(service: TrackService, usernameLabel: String?) :
this(usernameLabel, Bundle().apply { putInt("key", service.id) })
constructor(service: TrackService, @StringRes usernameLabelRes: Int?) :
this(R.string.login_title, service.name, usernameLabelRes, Bundle().apply { putInt("key", service.id) })
override fun setCredentialsOnView(view: View) = with(view) {
dialog_title.text = context.getString(R.string.login_title, service.name)
username.setText(service.getUsername())
password.setText(service.getPassword())
}