Convert all SY specific things to use ViewBindings instead of synthetics
This commit is contained in:
@@ -6,9 +6,9 @@ import androidx.core.view.isVisible
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.PrefItemMangadexBinding
|
||||
import eu.kanade.tachiyomi.source.online.all.MangaDex
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import kotlinx.android.synthetic.main.pref_item_mangadex.view.*
|
||||
|
||||
class MangaDexLoginPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
@@ -20,25 +20,28 @@ class MangaDexLoginPreference @JvmOverloads constructor(
|
||||
layoutResource = R.layout.pref_item_mangadex
|
||||
}
|
||||
|
||||
var binding: PrefItemMangadexBinding? = null
|
||||
|
||||
private var onLoginClick: () -> Unit = {}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
binding = PrefItemMangadexBinding.bind(holder.itemView)
|
||||
holder.itemView.setOnClickListener {
|
||||
onLoginClick()
|
||||
}
|
||||
val loginFrame = holder.itemView.login_frame
|
||||
val loginFrame = binding?.loginFrame
|
||||
val color = if (source.isLogged()) {
|
||||
context.getResourceColor(R.attr.colorAccent)
|
||||
} else {
|
||||
context.getResourceColor(R.attr.colorSecondary)
|
||||
}
|
||||
|
||||
holder.itemView.login.setImageResource(R.drawable.ic_outline_people_alt_24dp)
|
||||
holder.itemView.login.drawable.setTint(color)
|
||||
binding?.login?.setImageResource(R.drawable.ic_outline_people_alt_24dp)
|
||||
binding?.login?.drawable?.setTint(color)
|
||||
|
||||
loginFrame.isVisible = true
|
||||
loginFrame.setOnClickListener {
|
||||
loginFrame?.isVisible = true
|
||||
loginFrame?.setOnClickListener {
|
||||
onLoginClick()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,18 +9,13 @@ import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.customview.customView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.databinding.PrefSiteLoginTwoFactorAuthBinding
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.online.all.MangaDex
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.widget.preference.LoginDialogPreference
|
||||
import exh.source.getMainSource
|
||||
import kotlinx.android.synthetic.main.pref_site_login_two_factor_auth.view.login
|
||||
import kotlinx.android.synthetic.main.pref_site_login_two_factor_auth.view.password
|
||||
import kotlinx.android.synthetic.main.pref_site_login_two_factor_auth.view.two_factor_check
|
||||
import kotlinx.android.synthetic.main.pref_site_login_two_factor_auth.view.two_factor_edit
|
||||
import kotlinx.android.synthetic.main.pref_site_login_two_factor_auth.view.two_factor_holder
|
||||
import kotlinx.android.synthetic.main.pref_site_login_two_factor_auth.view.username
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -36,6 +31,8 @@ class MangadexLoginDialog(bundle: Bundle? = null) : LoginDialogPreference(bundle
|
||||
|
||||
val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
|
||||
var binding: PrefSiteLoginTwoFactorAuthBinding? = null
|
||||
|
||||
constructor(source: MangaDex) : this(
|
||||
bundleOf(
|
||||
"key" to source.id
|
||||
@@ -54,23 +51,24 @@ class MangadexLoginDialog(bundle: Bundle? = null) : LoginDialogPreference(bundle
|
||||
|
||||
override fun onViewCreated(view: View) {
|
||||
super.onViewCreated(view)
|
||||
v?.apply {
|
||||
two_factor_check?.setOnCheckedChangeListener { _, isChecked ->
|
||||
two_factor_holder.isVisible = isChecked
|
||||
v?.let { binding = PrefSiteLoginTwoFactorAuthBinding.bind(it) }
|
||||
binding?.apply {
|
||||
twoFactorCheck.setOnCheckedChangeListener { _, isChecked ->
|
||||
twoFactorHolder.isVisible = isChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setCredentialsOnView(view: View) = with(view) {
|
||||
username.setText(service.getUsername())
|
||||
password.setText(service.getPassword())
|
||||
override fun setCredentialsOnView(view: View) {
|
||||
binding?.username?.setText(service.getUsername())
|
||||
binding?.password?.setText(service.getPassword())
|
||||
}
|
||||
|
||||
override fun checkLogin() {
|
||||
v?.apply {
|
||||
if (username.text.isNullOrBlank() || password.text.isNullOrBlank() || (two_factor_check.isChecked && two_factor_edit.text.isNullOrBlank())) {
|
||||
binding?.apply {
|
||||
if (username.text.isNullOrBlank() || password.text.isNullOrBlank() || (twoFactorCheck.isChecked && twoFactorEdit.text.isNullOrBlank())) {
|
||||
errorResult()
|
||||
context.toast(R.string.fields_cannot_be_blank)
|
||||
root.context.toast(R.string.fields_cannot_be_blank)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -84,25 +82,25 @@ class MangadexLoginDialog(bundle: Bundle? = null) : LoginDialogPreference(bundle
|
||||
val result = source?.login(
|
||||
username.text.toString(),
|
||||
password.text.toString(),
|
||||
two_factor_edit.text.toString()
|
||||
twoFactorEdit.text.toString()
|
||||
) ?: false
|
||||
if (result) {
|
||||
dialog?.dismiss()
|
||||
preferences.setTrackCredentials(Injekt.get<TrackManager>().mdList, username.toString(), password.toString())
|
||||
context.toast(R.string.login_success)
|
||||
root.context.toast(R.string.login_success)
|
||||
} else {
|
||||
errorResult()
|
||||
}
|
||||
} catch (error: Exception) {
|
||||
errorResult()
|
||||
error.message?.let { context.toast(it) }
|
||||
error.message?.let { root.context.toast(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun errorResult() {
|
||||
v?.apply {
|
||||
binding?.apply {
|
||||
dialog?.setCancelable(true)
|
||||
dialog?.setCanceledOnTouchOutside(true)
|
||||
login.progress = -1
|
||||
|
||||
Reference in New Issue
Block a user