Add MangaDex only implementation of Mangadex Follows list
Add login dialog that pops up whenever you are not logged in when trying to browse MangaDex Remove attempts at porting over chapter read history from older galleries to new ones Disable latest for ExHentai, it was browse without buttons anyway
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package exh.widget.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
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,
|
||||
val source: MangaDex,
|
||||
attrs: AttributeSet? = null
|
||||
) : Preference(context, attrs) {
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.pref_item_mangadex
|
||||
}
|
||||
|
||||
private var onLoginClick: () -> Unit = {}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
holder.itemView.setOnClickListener {
|
||||
onLoginClick()
|
||||
}
|
||||
val loginFrame = holder.itemView.login_frame
|
||||
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)
|
||||
|
||||
loginFrame.isVisible = true
|
||||
loginFrame.setOnClickListener {
|
||||
onLoginClick()
|
||||
}
|
||||
}
|
||||
|
||||
fun setOnLoginClickListener(block: () -> Unit) {
|
||||
onLoginClick = block
|
||||
}
|
||||
|
||||
// Make method public
|
||||
public override fun notifyChanged() {
|
||||
super.notifyChanged()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package exh.widget.preference
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
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.source.Source
|
||||
import eu.kanade.tachiyomi.source.online.all.MangaDex
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.widget.preference.LoginDialogPreference
|
||||
import exh.md.utils.MdUtil
|
||||
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
|
||||
import kotlinx.android.synthetic.main.pref_site_login_two_factor_auth.view.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class MangadexLoginDialog(bundle: Bundle? = null) : LoginDialogPreference(bundle = bundle) {
|
||||
|
||||
val source by lazy { MdUtil.getEnabledMangaDex() }
|
||||
|
||||
val service = Injekt.get<TrackManager>().mdList
|
||||
|
||||
val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
|
||||
constructor(source: MangaDex, activity: Activity? = null) : this(
|
||||
Bundle().apply {
|
||||
putLong(
|
||||
"key",
|
||||
source.id
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
||||
val dialog = MaterialDialog(activity!!).apply {
|
||||
customView(R.layout.pref_site_login_two_factor_auth, scrollable = false)
|
||||
}
|
||||
|
||||
onViewCreated(dialog.view)
|
||||
|
||||
return dialog
|
||||
}
|
||||
|
||||
override fun setCredentialsOnView(view: View) = with(view) {
|
||||
username.setText(service.getUsername())
|
||||
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())) {
|
||||
errorResult()
|
||||
context.toast(R.string.fields_cannot_be_blank)
|
||||
return
|
||||
}
|
||||
|
||||
login.progress = 1
|
||||
|
||||
dialog?.setCancelable(false)
|
||||
dialog?.setCanceledOnTouchOutside(false)
|
||||
|
||||
scope.launch {
|
||||
try {
|
||||
val result = source?.login(
|
||||
username.text.toString(),
|
||||
password.text.toString(),
|
||||
two_factor_edit.text.toString()
|
||||
) ?: false
|
||||
if (result) {
|
||||
dialog?.dismiss()
|
||||
preferences.setTrackCredentials(Injekt.get<TrackManager>().mdList, username.toString(), password.toString())
|
||||
context.toast(R.string.login_success)
|
||||
} else {
|
||||
errorResult()
|
||||
}
|
||||
} catch (error: Exception) {
|
||||
errorResult()
|
||||
error.message?.let { context.toast(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun errorResult() {
|
||||
v?.apply {
|
||||
dialog?.setCancelable(true)
|
||||
dialog?.setCanceledOnTouchOutside(true)
|
||||
login.progress = -1
|
||||
login.setText(R.string.unknown_error)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDialogClosed() {
|
||||
super.onDialogClosed()
|
||||
if (activity != null) {
|
||||
(activity as? Listener)?.siteLoginDialogClosed(source!!)
|
||||
} else {
|
||||
(targetController as? Listener)?.siteLoginDialogClosed(source!!)
|
||||
}
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
fun siteLoginDialogClosed(source: Source)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package exh.widget.preference
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||
import eu.kanade.tachiyomi.util.lang.launchNow
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import exh.md.utils.MdUtil
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
class MangadexLogoutDialog(bundle: Bundle? = null) : DialogController(bundle) {
|
||||
|
||||
val source by lazy { MdUtil.getEnabledMangaDex() }
|
||||
|
||||
val trackManager: TrackManager by injectLazy()
|
||||
|
||||
constructor(source: Source) : this(Bundle().apply { putLong("key", source.id) })
|
||||
|
||||
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
||||
return MaterialDialog(activity!!)
|
||||
.title(R.string.logout)
|
||||
.positiveButton(R.string.logout) {
|
||||
launchNow {
|
||||
source?.let { source ->
|
||||
val loggedOut = withContext(Dispatchers.IO) { source.logout() }
|
||||
|
||||
if (loggedOut) {
|
||||
trackManager.mdList.logout()
|
||||
activity?.toast(R.string.logout_success)
|
||||
(targetController as? Listener)?.siteLogoutDialogClosed(source)
|
||||
} else {
|
||||
activity?.toast(R.string.unknown_error)
|
||||
}
|
||||
} ?: activity!!.toast("Mangadex not enabled")
|
||||
}
|
||||
}
|
||||
.negativeButton(android.R.string.cancel)
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
fun siteLogoutDialogClosed(source: Source)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user