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(
context,
0,
Intent(context, T::class.java).apply {
this.action = action
},
Intent(context, T::class.java).apply { this.action = action },
PendingIntent.FLAG_UPDATE_CURRENT
)
}

@ -297,24 +297,24 @@ abstract class BaseReadAloudService : BaseService(),
builder.addAction(
R.drawable.ic_play_24dp,
getString(R.string.resume),
aloudServicePendingIntent(this, Action.resume)
aloudServicePendingIntent(Action.resume)
)
} else {
builder.addAction(
R.drawable.ic_pause_24dp,
getString(R.string.pause),
aloudServicePendingIntent(this, Action.pause)
aloudServicePendingIntent(Action.pause)
)
}
builder.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.stop),
aloudServicePendingIntent(this, Action.stop)
aloudServicePendingIntent(Action.stop)
)
builder.addAction(
R.drawable.ic_time_add_24dp,
getString(R.string.set_timer),
aloudServicePendingIntent(this, Action.addTimer)
aloudServicePendingIntent(Action.addTimer)
)
builder.setStyle(
androidx.media.app.NotificationCompat.MediaStyle()
@ -326,6 +326,6 @@ abstract class BaseReadAloudService : BaseService(),
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
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.media.MediaPlayer
import io.legado.app.constant.Bus
import io.legado.app.help.IntentHelp
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getPrefString
import io.legado.app.utils.postEvent
@ -103,9 +102,7 @@ class HttpReadAloudService : BaseReadAloudService(),
}
}
override fun aloudServicePendingIntent(context: Context, actionStr: String): PendingIntent {
val intent = Intent(context, HttpReadAloudService::class.java)
intent.action = actionStr
return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
override fun aloudServicePendingIntent(actionStr: String): PendingIntent? {
return IntentHelp.servicePendingIntent<HttpReadAloudService>(this, actionStr)
}
}

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