From 21bfd4dd2d8dba06dc9c70bda7ad39c9ba44f15a Mon Sep 17 00:00:00 2001 From: Lokesh Gidra Date: Mon, 20 Nov 2023 21:25:41 +0800 Subject: [PATCH] Cleanup unused res --- .../ehviewer/ui/legacy/AddDeleteDrawable.kt | 149 ------------------ .../ehviewer/ui/legacy/LayoutManagerUtils.kt | 124 --------------- .../ui/legacy/SimpleSmoothScroller.kt | 38 ----- .../ui/legacy/WindowInsetsAnimationHelper.kt | 95 ----------- .../com/hippo/ehviewer/util/AnimationUtils.kt | 2 - .../hippo/ehviewer/util/WindowInsetsUtil.kt | 10 -- app/src/main/res/layout/scene_favorites.xml | 27 ---- 7 files changed, 445 deletions(-) delete mode 100644 app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/AddDeleteDrawable.kt delete mode 100644 app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/SimpleSmoothScroller.kt delete mode 100644 app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/WindowInsetsAnimationHelper.kt delete mode 100644 app/src/main/res/layout/scene_favorites.xml diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/AddDeleteDrawable.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/AddDeleteDrawable.kt deleted file mode 100644 index 4f21c99de..000000000 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/AddDeleteDrawable.kt +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (C) 2015 Hippo Seven - * - * 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 com.hippo.ehviewer.ui.legacy - -import android.animation.ObjectAnimator -import android.content.Context -import android.graphics.Canvas -import android.graphics.ColorFilter -import android.graphics.Paint -import android.graphics.Path -import android.graphics.PixelFormat -import android.graphics.drawable.Drawable -import androidx.annotation.Keep -import com.google.android.material.math.MathUtils -import com.hippo.ehviewer.R -import kotlin.math.roundToInt - -/** - * @param context used to get the configuration for the drawable from - */ -class AddDeleteDrawable(context: Context, color: Int) : Drawable() { - private val mPaint = Paint() - private val mPath = Path() - private val mSize: Int - private var mProgress = 0f - private var mAutoUpdateMirror = false - private var mVerticalMirror = false - - init { - val resources = context.resources - mSize = resources.getDimensionPixelSize(R.dimen.add_size) - val barThickness = resources.getDimension(R.dimen.add_thickness).roundToInt().toFloat() - mPaint.color = color - mPaint.style = Paint.Style.STROKE - mPaint.strokeJoin = Paint.Join.MITER - mPaint.strokeCap = Paint.Cap.BUTT - mPaint.strokeWidth = barThickness - val halfSize = (mSize / 2).toFloat() - mPath.moveTo(0f, -halfSize) - mPath.lineTo(0f, halfSize) - mPath.moveTo(-halfSize, 0f) - mPath.lineTo(halfSize, 0f) - } - - override fun draw(canvas: Canvas) { - val bounds = bounds - val canvasRotate = if (mVerticalMirror) { - MathUtils.lerp(270f, 135f, mProgress) - } else { - MathUtils.lerp(0f, 135f, mProgress) - } - canvas.save() - canvas.translate(bounds.centerX().toFloat(), bounds.centerY().toFloat()) - canvas.rotate(canvasRotate) - canvas.drawPath(mPath, mPaint) - canvas.restore() - } - - fun setColor(color: Int) { - mPaint.color = color - invalidateSelf() - } - - override fun setAlpha(alpha: Int) { - mPaint.alpha = alpha - } - - override fun setColorFilter(cf: ColorFilter?) { - mPaint.colorFilter = cf - } - - override fun getIntrinsicHeight(): Int { - return mSize * 6 / 5 - } - - override fun getIntrinsicWidth(): Int { - return mSize * 6 / 5 - } - - /** - * If set, canvas is flipped when progress reached to end and going back to start. - */ - private fun setVerticalMirror(verticalMirror: Boolean) { - mVerticalMirror = verticalMirror - } - - fun setAutoUpdateMirror(autoUpdateMirror: Boolean) { - mAutoUpdateMirror = autoUpdateMirror - } - - @get:Keep - @set:Keep - var progress: Float - get() = mProgress - set(progress) { - if (mAutoUpdateMirror) { - if (progress == 1f) { - setVerticalMirror(true) - } else if (progress == 0f) { - setVerticalMirror(false) - } - } - mProgress = progress - invalidateSelf() - } - - fun setAdd(duration: Long) { - setShape(false, duration) - } - - fun setDelete(duration: Long) { - setShape(true, duration) - } - - private fun setShape(delete: Boolean, duration: Long) { - if (!(!delete && mProgress == 0f || delete && mProgress == 1f)) { - val endProgress = if (delete) 1f else 0f - if (duration <= 0) { - progress = endProgress - } else { - val oa = ObjectAnimator.ofFloat(this, "progress", endProgress) - oa.duration = duration - oa.setAutoCancel(true) - oa.start() - } - } - } - - @Deprecated( - "Deprecated in Java", - ReplaceWith("PixelFormat.TRANSLUCENT", "android.graphics.PixelFormat"), - ) - override fun getOpacity(): Int { - return PixelFormat.TRANSLUCENT - } -} diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/LayoutManagerUtils.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/LayoutManagerUtils.kt index 28252c11b..4e9b2e777 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/LayoutManagerUtils.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/LayoutManagerUtils.kt @@ -15,139 +15,15 @@ */ package com.hippo.ehviewer.ui.legacy -import android.content.Context -import android.graphics.PointF import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView.LayoutManager import androidx.recyclerview.widget.StaggeredGridLayoutManager -import com.google.android.material.math.MathUtils -import com.hippo.ehviewer.util.SimpleHandler -import java.lang.reflect.InvocationTargetException -import java.lang.reflect.Method -import kotlin.math.abs object LayoutManagerUtils { - private var sCsdfp: Method? = null - - init { - try { - sCsdfp = StaggeredGridLayoutManager::class.java.getDeclaredMethod( - "calculateScrollDirectionForPosition", - Int::class.javaPrimitiveType, - ).apply { isAccessible = true } - } catch (e: NoSuchMethodException) { - // Ignore - e.printStackTrace() - } - } - - fun scrollToPositionWithOffset( - layoutManager: LayoutManager, - position: Int, - offset: Int, - ) { - when (layoutManager) { - is LinearLayoutManager -> layoutManager.scrollToPositionWithOffset(position, offset) - - is StaggeredGridLayoutManager -> - layoutManager.scrollToPositionWithOffset(position, offset) - - else -> throw IllegalStateException("Can't do scrollToPositionWithOffset for " + layoutManager.javaClass.name) - } - } - - fun smoothScrollToPosition( - layoutManager: LayoutManager, - context: Context, - position: Int, - millisecondsPerInch: Int = -1, - ) { - val smoothScroller: SimpleSmoothScroller - when (layoutManager) { - is LinearLayoutManager -> { - smoothScroller = - object : SimpleSmoothScroller(context, millisecondsPerInch.toFloat()) { - override fun computeScrollVectorForPosition(targetPosition: Int): PointF? { - return layoutManager.computeScrollVectorForPosition(targetPosition) - } - } - } - - is StaggeredGridLayoutManager -> { - smoothScroller = - object : SimpleSmoothScroller(context, millisecondsPerInch.toFloat()) { - override fun computeScrollVectorForPosition(targetPosition: Int): PointF? { - var direction = 0 - try { - direction = sCsdfp!!.invoke(layoutManager, targetPosition) as Int - } catch (e: IllegalAccessException) { - e.printStackTrace() - } catch (e: InvocationTargetException) { - e.printStackTrace() - } - if (direction == 0) { - return null - } - return if (layoutManager.orientation == StaggeredGridLayoutManager.HORIZONTAL) { - PointF(direction.toFloat(), 0f) - } else { - PointF(0f, direction.toFloat()) - } - } - } - } - - else -> throw IllegalStateException("Can't do smoothScrollToPosition for " + layoutManager.javaClass.name) - } - smoothScroller.targetPosition = position - layoutManager.startSmoothScroll(smoothScroller) - } - - fun scrollToPositionProperly( - layoutManager: LayoutManager, - context: Context, - position: Int, - listener: OnScrollToPositionListener?, - ) { - SimpleHandler.postDelayed({ - val first = layoutManager.firstVisibleItemPosition - val last = getLastVisibleItemPosition(layoutManager) - val offset = abs(position - first) - val max = last - first - if (offset < max && max > 0) { - smoothScrollToPosition( - layoutManager, - context, - position, - MathUtils.lerp(100F, 25F, (offset / max).toFloat()).toInt(), - ) - } else { - scrollToPositionWithOffset(layoutManager, position, 0) - listener?.onScrollToPosition(position) - } - }, 200) - } - val LayoutManager.firstVisibleItemPosition: Int get() = when (this) { is LinearLayoutManager -> findFirstVisibleItemPosition() is StaggeredGridLayoutManager -> findFirstVisibleItemPositions(null).min() else -> error("Can't do getFirstVisibleItemPosition for " + javaClass.name) } - - fun getLastVisibleItemPosition(layoutManager: LayoutManager): Int { - return when (layoutManager) { - is LinearLayoutManager -> layoutManager.findLastVisibleItemPosition() - is StaggeredGridLayoutManager -> { - val positions = layoutManager.findLastVisibleItemPositions(null) - positions.max() - } - - else -> throw IllegalStateException("Can't do getLastVisibleItemPosition for " + layoutManager.javaClass.name) - } - } - - fun interface OnScrollToPositionListener { - fun onScrollToPosition(position: Int) - } } diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/SimpleSmoothScroller.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/SimpleSmoothScroller.kt deleted file mode 100644 index 8dbaf46f6..000000000 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/SimpleSmoothScroller.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2015 Hippo Seven - * - * 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 com.hippo.ehviewer.ui.legacy - -import android.content.Context -import androidx.recyclerview.widget.LinearSmoothScroller -import kotlin.math.abs -import kotlin.math.ceil - -abstract class SimpleSmoothScroller(context: Context, millisecondsPerInch: Float) : - LinearSmoothScroller(context) { - private val mMillisecondsPerPx: Float - - init { - mMillisecondsPerPx = millisecondsPerInch / context.resources.displayMetrics.densityDpi - } - - override fun calculateTimeForScrolling(dx: Int): Int { - return if (mMillisecondsPerPx <= 0) { - super.calculateTimeForScrolling(dx) - } else { - ceil((abs(dx) * mMillisecondsPerPx).toDouble()).toInt() - } - } -} diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/WindowInsetsAnimationHelper.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/WindowInsetsAnimationHelper.kt deleted file mode 100644 index 04f29c67a..000000000 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/legacy/WindowInsetsAnimationHelper.kt +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2022 Tarsin Norbin - * - * This file is part of EhViewer - * - * EhViewer is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * EhViewer is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with EhViewer. - * If not, see . - */ -package com.hippo.ehviewer.ui.legacy - -import android.view.View -import androidx.core.view.WindowInsetsAnimationCompat -import androidx.core.view.WindowInsetsAnimationCompat.BoundsCompat -import androidx.core.view.WindowInsetsCompat -import com.google.android.material.math.MathUtils - -class WindowInsetsAnimationHelper(dispatchMode: Int, vararg views: View) : - WindowInsetsAnimationCompat.Callback(dispatchMode) { - private val views: Array - private val startPaddings = HashMap() - private val endPaddings = HashMap() - var animation: WindowInsetsAnimationCompat? = null - - init { - this.views = arrayOf(*views) - } - - override fun onPrepare(animation: WindowInsetsAnimationCompat) { - super.onPrepare(animation) - this.animation = animation - for (view in views) { - startPaddings[view] = view.paddingBottom - } - } - - override fun onStart( - animation: WindowInsetsAnimationCompat, - bounds: BoundsCompat, - ): BoundsCompat { - this.animation = animation - for (view in views) { - endPaddings[view] = view.paddingBottom - val startPadding = if (startPaddings.containsKey(view)) startPaddings[view]!! else 0 - view.translationY = -(startPadding - view.paddingBottom).toFloat() - } - return bounds - } - - override fun onProgress( - insets: WindowInsetsCompat, - runningAnimations: List, - ): WindowInsetsCompat { - if (animation == null) { - return insets - } - var imeAnimation: WindowInsetsAnimationCompat? = null - for (animation in runningAnimations) { - if (animation.typeMask and WindowInsetsCompat.Type.ime() != 0) { - imeAnimation = animation - break - } - } - if (imeAnimation != null) { - for (view in views) { - val startPadding = if (startPaddings.containsKey(view)) startPaddings[view]!! else 0 - val endPadding = if (endPaddings.containsKey(view)) endPaddings[view]!! else 0 - view.translationY = MathUtils.lerp( - (endPadding - startPadding).toFloat(), - 0f, - animation!!.interpolatedFraction, - ) - } - } - return insets - } - - override fun onEnd(animation: WindowInsetsAnimationCompat) { - super.onEnd(animation) - startPaddings.clear() - endPaddings.clear() - this.animation = null - for (view in views) { - view.translationY = 0f - } - } -} diff --git a/app/src/main/kotlin/com/hippo/ehviewer/util/AnimationUtils.kt b/app/src/main/kotlin/com/hippo/ehviewer/util/AnimationUtils.kt index 01bb95218..7983ff8e4 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/util/AnimationUtils.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/util/AnimationUtils.kt @@ -17,11 +17,9 @@ package com.hippo.ehviewer.util import android.view.animation.Interpolator import androidx.interpolator.view.animation.FastOutLinearInInterpolator -import androidx.interpolator.view.animation.FastOutSlowInInterpolator import androidx.interpolator.view.animation.LinearOutSlowInInterpolator object AnimationUtils { val FAST_SLOW_INTERPOLATOR: Interpolator = LinearOutSlowInInterpolator() val SLOW_FAST_INTERPOLATOR: Interpolator = FastOutLinearInInterpolator() - val SLOW_FAST_SLOW_INTERPOLATOR: Interpolator = FastOutSlowInInterpolator() } diff --git a/app/src/main/kotlin/com/hippo/ehviewer/util/WindowInsetsUtil.kt b/app/src/main/kotlin/com/hippo/ehviewer/util/WindowInsetsUtil.kt index 8f16e08d0..2b96b506f 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/util/WindowInsetsUtil.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/util/WindowInsetsUtil.kt @@ -1,14 +1,12 @@ package com.hippo.ehviewer.util import android.graphics.Rect -import android.view.View import androidx.compose.foundation.layout.WindowInsets import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalLayoutDirection import androidx.core.graphics.Insets import androidx.core.view.WindowInsetsCompat -import dev.chrisbanes.insetter.applyInsetter import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -47,11 +45,3 @@ fun WindowInsetsCompat.Builder.set(type: Int, insets: WindowInsets): WindowInset ), ) } - -fun View.applyNavigationBarsPadding() { - applyInsetter { - type(navigationBars = true) { - padding() - } - } -} diff --git a/app/src/main/res/layout/scene_favorites.xml b/app/src/main/res/layout/scene_favorites.xml deleted file mode 100644 index 56bb6cbd7..000000000 --- a/app/src/main/res/layout/scene_favorites.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - -