添加源地址订阅功能

pull/517/head
gedoor 4 years ago
parent c819890a43
commit 7811e49867
  1. 2
      app/src/main/AndroidManifest.xml
  2. 16
      app/src/main/java/io/legado/app/data/entities/SourceSub.kt
  3. 17
      app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubActivity.kt
  4. 32
      app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt
  5. 57
      app/src/main/res/layout/item_source_sub.xml

@ -173,7 +173,7 @@
android:launchMode="singleTask" />
<!-- 源订阅 -->
<activity
android:name=".ui.rss.subscription.SourceSubscription"
android:name=".ui.rss.subscription.SourceSubscriptionActivity"
android:launchMode="singleTask" />
<!-- 书源编辑 -->
<activity

@ -7,6 +7,16 @@ import androidx.room.PrimaryKey
data class SourceSub(
@PrimaryKey
val id: Long = System.currentTimeMillis(),
val name: String,
val url: String,
)
var name: String,
var url: String,
var type: Int = 0
) {
fun setType(type: Type) {
this.type = type.ordinal
}
enum class Type {
BookSource, RssSource
}
}

@ -3,11 +3,17 @@ package io.legado.app.ui.rss.subscription
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.lifecycle.LiveData
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.data.entities.SourceSub
import io.legado.app.databinding.ActivitySourceSubBinding
class SourceSubscription : BaseActivity<ActivitySourceSubBinding>() {
class SourceSubscriptionActivity : BaseActivity<ActivitySourceSubBinding>() {
private lateinit var adapter: SourceSubAdapter
private var liveData: LiveData<List<SourceSub>>? = null
override fun getViewBinding(): ActivitySourceSubBinding {
return ActivitySourceSubBinding.inflate(layoutInflater)
@ -31,11 +37,16 @@ class SourceSubscription : BaseActivity<ActivitySourceSubBinding>() {
}
private fun initView() {
binding.recyclerView
adapter = SourceSubAdapter(this)
binding.recyclerView.adapter = adapter
}
private fun initData() {
liveData?.removeObservers(this)
liveData = App.db.sourceSubDao().observeAll()
liveData?.observe(this) {
adapter.setItems(it)
}
}
private fun editSubscription() {

@ -0,0 +1,32 @@
package io.legado.app.ui.rss.subscription
import android.content.Context
import android.view.ViewGroup
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.SourceSub
import io.legado.app.databinding.ItemSourceSubBinding
class SourceSubAdapter(context: Context) :
SimpleRecyclerAdapter<SourceSub, ItemSourceSubBinding>(context) {
override fun convert(
holder: ItemViewHolder,
binding: ItemSourceSubBinding,
item: SourceSub,
payloads: MutableList<Any>
) {
binding.tvName.text = item.name
binding.tvUrl.text = item.url
}
override fun registerListener(holder: ItemViewHolder, binding: ItemSourceSubBinding) {
}
override fun getViewBinding(parent: ViewGroup): ItemSourceSubBinding {
return ItemSourceSubBinding.inflate(inflater, parent, false)
}
}

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:id="@+id/tv_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="@color/primaryText"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
tools:text="name" />
<TextView
android:id="@+id/tv_url"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="@color/secondaryText"
app:layout_constraintTop_toBottomOf="@+id/tv_name"
app:layout_constraintLeft_toLeftOf="parent"
tools:text="url" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_edit"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/edit"
android:padding="6dp"
android:src="@drawable/ic_edit"
android:tint="@color/primaryText"
app:layout_constraintRight_toLeftOf="@id/iv_menu_more"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_menu_more"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="6dp"
android:src="@drawable/ic_more_vert"
android:tint="@color/primaryText"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:ignore="RtlHardcoded" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save