diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt index aeb24f37b..356b48f96 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt @@ -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) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt index c3e836ca8..b9f14d7c9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt @@ -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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/TrackLoginDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/TrackLoginDialog.kt index 75dbf10c8..d5278d50d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/TrackLoginDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/TrackLoginDialog.kt @@ -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().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()) } diff --git a/app/src/main/res/color/text_input_stroke.xml b/app/src/main/res/color/text_input_stroke.xml index 3fb56da44..006464ff2 100644 --- a/app/src/main/res/color/text_input_stroke.xml +++ b/app/src/main/res/color/text_input_stroke.xml @@ -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 --> - + diff --git a/app/src/main/res/layout/pref_account_login.xml b/app/src/main/res/layout/pref_account_login.xml index a0dec017e..87cb89e50 100644 --- a/app/src/main/res/layout/pref_account_login.xml +++ b/app/src/main/res/layout/pref_account_login.xml @@ -4,23 +4,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - android:padding="24dp"> - - - - + android:paddingStart="24dp" + android:paddingEnd="24dp"> @color/text_input_stroke - ?attr/colorAccent + ?attr/colorSecondary