commit
7d2b47f930
@ -1,3 +1,74 @@ |
||||
package io.legado.app.ui.rss.article |
||||
|
||||
class RssArticlesActivity |
||||
import android.app.ProgressDialog |
||||
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.onItemClick |
||||
import java.net.URL |
||||
|
||||
class RssArticlesActivity : AppCompatActivity() { |
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
if (intent.hasExtra("QuickAddURL")) { |
||||
// 处理从 快速添加并预览 跳转到这个页面 |
||||
val urlString = intent.getStringExtra("QuickAddURL") |
||||
val adapter = ArticleAdapter(mutableListOf<RssArticle>(), this) |
||||
listView { |
||||
this.adapter = adapter |
||||
onItemClick { p0, p1, p2, p3 -> |
||||
startActivity<ReadRssActivity>("description" to adapter.articles[p2].description) |
||||
} |
||||
} |
||||
val loading = ProgressDialog(this@RssArticlesActivity) |
||||
loading.setMessage("加载中...") |
||||
loading.show() |
||||
Thread { |
||||
val xml = URL(urlString).readText() |
||||
val articles = RssParser.parseXML(xml) |
||||
runOnUiThread { |
||||
adapter.articles = articles |
||||
adapter.notifyDataSetChanged() |
||||
loading.dismiss() |
||||
} |
||||
}.start() |
||||
} |
||||
} |
||||
} |
||||
|
||||
class ArticleAdapter(var articles: MutableList<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 description = intent.getStringExtra("description") |
||||
webView.loadData("<style>img{max-width:100%}</style>$description","text/html", "utf-8") |
||||
} |
||||
|
||||
|
||||
} |
@ -1,7 +1,44 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:padding="16dp" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
app:cardCornerRadius="2dp" |
||||
app:cardElevation="8dp"> |
||||
|
||||
<LinearLayout |
||||
android:layout_margin="8dp" |
||||
android:orientation="vertical" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
android:layout_height="wrap_content"> |
||||
<TextView |
||||
android:id="@+id/title" |
||||
android:textSize="18sp" |
||||
android:text="Title" |
||||
android:layout_gravity="center" |
||||
android:textStyle="bold" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"/> |
||||
|
||||
<TextView |
||||
android:id="@+id/pub_date" |
||||
android:textSize="12sp" |
||||
android:layout_marginTop="8dp" |
||||
android:layout_marginBottom="8dp" |
||||
android:text="2019-10-01 13:48:00" |
||||
android:layout_gravity="center" |
||||
android:textStyle="italic" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"/> |
||||
|
||||
<TextView |
||||
android:id="@+id/author" |
||||
android:textSize="16sp" |
||||
android:text="author" |
||||
android:layout_gravity="center" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"/> |
||||
|
||||
</LinearLayout> |
||||
</LinearLayout> |
||||
</androidx.cardview.widget.CardView> |
Loading…
Reference in new issue