Merge pull request #36 from gedoor/mabdc

Mabdc
pull/35/head^2
西红柿大芝麻 5 years ago committed by GitHub
commit 7d2b47f930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/src/main/AndroidManifest.xml
  2. 2
      app/src/main/java/io/legado/app/constant/RSSKeywords.kt
  3. 28
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  4. 73
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt
  5. 18
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  6. 5
      app/src/main/res/layout/activity_read_rss.xml
  7. 1
      app/src/main/res/layout/fragment_rss.xml
  8. 41
      app/src/main/res/layout/item_rss.xml
  9. 5
      app/src/main/res/menu/main_rss.xml

@ -71,7 +71,7 @@
<activity android:name=".ui.explore.ExploreShowActivity" /> <activity android:name=".ui.explore.ExploreShowActivity" />
<activity android:name=".ui.rss.source.manage.RssSourceActivity" /> <activity android:name=".ui.rss.source.manage.RssSourceActivity" />
<activity android:name=".ui.rss.source.debug.RssSourceDebugActivity" /> <activity android:name=".ui.rss.source.debug.RssSourceDebugActivity" />
<activity android:name=".ui.rss.article.RssArticlesActivity"/>
<service android:name=".service.CheckSourceService" /> <service android:name=".service.CheckSourceService" />
<service android:name=".service.DownloadService" /> <service android:name=".service.DownloadService" />
<service android:name=".service.UpdateService" /> <service android:name=".service.UpdateService" />

@ -5,7 +5,7 @@ object RSSKeywords {
const val RSS_ITEM = "item" const val RSS_ITEM = "item"
const val RSS_ITEM_TITLE = "title" const val RSS_ITEM_TITLE = "title"
const val RSS_ITEM_LINK = "link" 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_CATEGORY = "category"
const val RSS_ITEM_THUMBNAIL = "media:thumbnail" const val RSS_ITEM_THUMBNAIL = "media:thumbnail"
const val RSS_ITEM_ENCLOSURE = "enclosure" const val RSS_ITEM_ENCLOSURE = "enclosure"

@ -1,19 +1,28 @@
package io.legado.app.ui.main.rss package io.legado.app.ui.main.rss
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.EditText
import android.widget.LinearLayout
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseFragment import io.legado.app.base.BaseFragment
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.cancelButton
import io.legado.app.lib.dialogs.yesButton
import io.legado.app.lib.theme.ATH 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.ui.rss.source.manage.RssSourceActivity
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import kotlinx.android.synthetic.main.fragment_rss.* import kotlinx.android.synthetic.main.fragment_rss.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.padding
class RssFragment : BaseFragment(R.layout.fragment_rss), class RssFragment : BaseFragment(R.layout.fragment_rss),
RssAdapter.CallBack { RssAdapter.CallBack {
@ -34,6 +43,25 @@ class RssFragment : BaseFragment(R.layout.fragment_rss),
super.onCompatOptionsItemSelected(item) super.onCompatOptionsItemSelected(item)
when (item.itemId) { when (item.itemId) {
R.id.menu_rss_config -> startActivity<RssSourceActivity>() R.id.menu_rss_config -> startActivity<RssSourceActivity>()
R.id.menu_rss_add -> {
alert {
title = "快速添加并预览"
val layout = LinearLayout(activity)
val urlEdit = EditText(activity)
urlEdit.hint = "输入RSS地址"
urlEdit.width = 800
layout.gravity = Gravity.CENTER
layout.addView(urlEdit)
customView = layout
cancelButton{
Log.i("RSS","Quick Add URL cancel")
}
yesButton{
Log.i("RSS","Quick Add URL: ${urlEdit.text}")
startActivity<RssArticlesActivity>("QuickAddURL" to urlEdit.text.toString().trim())
}
}.show()
}
} }
} }

@ -1,3 +1,74 @@
package io.legado.app.ui.rss.article 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 package io.legado.app.ui.rss.read
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity import kotlinx.android.synthetic.main.activity_read_rss.*
class ReadRssActivity : AppCompatActivity() {
class ReadRssActivity : BaseActivity(R.layout.activity_read_rss) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
override fun onActivityCreated(savedInstanceState: Bundle?) { setContentView(R.layout.activity_read_rss)
val description = intent.getStringExtra("description")
webView.loadData("<style>img{max-width:100%}</style>$description","text/html", "utf-8")
} }
} }

@ -3,5 +3,8 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout> </LinearLayout>

@ -11,7 +11,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:attachToActivity="false" app:attachToActivity="false"
app:title="@string/rss" /> app:title="@string/rss" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"

@ -1,7 +1,44 @@
<?xml version="1.0" encoding="utf-8"?> <?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:orientation="vertical"
android:layout_width="match_parent" 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>

@ -2,6 +2,11 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_rss_add"
android:title="@string/add"
android:icon="@drawable/ic_add"
app:showAsAction="always" />
<item <item
android:id="@+id/menu_rss_config" android:id="@+id/menu_rss_config"
android:title="@string/setting" android:title="@string/setting"

Loading…
Cancel
Save