mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-28 12:57:57 +01:00
Minor classes restructuration and optimize imports
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
|
||||
class DividerItemDecoration : RecyclerView.ItemDecoration {
|
||||
|
||||
private val divider: Drawable?
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) {
|
||||
val a = context.obtainStyledAttributes(attrs, intArrayOf(android.R.attr.listDivider))
|
||||
divider = a.getDrawable(0)
|
||||
a.recycle()
|
||||
}
|
||||
|
||||
constructor(divider: Drawable) {
|
||||
this.divider = divider
|
||||
}
|
||||
|
||||
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) {
|
||||
super.getItemOffsets(outRect, view, parent, state)
|
||||
if (divider == null) return
|
||||
if (parent.getChildPosition(view) < 1) return
|
||||
|
||||
if (getOrientation(parent) == LinearLayoutManager.VERTICAL)
|
||||
outRect.top = divider.intrinsicHeight
|
||||
else
|
||||
outRect.left = divider.intrinsicWidth
|
||||
}
|
||||
|
||||
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State?) {
|
||||
if (divider == null) {
|
||||
super.onDrawOver(c, parent, state)
|
||||
return
|
||||
}
|
||||
|
||||
if (getOrientation(parent) == LinearLayoutManager.VERTICAL) {
|
||||
val left = parent.paddingLeft
|
||||
val right = parent.width - parent.paddingRight
|
||||
val childCount = parent.childCount
|
||||
val dividerHeight = divider.intrinsicHeight
|
||||
|
||||
for (i in 1..childCount - 1) {
|
||||
val child = parent.getChildAt(i)
|
||||
val params = child.layoutParams as RecyclerView.LayoutParams
|
||||
val ty = (child.translationY + 0.5f).toInt()
|
||||
val top = child.top - params.topMargin + ty
|
||||
val bottom = top + dividerHeight
|
||||
divider.setBounds(left, top, right, bottom)
|
||||
divider.draw(c)
|
||||
}
|
||||
} else { //horizontal
|
||||
val top = parent.paddingTop
|
||||
val bottom = parent.height - parent.paddingBottom
|
||||
val childCount = parent.childCount
|
||||
|
||||
for (i in 1..childCount - 1) {
|
||||
val child = parent.getChildAt(i)
|
||||
val params = child.layoutParams as RecyclerView.LayoutParams
|
||||
val size = divider.intrinsicWidth
|
||||
val left = child.left - params.leftMargin
|
||||
val right = left + size
|
||||
divider.setBounds(left, top, right, bottom)
|
||||
divider.draw(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getOrientation(parent: RecyclerView): Int {
|
||||
if (parent.layoutManager is LinearLayoutManager) {
|
||||
val layoutManager = parent.layoutManager as LinearLayoutManager
|
||||
return layoutManager.orientation
|
||||
} else
|
||||
throw IllegalStateException("DividerItemDecoration can only be used with a LinearLayoutManager.")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.support.design.widget.CoordinatorLayout
|
||||
import android.support.design.widget.FloatingActionButton
|
||||
import android.support.v4.view.ViewCompat
|
||||
import android.view.View
|
||||
|
||||
abstract class FABAnimationBase() : FloatingActionButton.Behavior() {
|
||||
|
||||
var isAnimatingOut = false
|
||||
|
||||
override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionButton,
|
||||
directTargetChild: View, target: View, nestedScrollAxes: Int): Boolean {
|
||||
// Ensure we react to vertical scrolling
|
||||
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL ||
|
||||
super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes)
|
||||
}
|
||||
|
||||
override fun onNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionButton, target: View,
|
||||
dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int) {
|
||||
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed)
|
||||
if (dyConsumed > 0 && !isAnimatingOut && child.visibility == View.VISIBLE) {
|
||||
// User scrolled down and the FAB is currently visible -> hide the FAB
|
||||
animateOut(child)
|
||||
} else if (dyConsumed < 0 && child.visibility != View.VISIBLE) {
|
||||
// User scrolled up and the FAB is currently not visible -> show the FAB
|
||||
animateIn(child)
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun animateOut(button: FloatingActionButton)
|
||||
abstract fun animateIn(button: FloatingActionButton)
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.support.design.widget.FloatingActionButton
|
||||
import android.support.v4.view.animation.FastOutSlowInInterpolator
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
import eu.kanade.tachiyomi.R
|
||||
|
||||
class FABAnimationUpDown @JvmOverloads constructor(ctx: Context, attrs: AttributeSet? = null) : FABAnimationBase() {
|
||||
|
||||
private val INTERPOLATOR = FastOutSlowInInterpolator()
|
||||
|
||||
private val outAnimation by lazy {
|
||||
AnimationUtils.loadAnimation(ctx, R.anim.fab_hide_to_bottom).apply {
|
||||
duration = 200
|
||||
interpolator = INTERPOLATOR
|
||||
}
|
||||
}
|
||||
private val inAnimation by lazy {
|
||||
AnimationUtils.loadAnimation(ctx, R.anim.fab_show_from_bottom).apply {
|
||||
duration = 200
|
||||
interpolator = INTERPOLATOR
|
||||
}
|
||||
}
|
||||
|
||||
override fun animateOut(button: FloatingActionButton) {
|
||||
outAnimation.setAnimationListener(object : Animation.AnimationListener {
|
||||
override fun onAnimationStart(animation: Animation) {
|
||||
isAnimatingOut = true
|
||||
}
|
||||
|
||||
override fun onAnimationEnd(animation: Animation) {
|
||||
isAnimatingOut = false
|
||||
button.visibility = View.GONE
|
||||
}
|
||||
|
||||
override fun onAnimationRepeat(animation: Animation) {
|
||||
}
|
||||
})
|
||||
button.startAnimation(outAnimation)
|
||||
}
|
||||
|
||||
override fun animateIn(button: FloatingActionButton) {
|
||||
button.visibility = View.VISIBLE
|
||||
button.startAnimation(inAnimation)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.view.animation.Animation
|
||||
|
||||
open class SimpleAnimationListener : Animation.AnimationListener {
|
||||
override fun onAnimationRepeat(animation: Animation) {}
|
||||
|
||||
override fun onAnimationEnd(animation: Animation) {}
|
||||
|
||||
override fun onAnimationStart(animation: Animation) {}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.widget.SeekBar
|
||||
|
||||
open class SimpleSeekBarListener : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar) {}
|
||||
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar) {}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
|
||||
open class SimpleTextWatcher : TextWatcher {
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
|
||||
|
||||
override fun afterTextChanged(s: Editable) {}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ 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.base.listener.SimpleTextWatcher
|
||||
import eu.kanade.tachiyomi.ui.setting.SettingsActivity
|
||||
import eu.kanade.tachiyomi.widget.SimpleTextWatcher
|
||||
import kotlinx.android.synthetic.main.pref_account_login.view.*
|
||||
import rx.Subscription
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.widget.preference
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.source.base.OnlineSource
|
||||
import eu.kanade.tachiyomi.data.source.base.Source
|
||||
import eu.kanade.tachiyomi.data.source.Source
|
||||
import eu.kanade.tachiyomi.data.source.online.OnlineSource
|
||||
import eu.kanade.tachiyomi.ui.setting.SettingsActivity
|
||||
import eu.kanade.tachiyomi.util.toast
|
||||
import kotlinx.android.synthetic.main.pref_account_login.view.*
|
||||
|
||||
Reference in New Issue
Block a user