Skip to content

Commit

Permalink
refactor: move start method to PlayerService
Browse files Browse the repository at this point in the history
  • Loading branch information
j-m-hoffmann committed Dec 4, 2021
1 parent 3b5b741 commit b1bd45b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.cliambrown.easynoise
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import com.cliambrown.easynoise.helpers.*

class NotificationReceiver : BroadcastReceiver() {
Expand All @@ -14,6 +13,6 @@ class NotificationReceiver : BroadcastReceiver() {
if (!actions.contains(action) || action == null) {
return
}
Util.startPlayerService(context, action)
PlayerService.start(context, action)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class OutsidePauseReceiver : BroadcastReceiver() {
}

if (playerAction != null) {
Util.startPlayerService(context, playerAction)
PlayerService.start(context, playerAction)
}
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/com/cliambrown/easynoise/PlayerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.cliambrown.easynoise

import android.app.Activity
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.SharedPreferences
import android.media.AudioAttributes
import android.media.AudioManager
import android.media.SoundPool
import android.os.Binder
import android.os.Build
import android.os.IBinder
import com.cliambrown.easynoise.helpers.*
import android.widget.Toast
Expand Down Expand Up @@ -272,4 +274,14 @@ class PlayerService : Service(), SoundPool.OnLoadCompleteListener {
}
if (tempIsPlaying) play(false)
}

companion object {
fun start(context: Context, action: String): Boolean {
Intent(context, PlayerService::class.java).setAction(action).run {
if (Build.VERSION.SDK_INT < 26) context.startService(this)
else context.startForegroundService(this)
}
return true
}
}
}
22 changes: 0 additions & 22 deletions app/src/main/java/com/cliambrown/easynoise/helpers/Util.kt

This file was deleted.

0 comments on commit b1bd45b

Please sign in to comment.