PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt

100 lines
2.8 KiB
Kotlin
Raw Normal View History

2020-10-06 08:46:04 +00:00
/*
* Copyright (c) 2020 Hemanth Savarla.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*/
2019-04-20 05:29:45 +00:00
package code.name.monkey.retromusic.fragments.base
2018-11-30 01:06:16 +00:00
import android.content.Context
import android.os.Bundle
import android.view.View
import androidx.annotation.LayoutRes
2018-11-30 01:06:16 +00:00
import androidx.fragment.app.Fragment
2020-08-11 21:31:09 +00:00
import androidx.navigation.navOptions
import code.name.monkey.retromusic.R
2019-04-20 05:29:45 +00:00
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
import code.name.monkey.retromusic.interfaces.IMusicServiceEventListener
2018-11-30 01:06:16 +00:00
/**
* Created by hemanths on 18/08/17.
*/
open class AbsMusicServiceFragment(@LayoutRes layout: Int) : Fragment(layout),
IMusicServiceEventListener {
2020-08-13 17:48:49 +00:00
2020-08-11 21:31:09 +00:00
val navOptions by lazy {
navOptions {
2020-08-13 17:48:49 +00:00
launchSingleTop = false
2020-08-11 21:31:09 +00:00
anim {
enter = R.anim.retro_fragment_open_enter
exit = R.anim.retro_fragment_open_exit
popEnter = R.anim.retro_fragment_close_enter
popExit = R.anim.retro_fragment_close_exit
}
}
}
2020-08-13 17:48:49 +00:00
var serviceActivity: AbsMusicServiceActivity? = null
2018-11-30 01:06:16 +00:00
private set
2019-03-25 12:43:43 +00:00
override fun onAttach(context: Context) {
2018-11-30 01:06:16 +00:00
super.onAttach(context)
try {
serviceActivity = context as AbsMusicServiceActivity?
2018-11-30 01:06:16 +00:00
} catch (e: ClassCastException) {
2019-03-25 12:43:43 +00:00
throw RuntimeException(context.javaClass.simpleName + " must be an instance of " + AbsMusicServiceActivity::class.java.simpleName)
2018-11-30 01:06:16 +00:00
}
}
override fun onDetach() {
super.onDetach()
serviceActivity = null
2018-11-30 01:06:16 +00:00
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
serviceActivity?.addMusicServiceEventListener(this)
2018-11-30 01:06:16 +00:00
}
override fun onDestroyView() {
super.onDestroyView()
serviceActivity?.removeMusicServiceEventListener(this)
2018-11-30 01:06:16 +00:00
}
override fun onFavoriteStateChanged() {
}
2018-11-30 01:06:16 +00:00
override fun onPlayingMetaChanged() {
}
override fun onServiceConnected() {
}
override fun onServiceDisconnected() {
}
override fun onQueueChanged() {
}
override fun onPlayStateChanged() {
}
override fun onRepeatModeChanged() {
}
override fun onShuffleModeChanged() {
}
override fun onMediaStoreChanged() {
2020-01-06 03:12:32 +00:00
}
2018-11-30 01:06:16 +00:00
}