Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -109,6 +109,8 @@ data class BookChapter(
|
||||
}
|
||||
|
||||
fun getAbsoluteURL(): String {
|
||||
//二级目录解析的卷链接为空 返回目录页的链接
|
||||
if (url.startsWith(title) && isVolume) return baseUrl
|
||||
val urlMatcher = AnalyzeUrl.paramPattern.matcher(url)
|
||||
val urlBefore = if (urlMatcher.find()) url.substring(0, urlMatcher.start()) else url
|
||||
val urlAbsoluteBefore = NetworkUtils.getAbsoluteURL(baseUrl, urlBefore)
|
||||
|
||||
@@ -2,12 +2,27 @@ package io.legado.app.help
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import io.legado.app.R
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import splitties.init.appCtx
|
||||
|
||||
@Suppress("unused")
|
||||
object IntentHelp {
|
||||
|
||||
fun getBrowserIntent(url: String): Intent {
|
||||
return getBrowserIntent(Uri.parse(url))
|
||||
}
|
||||
|
||||
fun getBrowserIntent(uri: Uri): Intent {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.data = uri
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
if (intent.resolveActivity(appCtx.packageManager) == null) {
|
||||
return Intent.createChooser(intent, "请选择浏览器")
|
||||
}
|
||||
return intent
|
||||
}
|
||||
|
||||
fun toTTSSetting(context: Context) {
|
||||
//跳转到文字转语音设置界面
|
||||
|
||||
@@ -193,8 +193,8 @@ object BookChapterList {
|
||||
}
|
||||
if (bookChapter.url.isEmpty()) {
|
||||
if (bookChapter.isVolume) {
|
||||
bookChapter.url = bookChapter.title
|
||||
Debug.log(bookSource.bookSourceUrl, "一级目录${index}未获取到url,使用章节标题替代")
|
||||
bookChapter.url = bookChapter.title + index
|
||||
Debug.log(bookSource.bookSourceUrl, "一级目录${index}未获取到url,使用${bookChapter.title}${index}替代")
|
||||
} else {
|
||||
bookChapter.url = baseUrl
|
||||
Debug.log(bookSource.bookSourceUrl, "目录${index}未获取到url,使用baseUrl替代")
|
||||
|
||||
@@ -261,8 +261,8 @@ object WebBook {
|
||||
Debug.log(bookSource.bookSourceUrl, "⇒正文规则为空,使用章节链接:${bookChapter.url}")
|
||||
return bookChapter.url
|
||||
}
|
||||
if(bookChapter.isVolume && bookChapter.url == bookChapter.title) {
|
||||
Debug.log(bookSource.bookSourceUrl, "⇒一级目录获取链接为空,使用${bookChapter.tag}")
|
||||
if(bookChapter.isVolume && bookChapter.url.startsWith(bookChapter.title)) {
|
||||
Debug.log(bookSource.bookSourceUrl, "⇒一级目录正文不解析规则")
|
||||
return bookChapter.tag ?: ""
|
||||
}
|
||||
return if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) {
|
||||
|
||||
@@ -10,7 +10,6 @@ import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.EventBus
|
||||
import io.legado.app.constant.IntentAction
|
||||
import io.legado.app.constant.PreferKey
|
||||
import io.legado.app.ui.main.MainActivity
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.web.HttpServer
|
||||
import io.legado.app.web.WebSocketServer
|
||||
@@ -45,6 +44,15 @@ class WebService : BaseService() {
|
||||
upTile(true)
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
when (intent?.action) {
|
||||
IntentAction.stop -> stopSelf()
|
||||
"copyHostAddress" -> sendToClip(hostAddress)
|
||||
else -> upWebServer()
|
||||
}
|
||||
return super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
isRun = false
|
||||
@@ -58,14 +66,6 @@ class WebService : BaseService() {
|
||||
upTile(false)
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
when (intent?.action) {
|
||||
IntentAction.stop -> stopSelf()
|
||||
else -> upWebServer()
|
||||
}
|
||||
return super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
|
||||
private fun upWebServer() {
|
||||
if (httpServer?.isAlive == true) {
|
||||
httpServer?.stop()
|
||||
@@ -114,7 +114,7 @@ class WebService : BaseService() {
|
||||
.setContentTitle(getString(R.string.web_service))
|
||||
.setContentText(notificationContent)
|
||||
.setContentIntent(
|
||||
activityPendingIntent<MainActivity>("webService")
|
||||
servicePendingIntent<WebService>("copyHostAddress")
|
||||
)
|
||||
builder.addAction(
|
||||
R.drawable.ic_stop_black_24dp,
|
||||
|
||||
@@ -22,12 +22,6 @@ class AboutFragment : PreferenceFragmentCompat() {
|
||||
private val licenseUrl = "https://github.com/gedoor/legado/blob/master/LICENSE"
|
||||
private val disclaimerUrl = "https://gedoor.github.io/MyBookshelf/disclaimer.html"
|
||||
private val qqGroups = linkedMapOf(
|
||||
Pair("(QQ群VIP中转)1017837876", "0d9-zpmqbYfK3i_wt8uCvQoB2lmXadrg"),
|
||||
Pair("(QQ群VIP1)701903217", "-iolizL4cbJSutKRpeImHlXlpLDZnzeF"),
|
||||
Pair("(QQ群VIP2)263949160", "xwfh7_csb2Gf3Aw2qexEcEtviLfLfd4L"),
|
||||
Pair("(QQ群VIP3)680280282", "_N0i7yZObjKSeZQvzoe2ej7j02kLnOOK"),
|
||||
Pair("(QQ群VIP4)682555679", "VF2UwvUCuaqlo6pddWTe_kw__a1_Fr8O"),
|
||||
Pair("(QQ群VIP5)161622578", "S81xdnhJ5EBC389LTUvoyiyM-wr71pvJ"),
|
||||
Pair("(QQ群1)805192012", "6GlFKjLeIk5RhQnR3PNVDaKB6j10royo"),
|
||||
Pair("(QQ群2)773736122", "5Bm5w6OgLupXnICbYvbgzpPUgf0UlsJF"),
|
||||
Pair("(QQ群3)981838750", "g_Sgmp2nQPKqcZQ5qPcKLHziwX_mpps9"),
|
||||
|
||||
@@ -842,7 +842,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
startActivity<WebViewActivity> {
|
||||
putExtra("title", getString(R.string.chapter_pay))
|
||||
putExtra("url", it)
|
||||
IntentData.put(it, ReadBook.bookSource)
|
||||
IntentData.put(it, ReadBook.bookSource?.getHeaderMap(true))
|
||||
}
|
||||
}
|
||||
}.onError {
|
||||
|
||||
@@ -129,7 +129,7 @@ object ChapterProvider {
|
||||
matcher.appendTail(sb)
|
||||
text = sb.toString()
|
||||
val isTitle = index == 0
|
||||
val isVolumeTitle = bookChapter.isVolume && isTitle && bookChapter.url == bookChapter.title && bookChapter.tag.isNullOrBlank()
|
||||
val isVolumeTitle = bookChapter.isVolume && isTitle && contents.size == 1
|
||||
val textPaint = if (isTitle) titlePaint else contentPaint
|
||||
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
|
||||
setTypeText(
|
||||
@@ -147,7 +147,7 @@ object ChapterProvider {
|
||||
val text = content.substring(start, matcher.start())
|
||||
if (text.isNotBlank()) {
|
||||
val isTitle = index == 0
|
||||
val isVolumeTitle = bookChapter.isVolume && isTitle && bookChapter.url == bookChapter.title && bookChapter.tag.isNullOrBlank()
|
||||
val isVolumeTitle = bookChapter.isVolume && isTitle && contents.size == 1
|
||||
val textPaint = if (isTitle) titlePaint else contentPaint
|
||||
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
|
||||
setTypeText(
|
||||
@@ -169,7 +169,7 @@ object ChapterProvider {
|
||||
val text = content.substring(start, content.length)
|
||||
if (text.isNotBlank()) {
|
||||
val isTitle = index == 0
|
||||
val isVolumeTitle = bookChapter.isVolume && isTitle && bookChapter.url == bookChapter.title && bookChapter.tag.isNullOrBlank()
|
||||
val isVolumeTitle = bookChapter.isVolume && isTitle && contents.size == 1
|
||||
val textPaint = if (isTitle) titlePaint else contentPaint
|
||||
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
|
||||
setTypeText(
|
||||
|
||||
@@ -77,7 +77,7 @@ class BookSourceEditActivity :
|
||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
super.onPostCreate(savedInstanceState)
|
||||
if (!LocalConfig.ruleHelpVersionIsLast) {
|
||||
showRuleHelp()
|
||||
showHelp("ruleHelp")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ class BookSourceEditActivity :
|
||||
getString(R.string.share_book_source),
|
||||
ErrorCorrectionLevel.L
|
||||
)
|
||||
R.id.menu_help -> showRuleHelp()
|
||||
R.id.menu_help -> showHelp("ruleHelp")
|
||||
R.id.menu_login -> getSource().let { source ->
|
||||
if (checkSource(source)) {
|
||||
viewModel.save(source) {
|
||||
@@ -281,6 +281,7 @@ class BookSourceEditActivity :
|
||||
add(EditEntity("sourceRegex", cr?.sourceRegex, R.string.rule_source_regex))
|
||||
add(EditEntity("replaceRegex", cr?.replaceRegex, R.string.rule_replace_regex))
|
||||
add(EditEntity("imageStyle", cr?.imageStyle, R.string.rule_image_style))
|
||||
add(EditEntity("payAction", cr?.payAction, R.string.rule_pay_action))
|
||||
}
|
||||
binding.tabLayout.selectTab(binding.tabLayout.getTabAt(0))
|
||||
setEditEntities(0)
|
||||
@@ -376,6 +377,7 @@ class BookSourceEditActivity :
|
||||
"sourceRegex" -> contentRule.sourceRegex = it.value
|
||||
"replaceRegex" -> contentRule.replaceRegex = it.value
|
||||
"imageStyle" -> contentRule.imageStyle = it.value
|
||||
"payAction" -> contentRule.payAction = it.value
|
||||
}
|
||||
}
|
||||
source.ruleSearch = searchRule
|
||||
@@ -418,26 +420,23 @@ class BookSourceEditActivity :
|
||||
}
|
||||
|
||||
private fun showHelpDialog() {
|
||||
val items = arrayListOf("插入URL参数", "书源教程", "正则教程", "选择文件")
|
||||
val items = arrayListOf("插入URL参数", "书源教程", "js教程", "正则教程", "选择文件")
|
||||
selector(getString(R.string.help), items) { _, index ->
|
||||
when (index) {
|
||||
0 -> insertText(AppConst.urlOption)
|
||||
1 -> showRuleHelp()
|
||||
2 -> showRegexHelp()
|
||||
3 -> selectDoc.launch {
|
||||
1 -> showHelp("ruleHelp")
|
||||
2 -> showHelp("jsHelp")
|
||||
3 -> showHelp("regexHelp")
|
||||
4 -> selectDoc.launch {
|
||||
mode = HandleFileContract.FILE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showRuleHelp() {
|
||||
val mdText = String(assets.open("help/ruleHelp.md").readBytes())
|
||||
showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD))
|
||||
}
|
||||
|
||||
private fun showRegexHelp() {
|
||||
val mdText = String(assets.open("help/regexHelp.md").readBytes())
|
||||
private fun showHelp(fileName: String) {
|
||||
//显示目录help下的帮助文档
|
||||
val mdText = String(assets.open("help/${fileName}.md").readBytes())
|
||||
showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD))
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import androidx.preference.PreferenceManager
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
|
||||
import io.legado.app.R
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.help.IntentHelp
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
@@ -62,6 +63,20 @@ inline fun <reified T : Service> Context.servicePendingIntent(
|
||||
return getService(this, 0, intent, flags)
|
||||
}
|
||||
|
||||
@SuppressLint("UnspecifiedImmutableFlag")
|
||||
fun Context.activityPendingIntent(
|
||||
intent: Intent,
|
||||
action: String
|
||||
): PendingIntent? {
|
||||
intent.action = action
|
||||
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
FLAG_UPDATE_CURRENT or FLAG_MUTABLE
|
||||
} else {
|
||||
FLAG_UPDATE_CURRENT
|
||||
}
|
||||
return getActivity(this, 0, intent, flags)
|
||||
}
|
||||
|
||||
@SuppressLint("UnspecifiedImmutableFlag")
|
||||
inline fun <reified T : Activity> Context.activityPendingIntent(
|
||||
action: String,
|
||||
@@ -145,8 +160,8 @@ fun Context.restart() {
|
||||
intent?.let {
|
||||
intent.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
)
|
||||
startActivity(intent)
|
||||
//杀掉以前进程
|
||||
@@ -284,25 +299,18 @@ val Context.externalCache: File
|
||||
get() = this.externalCacheDir ?: this.cacheDir
|
||||
|
||||
fun Context.openUrl(url: String) {
|
||||
openUrl(Uri.parse(url))
|
||||
try {
|
||||
startActivity(IntentHelp.getBrowserIntent(url))
|
||||
} catch (e: Exception) {
|
||||
toastOnUi(e.localizedMessage ?: "open url error")
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.openUrl(uri: Uri) {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.data = uri
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
if (intent.resolveActivity(packageManager) != null) {
|
||||
try {
|
||||
startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
toastOnUi(e.localizedMessage ?: "open url error")
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
startActivity(Intent.createChooser(intent, "请选择浏览器"))
|
||||
} catch (e: Exception) {
|
||||
toastOnUi(e.localizedMessage ?: "open url error")
|
||||
}
|
||||
try {
|
||||
startActivity(IntentHelp.getBrowserIntent(uri))
|
||||
} catch (e: Exception) {
|
||||
toastOnUi(e.localizedMessage ?: "open url error")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ object NetworkUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取二级域名,供cookie保存和读取
|
||||
* 获取域名,供cookie保存和读取
|
||||
* http://1.2.3.4 => 1.2.3.4
|
||||
* https://www.example.com => example.com
|
||||
* http://www.biquge.com.cn => biquge.com.cn
|
||||
|
||||
Reference in New Issue
Block a user