Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Reef/src/main/java/dev/pranav/reef/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,9 @@ class MainActivity: ComponentActivity() {
}
}
}
startForegroundService(Intent(this, FocusModeService::class.java))
startForegroundService(Intent(this, FocusModeService::class.java).apply {
action = FocusModeService.ACTION_START
})
}

private fun pauseFocusMode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.content.pm.ServiceInfo
import android.os.Build
import android.os.CountDownTimer
import android.os.IBinder
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.ServiceCompat
Expand All @@ -34,6 +35,7 @@ class FocusModeService: Service() {
private const val BREAK_ALERT_NOTIFICATION_ID = 2
private const val COMPLETE_NOTIFICATION_ID = 3
const val ACTION_TIMER_UPDATED = "dev.pranav.reef.TIMER_UPDATED"
const val ACTION_START = "dev.pranav.reef.START_TIMER"
const val ACTION_PAUSE = "dev.pranav.reef.PAUSE_TIMER"
const val ACTION_RESUME = "dev.pranav.reef.RESUME_TIMER"
const val ACTION_RESTART = "dev.pranav.reef.RESTART_TIMER"
Expand All @@ -43,7 +45,6 @@ class FocusModeService: Service() {

private val notificationManager by lazy { NotificationManagerCompat.from(this) }
private val systemNotificationManager by lazy { getSystemService(NOTIFICATION_SERVICE) as NotificationManager }

private var countDownTimer: CountDownTimer? = null
private var notificationBuilder: NotificationCompat.Builder? = null
private var previousInterruptionFilter: Int? = null
Expand Down Expand Up @@ -79,21 +80,21 @@ class FocusModeService: Service() {
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val isFocusActive = prefs.getBoolean("focus_mode", false)

if (!isFocusActive && intent?.action == null) {
stopSelf()
if (intent?.action == null) {
return START_NOT_STICKY
}

promoteToForeground()
if (intent.action != ACTION_PAUSE) {
promoteToForeground()
}

when (intent?.action) {
when (intent.action) {
ACTION_PAUSE -> pauseTimer()
ACTION_RESUME -> resumeTimer()
ACTION_RESTART -> restartCurrentPhase()
else -> startTimer()
ACTION_START -> startTimer()
}

return START_STICKY
}

Expand Down