-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 优化rss阅读记录查看和删除 * 优化rss阅读记录功能
- Loading branch information
Showing
11 changed files
with
2,103 additions
and
35 deletions.
There are no files selected for viewing
1,930 changes: 1,930 additions & 0 deletions
1,930
app/schemas/io.legado.app.data.AppDatabase/74.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/src/main/java/io/legado/app/data/dao/RssReadRecordDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.legado.app.data.dao | ||
|
||
import androidx.room.* | ||
import io.legado.app.data.entities.RssReadRecord | ||
|
||
@Dao | ||
interface RssReadRecordDao { | ||
|
||
@Insert(onConflict = OnConflictStrategy.IGNORE) | ||
fun insertRecord(vararg rssReadRecord: RssReadRecord) | ||
|
||
@Query("select * from rssReadRecords order by readTime desc") | ||
fun getRecord(): List<RssReadRecord> | ||
|
||
@get:Query("select count(1) from rssReadRecords") | ||
val countRead: Int | ||
|
||
@Query("delete from rssReadRecords") | ||
fun deleteRecord() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
app/src/main/java/io/legado/app/ui/rss/article/ReadRecordDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package io.legado.app.ui.rss.article | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.MenuItem | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.appcompat.widget.Toolbar | ||
import androidx.fragment.app.viewModels | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import io.legado.app.R | ||
import io.legado.app.base.BaseDialogFragment | ||
import io.legado.app.base.adapter.ItemViewHolder | ||
import io.legado.app.base.adapter.RecyclerAdapter | ||
import io.legado.app.data.entities.RssReadRecord | ||
import io.legado.app.databinding.DialogRecyclerViewBinding | ||
import io.legado.app.databinding.ItemRssReadRecordBinding | ||
import io.legado.app.lib.dialogs.alert | ||
import io.legado.app.lib.theme.primaryColor | ||
import io.legado.app.utils.setLayout | ||
import io.legado.app.utils.viewbindingdelegate.viewBinding | ||
|
||
class ReadRecordDialog : BaseDialogFragment(R.layout.dialog_recycler_view), | ||
Toolbar.OnMenuItemClickListener { | ||
|
||
private val viewModel by viewModels<RssSortViewModel>() | ||
private val binding by viewBinding(DialogRecyclerViewBinding::bind) | ||
private val adapter by lazy { | ||
ReadRecordAdapter(requireContext()) | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
setLayout(0.9f, ViewGroup.LayoutParams.WRAP_CONTENT) | ||
} | ||
|
||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { | ||
binding.run { | ||
toolBar.setBackgroundColor(primaryColor) | ||
toolBar.setTitle(R.string.read_record) | ||
toolBar.inflateMenu(R.menu.rss_read_record) | ||
toolBar.setOnMenuItemClickListener(this@ReadRecordDialog) | ||
recyclerView.layoutManager = LinearLayoutManager(requireContext()) | ||
recyclerView.adapter = adapter | ||
} | ||
adapter.setItems(viewModel.getRecord()) | ||
} | ||
|
||
override fun onMenuItemClick(item: MenuItem?): Boolean { | ||
when (item?.itemId) { | ||
R.id.menu_clear -> { | ||
alert(R.string.draw) { | ||
val countRead = viewModel.countRead() | ||
setMessage(getString(R.string.sure_del) + "\n" + countRead + " " + getString(R.string.read_record)) | ||
noButton() | ||
yesButton{ | ||
viewModel.delReadRecord() | ||
adapter.clearItems() | ||
} | ||
} | ||
} | ||
} | ||
return true | ||
} | ||
|
||
inner class ReadRecordAdapter(context: Context) : | ||
RecyclerAdapter<RssReadRecord, ItemRssReadRecordBinding>(context) { | ||
|
||
override fun getViewBinding(parent: ViewGroup): ItemRssReadRecordBinding { | ||
return ItemRssReadRecordBinding.inflate(inflater, parent, false) | ||
} | ||
|
||
override fun convert( | ||
holder: ItemViewHolder, | ||
binding: ItemRssReadRecordBinding, | ||
item: RssReadRecord, | ||
payloads: MutableList<Any> | ||
) { | ||
binding.textTitle.text = item.title | ||
binding.textRecord.text = item.record | ||
} | ||
|
||
override fun registerListener(holder: ItemViewHolder, binding: ItemRssReadRecordBinding) { | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?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="wrap_content" | ||
android:padding="6dp" | ||
android:background="?android:attr/selectableItemBackground" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/text_title" | ||
android:text="@string/title" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textIsSelectable="true" /> | ||
|
||
<TextView | ||
android:id="@+id/text_record" | ||
android:text="@string/read_record" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:autoLink="web" | ||
android:textIsSelectable="true" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
tools:ignore="AlwaysShowAction"> | ||
|
||
<item | ||
android:id="@+id/menu_clear" | ||
android:title="@string/clear" | ||
app:showAsAction="always" /> | ||
|
||
</menu> |