parent
705b47e6a8
commit
c866df0196
@ -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" |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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> |
Loading…
Reference in new issue