pull/34/head
kunfei 5 years ago
parent 98003f6e08
commit 0e9e9a842d
  1. 4
      app/src/main/java/io/legado/app/help/IntentHelp.kt
  2. 10
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  3. 9
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  4. 8
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt

@ -25,9 +25,7 @@ object IntentHelp {
return PendingIntent.getService( return PendingIntent.getService(
context, context,
0, 0,
Intent(context, T::class.java).apply { Intent(context, T::class.java).apply { this.action = action },
this.action = action
},
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
) )
} }

@ -297,24 +297,24 @@ abstract class BaseReadAloudService : BaseService(),
builder.addAction( builder.addAction(
R.drawable.ic_play_24dp, R.drawable.ic_play_24dp,
getString(R.string.resume), getString(R.string.resume),
aloudServicePendingIntent(this, Action.resume) aloudServicePendingIntent(Action.resume)
) )
} else { } else {
builder.addAction( builder.addAction(
R.drawable.ic_pause_24dp, R.drawable.ic_pause_24dp,
getString(R.string.pause), getString(R.string.pause),
aloudServicePendingIntent(this, Action.pause) aloudServicePendingIntent(Action.pause)
) )
} }
builder.addAction( builder.addAction(
R.drawable.ic_stop_black_24dp, R.drawable.ic_stop_black_24dp,
getString(R.string.stop), getString(R.string.stop),
aloudServicePendingIntent(this, Action.stop) aloudServicePendingIntent(Action.stop)
) )
builder.addAction( builder.addAction(
R.drawable.ic_time_add_24dp, R.drawable.ic_time_add_24dp,
getString(R.string.set_timer), getString(R.string.set_timer),
aloudServicePendingIntent(this, Action.addTimer) aloudServicePendingIntent(Action.addTimer)
) )
builder.setStyle( builder.setStyle(
androidx.media.app.NotificationCompat.MediaStyle() androidx.media.app.NotificationCompat.MediaStyle()
@ -326,6 +326,6 @@ abstract class BaseReadAloudService : BaseService(),
startForeground(112201, notification) startForeground(112201, notification)
} }
abstract fun aloudServicePendingIntent(context: Context, actionStr: String): PendingIntent abstract fun aloudServicePendingIntent(actionStr: String): PendingIntent?
} }

@ -1,10 +1,9 @@
package io.legado.app.service package io.legado.app.service
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.media.MediaPlayer import android.media.MediaPlayer
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.help.IntentHelp
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
@ -103,9 +102,7 @@ class HttpReadAloudService : BaseReadAloudService(),
} }
} }
override fun aloudServicePendingIntent(context: Context, actionStr: String): PendingIntent { override fun aloudServicePendingIntent(actionStr: String): PendingIntent? {
val intent = Intent(context, HttpReadAloudService::class.java) return IntentHelp.servicePendingIntent<HttpReadAloudService>(this, actionStr)
intent.action = actionStr
return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
} }
} }

@ -1,8 +1,6 @@
package io.legado.app.service package io.legado.app.service
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build import android.os.Build
import android.speech.tts.TextToSpeech import android.speech.tts.TextToSpeech
import android.speech.tts.UtteranceProgressListener import android.speech.tts.UtteranceProgressListener
@ -190,10 +188,8 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
} }
override fun aloudServicePendingIntent(context: Context, actionStr: String): PendingIntent { override fun aloudServicePendingIntent(actionStr: String): PendingIntent? {
val intent = Intent(context, TTSReadAloudService::class.java) return IntentHelp.servicePendingIntent<TTSReadAloudService>(this, actionStr)
intent.action = actionStr
return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
} }
} }
Loading…
Cancel
Save