Merge branch 'master' of https://github.com/gedoor/legado into master

pull/399/head
Robot 4 years ago
commit b6d2cf43f8
  1. 14
      app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt
  2. 4
      app/src/main/java/io/legado/app/service/DownloadService.kt

@ -15,17 +15,17 @@ import java.util.*
*
* 通用的adapter 可添加headerfooter以及不同类型item
*/
abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context):
abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context) :
RecyclerView.Adapter<ItemViewHolder>() {
constructor(context: Context, vararg delegates: ItemViewDelegate<ITEM>): this(context) {
constructor(context: Context, vararg delegates: ItemViewDelegate<ITEM>) : this(context) {
addItemViewDelegates(*delegates)
}
constructor(
context: Context,
vararg delegates: Pair<Int, ItemViewDelegate<ITEM>>
): this(context) {
) : this(context) {
addItemViewDelegates(*delegates)
}
@ -57,15 +57,15 @@ abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context):
recyclerView.adapter = this
}
fun <DELEGATE: ItemViewDelegate<ITEM>> addItemViewDelegate(viewType: Int, delegate: DELEGATE) {
fun <DELEGATE : ItemViewDelegate<ITEM>> addItemViewDelegate(viewType: Int, delegate: DELEGATE) {
itemDelegates[viewType] = delegate
}
fun <DELEGATE: ItemViewDelegate<ITEM>> addItemViewDelegate(delegate: DELEGATE) {
fun <DELEGATE : ItemViewDelegate<ITEM>> addItemViewDelegate(delegate: DELEGATE) {
itemDelegates[itemDelegates.size] = delegate
}
fun <DELEGATE: ItemViewDelegate<ITEM>> addItemViewDelegates(vararg delegates: DELEGATE) {
fun <DELEGATE : ItemViewDelegate<ITEM>> addItemViewDelegates(vararg delegates: DELEGATE) {
delegates.forEach {
addItemViewDelegate(it)
}
@ -365,7 +365,7 @@ abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context):
super.onAttachedToRecyclerView(recyclerView)
val manager = recyclerView.layoutManager
if (manager is GridLayoutManager) {
manager.spanSizeLookup = object: GridLayoutManager.SpanSizeLookup() {
manager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return getItem(position)?.let {
if (isHeader(position) || isFooter(position)) manager.spanCount else getSpanSize(

@ -69,9 +69,7 @@ class DownloadService : BaseService() {
IntentAction.stop -> {
val downloadId = intent.getLongExtra("downloadId", 0)
downloads.remove(downloadId)
if (downloads.isEmpty()) {
stopSelf()
}
stopSelf()
}
}
return super.onStartCommand(intent, flags, startId)

Loading…
Cancel
Save