From e62d074da077286acec0971415d6324278203bf1 Mon Sep 17 00:00:00 2001 From: jean Date: Fri, 20 Jul 2018 15:09:55 -0300 Subject: [PATCH] Renaming... --- .../com/example/jean/jcplayer/JcPlayerManager.kt | 16 ++++++++-------- .../jean/jcplayer/service/JcPlayerService.kt | 2 +- .../jean/jcplayer/service/JcServiceConnection.kt | 6 +++--- ...icationService.kt => JcNotificationPlayer.kt} | 8 ++++---- .../notification/JcPlayerNotificationReceiver.kt | 12 ++++++------ 5 files changed, 22 insertions(+), 22 deletions(-) rename jcplayer/src/main/java/com/example/jean/jcplayer/service/notification/{JcNotificationService.kt => JcNotificationPlayer.kt} (95%) diff --git a/jcplayer/src/main/java/com/example/jean/jcplayer/JcPlayerManager.kt b/jcplayer/src/main/java/com/example/jean/jcplayer/JcPlayerManager.kt index 63b0e83..ee59937 100755 --- a/jcplayer/src/main/java/com/example/jean/jcplayer/JcPlayerManager.kt +++ b/jcplayer/src/main/java/com/example/jean/jcplayer/JcPlayerManager.kt @@ -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.* @@ -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 = ArrayList() @@ -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 } @@ -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 } @@ -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 } diff --git a/jcplayer/src/main/java/com/example/jean/jcplayer/service/JcPlayerService.kt b/jcplayer/src/main/java/com/example/jean/jcplayer/service/JcPlayerService.kt index 1028b9f..ccfb5e5 100755 --- a/jcplayer/src/main/java/com/example/jean/jcplayer/service/JcPlayerService.kt +++ b/jcplayer/src/main/java/com/example/jean/jcplayer/service/JcPlayerService.kt @@ -283,7 +283,7 @@ class JcPlayerService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.O } } - fun destroy() { + override fun onDestroy() { stop() stopSelf() } diff --git a/jcplayer/src/main/java/com/example/jean/jcplayer/service/JcServiceConnection.kt b/jcplayer/src/main/java/com/example/jean/jcplayer/service/JcServiceConnection.kt index 7bf1bed..588674b 100644 --- a/jcplayer/src/main/java/com/example/jean/jcplayer/service/JcServiceConnection.kt +++ b/jcplayer/src/main/java/com/example/jean/jcplayer/service/JcServiceConnection.kt @@ -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 /** @@ -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) } } diff --git a/jcplayer/src/main/java/com/example/jean/jcplayer/service/notification/JcNotificationService.kt b/jcplayer/src/main/java/com/example/jean/jcplayer/service/notification/JcNotificationPlayer.kt similarity index 95% rename from jcplayer/src/main/java/com/example/jean/jcplayer/service/notification/JcNotificationService.kt rename to jcplayer/src/main/java/com/example/jean/jcplayer/service/notification/JcNotificationPlayer.kt index 4842846..874f6e8 100755 --- a/jcplayer/src/main/java/com/example/jean/jcplayer/service/notification/JcNotificationService.kt +++ b/jcplayer/src/main/java/com/example/jean/jcplayer/service/notification/JcNotificationPlayer.kt @@ -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" @@ -54,11 +54,11 @@ class JcNotificationService private constructor(private val context: Context) : @Volatile - private var INSTANCE: WeakReference? = null + private var INSTANCE: WeakReference? = null @JvmStatic - fun getInstance(context: Context): WeakReference = INSTANCE ?: let { - INSTANCE = WeakReference(JcNotificationService(context)) + fun getInstance(context: Context): WeakReference = INSTANCE ?: let { + INSTANCE = WeakReference(JcNotificationPlayer(context)) INSTANCE!! } } diff --git a/jcplayer/src/main/java/com/example/jean/jcplayer/service/notification/JcPlayerNotificationReceiver.kt b/jcplayer/src/main/java/com/example/jean/jcplayer/service/notification/JcPlayerNotificationReceiver.kt index 8705c0d..b376073 100755 --- a/jcplayer/src/main/java/com/example/jean/jcplayer/service/notification/JcPlayerNotificationReceiver.kt +++ b/jcplayer/src/main/java/com/example/jean/jcplayer/service/notification/JcPlayerNotificationReceiver.kt @@ -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 { @@ -42,7 +42,7 @@ class JcPlayerNotificationReceiver : BroadcastReceiver() { } - JcNotificationService.PREVIOUS -> try { + JcNotificationPlayer.PREVIOUS -> try { jcPlayerManager.get()?.previousAudio() } catch (e: Exception) { try {