mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-28 12:57:57 +01:00
Support for sources from different languages
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v14.preference.PreferenceDialogFragment
|
||||
import android.support.v7.preference.Preference
|
||||
import android.support.v7.preference.PreferenceDialogFragmentCompat
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.ui.setting.SettingsActivity
|
||||
import kotlinx.android.synthetic.main.pref_library_columns.view.*
|
||||
|
||||
class LibraryColumnsDialog : PreferenceDialogFragmentCompat() {
|
||||
class LibraryColumnsDialog : PreferenceDialogFragment() {
|
||||
|
||||
companion object {
|
||||
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.preference.PreferenceDialogFragmentCompat
|
||||
import android.app.Dialog
|
||||
import android.app.DialogFragment
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.text.method.PasswordTransformationMethod
|
||||
import android.view.View
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.dd.processbutton.iml.ActionProcessButton
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.setting.SettingsActivity
|
||||
import kotlinx.android.synthetic.main.pref_account_login.view.*
|
||||
import rx.Subscription
|
||||
|
||||
abstract class LoginDialogPreference : PreferenceDialogFragmentCompat() {
|
||||
abstract class LoginDialogPreference : DialogFragment() {
|
||||
|
||||
var v: View? = null
|
||||
private set
|
||||
@@ -22,13 +27,18 @@ abstract class LoginDialogPreference : PreferenceDialogFragmentCompat() {
|
||||
|
||||
var requestSubscription: Subscription? = null
|
||||
|
||||
override fun onPrepareDialogBuilder(builder: AlertDialog.Builder) {
|
||||
// Hide positive button
|
||||
builder.setPositiveButton("", this)
|
||||
override fun onCreateDialog(savedState: Bundle?): Dialog {
|
||||
val dialog = MaterialDialog.Builder(activity)
|
||||
.customView(R.layout.pref_account_login, false)
|
||||
.negativeText(android.R.string.cancel)
|
||||
.build();
|
||||
|
||||
onViewCreated(dialog.view, savedState)
|
||||
|
||||
return dialog
|
||||
}
|
||||
|
||||
override fun onBindDialogView(view: View) {
|
||||
super.onBindDialogView(view)
|
||||
override fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
v = view.apply {
|
||||
show_password.setOnCheckedChangeListener { v, isChecked ->
|
||||
if (isChecked)
|
||||
@@ -59,10 +69,16 @@ abstract class LoginDialogPreference : PreferenceDialogFragmentCompat() {
|
||||
|
||||
}
|
||||
|
||||
override fun onDialogClosed(positiveResult: Boolean) {
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
requestSubscription?.unsubscribe()
|
||||
}
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface) {
|
||||
super.onDismiss(dialog)
|
||||
targetFragment?.onActivityResult(targetRequestCode, arguments.getInt("key"), Intent())
|
||||
}
|
||||
|
||||
protected abstract fun checkLogin()
|
||||
|
||||
protected abstract fun setCredentialsOnView(view: View)
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.preference.Preference
|
||||
import android.support.v7.preference.PreferenceViewHolder
|
||||
import android.util.AttributeSet
|
||||
import eu.kanade.tachiyomi.R
|
||||
import kotlinx.android.synthetic.main.preference_widget_imageview.view.*
|
||||
|
||||
class LoginPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
Preference(context, attrs) {
|
||||
|
||||
init {
|
||||
widgetLayoutResource = R.layout.preference_widget_imageview
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
|
||||
with(holder.itemView.image_view) {
|
||||
if (getPersistedString("").isNullOrEmpty()) {
|
||||
setImageResource(android.R.color.transparent)
|
||||
} else {
|
||||
setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_done_green_24dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public fun notifyChanged() {
|
||||
super.notifyChanged()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.support.v7.preference.Preference
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.mangasync.base.MangaSyncService
|
||||
@@ -16,10 +14,10 @@ class MangaSyncLoginDialog : LoginDialogPreference() {
|
||||
|
||||
companion object {
|
||||
|
||||
fun newInstance(preference: Preference): LoginDialogPreference {
|
||||
fun newInstance(sync: MangaSyncService): LoginDialogPreference {
|
||||
val fragment = MangaSyncLoginDialog()
|
||||
val bundle = Bundle(1)
|
||||
bundle.putString("key", preference.key)
|
||||
bundle.putInt("key", sync.id)
|
||||
fragment.arguments = bundle
|
||||
return fragment
|
||||
}
|
||||
@@ -30,12 +28,12 @@ class MangaSyncLoginDialog : LoginDialogPreference() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val syncId = Integer.parseInt(arguments.getString("key"))
|
||||
val syncId = arguments.getInt("key")
|
||||
sync = (activity as SettingsActivity).syncManager.getService(syncId)
|
||||
}
|
||||
|
||||
override fun setCredentialsOnView(view: View) = with(view) {
|
||||
accounts_login.text = getString(R.string.accounts_login_title, sync.name)
|
||||
title.text = getString(R.string.login_title, sync.name)
|
||||
username.setText(preferences.getMangaSyncUsername(sync))
|
||||
password.setText(preferences.getMangaSyncPassword(sync))
|
||||
}
|
||||
@@ -58,8 +56,6 @@ class MangaSyncLoginDialog : LoginDialogPreference() {
|
||||
username.text.toString(),
|
||||
password.text.toString())
|
||||
|
||||
// Simulate a positive button click and dismiss the dialog
|
||||
onClick(dialog, DialogInterface.BUTTON_POSITIVE)
|
||||
dialog.dismiss()
|
||||
context.toast(R.string.login_success)
|
||||
} else {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.support.v7.preference.Preference
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.source.base.Source
|
||||
@@ -16,10 +14,10 @@ class SourceLoginDialog : LoginDialogPreference() {
|
||||
|
||||
companion object {
|
||||
|
||||
fun newInstance(preference: Preference): LoginDialogPreference {
|
||||
fun newInstance(source: Source): LoginDialogPreference {
|
||||
val fragment = SourceLoginDialog()
|
||||
val bundle = Bundle(1)
|
||||
bundle.putString("key", preference.key)
|
||||
bundle.putInt("key", source.id)
|
||||
fragment.arguments = bundle
|
||||
return fragment
|
||||
}
|
||||
@@ -30,12 +28,12 @@ class SourceLoginDialog : LoginDialogPreference() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val sourceId = Integer.parseInt(arguments.getString("key"))
|
||||
val sourceId = arguments.getInt("key")
|
||||
source = (activity as SettingsActivity).sourceManager.get(sourceId)!!
|
||||
}
|
||||
|
||||
override fun setCredentialsOnView(view: View) = with(view) {
|
||||
accounts_login.text = getString(R.string.accounts_login_title, source.name)
|
||||
title.text = getString(R.string.login_title, source.visibleName)
|
||||
username.setText(preferences.getSourceUsername(source))
|
||||
password.setText(preferences.getSourcePassword(source))
|
||||
}
|
||||
@@ -58,8 +56,6 @@ class SourceLoginDialog : LoginDialogPreference() {
|
||||
username.text.toString(),
|
||||
password.text.toString())
|
||||
|
||||
// Simulate a positive button click and dismiss the dialog
|
||||
onClick(dialog, DialogInterface.BUTTON_POSITIVE)
|
||||
dialog.dismiss()
|
||||
context.toast(R.string.login_success)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user