parent
4ff6ea6653
commit
8d315cb833
@ -1,3 +1,94 @@ |
||||
package io.legado.app.ui.rss.article |
||||
|
||||
class RssArticlesActivity |
||||
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<RssArticle>() |
||||
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<ReadRssActivity>("description" to articles[p2].description) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
class ArticleAdapter(var articles: List<RssArticle>, 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 |
||||
} |
||||
} |
@ -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("<style>img{max-width:100%}</style>"+s,"text/html","utf-8") |
||||
} |
||||
|
||||
|
||||
} |
@ -1,7 +1,40 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:orientation="vertical" |
||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:padding="12dp" |
||||
android:layout_margin="20dp" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
android:layout_height="wrap_content" |
||||
app:cardCornerRadius="2dp" |
||||
app:cardElevation="8dp"> |
||||
|
||||
</LinearLayout> |
||||
<LinearLayout |
||||
android:layout_margin="8dp" |
||||
android:orientation="vertical" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"> |
||||
<TextView |
||||
android:id="@+id/title" |
||||
android:textSize="18sp" |
||||
android:text="Title" |
||||
android:textStyle="bold" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"/> |
||||
|
||||
<TextView |
||||
android:id="@+id/pub_date" |
||||
android:textSize="12sp" |
||||
android:text="2019-10-01 13:48:00" |
||||
android:textStyle="italic" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"/> |
||||
|
||||
<TextView |
||||
android:id="@+id/author" |
||||
android:textSize="16sp" |
||||
android:text="Content" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"/> |
||||
|
||||
</LinearLayout> |
||||
</androidx.cardview.widget.CardView> |
Loading…
Reference in new issue