Merge branch 'gedoor:master' into master
This commit is contained in:
@@ -115,6 +115,7 @@ object PreferKey {
|
||||
const val ignoreAudioFocus = "ignoreAudioFocus"
|
||||
const val parallelExportBook = "parallelExportBook"
|
||||
const val progressBarBehavior = "progressBarBehavior"
|
||||
const val sourceEditMaxLine = "sourceEditMaxLine"
|
||||
|
||||
const val cPrimary = "colorPrimary"
|
||||
const val cAccent = "colorAccent"
|
||||
|
||||
@@ -368,15 +368,27 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
appCtx.putPrefInt(PreferKey.bitmapCacheSize, value)
|
||||
}
|
||||
|
||||
var showReadTitleBarAddition : Boolean
|
||||
var showReadTitleBarAddition: Boolean
|
||||
get() = appCtx.getPrefBoolean(PreferKey.showReadTitleAddition, true)
|
||||
set(value) {
|
||||
appCtx.putPrefBoolean(PreferKey.showReadTitleAddition, value)
|
||||
}
|
||||
var readBarStyleFollowPage : Boolean
|
||||
var readBarStyleFollowPage: Boolean
|
||||
get() = appCtx.getPrefBoolean(PreferKey.readBarStyleFollowPage, false)
|
||||
set(value) {
|
||||
appCtx.putPrefBoolean(PreferKey.readBarStyleFollowPage, value)
|
||||
}
|
||||
|
||||
var sourceEditMaxLine: Int
|
||||
get() {
|
||||
val maxLine = appCtx.getPrefInt(PreferKey.sourceEditMaxLine, 99)
|
||||
if (maxLine < 10) {
|
||||
return 99
|
||||
}
|
||||
return maxLine
|
||||
}
|
||||
set(value) {
|
||||
appCtx.putPrefInt(PreferKey.sourceEditMaxLine, value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ class EpubFile(var book: Book) {
|
||||
cover.compress(Bitmap.CompressFormat.JPEG, 90, out)
|
||||
out.flush()
|
||||
out.close()
|
||||
}
|
||||
} ?: AppLog.putDebug("Epub: 封面获取为空. path: ${book.bookUrl}")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
@@ -131,25 +131,34 @@ class EpubFile(var book: Book) {
|
||||
val startFragmentId = chapter.startFragmentId
|
||||
val endFragmentId = chapter.endFragmentId
|
||||
val elements = Elements()
|
||||
var isChapter = false
|
||||
var hasMoreResources = false
|
||||
val includeNextChapterResource = !endFragmentId.isNullOrBlank()
|
||||
/*一些书籍依靠href索引的resource会包含多个章节,需要依靠fragmentId来截取到当前章节的内容*/
|
||||
/*注:这里较大增加了内容加载的时间,所以首次获取内容后可存储到本地cache,减少重复加载*/
|
||||
for (res in epubBook.contents) {
|
||||
if (chapter.url.substringBeforeLast("#") == res.href) {
|
||||
elements.add(getBody(res, startFragmentId, endFragmentId))
|
||||
isChapter = true
|
||||
/**
|
||||
* fix https://github.com/gedoor/legado/issues/1927 加载全部内容的bug
|
||||
* content src text/000001.html(当前章节)
|
||||
- * content src text/000001.html#toc_id_x (下一章节)
|
||||
*/
|
||||
if (res.href == nextUrl?.substringBeforeLast("#")) break
|
||||
} else if (isChapter) {
|
||||
// fix 最后一章存在多个html时 内容缺失
|
||||
if (res.href == nextUrl?.substringBeforeLast("#")) {
|
||||
val isFirstResource = chapter.url.substringBeforeLast("#") == res.href
|
||||
val isNextChapterResource = res.href == nextUrl?.substringBeforeLast("#")
|
||||
if (isFirstResource) {
|
||||
// add first resource to elements
|
||||
elements.add(
|
||||
/* pass endFragmentId if only has one resource */
|
||||
getBody(res, startFragmentId, endFragmentId)
|
||||
)
|
||||
// check current resource
|
||||
if (isNextChapterResource) {
|
||||
/* FragmentId should not be same in same resource */
|
||||
if (!endFragmentId.isNullOrBlank() && endFragmentId == startFragmentId)
|
||||
AppLog.putDebug("Epub: Resource (${res.href}) has same FragmentId, check the file: ${book.bookUrl}")
|
||||
break
|
||||
}
|
||||
elements.add(getBody(res, startFragmentId, endFragmentId))
|
||||
hasMoreResources = true
|
||||
} else if (hasMoreResources) {
|
||||
if (isNextChapterResource) {
|
||||
if (includeNextChapterResource) elements.add(getBody(res, null/* FragmentId may be same in different resources, pass null */, endFragmentId))
|
||||
break
|
||||
}
|
||||
// rest resource should not have fragmentId, pass null
|
||||
elements.add(getBody(res, null, null))
|
||||
}
|
||||
}
|
||||
//title标签中的内容不需要显示在正文中,去除
|
||||
@@ -226,7 +235,7 @@ class EpubFile(var book: Book) {
|
||||
epubBook?.let { eBook ->
|
||||
val refs = eBook.tableOfContents.tocReferences
|
||||
if (refs == null || refs.isEmpty()) {
|
||||
AppLog.put("NCX file parse error, check the epub file")
|
||||
AppLog.putDebug("Epub: NCX file parse error, check the file: ${book.bookUrl}")
|
||||
val spineReferences = eBook.spine.spineReferences
|
||||
var i = 0
|
||||
val size = spineReferences.size
|
||||
@@ -340,4 +349,4 @@ class EpubFile(var book: Book) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,15 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.legado.app.R
|
||||
import io.legado.app.databinding.ItemSourceEditBinding
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.ui.widget.code.addJsPattern
|
||||
import io.legado.app.ui.widget.code.addJsonPattern
|
||||
import io.legado.app.ui.widget.code.addLegadoPattern
|
||||
|
||||
class BookSourceEditAdapter : RecyclerView.Adapter<BookSourceEditAdapter.MyViewHolder>() {
|
||||
|
||||
val editEntityMaxLine = AppConfig.sourceEditMaxLine
|
||||
|
||||
var editEntities: ArrayList<EditEntity> = ArrayList()
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
set(value) {
|
||||
@@ -39,10 +42,12 @@ class BookSourceEditAdapter : RecyclerView.Adapter<BookSourceEditAdapter.MyViewH
|
||||
return editEntities.size
|
||||
}
|
||||
|
||||
class MyViewHolder(val binding: ItemSourceEditBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
inner class MyViewHolder(val binding: ItemSourceEditBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(editEntity: EditEntity) = binding.run {
|
||||
editText.setTag(R.id.tag, editEntity.key)
|
||||
editText.maxLines = editEntityMaxLine
|
||||
if (editText.getTag(R.id.tag1) == null) {
|
||||
val listener = object : View.OnAttachStateChangeListener {
|
||||
override fun onViewAttachedToWindow(v: View) {
|
||||
|
||||
@@ -60,6 +60,7 @@ class OtherConfigFragment : PreferenceFragment(),
|
||||
}
|
||||
upPreferenceSummary(PreferKey.checkSource, CheckSource.summary)
|
||||
upPreferenceSummary(PreferKey.bitmapCacheSize, AppConfig.bitmapCacheSize.toString())
|
||||
upPreferenceSummary(PreferKey.sourceEditMaxLine, AppConfig.sourceEditMaxLine.toString())
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
@@ -119,7 +120,16 @@ class OtherConfigFragment : PreferenceFragment(),
|
||||
ImageProvider.bitmapLruCache.resize(ImageProvider.cacheSize)
|
||||
}
|
||||
}
|
||||
|
||||
PreferKey.sourceEditMaxLine -> {
|
||||
NumberPickerDialog(requireContext())
|
||||
.setTitle(getString(R.string.source_edit_text_max_line))
|
||||
.setMaxValue(99)
|
||||
.setMinValue(10)
|
||||
.setValue(AppConfig.sourceEditMaxLine)
|
||||
.show {
|
||||
AppConfig.sourceEditMaxLine = it
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onPreferenceTreeClick(preference)
|
||||
}
|
||||
@@ -160,6 +170,9 @@ class OtherConfigFragment : PreferenceFragment(),
|
||||
PreferKey.bitmapCacheSize -> {
|
||||
upPreferenceSummary(key, AppConfig.bitmapCacheSize.toString())
|
||||
}
|
||||
PreferKey.sourceEditMaxLine -> {
|
||||
upPreferenceSummary(key, AppConfig.sourceEditMaxLine.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +183,10 @@ class OtherConfigFragment : PreferenceFragment(),
|
||||
getString(R.string.pre_download_s, value)
|
||||
PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, value)
|
||||
PreferKey.webPort -> preference.summary = getString(R.string.web_port_summary, value)
|
||||
PreferKey.bitmapCacheSize -> preference.summary = getString(R.string.bitmap_cache_size_summary, value)
|
||||
PreferKey.bitmapCacheSize -> preference.summary =
|
||||
getString(R.string.bitmap_cache_size_summary, value)
|
||||
PreferKey.sourceEditMaxLine -> preference.summary =
|
||||
getString(R.string.source_edit_max_line_summary, value)
|
||||
else -> if (preference is ListPreference) {
|
||||
val index = preference.findIndexOfValue(value)
|
||||
// Set the summary to reflect the new value.
|
||||
|
||||
@@ -9,12 +9,15 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.legado.app.R
|
||||
import io.legado.app.databinding.ItemSourceEditBinding
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.ui.widget.code.addJsPattern
|
||||
import io.legado.app.ui.widget.code.addJsonPattern
|
||||
import io.legado.app.ui.widget.code.addLegadoPattern
|
||||
|
||||
class RssSourceEditAdapter : RecyclerView.Adapter<RssSourceEditAdapter.MyViewHolder>() {
|
||||
|
||||
val editEntityMaxLine = AppConfig.sourceEditMaxLine
|
||||
|
||||
var editEntities: ArrayList<EditEntity> = ArrayList()
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
set(value) {
|
||||
@@ -39,9 +42,11 @@ class RssSourceEditAdapter : RecyclerView.Adapter<RssSourceEditAdapter.MyViewHol
|
||||
return editEntities.size
|
||||
}
|
||||
|
||||
class MyViewHolder(val binding: ItemSourceEditBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
inner class MyViewHolder(val binding: ItemSourceEditBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(editEntity: EditEntity) = binding.run {
|
||||
editText.maxLines = editEntityMaxLine
|
||||
if (editText.getTag(R.id.tag1) == null) {
|
||||
val listener = object : View.OnAttachStateChangeListener {
|
||||
override fun onViewAttachedToWindow(v: View) {
|
||||
|
||||
Reference in New Issue
Block a user