diff --git a/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt b/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt new file mode 100644 index 000000000..59d0424ee --- /dev/null +++ b/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.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 -> { + } + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 7c6c2d780..629a0bfeb 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -14,6 +14,7 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus import io.legado.app.constant.Status import io.legado.app.data.entities.Book +import io.legado.app.receiver.TimeElectricityReceiver import io.legado.app.service.ReadAloudService import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity @@ -29,6 +30,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea get() = getViewModel(ReadBookViewModel::class.java) private var changeSourceDialog: ChangeSourceDialog? = null + private var timeElectricityReceiver: TimeElectricityReceiver? = null private var menuBarShow: Boolean = false private lateinit var menuTopIn: Animation private lateinit var menuTopOut: Animation @@ -48,6 +50,19 @@ class ReadBookActivity : VMBaseActivity(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() { menuTopIn = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_top_in) menuBottomIn = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_bottom_in)