|
|
@ -9,7 +9,6 @@ import android.graphics.drawable.ColorDrawable |
|
|
|
import android.net.Uri |
|
|
|
import android.net.Uri |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Handler |
|
|
|
import android.os.Handler |
|
|
|
import android.util.Log |
|
|
|
|
|
|
|
import android.view.* |
|
|
|
import android.view.* |
|
|
|
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT |
|
|
|
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT |
|
|
|
import androidx.core.view.get |
|
|
|
import androidx.core.view.get |
|
|
@ -57,14 +56,16 @@ import io.legado.app.ui.widget.dialog.TextDialog |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.* |
|
|
|
import kotlinx.android.synthetic.main.activity_book_read.* |
|
|
|
import kotlinx.android.synthetic.main.activity_book_read.* |
|
|
|
import kotlinx.android.synthetic.main.view_read_menu.* |
|
|
|
import kotlinx.android.synthetic.main.view_read_menu.* |
|
|
|
import kotlinx.coroutines.* |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
|
|
|
|
import kotlinx.coroutines.delay |
|
|
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.startActivity |
|
|
|
import org.jetbrains.anko.startActivity |
|
|
|
import org.jetbrains.anko.startActivityForResult |
|
|
|
import org.jetbrains.anko.startActivityForResult |
|
|
|
import org.jetbrains.anko.toast |
|
|
|
import org.jetbrains.anko.toast |
|
|
|
import java.lang.Runnable |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_book_read), |
|
|
|
class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_book_read), |
|
|
|
View.OnTouchListener, |
|
|
|
View.OnTouchListener, |
|
|
@ -494,6 +495,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
R.id.menu_search_content -> { |
|
|
|
R.id.menu_search_content -> { |
|
|
|
|
|
|
|
viewModel.searchContentQuery = selectedText |
|
|
|
openSearchActivity(selectedText) |
|
|
|
openSearchActivity(selectedText) |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
@ -686,7 +688,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo |
|
|
|
startActivityForResult<SearchListActivity>( |
|
|
|
startActivityForResult<SearchListActivity>( |
|
|
|
requestCodeSearchResult, |
|
|
|
requestCodeSearchResult, |
|
|
|
Pair("bookUrl", it.bookUrl), |
|
|
|
Pair("bookUrl", it.bookUrl), |
|
|
|
Pair("searchWord", searchWord) |
|
|
|
Pair("searchWord", searchWord ?: viewModel.searchContentQuery) |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -779,7 +781,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo |
|
|
|
data?.getIntExtra("index", ReadBook.durChapterIndex)?.let { index -> |
|
|
|
data?.getIntExtra("index", ReadBook.durChapterIndex)?.let { index -> |
|
|
|
launch(IO) { |
|
|
|
launch(IO) { |
|
|
|
val indexWithinChapter = data.getIntExtra("indexWithinChapter", 0) |
|
|
|
val indexWithinChapter = data.getIntExtra("indexWithinChapter", 0) |
|
|
|
val query = data.getStringExtra("query") |
|
|
|
viewModel.searchContentQuery = data.getStringExtra("query") ?: "" |
|
|
|
viewModel.openChapter(index) |
|
|
|
viewModel.openChapter(index) |
|
|
|
// block until load correct chapter and pages |
|
|
|
// block until load correct chapter and pages |
|
|
|
var pages = ReadBook.curTextChapter?.pages |
|
|
|
var pages = ReadBook.curTextChapter?.pages |
|
|
@ -787,17 +789,34 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo |
|
|
|
delay(100L) |
|
|
|
delay(100L) |
|
|
|
pages = ReadBook.curTextChapter?.pages |
|
|
|
pages = ReadBook.curTextChapter?.pages |
|
|
|
} |
|
|
|
} |
|
|
|
val positions = ReadBook.searchResultPositions(pages, indexWithinChapter, query!!) |
|
|
|
val positions = |
|
|
|
|
|
|
|
ReadBook.searchResultPositions( |
|
|
|
|
|
|
|
pages, |
|
|
|
|
|
|
|
indexWithinChapter, |
|
|
|
|
|
|
|
viewModel.searchContentQuery |
|
|
|
|
|
|
|
) |
|
|
|
while (ReadBook.durPageIndex != positions[0]) { |
|
|
|
while (ReadBook.durPageIndex != positions[0]) { |
|
|
|
delay(100L) |
|
|
|
delay(100L) |
|
|
|
ReadBook.skipToPage(positions[0]) |
|
|
|
ReadBook.skipToPage(positions[0]) |
|
|
|
} |
|
|
|
} |
|
|
|
withContext(Main) { |
|
|
|
withContext(Main) { |
|
|
|
page_view.curPage.selectStartMoveIndex(0, positions[1], positions[2]) |
|
|
|
page_view.curPage.selectStartMoveIndex( |
|
|
|
|
|
|
|
0, |
|
|
|
|
|
|
|
positions[1], |
|
|
|
|
|
|
|
positions[2] |
|
|
|
|
|
|
|
) |
|
|
|
delay(20L) |
|
|
|
delay(20L) |
|
|
|
when (positions[3]) { |
|
|
|
when (positions[3]) { |
|
|
|
0 -> page_view.curPage.selectEndMoveIndex(0, positions[1], positions[2] + query.length - 1) |
|
|
|
0 -> page_view.curPage.selectEndMoveIndex( |
|
|
|
1 -> page_view.curPage.selectEndMoveIndex(0, positions[1] + 1, positions[4]) |
|
|
|
0, |
|
|
|
|
|
|
|
positions[1], |
|
|
|
|
|
|
|
positions[2] + viewModel.searchContentQuery.length - 1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
1 -> page_view.curPage.selectEndMoveIndex( |
|
|
|
|
|
|
|
0, |
|
|
|
|
|
|
|
positions[1] + 1, |
|
|
|
|
|
|
|
positions[4] |
|
|
|
|
|
|
|
) |
|
|
|
//todo: consider change page, jump to scroll position |
|
|
|
//todo: consider change page, jump to scroll position |
|
|
|
-1 -> page_view.curPage.selectEndMoveIndex(1, 0, positions[4]) |
|
|
|
-1 -> page_view.curPage.selectEndMoveIndex(1, 0, positions[4]) |
|
|
|
} |
|
|
|
} |
|
|
|