Skip to content

Commit ab92bb6

Browse files
authored
Merge pull request #24 from oxters168/fg-notification-action
Add exit button to service notification.
2 parents 008a51c + b91b047 commit ab92bb6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

app/src/main/java/com/OxGames/Pluvia/NotificationHelper.kt

+13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class NotificationHelper(private val context: Context) {
1515
private const val CHANNEL_ID = "pluvia_foreground_service"
1616
private const val CHANNEL_NAME = "Pluvia Foreground Service"
1717
private const val NOTIFICATION_ID = 1
18+
19+
const val ACTION_EXIT = "com.oxgames.pluvia.EXIT"
1820
}
1921

2022
private val notificationManager: NotificationManager =
@@ -63,6 +65,16 @@ class NotificationHelper(private val context: Context) {
6365
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
6466
)
6567

68+
val stopIntent = Intent(context, SteamService::class.java).apply {
69+
action = ACTION_EXIT
70+
}
71+
val stopPendingIntent = PendingIntent.getService(
72+
context,
73+
0,
74+
stopIntent,
75+
PendingIntent.FLAG_IMMUTABLE
76+
)
77+
6678
return NotificationCompat.Builder(context, CHANNEL_ID)
6779
.setContentTitle(context.getString(R.string.app_name))
6880
.setContentText(content)
@@ -71,6 +83,7 @@ class NotificationHelper(private val context: Context) {
7183
.setAutoCancel(false)
7284
.setOngoing(true)
7385
.setContentIntent(pendingIntent)
86+
.addAction(0, "Exit", stopPendingIntent) // 0 = no icon
7487
.build()
7588
}
7689
}

app/src/main/java/com/OxGames/Pluvia/SteamService.kt

+10
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import com.OxGames.Pluvia.enums.PathType
3737
import com.OxGames.Pluvia.enums.ReleaseState
3838
import com.OxGames.Pluvia.enums.SaveLocation
3939
import com.OxGames.Pluvia.enums.SyncResult
40+
import com.OxGames.Pluvia.events.AndroidEvent
4041
import com.OxGames.Pluvia.events.SteamEvent
4142
import com.OxGames.Pluvia.utils.FileUtils
4243
import com.OxGames.Pluvia.utils.SteamUtils
@@ -1723,6 +1724,15 @@ class SteamService : Service(), IChallengeUrlChanged {
17231724
}
17241725

17251726
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
1727+
1728+
// Notification intents
1729+
when (intent?.action) {
1730+
NotificationHelper.ACTION_EXIT -> {
1731+
PluviaApp.events.emit(AndroidEvent.EndProcess)
1732+
return START_NOT_STICKY
1733+
}
1734+
}
1735+
17261736
if (!isRunning) {
17271737
Timber.i("Using server list path: $serverListPath")
17281738

0 commit comments

Comments
 (0)