pull/36/head
kunfei 5 years ago
parent 6fb960f6de
commit bff4043607
  1. 13
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  2. 30
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt
  3. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt
  4. 27
      app/src/main/res/menu/book_group_manage.xml

@ -1,10 +1,7 @@
package io.legado.app.data.dao
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.*
import io.legado.app.data.entities.BookGroup
@Dao
@ -17,5 +14,11 @@ interface BookGroupDao {
val maxId: Int
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(bookGroup: BookGroup)
fun insert(vararg bookGroup: BookGroup)
@Update
fun update(vararg bookGroup: BookGroup)
@Delete
fun delete(vararg bookGroup: BookGroup)
}

@ -7,28 +7,28 @@ import io.legado.app.data.entities.BookGroup
class BookshelfViewModel(application: Application) : BaseViewModel(application) {
fun saveBookGroup(group: String?) {
if (!group.isNullOrBlank()) {
execute {
App.db.bookGroupDao().insert(
BookGroup(
App.db.bookGroupDao().maxId + 1,
group
)
)
}
}
}
fun addGroup(groupName: String) {
execute {
val maxId = App.db.bookGroupDao().maxId
val bookGroup = BookGroup(
groupId = maxId.plus(1),
groupName = groupName,
order = maxId.plus(1)
)
App.db.bookGroupDao().insert(bookGroup)
}
}
fun upGroup(bookGroup: BookGroup) {
execute {
App.db.bookGroupDao().update(bookGroup)
}
}
fun delGroup(bookGroup: BookGroup) {
execute {
App.db.bookGroupDao().delete(bookGroup)
}
}
}

@ -59,7 +59,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private fun initData() {
tool_bar.title = getString(R.string.group_manage)
tool_bar.inflateMenu(R.menu.group_manage)
tool_bar.inflateMenu(R.menu.book_group_manage)
tool_bar.menu.applyTint(requireContext(), false)
tool_bar.setOnMenuItemClickListener(this)
adapter = GroupAdapter(requireContext())

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_add"
android:icon="@drawable/ic_add"
android:title="@string/add_group"
app:showAsAction="always"
tools:ignore="AlwaysShowAction" />
<item
android:id="@+id/menu_group_local"
android:title="@string/local"
android:checkable="true"
android:checked="true"
app:showAsAction="never" />
<item
android:id="@+id/menu_group_audio"
android:title="@string/audio"
android:checkable="true"
android:checked="true"
app:showAsAction="never" />
</menu>
Loading…
Cancel
Save