diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ExploreKind.kt b/app/src/main/java/io/legado/app/data/entities/rule/ExploreKind.kt index d010b1a4eff0..802fd31d8d91 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/ExploreKind.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/ExploreKind.kt @@ -6,37 +6,11 @@ package io.legado.app.data.entities.rule data class ExploreKind( val title: String = "", val url: String? = null, - val style: Style? = null + val style: FlexChildStyle? = null ) { - companion object { - val defaultStyle = Style() - } - - fun style(): Style { - return style ?: defaultStyle - } - - data class Style( - val layout_flexGrow: Float = 0F, - val layout_flexShrink: Float = 1F, - val layout_alignSelf: String = "auto", - val layout_flexBasisPercent: Float = -1F, - val layout_wrapBefore: Boolean = false, - ) { - - fun alignSelf(): Int { - return when (layout_alignSelf) { - "auto" -> -1 - "flex_start" -> 0 - "flex_end" -> 1 - "center" -> 2 - "baseline" -> 3 - "stretch" -> 4 - else -> -1 - } - } - + fun style(): FlexChildStyle { + return style ?: FlexChildStyle.defaultStyle } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/rule/FlexChildStyle.kt b/app/src/main/java/io/legado/app/data/entities/rule/FlexChildStyle.kt new file mode 100644 index 000000000000..7efa750559ca --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/rule/FlexChildStyle.kt @@ -0,0 +1,39 @@ +package io.legado.app.data.entities.rule + +import android.view.View +import com.google.android.flexbox.FlexboxLayout + +data class FlexChildStyle( + val layout_flexGrow: Float = 0F, + val layout_flexShrink: Float = 1F, + val layout_alignSelf: String = "auto", + val layout_flexBasisPercent: Float = -1F, + val layout_wrapBefore: Boolean = false, +) { + + fun alignSelf(): Int { + return when (layout_alignSelf) { + "auto" -> -1 + "flex_start" -> 0 + "flex_end" -> 1 + "center" -> 2 + "baseline" -> 3 + "stretch" -> 4 + else -> -1 + } + } + + fun apply(view: View) { + val lp = view.layoutParams as FlexboxLayout.LayoutParams + lp.flexGrow = layout_flexGrow + lp.flexShrink = layout_flexShrink + lp.alignSelf = alignSelf() + lp.flexBasisPercent = layout_flexBasisPercent + lp.isWrapBefore = layout_wrapBefore + } + + companion object { + val defaultStyle = FlexChildStyle() + } + +} diff --git a/app/src/main/java/io/legado/app/data/entities/rule/RowUi.kt b/app/src/main/java/io/legado/app/data/entities/rule/RowUi.kt index ff4884891c0b..482d2aa3f853 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/RowUi.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/RowUi.kt @@ -1,15 +1,13 @@ package io.legado.app.data.entities.rule -import android.os.Parcelable -import kotlinx.parcelize.Parcelize - -@Parcelize data class RowUi( var name: String, var type: String = "text", - var action: String? = null -) : Parcelable { + var action: String? = null, + var style: FlexChildStyle? = null +) { + @Suppress("ConstPropertyName") object Type { const val text = "text" @@ -18,4 +16,8 @@ data class RowUi( } + fun style(): FlexChildStyle { + return style ?: FlexChildStyle.defaultStyle + } + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/book/BookHelp.kt b/app/src/main/java/io/legado/app/help/book/BookHelp.kt index 39833a136a13..c93bec606c64 100644 --- a/app/src/main/java/io/legado/app/help/book/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/book/BookHelp.kt @@ -148,7 +148,7 @@ object BookHelp { book.getFolderName(), bookChapter.getFileName(), ).writeText(content) - if (book.isOnLineTxt) { + if (book.isOnLineTxt && AppConfig.tocCountWords) { bookChapter.wordCount = StringUtils.wordCountFormat(content.length) appDb.bookChapterDao.update(bookChapter) } diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index 49d4fd4ae03d..15a1aa7dc9bf 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -270,12 +270,15 @@ object BookChapterList { } private fun getWordCount(list: ArrayList, book: Book) { + if (!AppConfig.tocCountWords) { + return + } val chapterList = appDb.bookChapterDao.getChapterList(book.bookUrl) - if (chapterList.isNotEmpty()){ + if (chapterList.isNotEmpty()) { val map = chapterList.associateBy({ it.getFileName() }, { it.wordCount }) for (bookChapter in list) { val wordCount = map[bookChapter.getFileName()] - if(wordCount != null){ + if (wordCount != null) { bookChapter.wordCount = wordCount } } diff --git a/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt b/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt index 535a607dfd8e..a8ab810187c4 100644 --- a/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt +++ b/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt @@ -35,11 +35,6 @@ import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import splitties.views.onClick -import kotlin.collections.HashMap -import kotlin.collections.List -import kotlin.collections.forEachIndexed -import kotlin.collections.hashMapOf -import kotlin.collections.set class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) { @@ -70,6 +65,7 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) { it.textInputLayout.hint = rowUi.name it.editText.setText(loginInfo?.get(rowUi.name)) } + RowUi.Type.password -> ItemSourceEditBinding.inflate( layoutInflater, binding.root, @@ -82,37 +78,19 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) { InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT it.editText.setText(loginInfo?.get(rowUi.name)) } + RowUi.Type.button -> ItemFilletTextBinding.inflate( layoutInflater, binding.root, false ).let { binding.flexbox.addView(it.root) + rowUi.style().apply(it.root) it.root.id = index + 1000 it.textView.text = rowUi.name it.textView.setPadding(16.dpToPx()) it.root.onClick { - Coroutine.async { - if (rowUi.action.isAbsUrl()) { - context?.openUrl(rowUi.action!!) - } else { - // JavaScript - rowUi.action?.let { buttonFunctionJS -> - kotlin.runCatching { - source.getLoginJs()?.let { loginJS -> - source.evalJS("$loginJS\n$buttonFunctionJS") { - put("result", getLoginData(loginUi)) - } - } - }.onFailure { e -> - AppLog.put( - "LoginUI Button ${rowUi.name} JavaScript error", - e - ) - } - } - } - } + handleButtonClick(source, rowUi, loginUi) } } } @@ -125,12 +103,14 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) { val loginData = getLoginData(loginUi) login(source, loginData) } + R.id.menu_show_login_header -> alert { setTitle(R.string.login_header) source.getLoginHeader()?.let { loginHeader -> setMessage(loginHeader) } } + R.id.menu_del_login_header -> source.removeLoginHeader() R.id.menu_log -> showDialogFragment() } @@ -138,6 +118,25 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) { } } + private fun handleButtonClick(source: BaseSource, rowUi: RowUi, loginUi: List) { + Coroutine.async { + if (rowUi.action.isAbsUrl()) { + context?.openUrl(rowUi.action!!) + } else if (rowUi.action != null) { + // JavaScript + val buttonFunctionJS = rowUi.action!! + val loginJS = source.getLoginJs() ?: return@async + kotlin.runCatching { + source.evalJS("$loginJS\n$buttonFunctionJS") { + put("result", getLoginData(loginUi)) + } + }.onFailure { e -> + AppLog.put("LoginUI Button ${rowUi.name} JavaScript error", e) + } + } + } + } + private fun getLoginData(loginUi: List?): HashMap { val loginData = hashMapOf() loginUi?.forEachIndexed { index, rowUi -> diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index e84b6a943cb6..b2664cf0379d 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -91,14 +91,7 @@ class ExploreAdapter(context: Context, val callBack: CallBack) : val tv = getFlexboxChild(flexbox) flexbox.addView(tv) tv.text = kind.title - val lp = tv.layoutParams as FlexboxLayout.LayoutParams - kind.style().let { style -> - lp.flexGrow = style.layout_flexGrow - lp.flexShrink = style.layout_flexShrink - lp.alignSelf = style.alignSelf() - lp.flexBasisPercent = style.layout_flexBasisPercent - lp.isWrapBefore = style.layout_wrapBefore - } + kind.style().apply(tv) if (kind.url.isNullOrBlank()) { tv.setOnClickListener(null) } else { diff --git a/app/src/main/res/layout/item_chapter_list.xml b/app/src/main/res/layout/item_chapter_list.xml index 95f8cfa081c4..9ea8805d8db8 100644 --- a/app/src/main/res/layout/item_chapter_list.xml +++ b/app/src/main/res/layout/item_chapter_list.xml @@ -2,11 +2,11 @@ + app:layout_constraintRight_toLeftOf="@+id/iv_checked" + app:layout_constraintTop_toTopOf="parent" /> @@ -35,25 +36,25 @@ android:id="@+id/tv_tag" android:layout_width="0dp" android:layout_height="wrap_content" + android:singleLine="true" android:textSize="12sp" android:visibility="gone" - android:singleLine="true" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintTop_toBottomOf="@+id/tv_chapter_name" app:layout_constraintLeft_toRightOf="@id/tv_word_count" - app:layout_constraintRight_toLeftOf="@+id/iv_checked" /> + app:layout_constraintRight_toLeftOf="@+id/iv_checked" + app:layout_constraintTop_toBottomOf="@+id/tv_chapter_name" /> + app:layout_constraintTop_toTopOf="parent" + app:tint="@color/secondaryText" /> \ No newline at end of file