feat: 优化

pull/209/head
kunfei 5 years ago
parent dd53f0a260
commit 9985f3b61c
  1. 2
      app/build.gradle
  2. 31
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  3. 26
      app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt
  4. 16
      app/src/main/res/menu/rss_main_item.xml

@ -117,7 +117,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
//fireBase
implementation 'com.google.firebase:firebase-core:17.3.0'
implementation 'com.google.firebase:firebase-core:17.4.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
//androidX

@ -51,7 +51,7 @@ class AnalyzeUrl(
private var queryStr: String? = null
private val fieldMap = LinkedHashMap<String, String>()
private var charset: String? = null
private var body: Any? = null
private var body: String? = null
private var requestBody: RequestBody? = null
private var method = RequestMethod.GET
@ -157,10 +157,10 @@ class AnalyzeUrl(
baseUrl = it
}
if (urlArray.size > 1) {
val options = GSON.fromJsonObject<UrlOption>(urlArray[1])
options?.let { _ ->
options.method?.let { if (it.equals("POST", true)) method = RequestMethod.POST }
options.headers?.let { headers ->
val option = GSON.fromJsonObject<UrlOption>(urlArray[1])
option?.let { _ ->
option.method?.let { if (it.equals("POST", true)) method = RequestMethod.POST }
option.headers?.let { headers ->
if (headers is Map<*, *>) {
@Suppress("unchecked_cast")
headerMap.putAll(headers as Map<out String, String>)
@ -170,9 +170,14 @@ class AnalyzeUrl(
?.let { headerMap.putAll(it) }
}
}
body = options.body
charset = options.charset
options.webView?.let {
charset = option.charset
body = if (option.body is String) {
option.body
} else {
GSON.toJson(option.body)
}
option.webView?.let {
if (it.toString().isNotEmpty()) {
useWebView = true
}
@ -191,13 +196,13 @@ class AnalyzeUrl(
}
RequestMethod.POST -> {
body?.let {
if (it is String) {
analyzeFields(it)
if (it.isJson()) {
requestBody = RequestBody.create(jsonType, GSON.toJson(it))
} else {
body = RequestBody.create(jsonType, GSON.toJson(it))
analyzeFields(it)
}
} ?: let {
body = FormBody.Builder().build()
requestBody = FormBody.Builder().build()
}
}
}
@ -288,7 +293,7 @@ class AnalyzeUrl(
params.requestMethod = method
params.javaScript = jsStr
params.sourceRegex = sourceRegex
params.postData = body?.toString()?.toByteArray()
params.postData = body?.toByteArray()
params.tag = tag
return HttpHelper.ajax(params)
}

@ -1,6 +1,8 @@
package io.legado.app.ui.main.rss
import android.content.Context
import android.view.View
import androidx.appcompat.widget.PopupMenu
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
@ -8,6 +10,7 @@ import io.legado.app.data.entities.RssSource
import io.legado.app.help.ImageLoader
import kotlinx.android.synthetic.main.item_rss.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick
class RssAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<RssSource>(context, R.layout.item_rss) {
@ -29,6 +32,29 @@ class RssAdapter(context: Context, val callBack: CallBack) :
callBack.openRss(it)
}
}
holder.itemView.onLongClick {
getItem(holder.layoutPosition)?.let {
showMenu(holder.itemView, it)
}
true
}
}
private fun showMenu(view: View, rssSource: RssSource) {
val popupMenu = PopupMenu(context, view)
popupMenu.inflate(R.menu.rss_main_item)
popupMenu.setOnMenuItemClickListener {
when (it.itemId) {
R.id.menu_top -> {
}
R.id.menu_edit -> {
}
R.id.menu_del -> {
}
}
true
}
popupMenu.show()
}
interface CallBack {

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_top"
android:title="@string/to_top" />
<item
android:id="@+id/menu_edit"
android:title="@string/edit" />
<item
android:id="@+id/menu_del"
android:title="@string/delete" />
</menu>
Loading…
Cancel
Save