pull/32/head
kunfei 5 years ago
parent 62bd71ac25
commit e5f27fbe97
  1. 4
      app/src/main/java/io/legado/app/App.kt
  2. 19
      app/src/main/java/io/legado/app/help/ActivityHelp.kt
  3. 10
      app/src/main/java/io/legado/app/help/ReadBookHelp.kt
  4. 2
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  5. 5
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt

@ -143,7 +143,7 @@ class App : Application() {
private fun registerActivityLife(){ private fun registerActivityLife(){
registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks{ registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks{
override fun onActivityPaused(activity: Activity) { override fun onActivityPaused(activity: Activity) {
ActivityHelp.getInstance().add(activity) ActivityHelp.add(activity)
} }
override fun onActivityResumed(activity: Activity) { override fun onActivityResumed(activity: Activity) {
@ -153,7 +153,7 @@ class App : Application() {
} }
override fun onActivityDestroyed(activity: Activity) { override fun onActivityDestroyed(activity: Activity) {
ActivityHelp.getInstance().remove(activity) ActivityHelp.remove(activity)
} }
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle?) { override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle?) {

@ -7,27 +7,10 @@ import java.util.*
/** /**
* Activity管理器,管理项目中Activity的状态 * Activity管理器,管理项目中Activity的状态
*/ */
class ActivityHelp private constructor() { object ActivityHelp {
companion object {
private var activities: MutableList<WeakReference<Activity>> = arrayListOf() private var activities: MutableList<WeakReference<Activity>> = arrayListOf()
@Volatile
private var instance: ActivityHelp? = null
fun getInstance(): ActivityHelp {
if (null == instance) {
synchronized(ActivityHelp::class.java) {
if (null == instance) {
instance = ActivityHelp()
}
}
}
return instance!!
}
}
fun getActivities(): List<WeakReference<Activity>> { fun getActivities(): List<WeakReference<Activity>> {
return activities return activities
} }

@ -0,0 +1,10 @@
package io.legado.app.help
import android.graphics.drawable.Drawable
object ReadBookHelp {
var bg: Drawable? = null
}

@ -46,7 +46,7 @@ class MediaButtonReceiver : BroadcastReceiver() {
} }
private fun readAloud(context: Context) { private fun readAloud(context: Context) {
ActivityHelp.getInstance().isExist(ReadBookActivity::class.java).let { ActivityHelp.isExist(ReadBookActivity::class.java).let {
if (!it) { if (!it) {
context.startActivity<ReadBookActivity>() context.startActivity<ReadBookActivity>()
} }

@ -3,15 +3,12 @@ package io.legado.app.ui.widget.page
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.Color
import android.util.AttributeSet import android.util.AttributeSet
import android.view.MotionEvent import android.view.MotionEvent
import android.widget.FrameLayout import android.widget.FrameLayout
import io.legado.app.R import io.legado.app.R
import io.legado.app.ui.widget.page.delegate.CoverPageDelegate import io.legado.app.ui.widget.page.delegate.CoverPageDelegate
import io.legado.app.ui.widget.page.delegate.PageDelegate import io.legado.app.ui.widget.page.delegate.PageDelegate
import kotlinx.android.synthetic.main.view_book_page.view.*
import org.jetbrains.anko.backgroundColor
class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), PageDelegate.PageInterface { class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), PageDelegate.PageInterface {
@ -32,8 +29,6 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
upBg() upBg()
setWillNotDraw(false) setWillNotDraw(false)
page_panel.backgroundColor = Color.WHITE
pageDelegate = CoverPageDelegate(this) pageDelegate = CoverPageDelegate(this)
} }

Loading…
Cancel
Save