|
|
@ -13,6 +13,7 @@ import io.legado.app.data.appDb |
|
|
|
import io.legado.app.data.entities.ReadRecordShow |
|
|
|
import io.legado.app.data.entities.ReadRecordShow |
|
|
|
import io.legado.app.databinding.ActivityReadRecordBinding |
|
|
|
import io.legado.app.databinding.ActivityReadRecordBinding |
|
|
|
import io.legado.app.databinding.ItemReadRecordBinding |
|
|
|
import io.legado.app.databinding.ItemReadRecordBinding |
|
|
|
|
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.lib.dialogs.alert |
|
|
|
import io.legado.app.lib.dialogs.alert |
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
import io.legado.app.ui.book.search.SearchActivity |
|
|
|
import io.legado.app.ui.book.search.SearchActivity |
|
|
@ -20,7 +21,6 @@ import io.legado.app.utils.cnCompare |
|
|
|
import io.legado.app.utils.startActivity |
|
|
|
import io.legado.app.utils.startActivity |
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
|
|
|
|
|
|
|
@ -41,6 +41,11 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() { |
|
|
|
return super.onCompatCreateOptionsMenu(menu) |
|
|
|
return super.onCompatCreateOptionsMenu(menu) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { |
|
|
|
|
|
|
|
menu.findItem(R.id.menu_enable_record)?.isChecked = AppConfig.enableReadRecord |
|
|
|
|
|
|
|
return super.onMenuOpened(featureId, menu) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
when (item.itemId) { |
|
|
|
when (item.itemId) { |
|
|
|
R.id.menu_sort_name -> { |
|
|
|
R.id.menu_sort_name -> { |
|
|
@ -51,6 +56,9 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() { |
|
|
|
sortMode = 1 |
|
|
|
sortMode = 1 |
|
|
|
initData() |
|
|
|
initData() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
R.id.menu_enable_record -> { |
|
|
|
|
|
|
|
AppConfig.enableReadRecord = !item.isChecked |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return super.onCompatOptionsItemSelected(item) |
|
|
|
return super.onCompatOptionsItemSelected(item) |
|
|
|
} |
|
|
|
} |
|
|
@ -70,23 +78,22 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initData() { |
|
|
|
private fun initData() { |
|
|
|
launch(IO) { |
|
|
|
launch { |
|
|
|
val allTime = appDb.readRecordDao.allTime |
|
|
|
val allTime = withContext(IO) { |
|
|
|
withContext(Main) { |
|
|
|
appDb.readRecordDao.allTime |
|
|
|
binding.readRecord.tvReadTime.text = formatDuring(allTime) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
var readRecords = appDb.readRecordDao.allShow |
|
|
|
binding.readRecord.tvReadTime.text = formatDuring(allTime) |
|
|
|
readRecords = when (sortMode) { |
|
|
|
val readRecords = withContext(IO) { |
|
|
|
1 -> readRecords.sortedBy { it.readTime } |
|
|
|
appDb.readRecordDao.allShow.let { records -> |
|
|
|
else -> { |
|
|
|
when (sortMode) { |
|
|
|
readRecords.sortedWith { o1, o2 -> |
|
|
|
1 -> records.sortedBy { it.readTime } |
|
|
|
o1.bookName.cnCompare(o2.bookName) |
|
|
|
else -> records.sortedWith { o1, o2 -> |
|
|
|
|
|
|
|
o1.bookName.cnCompare(o2.bookName) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
withContext(Main) { |
|
|
|
adapter.setItems(readRecords) |
|
|
|
adapter.setItems(readRecords) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|