Merge pull request #2 from gedoor/master

update
pull/316/head
Gladtbam 4 years ago committed by GitHub
commit f10f82d970
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/src/main/java/io/legado/app/App.kt
  2. 3
      app/src/main/java/io/legado/app/model/webBook/BookInfo.kt
  3. 5
      app/src/main/java/io/legado/app/model/webBook/BookList.kt
  4. 1
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  5. 4
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
  7. 2
      app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt
  8. 24
      app/src/main/java/io/legado/app/utils/StringUtils.kt
  9. 25
      app/src/main/res/layout-land/activity_book_info.xml
  10. 28
      app/src/main/res/layout/activity_book_info.xml

@ -63,7 +63,8 @@ class App : MultiDexApplication() {
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
when (newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES, Configuration.UI_MODE_NIGHT_NO -> applyDayNight()
Configuration.UI_MODE_NIGHT_YES,
Configuration.UI_MODE_NIGHT_NO -> applyDayNight()
}
}

@ -9,6 +9,7 @@ import io.legado.app.help.BookHelp
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.StringUtils.wordCountFormat
import io.legado.app.utils.htmlFormat
object BookInfo {
@ -51,7 +52,7 @@ object BookInfo {
}
Debug.log(bookSource.bookSourceUrl, "${book.kind}")
Debug.log(bookSource.bookSourceUrl, "┌获取字数")
analyzeRule.getString(infoRule.wordCount).let {
wordCountFormat(analyzeRule.getString(infoRule.wordCount)).let {
if (it.isNotEmpty()) book.wordCount = it
}
Debug.log(bookSource.bookSourceUrl, "${book.wordCount}")

@ -10,6 +10,7 @@ import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.StringUtils.wordCountFormat
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.isActive
@ -152,7 +153,7 @@ object BookList {
Debug.log(bookSource.bookSourceUrl, "${searchBook.kind}")
if (!scope.isActive) throw CancellationException()
Debug.log(bookSource.bookSourceUrl, "┌获取字数")
searchBook.wordCount = analyzeRule.getString(wordCount)
searchBook.wordCount = wordCountFormat(analyzeRule.getString(wordCount))
Debug.log(bookSource.bookSourceUrl, "${searchBook.wordCount}")
if (!scope.isActive) throw CancellationException()
Debug.log(bookSource.bookSourceUrl, "┌获取最新章节")
@ -212,7 +213,7 @@ object BookList {
Debug.log(bookSource.bookSourceUrl, "${searchBook.kind}", log)
if (!scope.isActive) throw CancellationException()
Debug.log(bookSource.bookSourceUrl, "┌获取字数", log)
searchBook.wordCount = analyzeRule.getString(ruleWordCount)
searchBook.wordCount = wordCountFormat(analyzeRule.getString(ruleWordCount))
Debug.log(bookSource.bookSourceUrl, "${searchBook.wordCount}", log)
if (!scope.isActive) throw CancellationException()
Debug.log(bookSource.bookSourceUrl, "┌获取最新章节", log)

@ -163,6 +163,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
ReadBook.book!!,
textPage.chapterIndex,
textChar.charData,
textChar.charData,
true
)?.let {
canvas.drawBitmap(it, null, rectF, null)

@ -122,7 +122,7 @@ object ChapterProvider {
imageStyle: String?
): Float {
var durY = y
ImageProvider.getImage(book, chapter.index, src)?.let {
ImageProvider.getImage(book, chapter.index, src, chapter.url)?.let {
if (durY > visibleHeight) {
textPages.last().height = durY
textPages.add(TextPage())
@ -453,4 +453,4 @@ object ChapterProvider {
val TextPaint.textHeight: Float
get() = fontMetrics.descent - fontMetrics.ascent + fontMetrics.leading
}
}

@ -31,7 +31,7 @@ object ImageProvider {
indexCache[src] = bitmap
}
fun getImage(book: Book, chapterIndex: Int, src: String, onUi: Boolean = false): Bitmap? {
fun getImage(book: Book, chapterIndex: Int, src: String, baseUrl: String, onUi: Boolean = false): Bitmap? {
getCache(chapterIndex, src)?.let {
return it
}

@ -56,7 +56,7 @@ class PhotoDialog : BaseDialogFragment() {
val src = it.getString("src")
ReadBook.book?.let { book ->
src?.let {
ImageProvider.getImage(book, chapterIndex, src)?.let { bitmap ->
ImageProvider.getImage(book, chapterIndex, src, src)?.let { bitmap ->
photo_view.setImageBitmap(bitmap)
}
}

@ -214,7 +214,7 @@ object StringUtils {
fun stringToInt(str: String?): Int {
if (str != null) {
val num = fullToHalf(str).replace("\\s".toRegex(), "")
val num = fullToHalf(str).replace("\\s+".toRegex(), "")
return try {
Integer.parseInt(num)
} catch (e: Exception) {
@ -226,17 +226,35 @@ object StringUtils {
}
fun isContainNumber(company: String): Boolean {
val p = Pattern.compile("[0-9]")
val p = Pattern.compile("[0-9]+")
val m = p.matcher(company)
return m.find()
}
fun isNumeric(str: String): Boolean {
val pattern = Pattern.compile("[0-9]*")
val pattern = Pattern.compile("[0-9]+")
val isNum = pattern.matcher(str)
return isNum.matches()
}
fun wordCountFormat(wc: String?): String {
if (wc == null) return ""
var wordsS = ""
if (isNumeric(wc)) {
val words: Int = wc.toInt()
if (words > 0) {
wordsS = words.toString() + ""
if (words > 10000) {
val df = DecimalFormat("#.#")
wordsS = df.format(words * 1.0f / 10000f.toDouble()) + "万字"
}
}
} else {
wordsS = wc
}
return wordsS
}
// 移除字符串首尾空字符的高效方法(利用ASCII值判断,包括全角空格)
fun trim(s: String): String {
if (isEmpty(s)) return ""

@ -27,7 +27,8 @@
android:layout_height="match_parent"
android:background="#50000000"
android:orientation="horizontal"
android:fitsSystemWindows="true">
android:fitsSystemWindows="true"
tools:ignore="DisableBaselineAlignment">
<LinearLayout
android:layout_width="match_parent"
@ -112,7 +113,8 @@
android:layout_gravity="center"
android:orientation="horizontal"
android:paddingTop="3dp"
android:paddingBottom="3dp">
android:paddingBottom="3dp"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="18sp"
@ -209,10 +211,10 @@
android:includeFontPadding="false"
android:paddingRight="6dp"
android:singleLine="true"
android:text="@string/origin_format"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" />
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry"
tools:text="@string/origin_format" />
<io.legado.app.ui.widget.text.AccentBgTextView
android:id="@+id/tv_change_source"
@ -233,7 +235,8 @@
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingTop="3dp"
android:paddingBottom="3dp">
android:paddingBottom="3dp"
tools:ignore="UseCompoundDrawables">
<ImageView
android:id="@+id/ic_book_last"
@ -254,10 +257,10 @@
android:includeFontPadding="false"
android:paddingRight="6dp"
android:singleLine="true"
android:text="@string/read_dur_progress"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" />
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry"
tools:text="@string/read_dur_progress" />
</LinearLayout>
@ -287,10 +290,10 @@
android:includeFontPadding="false"
android:paddingRight="6dp"
android:singleLine="true"
android:text="@string/group_s"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" />
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry"
tools:text="@string/group_s" />
<io.legado.app.ui.widget.text.AccentBgTextView
android:id="@+id/tv_change_group"
@ -331,10 +334,10 @@
android:includeFontPadding="false"
android:paddingRight="6dp"
android:singleLine="true"
android:text="@string/toc_s"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" />
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry"
tools:text="@string/toc_s" />
<io.legado.app.ui.widget.text.AccentBgTextView
android:id="@+id/tv_toc_view"

@ -132,7 +132,8 @@
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingTop="3dp"
android:paddingBottom="3dp">
android:paddingBottom="3dp"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="18sp"
@ -186,10 +187,10 @@
android:includeFontPadding="false"
android:paddingRight="6dp"
android:singleLine="true"
android:text="@string/origin_format"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" />
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry"
tools:text="@string/origin_format" />
<io.legado.app.ui.widget.text.AccentBgTextView
android:id="@+id/tv_change_source"
@ -198,8 +199,8 @@
android:layout_marginStart="8dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/change_origin"
android:textSize="13sp"
android:text="@string/change_origin"
app:radius="2dp" />
</LinearLayout>
@ -210,16 +211,17 @@
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingTop="3dp"
android:paddingBottom="3dp">
android:paddingBottom="3dp"
tools:ignore="UseCompoundDrawables">
<ImageView
android:id="@+id/ic_book_last"
android:layout_width="18sp"
android:layout_height="18sp"
android:contentDescription="@string/read_dur_progress"
android:paddingRight="2dp"
android:src="@drawable/ic_book_last"
app:tint="@color/tv_text_summary"
android:contentDescription="@string/read_dur_progress"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
@ -231,10 +233,10 @@
android:includeFontPadding="false"
android:paddingRight="6dp"
android:singleLine="true"
android:text="@string/read_dur_progress"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" />
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry"
tools:text="@string/read_dur_progress" />
</LinearLayout>
@ -249,10 +251,10 @@
<ImageView
android:layout_width="18sp"
android:layout_height="18sp"
android:contentDescription="@string/read_dur_progress"
android:paddingRight="2dp"
android:src="@drawable/ic_groups"
app:tint="@color/tv_text_summary"
android:contentDescription="@string/read_dur_progress"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
@ -264,10 +266,10 @@
android:includeFontPadding="false"
android:paddingRight="6dp"
android:singleLine="true"
android:text="@string/group_s"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" />
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry"
tools:text="@string/group_s" />
<io.legado.app.ui.widget.text.AccentBgTextView
android:id="@+id/tv_change_group"
@ -308,10 +310,10 @@
android:includeFontPadding="false"
android:paddingRight="6dp"
android:singleLine="true"
android:text="@string/toc_s"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" />
tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry"
tools:text="@string/toc_s" />
<io.legado.app.ui.widget.text.AccentBgTextView
android:id="@+id/tv_toc_view"

Loading…
Cancel
Save