|
|
@ -2,6 +2,8 @@ package io.legado.app.ui.about |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
|
|
|
|
import android.view.Menu |
|
|
|
|
|
|
|
import android.view.MenuItem |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
@ -12,15 +14,18 @@ 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.lib.dialogs.alert |
|
|
|
import io.legado.app.lib.dialogs.alert |
|
|
|
|
|
|
|
import io.legado.app.utils.cnCompare |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() { |
|
|
|
class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() { |
|
|
|
|
|
|
|
|
|
|
|
lateinit var adapter: RecordAdapter |
|
|
|
lateinit var adapter: RecordAdapter |
|
|
|
|
|
|
|
private var sortMode = 0 |
|
|
|
|
|
|
|
|
|
|
|
override fun getViewBinding(): ActivityReadRecordBinding { |
|
|
|
override fun getViewBinding(): ActivityReadRecordBinding { |
|
|
|
return ActivityReadRecordBinding.inflate(layoutInflater) |
|
|
|
return ActivityReadRecordBinding.inflate(layoutInflater) |
|
|
@ -31,6 +36,25 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() { |
|
|
|
initData() |
|
|
|
initData() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { |
|
|
|
|
|
|
|
menuInflater.inflate(R.menu.book_read_record, menu) |
|
|
|
|
|
|
|
return super.onCompatCreateOptionsMenu(menu) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
|
|
|
|
when (item.itemId) { |
|
|
|
|
|
|
|
R.id.menu_sort_name -> { |
|
|
|
|
|
|
|
sortMode = 0 |
|
|
|
|
|
|
|
initData() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
R.id.menu_sort_time -> { |
|
|
|
|
|
|
|
sortMode = 1 |
|
|
|
|
|
|
|
initData() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return super.onCompatOptionsItemSelected(item) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initView() = with(binding) { |
|
|
|
private fun initView() = with(binding) { |
|
|
|
readRecord.tvBookName.setText(R.string.all_read_time) |
|
|
|
readRecord.tvBookName.setText(R.string.all_read_time) |
|
|
|
adapter = RecordAdapter(this@ReadRecordActivity) |
|
|
|
adapter = RecordAdapter(this@ReadRecordActivity) |
|
|
@ -52,7 +76,15 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() { |
|
|
|
withContext(Main) { |
|
|
|
withContext(Main) { |
|
|
|
binding.readRecord.tvReadTime.text = formatDuring(allTime) |
|
|
|
binding.readRecord.tvReadTime.text = formatDuring(allTime) |
|
|
|
} |
|
|
|
} |
|
|
|
val readRecords = App.db.readRecordDao().allShow |
|
|
|
var readRecords = App.db.readRecordDao().allShow |
|
|
|
|
|
|
|
readRecords = when (sortMode) { |
|
|
|
|
|
|
|
1 -> readRecords.sortedBy { it.readTime } |
|
|
|
|
|
|
|
else -> { |
|
|
|
|
|
|
|
readRecords.sortedWith { o1, o2 -> |
|
|
|
|
|
|
|
o1.bookName.cnCompare(o2.bookName) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
withContext(Main) { |
|
|
|
withContext(Main) { |
|
|
|
adapter.setItems(readRecords) |
|
|
|
adapter.setItems(readRecords) |
|
|
|
} |
|
|
|
} |
|
|
|