pull/32/head
kunfei 5 years ago
parent 488df49270
commit 1ca339c194
  1. 36
      app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt
  2. 15
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt

@ -0,0 +1,36 @@
package io.legado.app.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
class TimeElectricityReceiver : BroadcastReceiver() {
companion object {
fun register(context: Context): TimeElectricityReceiver {
val receiver = TimeElectricityReceiver()
val filter = IntentFilter()
filter.addAction(Intent.ACTION_TIME_TICK)
filter.addAction(Intent.ACTION_BATTERY_CHANGED)
context.registerReceiver(receiver, filter)
return receiver
}
}
override fun onReceive(context: Context?, intent: Intent?) {
intent?.action?.let {
when (it) {
Intent.ACTION_TIME_TICK -> {
}
Intent.ACTION_BATTERY_CHANGED -> {
}
}
}
}
}

@ -14,6 +14,7 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.constant.Status import io.legado.app.constant.Status
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.receiver.TimeElectricityReceiver
import io.legado.app.service.ReadAloudService import io.legado.app.service.ReadAloudService
import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.changesource.ChangeSourceDialog
import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.ui.chapterlist.ChapterListActivity
@ -29,6 +30,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
get() = getViewModel(ReadBookViewModel::class.java) get() = getViewModel(ReadBookViewModel::class.java)
private var changeSourceDialog: ChangeSourceDialog? = null private var changeSourceDialog: ChangeSourceDialog? = null
private var timeElectricityReceiver: TimeElectricityReceiver? = null
private var menuBarShow: Boolean = false private var menuBarShow: Boolean = false
private lateinit var menuTopIn: Animation private lateinit var menuTopIn: Animation
private lateinit var menuTopOut: Animation private lateinit var menuTopOut: Animation
@ -48,6 +50,19 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
} }
override fun onResume() {
super.onResume()
timeElectricityReceiver = TimeElectricityReceiver.register(this)
}
override fun onPause() {
super.onPause()
timeElectricityReceiver?.let {
unregisterReceiver(it)
timeElectricityReceiver = null
}
}
private fun initAnimation() { private fun initAnimation() {
menuTopIn = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_top_in) menuTopIn = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_top_in)
menuBottomIn = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_bottom_in) menuBottomIn = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_bottom_in)

Loading…
Cancel
Save