pull/32/head
Invinciblelee 6 years ago
parent 09e94d8b5c
commit 6302b28f26
  1. 1
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.java
  2. 40
      app/src/main/java/io/legado/app/ui/widget/RotateLoading.kt
  3. 38
      app/src/main/res/layout/activity_search.xml
  4. 32
      app/src/main/res/layout/fragment_bookshelf.xml

@ -7,5 +7,6 @@ import org.jetbrains.annotations.NotNull;
public class ReplaceRuleViewModel extends BaseViewModel { public class ReplaceRuleViewModel extends BaseViewModel {
public ReplaceRuleViewModel(@NotNull Application application) { public ReplaceRuleViewModel(@NotNull Application application) {
super(application); super(application);
} }
} }

@ -9,10 +9,11 @@ import android.graphics.Color
import android.graphics.Paint import android.graphics.Paint
import android.graphics.RectF import android.graphics.RectF
import android.util.AttributeSet import android.util.AttributeSet
import android.util.TypedValue
import android.view.View import android.view.View
import android.view.animation.LinearInterpolator import android.view.animation.LinearInterpolator
import androidx.core.view.isVisible
import io.legado.app.R import io.legado.app.R
import io.legado.app.utils.dp
/** /**
* RotateLoading * RotateLoading
@ -59,8 +60,8 @@ class RotateLoading : View {
private fun initView(context: Context, attrs: AttributeSet?) { private fun initView(context: Context, attrs: AttributeSet?) {
loadingColor = Color.WHITE loadingColor = Color.WHITE
thisWidth = dpToPx(context, DEFAULT_WIDTH.toFloat()) thisWidth = DEFAULT_WIDTH.dp
shadowPosition = dpToPx(getContext(), DEFAULT_SHADOW_POSITION.toFloat()) shadowPosition = DEFAULT_SHADOW_POSITION.dp
speedOfDegree = DEFAULT_SPEED_OF_DEGREE speedOfDegree = DEFAULT_SPEED_OF_DEGREE
if (null != attrs) { if (null != attrs) {
@ -68,7 +69,7 @@ class RotateLoading : View {
loadingColor = typedArray.getColor(R.styleable.RotateLoading_loading_color, Color.WHITE) loadingColor = typedArray.getColor(R.styleable.RotateLoading_loading_color, Color.WHITE)
thisWidth = typedArray.getDimensionPixelSize( thisWidth = typedArray.getDimensionPixelSize(
R.styleable.RotateLoading_loading_width, R.styleable.RotateLoading_loading_width,
dpToPx(context, DEFAULT_WIDTH.toFloat()) DEFAULT_WIDTH.dp
) )
shadowPosition = typedArray.getInt(R.styleable.RotateLoading_shadow_position, DEFAULT_SHADOW_POSITION) shadowPosition = typedArray.getInt(R.styleable.RotateLoading_shadow_position, DEFAULT_SHADOW_POSITION)
speedOfDegree = typedArray.getInt(R.styleable.RotateLoading_loading_speed, DEFAULT_SPEED_OF_DEGREE) 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() startAnimator()
isStart = true isStart = true
invalidate() invalidate()
} }
fun stop() { private fun stop() {
stopAnimator() stopAnimator()
invalidate() invalidate()
} }
@ -197,16 +214,11 @@ class RotateLoading : View {
animatorSet.start() animatorSet.start()
} }
fun dpToPx(context: Context, dpVal: Float): Int {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal, context.resources.displayMetrics).toInt()
}
companion object { companion object {
private val DEFAULT_WIDTH = 6 private const val DEFAULT_WIDTH = 6
private val DEFAULT_SHADOW_POSITION = 2 private const val DEFAULT_SHADOW_POSITION = 2
private val DEFAULT_SPEED_OF_DEGREE = 10 private const val DEFAULT_SPEED_OF_DEGREE = 10
} }
} }

@ -1,29 +1,31 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout
xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent" android:layout_width="match_parent"
tools:context="io.legado.app.ui.search.SearchActivity"> android:layout_height="match_parent"
tools:context="io.legado.app.ui.search.SearchActivity">
<io.legado.app.ui.widget.TitleBar <io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar" android:id="@+id/title_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:title="搜索" /> app:title="搜索"/>
<io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout <io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout
android:layout_width="match_parent" android:id="@+id/content_view"
android:layout_height="0dp" android:layout_width="match_parent"
app:layout_constraintBottom_toBottomOf="parent" android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/title_bar"> app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/title_bar">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_search_list" android:id="@+id/rv_search_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"/>
</io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout> </io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout>

@ -1,24 +1,24 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<io.legado.app.ui.widget.TitleBar <io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar" android:id="@+id/title_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:attachToActivity="false" app:attachToActivity="false"
app:title="@string/bookshelf" /> app:title="@string/bookshelf"/>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_book_group" android:id="@+id/rv_book_group"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"/>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_bookshelf" android:id="@+id/rv_bookshelf"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"/>
</LinearLayout> </LinearLayout>
Loading…
Cancel
Save