From 8d315cb83369087b17ea57e1421c8baf31637cb0 Mon Sep 17 00:00:00 2001
From: mabdc <747455334@qq.com>
Date: Wed, 2 Oct 2019 03:24:38 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E6=B5=8B=E8=AF=95RSS=E8=A7=A3=E6=9E=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/src/main/AndroidManifest.xml | 2 +-
.../io/legado/app/constant/RSSKeywords.kt | 2 +-
.../io/legado/app/ui/main/rss/RssFragment.kt | 4 +
.../app/ui/rss/article/RssArticlesActivity.kt | 93 ++++++++++++++++++-
.../legado/app/ui/rss/read/ReadRssActivity.kt | 18 ++--
app/src/main/res/layout/activity_read_rss.xml | 5 +-
app/src/main/res/layout/fragment_rss.xml | 1 -
app/src/main/res/layout/item_rss.xml | 41 +++++++-
app/src/main/res/menu/main_rss.xml | 5 +
9 files changed, 153 insertions(+), 18 deletions(-)
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 96e2b7ea2..98701bba5 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -70,7 +70,7 @@
-
+
diff --git a/app/src/main/java/io/legado/app/constant/RSSKeywords.kt b/app/src/main/java/io/legado/app/constant/RSSKeywords.kt
index 5a4119e05..bb8d4207a 100644
--- a/app/src/main/java/io/legado/app/constant/RSSKeywords.kt
+++ b/app/src/main/java/io/legado/app/constant/RSSKeywords.kt
@@ -5,7 +5,7 @@ object RSSKeywords {
const val RSS_ITEM = "item"
const val RSS_ITEM_TITLE = "title"
const val RSS_ITEM_LINK = "link"
- const val RSS_ITEM_AUTHOR = "dc:creator"
+ const val RSS_ITEM_AUTHOR = "author"
const val RSS_ITEM_CATEGORY = "category"
const val RSS_ITEM_THUMBNAIL = "media:thumbnail"
const val RSS_ITEM_ENCLOSURE = "enclosure"
diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
index 79c82bf1d..347b95a23 100644
--- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
+++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
@@ -10,6 +10,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseFragment
import io.legado.app.lib.theme.ATH
+import io.legado.app.ui.rss.article.RssArticlesActivity
import io.legado.app.ui.rss.source.manage.RssSourceActivity
import io.legado.app.utils.startActivity
import kotlinx.android.synthetic.main.fragment_rss.*
@@ -34,6 +35,9 @@ class RssFragment : BaseFragment(R.layout.fragment_rss),
super.onCompatOptionsItemSelected(item)
when (item.itemId) {
R.id.menu_rss_config -> startActivity()
+ R.id.menu_rss_add -> {
+ startActivity()
+ }
}
}
diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt
index a69c70fb5..6a52df7b3 100644
--- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt
+++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt
@@ -1,3 +1,94 @@
package io.legado.app.ui.rss.article
-class RssArticlesActivity
\ No newline at end of file
+import android.content.Context
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.BaseAdapter
+import androidx.appcompat.app.AppCompatActivity
+import io.legado.app.R
+import io.legado.app.data.entities.RssArticle
+import io.legado.app.model.rss.RssParser
+import io.legado.app.ui.rss.read.ReadRssActivity
+import kotlinx.android.synthetic.main.item_rss.view.*
+import org.jetbrains.anko.*
+import org.jetbrains.anko.sdk27.listeners.onClick
+import org.jetbrains.anko.sdk27.listeners.onItemClick
+import java.net.URL
+
+class RssArticlesActivity : AppCompatActivity() {
+ val zhihu_dayli = "https://rsshub.app/zhihu/daily"
+ val nytimes = "https://rsshub.app/nytimes/dual"
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ var articles = mutableListOf()
+ val adapter = ArticleAdapter(articles, this)
+ verticalLayout {
+ val url = editText {
+ hint = "请输入RSS地址"
+ }
+ fun loadRss(urlString:String){
+ Thread {
+ val xml = URL(urlString).readText()
+ articles = RssParser.parseXML(xml)
+ runOnUiThread {
+ adapter.articles = articles
+ adapter.notifyDataSetChanged()
+ }
+ }.start()
+ }
+ button("解析") {
+ onClick {
+ val urlString = url.text.toString().trim()
+ if(urlString != ""){
+ loadRss(urlString)
+ }
+ }
+ }
+ button("知乎日报") {
+ onClick {
+ loadRss(zhihu_dayli)
+ }
+ }
+ button("纽约时报") {
+ onClick {
+ loadRss(nytimes)
+ }
+ }
+ listView {
+ this.adapter = adapter
+ onItemClick { p0, p1, p2, p3 ->
+ startActivity("description" to articles[p2].description)
+ }
+ }
+ }
+ }
+}
+
+class ArticleAdapter(var articles: List, var context: Context) : BaseAdapter() {
+ override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
+ val item_rss= LayoutInflater.from(context).inflate(R.layout.item_rss, null)
+ val article = articles[position]
+ item_rss.title.text = article.title
+ item_rss.pub_date.text = article.pubDate
+ if(article.author != null && article.author != ""){
+ item_rss.author.text = article.author
+ } else{
+ item_rss.author.text = article.link
+ }
+ return item_rss
+ }
+
+ override fun getItem(position: Int): Any {
+ return articles[position]
+ }
+
+ override fun getItemId(position: Int): Long {
+ return 1
+ }
+
+ override fun getCount(): Int {
+ return articles.size
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
index 5e7972c6d..984cc0ea4 100644
--- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
+++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
@@ -1,15 +1,15 @@
package io.legado.app.ui.rss.read
import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
import io.legado.app.R
-import io.legado.app.base.BaseActivity
-
-
-class ReadRssActivity : BaseActivity(R.layout.activity_read_rss) {
-
- override fun onActivityCreated(savedInstanceState: Bundle?) {
-
+import kotlinx.android.synthetic.main.activity_read_rss.*
+
+class ReadRssActivity : AppCompatActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_read_rss)
+ val s = intent.getStringExtra("description")
+ webView.loadData(""+s,"text/html","utf-8")
}
-
-
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_read_rss.xml b/app/src/main/res/layout/activity_read_rss.xml
index d829e291c..0650007cf 100644
--- a/app/src/main/res/layout/activity_read_rss.xml
+++ b/app/src/main/res/layout/activity_read_rss.xml
@@ -3,5 +3,8 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
-
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_rss.xml b/app/src/main/res/layout/fragment_rss.xml
index 3d9e9a4b5..f5a3b374c 100644
--- a/app/src/main/res/layout/fragment_rss.xml
+++ b/app/src/main/res/layout/fragment_rss.xml
@@ -11,7 +11,6 @@
android:layout_height="wrap_content"
app:attachToActivity="false"
app:title="@string/rss" />
-
-
+ android:layout_height="wrap_content"
+ app:cardCornerRadius="2dp"
+ app:cardElevation="8dp">
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/main_rss.xml b/app/src/main/res/menu/main_rss.xml
index 9c051a1d2..f1e39cae2 100644
--- a/app/src/main/res/menu/main_rss.xml
+++ b/app/src/main/res/menu/main_rss.xml
@@ -2,6 +2,11 @@