Skip to content

Commit

Permalink
new code
Browse files Browse the repository at this point in the history
  • Loading branch information
devrath committed Jan 5, 2024
1 parent d269b49 commit 7874e30
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,26 @@ object NotificationModule {
fun provideNotificationBuilder(
@ApplicationContext context: Context
): NotificationCompat.Builder {

val resource = context.resources
// -------------> Strings
val title = resource.getString(R.string.app_name)
val strStop = resource.getString(R.string.str_stop)
val strCancel = resource.getString(R.string.str_cancel)
val strCounter = resource.getString(R.string.counter_initial_text)
// -------------> Intents
val stopIntent = ServiceHelper.stopPendingIntent(context)
val cancelIntent = ServiceHelper.cancelPendingIntent(context)
val clickActionIntent = ServiceHelper.clickPendingIntent(context)

return NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setContentTitle("Stopwatch")
.setContentText("00:00:00")
.setContentTitle(title)
.setContentText(strCounter)
.setSmallIcon(R.drawable.ic_baseline_timer_24)
.setOngoing(true)
.addAction(0, "Stop", ServiceHelper.stopPendingIntent(context))
.addAction(0, "Cancel", ServiceHelper.cancelPendingIntent(context))
.setContentIntent(ServiceHelper.clickPendingIntent(context))
.addAction(0, strStop, stopIntent)
.addAction(0, strCancel,cancelIntent)
.setContentIntent(clickActionIntent)
}

@ServiceScoped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.os.Build
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.runtime.mutableStateOf
import androidx.core.app.NotificationCompat
import com.istudio.app.R
import com.istudio.app.util.Constants.ACTION_SERVICE_CANCEL
import com.istudio.app.util.Constants.ACTION_SERVICE_START
import com.istudio.app.util.Constants.ACTION_SERVICE_STOP
Expand Down Expand Up @@ -178,7 +179,7 @@ class StopwatchService : Service() {

private fun setStopButton() {
val index = 0
val title = "Stop"
val title = baseContext.resources.getString(R.string.str_stop)
val intent = ServiceHelper.stopPendingIntent(baseContext)
val notification = NotificationCompat.Action(0, title,intent)

Expand All @@ -189,9 +190,8 @@ class StopwatchService : Service() {


private fun setResumeButton() {

val index = 0
val title = "Resume"
val title = baseContext.resources.getString(R.string.str_resume)
val intent = ServiceHelper.resumePendingIntent(baseContext)
val notification = NotificationCompat.Action(0, title,intent)

Expand Down
7 changes: 6 additions & 1 deletion Code/StopwatchServiceApp/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<resources>
<string name="app_name">StopWatchServiceApp</string>
<string name="app_name">ForegroundServiceApp</string>
<string name="counter_initial_text">00:00:00</string>
<string name="str_start">Start</string>
<string name="str_stop">Stop</string>
<string name="str_cancel">Cancel</string>
<string name="str_resume">Resume</string>
</resources>
2 changes: 1 addition & 1 deletion Code/StopwatchServiceApp/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ dependencyResolutionManagement {
}
}

rootProject.name = "StopWatchServiceApp"
rootProject.name = "ForegroundServiceApp"
include(":app")

0 comments on commit 7874e30

Please sign in to comment.