添加阅读记录

pull/328/head
gedoor 5 years ago
parent 705b47e6a8
commit c866df0196
  1. 5
      app/src/main/AndroidManifest.xml
  2. 3
      app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt
  3. 77
      app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt
  5. 5
      app/src/main/res/drawable/ic_cfg_e_lnk.xml
  6. 17
      app/src/main/res/drawable/ic_faq.xml
  7. 30
      app/src/main/res/layout/activity_read_record.xml
  8. 25
      app/src/main/res/layout/item_read_record.xml
  9. 2
      app/src/main/res/values-zh-rHK/strings.xml
  10. 2
      app/src/main/res/values-zh-rTW/strings.xml
  11. 2
      app/src/main/res/values-zh/strings.xml
  12. 2
      app/src/main/res/values/strings.xml
  13. 7
      app/src/main/res/xml/pref_main.xml

@ -257,6 +257,11 @@
android:name=".ui.login.SourceLogin" android:name=".ui.login.SourceLogin"
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:hardwareAccelerated="true" /> android:hardwareAccelerated="true" />
<!-- 阅读记录 -->
<activity
android:name=".ui.about.ReadRecordActivity"
android:configChanges="orientation|screenSize"
android:hardwareAccelerated="true" />
<!-- 文字处理 --> <!-- 文字处理 -->
<activity <activity
android:name=".receiver.SharedReceiverActivity" android:name=".receiver.SharedReceiverActivity"

@ -9,6 +9,9 @@ interface ReadRecordDao {
@get:Query("select * from readRecord") @get:Query("select * from readRecord")
val all: List<ReadRecord> val all: List<ReadRecord>
@get:Query("select sum(readTime) from readRecord")
val allTime: Long
@Query("select readTime from readRecord where bookName = :bookName") @Query("select readTime from readRecord where bookName = :bookName")
fun getReadTime(bookName: String): Long? fun getReadTime(bookName: String): Long?

@ -0,0 +1,77 @@
package io.legado.app.ui.about
import android.content.Context
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.ReadRecord
import kotlinx.android.synthetic.main.activity_read_record.*
import kotlinx.android.synthetic.main.item_read_record.*
import kotlinx.android.synthetic.main.item_read_record.view.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class ReadRecordActivity : BaseActivity(R.layout.activity_read_record) {
lateinit var adapter: RecordAdapter
override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
initData()
}
private fun initView() {
tv_book_name.text = "总阅读时间"
recycler_view.layoutManager = LinearLayoutManager(this)
adapter = RecordAdapter(this)
recycler_view.adapter = adapter
}
private fun initData() {
launch(IO) {
val allTime = App.db.readRecordDao().allTime
withContext(Main) {
tv_read_time.text = formatDuring(allTime)
}
val readRecords = App.db.readRecordDao().all
withContext(Main) {
adapter.setItems(readRecords)
}
}
}
inner class RecordAdapter(context: Context) :
SimpleRecyclerAdapter<ReadRecord>(context, R.layout.item_read_record) {
override fun convert(holder: ItemViewHolder, item: ReadRecord, payloads: MutableList<Any>) {
holder.itemView.apply {
tv_book_name.text = item.bookName
tv_read_time.text = formatDuring(item.readTime)
}
}
override fun registerListener(holder: ItemViewHolder) {
}
}
fun formatDuring(mss: Long): String {
val days = mss / (1000 * 60 * 60 * 24)
val hours = mss % (1000 * 60 * 60 * 24) / (1000 * 60 * 60)
val minutes = mss % (1000 * 60 * 60) / (1000 * 60)
val seconds = mss % (1000 * 60) / 1000
val d = if (days > 0) "${days}" else ""
val h = if (hours > 0) "${hours}小时" else ""
val m = if (minutes > 0) "${minutes}分钟" else ""
val s = if (seconds > 0) "${seconds}" else ""
return "$d$h$m$s"
}
}

@ -18,6 +18,7 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.service.WebService import io.legado.app.service.WebService
import io.legado.app.ui.about.AboutActivity import io.legado.app.ui.about.AboutActivity
import io.legado.app.ui.about.DonateActivity import io.legado.app.ui.about.DonateActivity
import io.legado.app.ui.about.ReadRecordActivity
import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.ui.config.BackupRestoreUi import io.legado.app.ui.config.BackupRestoreUi
import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigActivity
@ -140,6 +141,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog.
"theme_setting" -> context?.startActivity<ConfigActivity>( "theme_setting" -> context?.startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG) Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG)
) )
"readRecord" -> context?.startActivity<ReadRecordActivity>()
"donate" -> context?.startActivity<DonateActivity>() "donate" -> context?.startActivity<DonateActivity>()
"about" -> context?.startActivity<AboutActivity>() "about" -> context?.startActivity<AboutActivity>()
} }

@ -1,5 +0,0 @@
<vector android:height="32dp" android:viewportHeight="24"
android:viewportWidth="24" android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,4.5A7.5,7.5 0,1 1,4.5 12,7.5 7.5,0 0,1 12,4.5M12,3a9,9 0,1 0,9 9,9 9,0 0,0 -9,-9Z"/>
<path android:fillColor="#FF000000" android:pathData="M12,5.25v13.5a6.75,6.75 0,0 0,0 -13.5Z"/>
</vector>

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#595757"
android:pathData="M4,4v16h16V4H4z M18.546,5.454v0.485H5.454V5.454H18.546z M5.454,18.546V7.394h13.092v11.152H5.454z" />
<path
android:fillColor="#595757"
android:pathData="M 10.729 9.819 L 9.819 10.729 L 9.819 12 L 11.273 12 L 11.273 11.332 L 11.329 11.273 L 12.668 11.273 L 12.728 11.333 L 12.728 11.699 L 11.273 13.153 L 11.273 14.425 L 12.727 14.425 L 12.727 13.756 L 14.182 12.302 L 14.182 10.729 L 13.27 9.819 Z" />
<path
android:fillColor="#595757"
android:pathData="M 11.273 14.909 H 12.726 V 15.879 H 11.273 V 14.909 Z" />
</vector>

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/read_record" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<include layout="@layout/item_read_record" />
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_book_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:gravity="right"
android:textIsSelectable="true"
tools:ignore="RtlHardcoded" />
<TextView
android:id="@+id/tv_read_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp" />
</LinearLayout>

@ -746,4 +746,6 @@
<string name="import_rss_source">导入订阅源</string> <string name="import_rss_source">导入订阅源</string>
<string name="donate_summary">您的支持是我更新的动力</string> <string name="donate_summary">您的支持是我更新的动力</string>
<string name="about_summary">公众号[开源阅读软件]</string> <string name="about_summary">公众号[开源阅读软件]</string>
<string name="read_record">阅读记录</string>
<string name="read_record_summary">阅读时间记录</string>
</resources> </resources>

@ -746,5 +746,7 @@
<string name="import_rss_source">导入订阅源</string> <string name="import_rss_source">导入订阅源</string>
<string name="donate_summary">您的支持是我更新的动力</string> <string name="donate_summary">您的支持是我更新的动力</string>
<string name="about_summary">公众号[开源阅读软件]</string> <string name="about_summary">公众号[开源阅读软件]</string>
<string name="read_record">阅读记录</string>
<string name="read_record_summary">阅读时间记录</string>
</resources> </resources>

@ -746,4 +746,6 @@
<string name="import_rss_source">导入订阅源</string> <string name="import_rss_source">导入订阅源</string>
<string name="donate_summary">您的支持是我更新的动力</string> <string name="donate_summary">您的支持是我更新的动力</string>
<string name="about_summary">公众号[开源阅读软件]</string> <string name="about_summary">公众号[开源阅读软件]</string>
<string name="read_record">阅读记录</string>
<string name="read_record_summary">阅读时间记录</string>
</resources> </resources>

@ -747,5 +747,7 @@
<string name="import_rss_source">导入订阅源</string> <string name="import_rss_source">导入订阅源</string>
<string name="donate_summary">您的支持是我更新的动力</string> <string name="donate_summary">您的支持是我更新的动力</string>
<string name="about_summary">公众号[开源阅读软件]</string> <string name="about_summary">公众号[开源阅读软件]</string>
<string name="read_record">阅读记录</string>
<string name="read_record_summary">阅读时间记录</string>
</resources> </resources>

@ -76,6 +76,13 @@
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:layout="@layout/view_preference_category"> app:layout="@layout/view_preference_category">
<io.legado.app.ui.widget.prefs.Preference
android:key="readRecord"
android:title="@string/read_record"
android:summary="@string/read_record_summary"
android:icon="@drawable/ic_history"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:key="donate" android:key="donate"
android:summary="@string/donate_summary" android:summary="@string/donate_summary"

Loading…
Cancel
Save