|
|
@ -6,6 +6,7 @@ import android.content.Intent |
|
|
|
import android.net.Uri |
|
|
|
import android.net.Uri |
|
|
|
import android.os.AsyncTask.execute |
|
|
|
import android.os.AsyncTask.execute |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
|
|
|
|
import android.os.Handler |
|
|
|
import android.text.SpannableStringBuilder |
|
|
|
import android.text.SpannableStringBuilder |
|
|
|
import android.view.KeyEvent |
|
|
|
import android.view.KeyEvent |
|
|
|
import android.view.Menu |
|
|
|
import android.view.Menu |
|
|
@ -63,20 +64,26 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo |
|
|
|
ChangeSourceDialog.CallBack, |
|
|
|
ChangeSourceDialog.CallBack, |
|
|
|
ReadBook.CallBack, |
|
|
|
ReadBook.CallBack, |
|
|
|
ColorPickerDialogListener { |
|
|
|
ColorPickerDialogListener { |
|
|
|
|
|
|
|
private val requestCodeChapterList = 568 |
|
|
|
|
|
|
|
private val requestCodeEditSource = 111 |
|
|
|
|
|
|
|
private val requestCodeReplace = 31242 |
|
|
|
|
|
|
|
|
|
|
|
override val viewModel: ReadBookViewModel |
|
|
|
override val viewModel: ReadBookViewModel |
|
|
|
get() = getViewModel(ReadBookViewModel::class.java) |
|
|
|
get() = getViewModel(ReadBookViewModel::class.java) |
|
|
|
|
|
|
|
|
|
|
|
override val isInitFinish: Boolean |
|
|
|
override val isInitFinish: Boolean |
|
|
|
get() = viewModel.isInitFinish |
|
|
|
get() = viewModel.isInitFinish |
|
|
|
|
|
|
|
|
|
|
|
private val requestCodeChapterList = 568 |
|
|
|
private val mHandler = Handler() |
|
|
|
private val requestCodeEditSource = 111 |
|
|
|
private val keepScreenRunnable: Runnable = Runnable { Help.keepScreenOn(window, false) } |
|
|
|
private val requestCodeReplace = 31242 |
|
|
|
|
|
|
|
|
|
|
|
private var screenTimeOut: Long = 0 |
|
|
|
private var timeElectricityReceiver: TimeElectricityReceiver? = null |
|
|
|
private var timeElectricityReceiver: TimeElectricityReceiver? = null |
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
Help.upLayoutInDisplayCutoutMode(window) |
|
|
|
Help.upLayoutInDisplayCutoutMode(window) |
|
|
|
initView() |
|
|
|
initView() |
|
|
|
|
|
|
|
upScreenTimeOut() |
|
|
|
ReadBook.callBack = this |
|
|
|
ReadBook.callBack = this |
|
|
|
ReadBook.titleDate.observe(this, Observer { title_bar.title = it }) |
|
|
|
ReadBook.titleDate.observe(this, Observer { title_bar.title = it }) |
|
|
|
viewModel.initData(intent) |
|
|
|
viewModel.initData(intent) |
|
|
@ -179,11 +186,11 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo |
|
|
|
}.show().applyTint() |
|
|
|
}.show().applyTint() |
|
|
|
} |
|
|
|
} |
|
|
|
R.id.menu_add_bookmark -> { |
|
|
|
R.id.menu_add_bookmark -> { |
|
|
|
val book = ReadBook.book |
|
|
|
val book = ReadBook.book ?: return true |
|
|
|
val textChapter = ReadBook.curTextChapter |
|
|
|
val textChapter = ReadBook.curTextChapter |
|
|
|
alert(title = getString(R.string.bookmark_add)) { |
|
|
|
alert(title = getString(R.string.bookmark_add)) { |
|
|
|
var editText: EditText? = null |
|
|
|
var editText: EditText? = null |
|
|
|
message = book?.name + " • " + textChapter?.title |
|
|
|
message = book.name + " • " + textChapter?.title |
|
|
|
customView { |
|
|
|
customView { |
|
|
|
layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { |
|
|
|
layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { |
|
|
|
editText = edit_view.apply { |
|
|
|
editText = edit_view.apply { |
|
|
@ -195,9 +202,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo |
|
|
|
editText?.text?.toString()?.let { editContent -> |
|
|
|
editText?.text?.toString()?.let { editContent -> |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
val bookmark = Bookmark( |
|
|
|
val bookmark = Bookmark( |
|
|
|
book!!.durChapterTime, |
|
|
|
book.durChapterTime, |
|
|
|
book!!.bookUrl, |
|
|
|
book.bookUrl, |
|
|
|
book!!.name, |
|
|
|
book.name, |
|
|
|
ReadBook.durChapterIndex, |
|
|
|
ReadBook.durChapterIndex, |
|
|
|
ReadBook.durPageIndex, |
|
|
|
ReadBook.durPageIndex, |
|
|
|
textChapter!!.title, |
|
|
|
textChapter!!.title, |
|
|
@ -548,4 +555,27 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun upScreenTimeOut() { |
|
|
|
|
|
|
|
getPrefString("keep_light")?.let { |
|
|
|
|
|
|
|
screenTimeOut = it.toLong() * 1000 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 重置黑屏时间 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
fun screenOffTimerStart() { |
|
|
|
|
|
|
|
if (screenTimeOut < 0) { |
|
|
|
|
|
|
|
Help.keepScreenOn(window, true) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
val t = screenTimeOut - getScreenOffTime() |
|
|
|
|
|
|
|
if (t > 0) { |
|
|
|
|
|
|
|
mHandler.removeCallbacks(keepScreenRunnable) |
|
|
|
|
|
|
|
Help.keepScreenOn(window, true) |
|
|
|
|
|
|
|
mHandler.postDelayed(keepScreenRunnable, screenTimeOut) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Help.keepScreenOn(window, false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |