优化代码

pull/743/head
gedoor 5 years ago
parent 3cb4017c3a
commit 9e63f6aa70
  1. 7
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 12
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  3. 24
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  4. 7
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  5. 1
      app/src/main/res/values-zh-rHK/strings.xml
  6. 1
      app/src/main/res/values-zh-rTW/strings.xml
  7. 1
      app/src/main/res/values-zh/strings.xml
  8. 1
      app/src/main/res/values/strings.xml

@ -430,7 +430,12 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun onMenuItemSelected(itemId: Int): Boolean {
when (itemId) {
R.id.menu_bookmark -> binding.readView.curPage.let {
showBookMark(it.selectStartPos, it.selectedText)
val bookmark = it.createBookmark()
if (bookmark == null) {
toast(R.string.create_bookmark_error)
} else {
showBookMark(bookmark)
}
return true
}
R.id.menu_replace -> {

@ -199,7 +199,7 @@ abstract class ReadBookBaseActivity :
}
@SuppressLint("InflateParams")
fun showBookMark(chapterPos: Int, bookText: String) {
fun showBookMark(bookmark: Bookmark) {
val book = ReadBook.book ?: return
val textChapter = ReadBook.curTextChapter ?: return
alert(title = getString(R.string.bookmark_add)) {
@ -211,15 +211,7 @@ abstract class ReadBookBaseActivity :
yesButton {
alertBinding.editView.text?.toString()?.let { editContent ->
Coroutine.async {
val bookmark = Bookmark(
bookUrl = book.bookUrl,
bookName = book.name,
chapterIndex = ReadBook.durChapterIndex,
chapterPos = chapterPos,
chapterName = textChapter.title,
bookText = bookText,
content = editContent
)
bookmark.content = editContent
App.db.bookmarkDao.insert(bookmark)
}
}

@ -9,6 +9,7 @@ import android.util.Log
import android.view.View
import io.legado.app.R
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.Bookmark
import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.accentColor
import io.legado.app.service.help.ReadBook
@ -480,15 +481,24 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
return stringBuilder.toString()
}
val selectStartPos: Int
get() {
val page = relativePage(selectStart[0])
page.getTextChapter()?.let {
return it.getReadLength(page.index) +
page.getSelectStartLength(selectStart[1], selectStart[2])
fun createBookmark(): Bookmark? {
val page = relativePage(selectStart[0])
page.getTextChapter()?.let { chapter ->
val chapterPos = chapter.getReadLength(page.index) +
page.getSelectStartLength(selectStart[1], selectStart[2])
ReadBook.book?.let { book ->
return Bookmark(
bookUrl = book.bookUrl,
bookName = book.name,
chapterIndex = page.chapterIndex,
chapterPos = chapterPos,
chapterName = chapter.title,
bookText = selectedText
)
}
return 0
}
return null
}
private fun selectToInt(page: Int, line: Int, char: Int): Int {
return page * 10000000 + line * 100000 + char

@ -11,6 +11,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.constant.AppConst.timeFormat
import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.ViewBookPageBinding
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ReadTipConfig
@ -270,9 +271,11 @@ class PageView(context: Context) : FrameLayout(context) {
binding.contentTextView.cancelSelect()
}
val selectedText: String get() = binding.contentTextView.selectedText
fun createBookmark(): Bookmark? {
return binding.contentTextView.createBookmark()
}
val selectStartPos get() = binding.contentTextView.selectStartPos
val selectedText: String get() = binding.contentTextView.selectedText
val textPage get() = binding.contentTextView.textPage
}

@ -792,5 +792,6 @@
<string name="current_progress_exceeds_cloud">当前进度超过云端进度,是否同步?</string>
<string name="sync_book_progress_t">同步阅读进度</string>
<string name="sync_book_progress_s">进入退出阅读界面时同步阅读进度</string>
<string name="create_bookmark_error">创建书签失败</string>
</resources>

@ -793,5 +793,6 @@
<string name="current_progress_exceeds_cloud">目前進度超過雲端進度,是否同步?</string>
<string name="sync_book_progress_t">同步閱讀進度</string>
<string name="sync_book_progress_s">進入退出閱讀介面時同步閱讀進度</string>
<string name="create_bookmark_error">创建书签失败</string>
</resources>

@ -796,5 +796,6 @@
<string name="current_progress_exceeds_cloud">当前进度超过云端进度,是否同步?</string>
<string name="sync_book_progress_t">同步阅读进度</string>
<string name="sync_book_progress_s">进入退出阅读界面时同步阅读进度</string>
<string name="create_bookmark_error">创建书签失败</string>
</resources>

@ -799,5 +799,6 @@
<string name="current_progress_exceeds_cloud">当前进度超过云端进度,是否同步?</string>
<string name="sync_book_progress_t">同步阅读进度</string>
<string name="sync_book_progress_s">进入退出阅读界面时同步阅读进度</string>
<string name="create_bookmark_error">创建书签失败</string>
</resources>

Loading…
Cancel
Save