-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
197 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.maary.liveinpeace | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Notification | ||
import android.content.Context | ||
import android.os.Handler | ||
import android.os.Looper | ||
import android.util.Log | ||
import androidx.core.app.NotificationCompat | ||
import androidx.core.app.NotificationManagerCompat | ||
|
||
class DeviceTimer(private val context: Context, private val deviceName: String) { | ||
private val handler = Handler(Looper.getMainLooper()) | ||
|
||
@SuppressLint("MissingPermission") | ||
private val runnable = Runnable { | ||
with(NotificationManagerCompat.from(context)) { | ||
notify(Constants.ID_NOTIFICATION_ALERT, createTimerNotification(context = context, deviceName = deviceName)) | ||
} | ||
} | ||
|
||
fun start() { | ||
handler.postDelayed(runnable, Constants.ALERT_TIME) | ||
Log.v("MUTE_TIMER", "TIMER_STARTED") | ||
} | ||
|
||
fun stop() { | ||
handler.removeCallbacks(runnable) | ||
|
||
} | ||
|
||
private fun createTimerNotification(context: Context, deviceName: String) : Notification { | ||
return NotificationCompat.Builder(context, Constants.CHANNEL_ID_ALERT) | ||
.setContentTitle(context.getString(R.string.alert)) | ||
.setContentText(String.format( | ||
context.resources.getString(R.string.device_connected_too_long), | ||
deviceName | ||
)) | ||
.setSmallIcon(R.drawable.ic_headphone) | ||
.setPriority(NotificationCompat.PRIORITY_HIGH) | ||
.setAutoCancel(true) | ||
.setGroupSummary(false) | ||
.setGroup(Constants.ID_NOTIFICATION_GROUP_ALERTS) | ||
.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.