pull/31/head
Awesome 6 years ago
parent 7b0d3d0be2
commit 57acb76df6
  1. 32
      app/src/main/java/io/legado/app/base/adapter/InfiniteScrollListener.kt
  2. 2
      app/src/main/java/io/legado/app/base/adapter/ItemAnimation.kt
  3. 3
      app/src/main/java/io/legado/app/base/adapter/animations/ScaleInAnimation.kt
  4. 1
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt
  5. 4
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  6. 1
      app/src/main/java/io/legado/app/ui/search/SearchActivity.kt
  7. 34
      app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt
  8. 18
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt
  9. 15
      app/src/main/res/layout/app_bar_main.xml
  10. 19
      app/src/main/res/layout/item_search.xml
  11. 1
      app/src/main/res/layout/view_titlebar.xml
  12. 2
      app/src/main/res/values/attrs.xml

@ -0,0 +1,32 @@
package io.legado.app.base.adapter
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
/**
* Created by Invincible on 2017/12/15.
*
* 上拉加载更多
*/
abstract class InfiniteScrollListener() : RecyclerView.OnScrollListener() {
private val loadMoreRunnable = Runnable { onLoadMore() }
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
// if (dy < 0 || dataLoading.isDataLoading()) return
val layoutManager:LinearLayoutManager = recyclerView.layoutManager as LinearLayoutManager
val visibleItemCount = recyclerView.childCount
val totalItemCount = layoutManager.itemCount
val firstVisibleItem = layoutManager.findFirstVisibleItemPosition()
if (totalItemCount - visibleItemCount <= firstVisibleItem + VISIBLE_THRESHOLD) {
recyclerView.post(loadMoreRunnable)
}
}
abstract fun onLoadMore()
companion object {
private const val VISIBLE_THRESHOLD = 5
}
}

@ -4,7 +4,7 @@ import android.view.animation.Interpolator
import android.view.animation.LinearInterpolator
import io.legado.app.base.adapter.animations.AlphaInAnimation
import io.legado.app.base.adapter.animations.BaseAnimation
import io.legado.app.base.animations.ScaleInAnimation
import io.legado.app.base.adapter.animations.ScaleInAnimation
import io.legado.app.base.adapter.animations.SlideInBottomAnimation
import io.legado.app.base.adapter.animations.SlideInLeftAnimation
import io.legado.app.base.adapter.animations.SlideInRightAnimation

@ -1,9 +1,8 @@
package io.legado.app.base.animations
package io.legado.app.base.adapter.animations
import android.animation.Animator
import android.animation.ObjectAnimator
import android.view.View
import io.legado.app.base.adapter.animations.BaseAnimation
class ScaleInAnimation @JvmOverloads constructor(private val mFrom: Float = DEFAULT_SCALE_FROM) : BaseAnimation {

@ -1,2 +1,3 @@
package io.legado.app.data.entities
class SearchBook

@ -14,6 +14,7 @@ import io.legado.app.base.BaseActivity
import io.legado.app.ui.search.SearchActivity
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.app_bar_main.*
import kotlinx.android.synthetic.main.view_titlebar.*
class MainActivity : BaseActivity<MainDataBinding, MainViewModel>(), NavigationView.OnNavigationItemSelectedListener {
override val viewModel: MainViewModel
@ -22,11 +23,10 @@ class MainActivity : BaseActivity<MainDataBinding, MainViewModel>(), NavigationV
get() = R.layout.activity_main
override fun onViewModelCreated(viewModel: MainViewModel, savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
fab.setOnClickListener { startActivity(Intent(this, SearchActivity::class.java)) }
val toggle = ActionBarDrawerToggle(
this, drawer_layout, toolbar,
this, drawer_layout, titleBar.toolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close
)

@ -15,7 +15,6 @@ class SearchActivity : BaseActivity<SearchDataBinding, SearchViewModel>() {
get() = R.layout.activity_search
override fun onViewModelCreated(viewModel: SearchViewModel, savedInstanceState: Bundle?) {
}
}

@ -0,0 +1,34 @@
package io.legado.app.ui.search
import android.content.Context
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewDelegate
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.SearchBook
import kotlinx.android.synthetic.main.item_search.view.*
class SearchAdapter(context: Context) : SimpleRecyclerAdapter<SearchBook>(context) {
init {
addItemViewDelegate(TestItemDelegate(context))
}
override val layoutID: Int
get() = R.layout.item_search
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) {
holder.itemView.bookName.text = "我欲封天"
}
internal class TestItemDelegate(context: Context) : ItemViewDelegate<SearchBook>(context){
override val layoutID: Int
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
}

@ -5,7 +5,10 @@ import android.content.res.ColorStateList
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.Menu
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.graphics.drawable.DrawableCompat
import com.google.android.material.appbar.AppBarLayout
import io.legado.app.R
@ -13,11 +16,16 @@ import kotlinx.android.synthetic.main.view_titlebar.view.*
class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, attrs) {
val toolbar: Toolbar
val menu: Menu
get() = toolbar.menu
init {
inflate(context, R.layout.view_titlebar, this)
toolbar = findViewById(R.id.toolbar)
val a = context.obtainStyledAttributes(
attrs, R.styleable.TitleBar,
0, 0
R.attr.titleBarStyle, 0
)
val navigationIcon = a.getDrawable(R.styleable.TitleBar_navigationIcon)
val navigationContentDescription = a.getText(R.styleable.TitleBar_navigationContentDescription)
@ -40,13 +48,15 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
}
}
fun setNavigationOnClickListener(clickListener: ((View) -> Unit)){
toolbar.setNavigationOnClickListener(clickListener)
}
private fun attachToActivity(context: Context) {
val activity = getCompatActivity(context)
activity?.let {
activity.setSupportActionBar(toolbar)
activity.supportActionBar?.let {
it.setDisplayHomeAsUpEnabled(true)
}
activity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
}

@ -7,19 +7,10 @@
android:layout_height="match_parent"
tools:context=".ui.main.MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
<io.legado.app.ui.widget.TitleBar
android:id="@+id/titleBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</com.google.android.material.appbar.AppBarLayout>
android:layout_height="wrap_content"/>
<include layout="@layout/content_main"/>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/bookName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:text="测试"/>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -5,4 +5,5 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay"/>

@ -29,6 +29,8 @@
</attr>
</declare-styleable>
<attr name="titleBarStyle" format="reference" />
<declare-styleable name="DynamicFrameLayout">
<attr name="errorSrc" format="reference" />
<attr name="emptySrc" format="reference" />

Loading…
Cancel
Save