# Conflicts:
#	app/build.gradle
#	app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/ActivityMixin.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/base/adapter/FlexibleViewHolder.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/base/adapter/SmartFragmentStatePagerAdapter.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/BaseFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/BaseRxFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/FragmentMixin.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryActivity.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/latest_updates/LatestUpdatesFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/main/ChangelogDialogFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaActivity.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaEvent.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/ChapterCountEvent.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaFavoriteEvent.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsActivity.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadsFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingFragment.kt
#	app/src/main/java/eu/kanade/tachiyomi/util/AndroidComponentUtil.java
#	app/src/main/java/eu/kanade/tachiyomi/widget/preference/LibraryColumnsDialog.kt
#	app/src/main/java/eu/kanade/tachiyomi/widget/preference/SimpleDialogPreference.kt
#	app/src/main/res/layout/activity_download_manager.xml
#	app/src/main/res/layout/activity_edit_categories.xml
#	app/src/main/res/layout/activity_manga.xml
#	app/src/main/res/layout/activity_preferences.xml
#	app/src/main/res/layout/fragment_backup.xml
#	app/src/main/res/layout/fragment_download_queue.xml
#	app/src/main/res/layout/fragment_library.xml
#	app/src/main/res/layout/fragment_library_category.xml
#	app/src/main/res/layout/item_chapter.xml
#	app/src/main/res/layout/item_recent_chapters.xml
#	app/src/main/res/layout/toolbar.xml
#	app/src/main/res/raw/changelog_release.xml
#	app/src/main/res/values/arrays.xml
#	app/src/main/res/xml/pref_about.xml
#	app/src/main/res/xml/pref_advanced.xml
#	app/src/main/res/xml/pref_downloads.xml
#	app/src/main/res/xml/pref_general.xml
#	app/src/main/res/xml/pref_reader.xml
#	app/src/main/res/xml/pref_sources.xml
#	app/src/main/res/xml/pref_tracking.xml

Migrate to Tachiyomi 6.1
Rewrite batch add UI
This commit is contained in:
NerdNumber9
2017-08-24 11:24:23 -04:00
301 changed files with 12222 additions and 10356 deletions

View File

@@ -24,7 +24,7 @@ class CustomLayoutFilePickerFragment : FilePickerFragment() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
when (viewType) {
LogicHandler.VIEWTYPE_DIR -> {
val view = parent.inflate(R.layout.listitem_dir)
val view = parent.inflate(R.layout.common_listitem_dir)
return DirViewHolder(view)
}
else -> return super.onCreateViewHolder(parent, viewType)

View File

@@ -1,22 +0,0 @@
package eu.kanade.tachiyomi.widget
import android.app.Dialog
import android.os.Bundle
import android.support.v4.app.DialogFragment
import com.afollestad.materialdialogs.MaterialDialog
import eu.kanade.tachiyomi.R
class DeletingChaptersDialog : DialogFragment() {
companion object {
const val TAG = "deleting_dialog"
}
override fun onCreateDialog(savedState: Bundle?): Dialog {
return MaterialDialog.Builder(activity)
.progress(true, 0)
.content(R.string.deleting)
.build()
}
}

View File

@@ -6,13 +6,13 @@ import android.util.AttributeSet
import android.widget.LinearLayout
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.inflate
import kotlinx.android.synthetic.main.dialog_with_checkbox.view.*
import kotlinx.android.synthetic.main.common_dialog_with_checkbox.view.*
class DialogCheckboxView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
LinearLayout(context, attrs) {
init {
addView(inflate(R.layout.dialog_with_checkbox))
addView(inflate(R.layout.common_dialog_with_checkbox))
}
fun setDescription(@StringRes id: Int){

View File

@@ -0,0 +1,23 @@
package eu.kanade.tachiyomi.widget
import android.support.v4.widget.DrawerLayout
import android.view.View
import android.view.ViewGroup
class DrawerSwipeCloseListener(
private val drawer: DrawerLayout,
private val navigationView: ViewGroup
) : DrawerLayout.SimpleDrawerListener() {
override fun onDrawerOpened(drawerView: View) {
if (drawerView == navigationView) {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, drawerView)
}
}
override fun onDrawerClosed(drawerView: View) {
if (drawerView == navigationView) {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, drawerView)
}
}
}

View File

@@ -7,13 +7,13 @@ import android.widget.RelativeLayout
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.getResourceColor
import eu.kanade.tachiyomi.util.setVectorCompat
import kotlinx.android.synthetic.main.view_empty.view.*
import kotlinx.android.synthetic.main.common_view_empty.view.*
class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
RelativeLayout (context, attrs) {
init {
inflate(context, R.layout.view_empty, this)
inflate(context, R.layout.common_view_empty, this)
}
/**

View File

@@ -1,11 +1,11 @@
package eu.kanade.tachiyomi.widget
import android.support.v4.view.PagerAdapter
import android.view.View
import android.view.ViewGroup
import com.nightlynexus.viewstatepageradapter.ViewStatePagerAdapter
import java.util.*
abstract class RecyclerViewPagerAdapter : PagerAdapter() {
abstract class RecyclerViewPagerAdapter : ViewStatePagerAdapter() {
private val pool = Stack<View>()
@@ -21,22 +21,16 @@ abstract class RecyclerViewPagerAdapter : PagerAdapter() {
protected open fun recycleView(view: View, position: Int) {}
override fun instantiateItem(container: ViewGroup, position: Int): Any {
override fun createView(container: ViewGroup, position: Int): View {
val view = if (pool.isNotEmpty()) pool.pop() else createView(container)
bindView(view, position)
container.addView(view)
return view
}
override fun destroyItem(container: ViewGroup, position: Int, obj: Any) {
val view = obj as View
override fun destroyView(container: ViewGroup, position: Int, view: View) {
recycleView(view, position)
container.removeView(view)
if (recycle) pool.push(view)
}
override fun isViewFromObject(view: View, obj: Any): Boolean {
return view === obj
}
}

View File

@@ -0,0 +1,281 @@
/*
* Copyright 2016 Davide Steduto
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.kanade.tachiyomi.widget;
import android.content.Context;
import android.graphics.Color;
import android.support.annotation.ColorInt;
import android.support.annotation.IntDef;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar;
import android.view.View;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import eu.davidea.flexibleadapter.FlexibleAdapter;
/**
* Helper to simplify the Undo operation with FlexibleAdapter.
*
* @author Davide Steduto
* @since 30/04/2016
*/
@SuppressWarnings("WeakerAccess")
public class UndoHelper extends Snackbar.Callback {
/**
* Default undo-timeout of 5''.
*/
public static final int UNDO_TIMEOUT = 5000;
/**
* Indicates that the Confirmation Listener (Undo and Delete) will perform a deletion.
*/
public static final int ACTION_REMOVE = 0;
/**
* Indicates that the Confirmation Listener (Undo and Delete) will perform an update.
*/
public static final int ACTION_UPDATE = 1;
/**
* Annotation interface for Undo actions.
*/
@IntDef({ACTION_REMOVE, ACTION_UPDATE})
@Retention(RetentionPolicy.SOURCE)
public @interface Action {
}
@Action
private int mAction = ACTION_REMOVE;
private List<Integer> mPositions = null;
private Object mPayload = null;
private FlexibleAdapter mAdapter;
private Snackbar mSnackbar = null;
private OnActionListener mActionListener;
private OnUndoListener mUndoListener;
private @ColorInt int mActionTextColor = Color.TRANSPARENT;
/**
* Default constructor.
* <p>By calling this constructor, {@link FlexibleAdapter#setPermanentDelete(boolean)}
* is set {@code false} automatically.
*
* @param adapter the instance of {@code FlexibleAdapter}
* @param undoListener the callback for the Undo and Delete confirmation
*/
public UndoHelper(FlexibleAdapter adapter, OnUndoListener undoListener) {
this.mAdapter = adapter;
this.mUndoListener = undoListener;
adapter.setPermanentDelete(false);
}
/**
* Sets the payload to inform other linked items about the change in action.
*
* @param payload any non-null user object to notify the parent (the payload will be
* therefore passed to the bind method of the parent ViewHolder),
* pass null to <u>not</u> notify the parent
* @return this object, so it can be chained
*/
public UndoHelper withPayload(Object payload) {
this.mPayload = payload;
return this;
}
/**
* By default {@link UndoHelper#ACTION_REMOVE} is performed.
*
* @param action the action, one of {@link UndoHelper#ACTION_REMOVE}, {@link UndoHelper#ACTION_UPDATE}
* @param actionListener the listener for the custom action to perform before the deletion
* @return this object, so it can be chained
*/
public UndoHelper withAction(@Action int action, @NonNull OnActionListener actionListener) {
this.mAction = action;
this.mActionListener = actionListener;
return this;
}
/**
* Sets the text color of the action.
*
* @param color the color for the action button
* @return this object, so it can be chained
*/
public UndoHelper withActionTextColor(@ColorInt int color) {
this.mActionTextColor = color;
return this;
}
/**
* As {@link #remove(List, View, CharSequence, CharSequence, int)} but with String
* resources instead of CharSequence.
*/
public void remove(List<Integer> positions, @NonNull View mainView,
@StringRes int messageStringResId, @StringRes int actionStringResId,
@IntRange(from = -1) int undoTime) {
Context context = mainView.getContext();
remove(positions, mainView, context.getString(messageStringResId),
context.getString(actionStringResId), undoTime);
}
/**
* Performs the action on the specified positions and displays a SnackBar to Undo
* the operation. To customize the UPDATE event, please set a custom listener with
* {@link #withAction(int, OnActionListener)} method.
* <p>By default the DELETE action will be performed.</p>
*
* @param positions the position to delete or update
* @param mainView the view to find a parent from
* @param message the text to show. Can be formatted text
* @param actionText the action text to display
* @param undoTime How long to display the message. Either {@link Snackbar#LENGTH_SHORT} or
* {@link Snackbar#LENGTH_LONG} or any custom Integer.
* @see #remove(List, View, int, int, int)
*/
@SuppressWarnings("WrongConstant")
public void remove(List<Integer> positions, @NonNull View mainView,
CharSequence message, CharSequence actionText,
@IntRange(from = -1) int undoTime) {
this.mPositions = positions;
Snackbar snackbar;
if (!mAdapter.isPermanentDelete()) {
snackbar = Snackbar.make(mainView, message, undoTime > 0 ? undoTime + 400 : undoTime)
.setAction(actionText, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mUndoListener != null)
mUndoListener.onUndoConfirmed(mAction);
}
});
} else {
snackbar = Snackbar.make(mainView, message, undoTime);
}
if (mActionTextColor != Color.TRANSPARENT) {
snackbar.setActionTextColor(mActionTextColor);
}
mSnackbar = snackbar;
snackbar.addCallback(this);
snackbar.show();
}
public void dismissNow() {
if (mSnackbar != null) {
mSnackbar.removeCallback(this);
mSnackbar.dismiss();
onDismissed(mSnackbar, Snackbar.Callback.DISMISS_EVENT_MANUAL);
}
}
/**
* {@inheritDoc}
*/
@Override
public void onDismissed(Snackbar snackbar, int event) {
if (mAdapter.isPermanentDelete()) return;
switch (event) {
case DISMISS_EVENT_SWIPE:
case DISMISS_EVENT_MANUAL:
case DISMISS_EVENT_TIMEOUT:
if (mUndoListener != null)
mUndoListener.onDeleteConfirmed(mAction);
mAdapter.emptyBin();
mSnackbar = null;
case DISMISS_EVENT_CONSECUTIVE:
case DISMISS_EVENT_ACTION:
default:
break;
}
}
/**
* {@inheritDoc}
*/
@Override
public void onShown(Snackbar snackbar) {
boolean consumed = false;
// Perform the action before deletion
if (mActionListener != null) consumed = mActionListener.onPreAction();
// Remove selected items from Adapter list after SnackBar is shown
if (!consumed) mAdapter.removeItems(mPositions, mPayload);
// Perform the action after the deletion
if (mActionListener != null) mActionListener.onPostAction();
// Here, we can notify the callback only in case of permanent deletion
if (mAdapter.isPermanentDelete() && mUndoListener != null)
mUndoListener.onDeleteConfirmed(mAction);
}
/**
* Basic implementation of {@link OnActionListener} interface.
* <p>Override the methods as your convenience.</p>
*/
public static class SimpleActionListener implements OnActionListener {
@Override
public boolean onPreAction() {
return false;
}
@Override
public void onPostAction() {
}
}
public interface OnActionListener {
/**
* Performs the custom action before item deletion.
*
* @return true if action has been consumed and should stop the deletion, false to
* continue with the deletion
*/
boolean onPreAction();
/**
* Performs custom action After items deletion. Useful to finish the action mode and perform
* secondary custom actions.
*/
void onPostAction();
}
/**
* @since 30/04/2016
*/
public interface OnUndoListener {
/**
* Called when Undo event is triggered. Perform custom action after restoration.
* <p>Usually for a delete restoration you should call
* {@link FlexibleAdapter#restoreDeletedItems()}.</p>
*
* @param action one of {@link UndoHelper#ACTION_REMOVE}, {@link UndoHelper#ACTION_UPDATE}
*/
void onUndoConfirmed(int action);
/**
* Called when Undo timeout is over and action must be committed in the user Database.
* <p>Due to Java Generic, it's too complicated and not well manageable if we pass the
* List&lt;T&gt; object.<br/>
* So, to get deleted items, use {@link FlexibleAdapter#getDeletedItems()} from the
* implementation of this method.</p>
*
* @param action one of {@link UndoHelper#ACTION_REMOVE}, {@link UndoHelper#ACTION_UPDATE}
*/
void onDeleteConfirmed(int action);
}
}

View File

@@ -1,55 +0,0 @@
package eu.kanade.tachiyomi.widget.preference
import android.os.Bundle
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 kotlinx.android.synthetic.main.pref_library_columns.view.*
import uy.kohesive.injekt.injectLazy
class LibraryColumnsDialog : PreferenceDialogFragmentCompat() {
companion object {
fun newInstance(preference: Preference): LibraryColumnsDialog {
val fragment = LibraryColumnsDialog()
val bundle = Bundle(1)
bundle.putString("key", preference.key)
fragment.arguments = bundle
return fragment
}
}
var portrait: Int = 0
var landscape: Int = 0
val preferences: PreferencesHelper by injectLazy()
override fun onBindDialogView(view: View) {
super.onBindDialogView(view)
portrait = preferences.portraitColumns().getOrDefault()
landscape = preferences.landscapeColumns().getOrDefault()
view.portrait_columns.value = portrait
view.landscape_columns.value = landscape
view.portrait_columns.setOnValueChangedListener { picker, oldValue, newValue ->
portrait = newValue
}
view.landscape_columns.setOnValueChangedListener { picker, oldValue, newValue ->
landscape = newValue
}
}
override fun onDialogClosed(positiveResult: Boolean) {
if (positiveResult) {
preferences.portraitColumns().set(portrait)
preferences.landscapeColumns().set(landscape)
}
}
}

View File

@@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.widget.preference
import android.content.Context
import android.graphics.Color
import android.support.v7.preference.CheckBoxPreference
import android.support.v7.preference.PreferenceViewHolder
import android.util.AttributeSet
import android.view.View
@@ -11,7 +12,6 @@ import eu.kanade.tachiyomi.source.online.LoginSource
import eu.kanade.tachiyomi.util.getResourceColor
import eu.kanade.tachiyomi.util.setVectorCompat
import kotlinx.android.synthetic.main.pref_item_source.view.*
import net.xpece.android.support.preference.CheckBoxPreference
class LoginCheckBoxPreference @JvmOverloads constructor(
context: Context,

View File

@@ -1,23 +1,22 @@
package eu.kanade.tachiyomi.widget.preference
import android.app.Activity
import android.app.Dialog
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.text.method.PasswordTransformationMethod
import android.view.View
import com.afollestad.materialdialogs.MaterialDialog
import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType
import com.dd.processbutton.iml.ActionProcessButton
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.widget.SimpleTextWatcher
import kotlinx.android.synthetic.main.pref_account_login.view.*
import rx.Subscription
import uy.kohesive.injekt.injectLazy
abstract class LoginDialogPreference : DialogFragment() {
abstract class LoginDialogPreference(bundle: Bundle? = null) : DialogController(bundle) {
var v: View? = null
private set
@@ -27,7 +26,7 @@ abstract class LoginDialogPreference : DialogFragment() {
var requestSubscription: Subscription? = null
override fun onCreateDialog(savedState: Bundle?): Dialog {
val dialog = MaterialDialog.Builder(activity)
val dialog = MaterialDialog.Builder(activity!!)
.customView(R.layout.pref_account_login, false)
.negativeText(android.R.string.cancel)
.build()
@@ -37,7 +36,7 @@ abstract class LoginDialogPreference : DialogFragment() {
return dialog
}
override fun onViewCreated(view: View, savedState: Bundle?) {
fun onViewCreated(view: View, savedState: Bundle?) {
v = view.apply {
show_password.setOnCheckedChangeListener { v, isChecked ->
if (isChecked)
@@ -55,7 +54,7 @@ abstract class LoginDialogPreference : DialogFragment() {
password.addTextChangedListener(object : SimpleTextWatcher() {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (s.length == 0) {
if (s.isEmpty()) {
show_password.isEnabled = true
}
}
@@ -64,15 +63,15 @@ abstract class LoginDialogPreference : DialogFragment() {
}
override fun onPause() {
super.onPause()
requestSubscription?.unsubscribe()
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
super.onChangeStarted(handler, type)
if (!type.isEnter) {
onDialogClosed()
}
}
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
val intent = Intent().putExtras(arguments)
targetFragment?.onActivityResult(targetRequestCode, Activity.RESULT_OK, intent)
open fun onDialogClosed() {
requestSubscription?.unsubscribe()
}
protected abstract fun checkLogin()

View File

@@ -5,13 +5,13 @@ 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.*
import kotlinx.android.synthetic.main.pref_widget_imageview.view.*
class LoginPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Preference(context, attrs) {
init {
widgetLayoutResource = R.layout.preference_widget_imageview
widgetLayoutResource = R.layout.pref_widget_imageview
}
override fun onBindViewHolder(holder: PreferenceViewHolder) {

View File

@@ -1,11 +0,0 @@
package eu.kanade.tachiyomi.widget.preference
import android.content.Context
import android.support.v7.preference.DialogPreference
import android.support.v7.preference.R.attr
import android.util.AttributeSet
open class SimpleDialogPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = attr.dialogPreferenceStyle, defStyleRes: Int = 0) :
DialogPreference(context, attrs, defStyleAttr, defStyleRes) {
}

View File

@@ -10,34 +10,17 @@ import eu.kanade.tachiyomi.util.toast
import kotlinx.android.synthetic.main.pref_account_login.view.*
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import uy.kohesive.injekt.injectLazy
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class SourceLoginDialog : LoginDialogPreference() {
class SourceLoginDialog(bundle: Bundle? = null) : LoginDialogPreference(bundle) {
companion object {
private val source = Injekt.get<SourceManager>().get(args.getLong("key")) as LoginSource
fun newInstance(source: Source): LoginDialogPreference {
val fragment = SourceLoginDialog()
val bundle = Bundle(1)
bundle.putLong("key", source.id)
fragment.arguments = bundle
return fragment
}
}
val sourceManager: SourceManager by injectLazy()
lateinit var source: LoginSource
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val sourceId = arguments.getLong("key")
source = sourceManager.get(sourceId) as LoginSource
}
constructor(source: Source) : this(Bundle().apply { putLong("key", source.id) })
override fun setCredentialsOnView(view: View) = with(view) {
dialog_title.text = getString(R.string.login_title, source.toString())
dialog_title.text = context.getString(R.string.login_title, source.toString())
username.setText(preferences.sourceUsername(source))
password.setText(preferences.sourcePassword(source))
}
@@ -60,7 +43,7 @@ class SourceLoginDialog : LoginDialogPreference() {
username.text.toString(),
password.text.toString())
dialog.dismiss()
dialog?.dismiss()
context.toast(R.string.login_success)
} else {
preferences.setSourceCredentials(source, "", "")
@@ -74,4 +57,13 @@ class SourceLoginDialog : LoginDialogPreference() {
}
}
override fun onDialogClosed() {
super.onDialogClosed()
(targetController as? Listener)?.loginDialogClosed(source)
}
interface Listener {
fun loginDialogClosed(source: LoginSource)
}
}

View File

@@ -4,15 +4,16 @@ import android.annotation.TargetApi
import android.content.Context
import android.content.res.TypedArray
import android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH
import android.support.v7.preference.PreferenceCategory
import android.support.v7.preference.PreferenceViewHolder
import android.support.v7.widget.SwitchCompat
import android.util.AttributeSet
import android.view.View
import android.widget.Checkable
import android.widget.CompoundButton
import android.widget.TextView
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.getResourceColor
import net.xpece.android.support.preference.PreferenceCategory
import net.xpece.android.support.preference.R
class SwitchPreferenceCategory @JvmOverloads constructor(
context: Context,
@@ -20,20 +21,17 @@ class SwitchPreferenceCategory @JvmOverloads constructor(
: PreferenceCategory(
context,
attrs,
R.attr.switchPreferenceCompatStyle,
R.style.Preference_Material_SwitchPreferenceCompat),
R.attr.switchPreferenceCompatStyle),
CompoundButton.OnCheckedChangeListener {
init {
setTitleTextColor(context.getResourceColor(R.attr.colorAccent))
}
private var mChecked = false
private var mCheckedSet = false
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
val titleView = holder.findViewById(android.R.id.title) as TextView
titleView.setTextColor(context.getResourceColor(R.attr.colorAccent))
syncSwitchView(holder)
}

View File

@@ -9,36 +9,19 @@ import eu.kanade.tachiyomi.util.toast
import kotlinx.android.synthetic.main.pref_account_login.view.*
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import uy.kohesive.injekt.injectLazy
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class TrackLoginDialog : LoginDialogPreference() {
class TrackLoginDialog(bundle: Bundle? = null) : LoginDialogPreference(bundle) {
companion object {
private val service = Injekt.get<TrackManager>().getService(args.getInt("key"))!!
fun newInstance(sync: TrackService): LoginDialogPreference {
val fragment = TrackLoginDialog()
val bundle = Bundle(1)
bundle.putInt("key", sync.id)
fragment.arguments = bundle
return fragment
}
}
val trackManager: TrackManager by injectLazy()
lateinit var sync: TrackService
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val syncId = arguments.getInt("key")
sync = trackManager.getService(syncId)!!
}
constructor(service: TrackService) : this(Bundle().apply { putInt("key", service.id) })
override fun setCredentialsOnView(view: View) = with(view) {
dialog_title.text = getString(R.string.login_title, sync.name)
username.setText(sync.getUsername())
password.setText(sync.getPassword())
dialog_title.text = context.getString(R.string.login_title, service.name)
username.setText(service.getUsername())
password.setText(service.getPassword())
}
override fun checkLogin() {
@@ -52,11 +35,11 @@ class TrackLoginDialog : LoginDialogPreference() {
val user = username.text.toString()
val pass = password.text.toString()
requestSubscription = sync.login(user, pass)
requestSubscription = service.login(user, pass)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
dialog.dismiss()
dialog?.dismiss()
context.toast(R.string.login_success)
}, { error ->
login.progress = -1
@@ -67,4 +50,13 @@ class TrackLoginDialog : LoginDialogPreference() {
}
}
override fun onDialogClosed() {
super.onDialogClosed()
(targetController as? Listener)?.trackDialogClosed(service)
}
interface Listener {
fun trackDialogClosed(service: TrackService)
}
}