diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/lang/RxExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/lang/RxExtensions.kt index 040265d5f..e46cc909a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/lang/RxExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/lang/RxExtensions.kt @@ -4,8 +4,6 @@ import rx.Observable import rx.Subscription import rx.subscriptions.CompositeSubscription -fun Subscription?.isNullOrUnsubscribed() = this == null || isUnsubscribed - operator fun CompositeSubscription.plusAssign(subscription: Subscription) = add(subscription) fun Observable.combineLatest(o2: Observable, combineFn: (T, U) -> R): Observable { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt index ef2ed1d91..7ecd1ae8b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt @@ -24,7 +24,6 @@ import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.widget.preference.AdaptiveTitlePreferenceCategory import eu.kanade.tachiyomi.widget.preference.IntListPreference -import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory @DslMarker @Target(AnnotationTarget.TYPE) @@ -53,10 +52,6 @@ inline fun PreferenceGroup.switchPreference(block: (@DSL SwitchPreferenceCompat) return initThenAdd(SwitchPreferenceCompat(context), block) } -inline fun PreferenceGroup.switchPreferenceCategory(block: (@DSL SwitchPreferenceCategory).() -> Unit): SwitchPreferenceCategory { - return initThenAdd(SwitchPreferenceCategory(context), block) -} - inline fun PreferenceGroup.checkBoxPreference(block: (@DSL CheckBoxPreference).() -> Unit): CheckBoxPreference { return initThenAdd(CheckBoxPreference(context), block) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index 27e123a28..4397fe3e1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -32,8 +32,6 @@ import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.core.view.children import androidx.core.view.descendants import androidx.core.view.forEach -import androidx.recyclerview.widget.RecyclerView -import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton import com.google.android.material.shape.MaterialShapeDrawable import com.google.android.material.snackbar.Snackbar import eu.kanade.presentation.theme.TachiyomiTheme @@ -174,42 +172,6 @@ inline fun View.popupMenu( return popup } -/** - * Shrink an ExtendedFloatingActionButton when the associated RecyclerView is scrolled down. - * - * @param recycler [RecyclerView] that the FAB should shrink/extend in response to. - */ -inline fun ExtendedFloatingActionButton.shrinkOnScroll(recycler: RecyclerView): RecyclerView.OnScrollListener { - val listener = object : RecyclerView.OnScrollListener() { - override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { - if (dy <= 0) { - extend() - } else { - shrink() - } - } - } - recycler.addOnScrollListener(listener) - return listener -} - -/** - * Callback will be run immediately when no animation running - */ -fun RecyclerView.onAnimationsFinished(callback: (RecyclerView) -> Unit) = post( - object : Runnable { - override fun run() { - if (isAnimating) { - itemAnimator?.isRunning { - post(this) - } - } else { - callback(this@onAnimationsFinished) - } - } - }, -) - /** * Returns this ViewGroup's first child of specified class */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/MaterialAlertDialogBuilderExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/MaterialAlertDialogBuilderExtensions.kt index 0a7d8a770..7c0ed2c49 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/MaterialAlertDialogBuilderExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/MaterialAlertDialogBuilderExtensions.kt @@ -1,40 +1,15 @@ package eu.kanade.tachiyomi.widget.materialdialogs import android.view.LayoutInflater -import android.view.inputmethod.InputMethodManager -import android.widget.TextView import androidx.annotation.StringRes import androidx.appcompat.app.AlertDialog -import androidx.core.content.getSystemService import androidx.core.view.isVisible -import androidx.core.widget.doAfterTextChanged import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.dialog.MaterialAlertDialogBuilder import eu.kanade.tachiyomi.databinding.DialogStubQuadstatemultichoiceBinding -import eu.kanade.tachiyomi.databinding.DialogStubTextinputBinding import kotlinx.coroutines.suspendCancellableCoroutine import kotlin.coroutines.resume -fun MaterialAlertDialogBuilder.setTextInput( - hint: String? = null, - prefill: String? = null, - onTextChanged: (String) -> Unit, -): MaterialAlertDialogBuilder { - val binding = DialogStubTextinputBinding.inflate(LayoutInflater.from(context)) - binding.textField.hint = hint - binding.textField.editText?.apply { - setText(prefill, TextView.BufferType.EDITABLE) - doAfterTextChanged { - onTextChanged(it?.toString() ?: "") - } - post { - requestFocusFromTouch() - context.getSystemService()?.showSoftInput(this, 0) - } - } - return setView(binding.root) -} - /** * Sets a list of items with checkboxes that supports 4 states. * @@ -79,7 +54,7 @@ suspend fun MaterialAlertDialogBuilder.await( @StringRes positiveLabelId: Int, @StringRes negativeLabelId: Int, @StringRes neutralLabelId: Int? = null, -) = suspendCancellableCoroutine { cont -> +) = suspendCancellableCoroutine { cont -> setPositiveButton(positiveLabelId) { _, _ -> cont.resume(AlertDialog.BUTTON_POSITIVE) } setNegativeButton(negativeLabelId) { _, _ -> cont.resume(AlertDialog.BUTTON_NEGATIVE) } if (neutralLabelId != null) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SwitchPreferenceCategory.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SwitchPreferenceCategory.kt deleted file mode 100644 index 26bdaba09..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SwitchPreferenceCategory.kt +++ /dev/null @@ -1,126 +0,0 @@ -package eu.kanade.tachiyomi.widget.preference - -import android.content.Context -import android.content.res.TypedArray -import android.util.AttributeSet -import android.view.View -import android.widget.Checkable -import android.widget.CompoundButton -import android.widget.TextView -import androidx.appcompat.widget.SwitchCompat -import androidx.preference.PreferenceCategory -import androidx.preference.PreferenceViewHolder -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.util.system.getResourceColor - -class SwitchPreferenceCategory @JvmOverloads constructor( - context: Context, - attrs: AttributeSet? = null, -) : - PreferenceCategory( - context, - attrs, - R.attr.switchPreferenceCompatStyle, - ), - CompoundButton.OnCheckedChangeListener { - - 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) - } - - private fun syncSwitchView(holder: PreferenceViewHolder) { - val switchView = holder.findViewById(R.id.switchWidget) - syncSwitchView(switchView) - } - - private fun syncSwitchView(view: View) { - if (view is Checkable) { - val isChecked = view.isChecked - if (isChecked == mChecked) return - - if (view is SwitchCompat) { - view.setOnCheckedChangeListener(null) - } - - view.toggle() - - if (view is SwitchCompat) { - view.setOnCheckedChangeListener(this) - } - } - } - - override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) { - if (!callChangeListener(isChecked)) { - buttonView.isChecked = !isChecked - } else { - setChecked(isChecked) - } - } - - override fun onClick() { - super.onClick() - - val newValue = !isChecked() - if (callChangeListener(newValue)) { - setChecked(newValue) - } - } - - /** - * Sets the checked state and saves it to the [SharedPreferences]. - * - * @param checked The checked state. - */ - fun setChecked(checked: Boolean) { - // Always persist/notify the first time; don't assume the field's default of false. - val changed = mChecked != checked - if (changed || !mCheckedSet) { - mChecked = checked - mCheckedSet = true - persistBoolean(checked) - if (changed) { - notifyDependencyChange(shouldDisableDependents()) - notifyChanged() - } - } - } - - /** - * Returns the checked state. - * - * @return The checked state. - */ - fun isChecked(): Boolean { - return mChecked - } - - override fun isEnabled(): Boolean { - return true - } - - override fun shouldDisableDependents(): Boolean { - return false - } - - override fun onGetDefaultValue(a: TypedArray, index: Int): Any { - return a.getBoolean(index, false) - } - - override fun onSetInitialValue(restoreValue: Boolean, defaultValue: Any?) { - setChecked( - if (restoreValue) { - getPersistedBoolean(mChecked) - } else { - defaultValue as Boolean - }, - ) - } -}