diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.java b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.java index fac35d61d..4755b3819 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.java +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.java @@ -7,5 +7,6 @@ import org.jetbrains.annotations.NotNull; public class ReplaceRuleViewModel extends BaseViewModel { public ReplaceRuleViewModel(@NotNull Application application) { super(application); + } } diff --git a/app/src/main/java/io/legado/app/ui/widget/RotateLoading.kt b/app/src/main/java/io/legado/app/ui/widget/RotateLoading.kt index 441efc6e0..eee218bf8 100644 --- a/app/src/main/java/io/legado/app/ui/widget/RotateLoading.kt +++ b/app/src/main/java/io/legado/app/ui/widget/RotateLoading.kt @@ -9,10 +9,11 @@ import android.graphics.Color import android.graphics.Paint import android.graphics.RectF import android.util.AttributeSet -import android.util.TypedValue import android.view.View import android.view.animation.LinearInterpolator +import androidx.core.view.isVisible import io.legado.app.R +import io.legado.app.utils.dp /** * RotateLoading @@ -59,8 +60,8 @@ class RotateLoading : View { private fun initView(context: Context, attrs: AttributeSet?) { loadingColor = Color.WHITE - thisWidth = dpToPx(context, DEFAULT_WIDTH.toFloat()) - shadowPosition = dpToPx(getContext(), DEFAULT_SHADOW_POSITION.toFloat()) + thisWidth = DEFAULT_WIDTH.dp + shadowPosition = DEFAULT_SHADOW_POSITION.dp speedOfDegree = DEFAULT_SPEED_OF_DEGREE if (null != attrs) { @@ -68,7 +69,7 @@ class RotateLoading : View { loadingColor = typedArray.getColor(R.styleable.RotateLoading_loading_color, Color.WHITE) thisWidth = typedArray.getDimensionPixelSize( R.styleable.RotateLoading_loading_width, - dpToPx(context, DEFAULT_WIDTH.toFloat()) + DEFAULT_WIDTH.dp ) shadowPosition = typedArray.getInt(R.styleable.RotateLoading_shadow_position, DEFAULT_SHADOW_POSITION) speedOfDegree = typedArray.getInt(R.styleable.RotateLoading_loading_speed, DEFAULT_SPEED_OF_DEGREE) @@ -145,13 +146,29 @@ class RotateLoading : View { } } - fun start() { + override fun onAttachedToWindow() { + super.onAttachedToWindow() + if (isVisible) { + start() + } + } + + override fun onVisibilityChanged(changedView: View, visibility: Int) { + super.onVisibilityChanged(changedView, visibility) + if (visibility == VISIBLE) { + start() + } else { + stop() + } + } + + private fun start() { startAnimator() isStart = true invalidate() } - fun stop() { + private fun stop() { stopAnimator() invalidate() } @@ -197,16 +214,11 @@ class RotateLoading : View { animatorSet.start() } - - fun dpToPx(context: Context, dpVal: Float): Int { - return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal, context.resources.displayMetrics).toInt() - } - companion object { - private val DEFAULT_WIDTH = 6 - private val DEFAULT_SHADOW_POSITION = 2 - private val DEFAULT_SPEED_OF_DEGREE = 10 + private const val DEFAULT_WIDTH = 6 + private const val DEFAULT_SHADOW_POSITION = 2 + private const val DEFAULT_SPEED_OF_DEGREE = 10 } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml index d5e31a0c7..3837883c7 100644 --- a/app/src/main/res/layout/activity_search.xml +++ b/app/src/main/res/layout/activity_search.xml @@ -1,29 +1,31 @@ - + + android:id="@+id/title_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + app:layout_constraintTop_toTopOf="parent" + app:title="搜索"/> + android:id="@+id/content_view" + android:layout_width="match_parent" + android:layout_height="0dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintTop_toBottomOf="@id/title_bar"> + android:id="@+id/rv_search_list" + android:layout_width="match_parent" + android:layout_height="match_parent"/> diff --git a/app/src/main/res/layout/fragment_bookshelf.xml b/app/src/main/res/layout/fragment_bookshelf.xml index b7be3a24d..e018605d4 100644 --- a/app/src/main/res/layout/fragment_bookshelf.xml +++ b/app/src/main/res/layout/fragment_bookshelf.xml @@ -1,24 +1,24 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> - + android:id="@+id/title_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + app:attachToActivity="false" + app:title="@string/bookshelf"/> + + android:id="@+id/rv_book_group" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> + android:id="@+id/rv_bookshelf" + android:layout_width="match_parent" + android:layout_height="match_parent"/> \ No newline at end of file