Skip to content

Commit

Permalink
Renaming...
Browse files Browse the repository at this point in the history
  • Loading branch information
jeancsanchez committed Jul 20, 2018
1 parent 6335750 commit e62d074
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.example.jean.jcplayer.model.JcAudio
import com.example.jean.jcplayer.service.JcPlayerManagerListener
import com.example.jean.jcplayer.service.JcPlayerService
import com.example.jean.jcplayer.service.JcServiceConnection
import com.example.jean.jcplayer.service.notification.JcNotificationService
import com.example.jean.jcplayer.service.notification.JcNotificationPlayer
import java.lang.ref.WeakReference
import java.util.*

Expand All @@ -21,7 +21,7 @@ import java.util.*
class JcPlayerManager private constructor(private val serviceConnection: JcServiceConnection) {

lateinit var context: Context
private var jcNotificationPlayerService: JcNotificationService? = null
private var jcNotificationPlayer: JcNotificationPlayer? = null
private var jcPlayerService: JcPlayerService? = null
private var serviceBound = false
var playlist: ArrayList<JcAudio> = ArrayList()
Expand Down Expand Up @@ -270,10 +270,10 @@ class JcPlayerManager private constructor(private val serviceConnection: JcServi
* @param iconResource The icon resource path.
*/
fun createNewNotification(iconResource: Int) {
jcNotificationPlayerService
jcNotificationPlayer
?.createNotificationPlayer(currentAudio?.title, iconResource)
?: let {
jcNotificationPlayerService = JcNotificationService
jcNotificationPlayer = JcNotificationPlayer
.getInstance(context)
.get()
.also { jcPlayerManagerListener = it }
Expand All @@ -286,10 +286,10 @@ class JcPlayerManager private constructor(private val serviceConnection: JcServi
* Updates the current notification
*/
fun updateNotification() {
jcNotificationPlayerService
jcNotificationPlayer
?.updateNotification()
?: let {
jcNotificationPlayerService = JcNotificationService
jcNotificationPlayer = JcNotificationPlayer
.getInstance(context)
.get()
.also { jcPlayerManagerListener = it }
Expand Down Expand Up @@ -375,11 +375,11 @@ class JcPlayerManager private constructor(private val serviceConnection: JcServi
fun kill() {
jcPlayerService?.let {
it.stop()
it.destroy()
it.onDestroy()
}

serviceConnection.disconnect()
jcNotificationPlayerService?.destroyNotificationIfExists()
jcNotificationPlayer?.destroyNotificationIfExists()
managerListeners.clear()
INSTANCE = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class JcPlayerService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.O
}
}

fun destroy() {
override fun onDestroy() {
stop()
stopSelf()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.content.Intent
import android.content.ServiceConnection
import android.os.IBinder
import com.example.jean.jcplayer.model.JcAudio
import com.example.jean.jcplayer.service.notification.JcNotificationService
import com.example.jean.jcplayer.service.notification.JcNotificationPlayer
import java.io.Serializable

/**
Expand Down Expand Up @@ -45,8 +45,8 @@ class JcServiceConnection(private val context: Context) : ServiceConnection {

if (serviceBound.not()) {
val intent = Intent(context.applicationContext, JcPlayerService::class.java)
intent.putExtra(JcNotificationService.PLAYLIST, playlist as Serializable?)
intent.putExtra(JcNotificationService.CURRENT_AUDIO, currentAudio)
intent.putExtra(JcNotificationPlayer.PLAYLIST, playlist as Serializable?)
intent.putExtra(JcNotificationPlayer.CURRENT_AUDIO, currentAudio)
context.bindService(intent, this, Context.BIND_AUTO_CREATE)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import java.lang.ref.WeakReference
* @date 12/07/16.
* Jesus loves you.
*/
class JcNotificationService private constructor(private val context: Context) : JcPlayerManagerListener {
class JcNotificationPlayer private constructor(private val context: Context) : JcPlayerManagerListener {

private var title: String? = null
private var time = "00:00"
Expand Down Expand Up @@ -54,11 +54,11 @@ class JcNotificationService private constructor(private val context: Context) :


@Volatile
private var INSTANCE: WeakReference<JcNotificationService>? = null
private var INSTANCE: WeakReference<JcNotificationPlayer>? = null

@JvmStatic
fun getInstance(context: Context): WeakReference<JcNotificationService> = INSTANCE ?: let {
INSTANCE = WeakReference(JcNotificationService(context))
fun getInstance(context: Context): WeakReference<JcNotificationPlayer> = INSTANCE ?: let {
INSTANCE = WeakReference(JcNotificationPlayer(context))
INSTANCE!!
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ class JcPlayerNotificationReceiver : BroadcastReceiver() {
val jcPlayerManager = JcPlayerManager.getInstance(context)
var action = ""

if (intent.hasExtra(JcNotificationService.ACTION)) {
action = intent.getStringExtra(JcNotificationService.ACTION)
if (intent.hasExtra(JcNotificationPlayer.ACTION)) {
action = intent.getStringExtra(JcNotificationPlayer.ACTION)
}

when (action) {
JcNotificationService.PLAY -> try {
JcNotificationPlayer.PLAY -> try {
jcPlayerManager.get()?.continueAudio()
jcPlayerManager.get()?.updateNotification()
} catch (e: Exception) {
e.printStackTrace()
}

JcNotificationService.PAUSE -> try {
JcNotificationPlayer.PAUSE -> try {
jcPlayerManager.get()?.pauseAudio()
jcPlayerManager.get()?.updateNotification()
} catch (e: Exception) {
e.printStackTrace()
}

JcNotificationService.NEXT -> try {
JcNotificationPlayer.NEXT -> try {
jcPlayerManager.get()?.nextAudio()
} catch (e: AudioListNullPointerException) {
try {
Expand All @@ -42,7 +42,7 @@ class JcPlayerNotificationReceiver : BroadcastReceiver() {

}

JcNotificationService.PREVIOUS -> try {
JcNotificationPlayer.PREVIOUS -> try {
jcPlayerManager.get()?.previousAudio()
} catch (e: Exception) {
try {
Expand Down

0 comments on commit e62d074

Please sign in to comment.