pull/78/head
kunfei 5 years ago
parent b4939e64c5
commit cc6db2733a
  1. 46
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 11
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt

@ -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)
}
}
} }

@ -6,6 +6,7 @@ import android.content.Intent
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.provider.Settings
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -63,6 +64,16 @@ fun Context.getCompatDrawable(@DrawableRes id: Int): Drawable? = ContextCompat.g
fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? =
ContextCompat.getColorStateList(this, id) ContextCompat.getColorStateList(this, id)
fun Context.getScreenOffTime(): Int {
var screenOffTime = 0
try {
screenOffTime = Settings.System.getInt(contentResolver, Settings.System.SCREEN_OFF_TIMEOUT)
} catch (e: Exception) {
e.printStackTrace()
}
return screenOffTime
}
fun Context.getStatusBarHeight(): Int { fun Context.getStatusBarHeight(): Int {
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
return resources.getDimensionPixelSize(resourceId) return resources.getDimensionPixelSize(resourceId)

Loading…
Cancel
Save