pull/32/head
kunfei 5 years ago
parent 728ba09679
commit 27f7af2615
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 11
      app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt
  3. 3
      app/src/main/java/io/legado/app/ui/booksource/BookSourceAdapter.kt
  4. 11
      app/src/main/java/io/legado/app/ui/booksource/BookSourceViewModel.kt

@ -48,4 +48,7 @@ interface BookSourceDao {
@Delete @Delete
fun delete(vararg bookSource: BookSource) fun delete(vararg bookSource: BookSource)
@get:Query("select min(customOrder) from book_sources")
val minOrder: Int
} }

@ -19,7 +19,6 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.ItemTouchCallback import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.bookshelf.BookshelfViewModel
import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.ui.sourceedit.SourceEditActivity import io.legado.app.ui.sourceedit.SourceEditActivity
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
@ -30,11 +29,11 @@ import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
class BookSourceActivity : VMBaseActivity<BookshelfViewModel>(R.layout.activity_book_source), class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity_book_source),
BookSourceAdapter.CallBack, BookSourceAdapter.CallBack,
SearchView.OnQueryTextListener { SearchView.OnQueryTextListener {
override val viewModel: BookshelfViewModel override val viewModel: BookSourceViewModel
get() = getViewModel(BookshelfViewModel::class.java) get() = getViewModel(BookSourceViewModel::class.java)
private lateinit var adapter: BookSourceAdapter private lateinit var adapter: BookSourceAdapter
private var bookSourceLiveDate: LiveData<PagedList<BookSource>>? = null private var bookSourceLiveDate: LiveData<PagedList<BookSource>>? = null
@ -139,6 +138,10 @@ class BookSourceActivity : VMBaseActivity<BookshelfViewModel>(R.layout.activity_
startActivity<SourceEditActivity>(Pair("data", bookSource.bookSourceUrl)) startActivity<SourceEditActivity>(Pair("data", bookSource.bookSourceUrl))
} }
override fun topSource(bookSource: BookSource) {
viewModel.topSource(bookSource)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
when (requestCode) { when (requestCode) {

@ -83,7 +83,7 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
callBack?.update(bookSource) callBack?.update(bookSource)
} }
iv_edit_source.onClick { callBack?.edit(bookSource) } iv_edit_source.onClick { callBack?.edit(bookSource) }
iv_top_source.onClick { } iv_top_source.onClick { callBack?.topSource(bookSource) }
iv_del_source.onClick { callBack?.del(bookSource) } iv_del_source.onClick { callBack?.del(bookSource) }
} }
} }
@ -94,5 +94,6 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
fun edit(bookSource: BookSource) fun edit(bookSource: BookSource)
fun update(bookSource: BookSource) fun update(bookSource: BookSource)
fun update(vararg bookSource: BookSource) fun update(vararg bookSource: BookSource)
fun topSource(bookSource: BookSource)
} }
} }

@ -1,8 +1,19 @@
package io.legado.app.ui.booksource package io.legado.app.ui.booksource
import android.app.Application import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.BookSource
class BookSourceViewModel(application: Application) : BaseViewModel(application) { class BookSourceViewModel(application: Application) : BaseViewModel(application) {
fun topSource(bookSource: BookSource) {
execute {
val minXh = App.db.bookSourceDao().minOrder
bookSource.customOrder = minXh - 1
App.db.bookSourceDao().insert(bookSource)
}
}
} }
Loading…
Cancel
Save