parent
246019df60
commit
9a2ba5650c
@ -0,0 +1,29 @@ |
||||
package io.legado.app.ui.book.bookmark |
||||
|
||||
import android.os.Bundle |
||||
import androidx.activity.viewModels |
||||
import io.legado.app.base.VMBaseActivity |
||||
import io.legado.app.databinding.ActivityAllBookmarkBinding |
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding |
||||
|
||||
class AllBookmarkActivity : VMBaseActivity<ActivityAllBookmarkBinding, AllBookmarkViewModel>() { |
||||
|
||||
override val viewModel by viewModels<AllBookmarkViewModel>() |
||||
override val binding by viewBinding(ActivityAllBookmarkBinding::inflate) |
||||
private val adapter by lazy { |
||||
BookmarkAdapter(this) |
||||
} |
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) { |
||||
initView() |
||||
viewModel.initData { |
||||
adapter.setItems(it) |
||||
} |
||||
} |
||||
|
||||
private fun initView() { |
||||
binding.recyclerView.adapter = adapter |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,19 @@ |
||||
package io.legado.app.ui.book.bookmark |
||||
|
||||
import android.app.Application |
||||
import io.legado.app.base.BaseViewModel |
||||
import io.legado.app.data.appDb |
||||
import io.legado.app.data.entities.Bookmark |
||||
|
||||
class AllBookmarkViewModel(application: Application) : BaseViewModel(application) { |
||||
|
||||
|
||||
fun initData(onSuccess: (bookmarks: List<Bookmark>) -> Unit) { |
||||
execute { |
||||
appDb.bookmarkDao.all |
||||
}.onSuccess { |
||||
onSuccess.invoke(it) |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,32 @@ |
||||
package io.legado.app.ui.book.bookmark |
||||
|
||||
import android.content.Context |
||||
import android.view.ViewGroup |
||||
import io.legado.app.base.adapter.ItemViewHolder |
||||
import io.legado.app.base.adapter.RecyclerAdapter |
||||
import io.legado.app.data.entities.Bookmark |
||||
import io.legado.app.databinding.ItemBookmarkBinding |
||||
|
||||
class BookmarkAdapter(context: Context) : RecyclerAdapter<Bookmark, ItemBookmarkBinding>(context) { |
||||
|
||||
override fun getViewBinding(parent: ViewGroup): ItemBookmarkBinding { |
||||
return ItemBookmarkBinding.inflate(inflater, parent, false) |
||||
} |
||||
|
||||
override fun convert( |
||||
holder: ItemViewHolder, |
||||
binding: ItemBookmarkBinding, |
||||
item: Bookmark, |
||||
payloads: MutableList<Any> |
||||
) { |
||||
binding.tvChapterName.text = item.chapterName |
||||
binding.tvBookText.text = item.bookText |
||||
binding.tvContent.text = item.content |
||||
} |
||||
|
||||
override fun registerListener(holder: ItemViewHolder, binding: ItemBookmarkBinding) { |
||||
|
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,22 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout 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"> |
||||
|
||||
<io.legado.app.ui.widget.TitleBar |
||||
android:id="@+id/title_bar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
app:title="@string/all_bookmark" |
||||
app:layout_constraintTop_toTopOf="parent" /> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recycler_view" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="0dp" |
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" |
||||
app:layout_constraintTop_toBottomOf="@+id/title_bar" |
||||
app:layout_constraintBottom_toBottomOf="parent" /> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
Loading…
Reference in new issue