Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move start method to PlayerService #3

Merged
merged 1 commit into from
Dec 8, 2021
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
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.