Added Dagger
This commit is contained in:
parent
074298dcb0
commit
6cdea14316
47 changed files with 1130 additions and 826 deletions
|
@ -75,7 +75,9 @@ android {
|
||||||
androidExtensions {
|
androidExtensions {
|
||||||
experimental = true
|
experimental = true
|
||||||
}
|
}
|
||||||
|
kapt {
|
||||||
|
generateStubs = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getProperties(String fileName) {
|
def getProperties(String fileName) {
|
||||||
|
@ -150,6 +152,9 @@ dependencies {
|
||||||
implementation 'com.r0adkll:slidableactivity:2.1.0'
|
implementation 'com.r0adkll:slidableactivity:2.1.0'
|
||||||
implementation 'com.heinrichreimersoftware:material-intro:1.6'
|
implementation 'com.heinrichreimersoftware:material-intro:1.6'
|
||||||
|
|
||||||
|
implementation 'com.google.dagger:dagger:2.23.1'
|
||||||
|
kapt 'com.google.dagger:dagger-compiler:2.23.1'
|
||||||
|
|
||||||
implementation project(':appthemehelper')
|
implementation project(':appthemehelper')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,9 @@ import androidx.multidex.MultiDexApplication
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||||
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
|
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
|
||||||
|
import code.name.monkey.retromusic.dagger.DaggerMusicComponent
|
||||||
|
import code.name.monkey.retromusic.dagger.MusicComponent
|
||||||
|
import code.name.monkey.retromusic.dagger.module.AppModule
|
||||||
import com.anjlab.android.iab.v3.BillingProcessor
|
import com.anjlab.android.iab.v3.BillingProcessor
|
||||||
import com.anjlab.android.iab.v3.TransactionDetails
|
import com.anjlab.android.iab.v3.TransactionDetails
|
||||||
|
|
||||||
|
@ -32,6 +35,11 @@ class App : MultiDexApplication() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
instance = this
|
instance = this
|
||||||
|
|
||||||
|
|
||||||
|
musicComponent = DaggerMusicComponent.builder()
|
||||||
|
.appModule(AppModule(this))
|
||||||
|
.build()
|
||||||
|
|
||||||
// default theme
|
// default theme
|
||||||
if (!ThemeStore.isConfigured(this, 3)) {
|
if (!ThemeStore.isConfigured(this, 3)) {
|
||||||
ThemeStore.editTheme(this)
|
ThemeStore.editTheme(this)
|
||||||
|
@ -65,6 +73,9 @@ class App : MultiDexApplication() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
|
||||||
|
lateinit var musicComponent: MusicComponent
|
||||||
|
|
||||||
const val PRO_VERSION_PRODUCT_ID = "pro_version"
|
const val PRO_VERSION_PRODUCT_ID = "pro_version"
|
||||||
|
|
||||||
lateinit var instance: App
|
lateinit var instance: App
|
||||||
|
|
|
@ -18,6 +18,7 @@ import code.name.monkey.appthemehelper.util.ATHUtil
|
||||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||||
|
import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
||||||
import code.name.monkey.retromusic.activities.tageditor.AbsTagEditorActivity
|
import code.name.monkey.retromusic.activities.tageditor.AbsTagEditorActivity
|
||||||
|
@ -26,6 +27,7 @@ import code.name.monkey.retromusic.adapter.album.HorizontalAlbumAdapter
|
||||||
import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter
|
import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter
|
||||||
import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog
|
import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog
|
||||||
import code.name.monkey.retromusic.dialogs.DeleteSongsDialog
|
import code.name.monkey.retromusic.dialogs.DeleteSongsDialog
|
||||||
|
import code.name.monkey.retromusic.extensions.show
|
||||||
import code.name.monkey.retromusic.glide.GlideApp
|
import code.name.monkey.retromusic.glide.GlideApp
|
||||||
import code.name.monkey.retromusic.glide.RetroGlideExtension
|
import code.name.monkey.retromusic.glide.RetroGlideExtension
|
||||||
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
|
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
|
||||||
|
@ -34,8 +36,9 @@ import code.name.monkey.retromusic.helper.SortOrder.AlbumSongSortOrder
|
||||||
import code.name.monkey.retromusic.loaders.ArtistLoader
|
import code.name.monkey.retromusic.loaders.ArtistLoader
|
||||||
import code.name.monkey.retromusic.misc.AppBarStateChangeListener
|
import code.name.monkey.retromusic.misc.AppBarStateChangeListener
|
||||||
import code.name.monkey.retromusic.model.Album
|
import code.name.monkey.retromusic.model.Album
|
||||||
import code.name.monkey.retromusic.mvp.contract.AlbumDetailsContract
|
import code.name.monkey.retromusic.model.Artist
|
||||||
import code.name.monkey.retromusic.mvp.presenter.AlbumDetailsPresenter
|
import code.name.monkey.retromusic.mvp.presenter.AlbumDetailsPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.AlbumDetailsView
|
||||||
import code.name.monkey.retromusic.util.MusicUtil
|
import code.name.monkey.retromusic.util.MusicUtil
|
||||||
import code.name.monkey.retromusic.util.NavigationUtil
|
import code.name.monkey.retromusic.util.NavigationUtil
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
|
@ -45,10 +48,10 @@ import io.reactivex.disposables.CompositeDisposable
|
||||||
import kotlinx.android.synthetic.main.activity_album.*
|
import kotlinx.android.synthetic.main.activity_album.*
|
||||||
import kotlinx.android.synthetic.main.activity_album_content.*
|
import kotlinx.android.synthetic.main.activity_album_content.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContract.AlbumDetailsView {
|
class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView {
|
||||||
|
|
||||||
private lateinit var albumDetailsPresenter: AlbumDetailsPresenter
|
|
||||||
private lateinit var simpleSongAdapter: SimpleSongAdapter
|
private lateinit var simpleSongAdapter: SimpleSongAdapter
|
||||||
private var disposable = CompositeDisposable()
|
private var disposable = CompositeDisposable()
|
||||||
|
|
||||||
|
@ -67,6 +70,9 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac
|
||||||
window.enterTransition = slide
|
window.enterTransition = slide
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var albumDetailsPresenter: AlbumDetailsPresenter
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
setDrawUnderStatusBar()
|
setDrawUnderStatusBar()
|
||||||
setupWindowTransition()
|
setupWindowTransition()
|
||||||
|
@ -81,10 +87,6 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac
|
||||||
|
|
||||||
artistImage = findViewById(R.id.artistImage)
|
artistImage = findViewById(R.id.artistImage)
|
||||||
|
|
||||||
val albumId = intent.getIntExtra(EXTRA_ALBUM_ID, -1)
|
|
||||||
albumDetailsPresenter = AlbumDetailsPresenter(this, albumId)
|
|
||||||
albumDetailsPresenter.subscribe()
|
|
||||||
|
|
||||||
setupRecyclerView()
|
setupRecyclerView()
|
||||||
setupToolbarMarginHeight()
|
setupToolbarMarginHeight()
|
||||||
|
|
||||||
|
@ -98,6 +100,15 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac
|
||||||
shuffleAction.apply {
|
shuffleAction.apply {
|
||||||
setOnClickListener { MusicPlayerRemote.openAndShuffleQueue(album.songs!!, true) }
|
setOnClickListener { MusicPlayerRemote.openAndShuffleQueue(album.songs!!, true) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App.musicComponent.inject(this)
|
||||||
|
albumDetailsPresenter.attachView(this)
|
||||||
|
|
||||||
|
if (intent.extras!!.containsKey(EXTRA_ALBUM_ID)) {
|
||||||
|
albumDetailsPresenter.loadAlbum(intent.extras!!.getInt(EXTRA_ALBUM_ID))
|
||||||
|
} else {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupRecyclerView() {
|
private fun setupRecyclerView() {
|
||||||
|
@ -151,42 +162,31 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
super.onPause()
|
|
||||||
albumDetailsPresenter.unsubscribe()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
disposable.dispose()
|
disposable.dispose()
|
||||||
|
albumDetailsPresenter.detachView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loading() {
|
override fun complete() {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showEmptyView() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun completed() {
|
|
||||||
ActivityCompat.startPostponedEnterTransition(this)
|
ActivityCompat.startPostponedEnterTransition(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showData(list: Album) {
|
override fun album(album: Album) {
|
||||||
if (list.songs!!.isEmpty()) {
|
|
||||||
|
if (album.songs!!.isEmpty()) {
|
||||||
finish()
|
finish()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.album = list
|
this.album = album
|
||||||
|
|
||||||
albumTitle.text = list.title
|
albumTitle.text = album.title
|
||||||
albumText.text = String.format("%s • %s • %s", list.artistName, MusicUtil.getYearString(list.year), MusicUtil.getReadableDurationString(MusicUtil.getTotalDuration(this, list.songs)))
|
albumText.text = String.format("%s • %s • %s", album.artistName, MusicUtil.getYearString(album.year), MusicUtil.getReadableDurationString(MusicUtil.getTotalDuration(this, album.songs)))
|
||||||
|
|
||||||
loadAlbumCover()
|
loadAlbumCover()
|
||||||
loadMoreFrom(list)
|
simpleSongAdapter.swapDataSet(album.songs)
|
||||||
|
|
||||||
simpleSongAdapter.swapDataSet(list.songs)
|
albumDetailsPresenter.loadMore(album.artistId)
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var artistImage: ImageView
|
private lateinit var artistImage: ImageView
|
||||||
|
@ -194,17 +194,7 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac
|
||||||
private fun loadMoreFrom(album: Album) {
|
private fun loadMoreFrom(album: Album) {
|
||||||
disposable.add(ArtistLoader.getArtistFlowable(this, album.artistId)
|
disposable.add(ArtistLoader.getArtistFlowable(this, album.artistId)
|
||||||
.map {
|
.map {
|
||||||
GlideApp.with(this@AlbumDetailsActivity)
|
|
||||||
.asBitmapPalette()
|
|
||||||
.load(RetroGlideExtension.getArtistModel(it))
|
|
||||||
.transition(RetroGlideExtension.getDefaultTransition())
|
|
||||||
.artistOptions(it)
|
|
||||||
.dontAnimate()
|
|
||||||
.into(object : RetroMusicColoredTarget(artistImage) {
|
|
||||||
override fun onColorReady(color: Int) {
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return@map it.albums!!
|
return@map it.albums!!
|
||||||
}
|
}
|
||||||
.map { it.filter { albumSearch -> albumSearch.id != album.id } }
|
.map { it.filter { albumSearch -> albumSearch.id != album.id } }
|
||||||
|
@ -227,6 +217,30 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun moreAlbums(albums: ArrayList<Album>) {
|
||||||
|
moreTitle.show()
|
||||||
|
moreRecyclerView.show()
|
||||||
|
moreTitle.text = String.format("More from %s", album.artistName)
|
||||||
|
|
||||||
|
val albumAdapter = HorizontalAlbumAdapter(this, albums, false, null)
|
||||||
|
moreRecyclerView.layoutManager = GridLayoutManager(this, 1, GridLayoutManager.HORIZONTAL, false)
|
||||||
|
moreRecyclerView.adapter = albumAdapter
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun loadArtistImage(artist: Artist) {
|
||||||
|
GlideApp.with(this@AlbumDetailsActivity)
|
||||||
|
.asBitmapPalette()
|
||||||
|
.load(RetroGlideExtension.getArtistModel(artist))
|
||||||
|
.transition(RetroGlideExtension.getDefaultTransition())
|
||||||
|
.artistOptions(artist)
|
||||||
|
.dontAnimate()
|
||||||
|
.into(object : RetroMusicColoredTarget(artistImage) {
|
||||||
|
override fun onColorReady(color: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadAlbumCover() {
|
private fun loadAlbumCover() {
|
||||||
GlideApp.with(this)
|
GlideApp.with(this)
|
||||||
.asBitmapPalette()
|
.asBitmapPalette()
|
||||||
|
@ -238,7 +252,6 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac
|
||||||
override fun onColorReady(color: Int) {
|
override fun onColorReady(color: Int) {
|
||||||
setColors(color)
|
setColors(color)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,7 +350,7 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reload() {
|
private fun reload() {
|
||||||
albumDetailsPresenter.subscribe()
|
albumDetailsPresenter.loadAlbum(intent.extras!!.getInt(ArtistDetailActivity.EXTRA_ARTIST_ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import code.name.monkey.appthemehelper.util.ATHUtil
|
||||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||||
|
import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
||||||
import code.name.monkey.retromusic.adapter.album.AlbumAdapter
|
import code.name.monkey.retromusic.adapter.album.AlbumAdapter
|
||||||
|
@ -34,26 +35,23 @@ import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.misc.AppBarStateChangeListener
|
import code.name.monkey.retromusic.misc.AppBarStateChangeListener
|
||||||
import code.name.monkey.retromusic.model.Artist
|
import code.name.monkey.retromusic.model.Artist
|
||||||
import code.name.monkey.retromusic.mvp.contract.ArtistDetailContract
|
|
||||||
import code.name.monkey.retromusic.mvp.presenter.ArtistDetailsPresenter
|
import code.name.monkey.retromusic.mvp.presenter.ArtistDetailsPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.ArtistDetailsView
|
||||||
import code.name.monkey.retromusic.rest.LastFMRestClient
|
import code.name.monkey.retromusic.rest.LastFMRestClient
|
||||||
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
||||||
import code.name.monkey.retromusic.util.*
|
import code.name.monkey.retromusic.util.*
|
||||||
import com.google.android.material.appbar.AppBarLayout
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
import kotlinx.android.synthetic.main.activity_artist_content.*
|
import kotlinx.android.synthetic.main.activity_artist_content.*
|
||||||
import kotlinx.android.synthetic.main.activity_artist_details.*
|
import kotlinx.android.synthetic.main.activity_artist_details.*
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.Callback
|
|
||||||
import retrofit2.Response
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContract.ArtistsDetailsView {
|
class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView {
|
||||||
|
|
||||||
private var biography: Spanned? = null
|
private var biography: Spanned? = null
|
||||||
private lateinit var artist: Artist
|
private lateinit var artist: Artist
|
||||||
private var lastFMRestClient: LastFMRestClient? = null
|
private var lastFMRestClient: LastFMRestClient? = null
|
||||||
private lateinit var artistDetailsPresenter: ArtistDetailsPresenter
|
|
||||||
private lateinit var songAdapter: SimpleSongAdapter
|
private lateinit var songAdapter: SimpleSongAdapter
|
||||||
private lateinit var albumAdapter: AlbumAdapter
|
private lateinit var albumAdapter: AlbumAdapter
|
||||||
private var forceDownload: Boolean = false
|
private var forceDownload: Boolean = false
|
||||||
|
@ -68,11 +66,13 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac
|
||||||
return wrapSlidingMusicPanel(R.layout.activity_artist_details)
|
return wrapSlidingMusicPanel(R.layout.activity_artist_details)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var artistDetailsPresenter: ArtistDetailsPresenter
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
setDrawUnderStatusBar()
|
setDrawUnderStatusBar()
|
||||||
setupWindowTransitions()
|
setupWindowTransitions()
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
//collapsingToolbarLayout?.setBackgroundColor(ThemeStore.primaryColor(this))
|
|
||||||
contentContainer?.setCardBackgroundColor(ColorStateList.valueOf(ThemeStore.primaryColor(this)))
|
contentContainer?.setCardBackgroundColor(ColorStateList.valueOf(ThemeStore.primaryColor(this)))
|
||||||
toggleBottomNavigationView(true)
|
toggleBottomNavigationView(true)
|
||||||
setNavigationbarColorAuto()
|
setNavigationbarColorAuto()
|
||||||
|
@ -80,13 +80,20 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac
|
||||||
|
|
||||||
ActivityCompat.postponeEnterTransition(this)
|
ActivityCompat.postponeEnterTransition(this)
|
||||||
|
|
||||||
|
|
||||||
|
App.musicComponent.inject(this)
|
||||||
|
artistDetailsPresenter.attachView(this)
|
||||||
|
|
||||||
|
if (intent.extras!!.containsKey(EXTRA_ARTIST_ID)) {
|
||||||
|
artistDetailsPresenter.loadArtist(intent.extras!!.getInt(EXTRA_ARTIST_ID))
|
||||||
|
} else {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
lastFMRestClient = LastFMRestClient(this)
|
lastFMRestClient = LastFMRestClient(this)
|
||||||
|
|
||||||
setUpViews()
|
setUpViews()
|
||||||
|
|
||||||
artistDetailsPresenter = ArtistDetailsPresenter(this, intent.extras!!)
|
|
||||||
artistDetailsPresenter.subscribe()
|
|
||||||
|
|
||||||
playAction.apply {
|
playAction.apply {
|
||||||
setOnClickListener { MusicPlayerRemote.openQueue(artist.songs, 0, true) }
|
setOnClickListener { MusicPlayerRemote.openQueue(artist.songs, 0, true) }
|
||||||
}
|
}
|
||||||
|
@ -110,10 +117,10 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupContainerHeight() {
|
private fun setupContainerHeight() {
|
||||||
if (imageContainer != null) {
|
imageContainer?.let {
|
||||||
val params = imageContainer!!.layoutParams
|
val params = it.layoutParams
|
||||||
params.width = DensityUtil.getScreenHeight(this) / 2
|
params.width = DensityUtil.getScreenHeight(this) / 2
|
||||||
imageContainer!!.layoutParams = params
|
it.layoutParams = params
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +135,7 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac
|
||||||
toolbar?.setNavigationIcon(R.drawable.ic_keyboard_backspace_black_24dp)
|
toolbar?.setNavigationIcon(R.drawable.ic_keyboard_backspace_black_24dp)
|
||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
|
|
||||||
supportActionBar!!.title = null
|
supportActionBar?.title = null
|
||||||
|
|
||||||
if (toolbar != null && !PreferenceUtil.getInstance().fullScreenMode) {
|
if (toolbar != null && !PreferenceUtil.getInstance().fullScreenMode) {
|
||||||
val params = toolbar!!.layoutParams as ViewGroup.MarginLayoutParams
|
val params = toolbar!!.layoutParams as ViewGroup.MarginLayoutParams
|
||||||
|
@ -183,23 +190,16 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
super.onPause()
|
|
||||||
artistDetailsPresenter.unsubscribe()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun loading() {}
|
|
||||||
|
|
||||||
override fun showEmptyView() {
|
override fun showEmptyView() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun completed() {
|
override fun complete() {
|
||||||
ActivityCompat.startPostponedEnterTransition(this)
|
ActivityCompat.startPostponedEnterTransition(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showData(list: Artist) {
|
override fun artist(artist: Artist) {
|
||||||
setArtist(list)
|
setArtist(artist)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getArtist(): Artist {
|
private fun getArtist(): Artist {
|
||||||
|
@ -214,11 +214,12 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac
|
||||||
loadArtistImage()
|
loadArtistImage()
|
||||||
|
|
||||||
if (RetroUtil.isAllowedToDownloadMetadata(this)) {
|
if (RetroUtil.isAllowedToDownloadMetadata(this)) {
|
||||||
loadBiography()
|
loadBiography(artist.name)
|
||||||
}
|
}
|
||||||
artistTitle.text = artist.name
|
artistTitle.text = artist.name
|
||||||
text.text = String.format("%s • %s", MusicUtil.getArtistInfoString(this, artist), MusicUtil
|
text.text = String.format("%s • %s", MusicUtil.getArtistInfoString(this, artist), MusicUtil
|
||||||
.getReadableDurationString(MusicUtil.getTotalDuration(this, artist.songs)))
|
.getReadableDurationString(MusicUtil.getTotalDuration(this, artist.songs)))
|
||||||
|
|
||||||
//val songs = artist.songs.sortedWith(compareBy { it.title }) as ArrayList<Song>
|
//val songs = artist.songs.sortedWith(compareBy { it.title }) as ArrayList<Song>
|
||||||
songAdapter.swapDataSet(artist.songs)
|
songAdapter.swapDataSet(artist.songs)
|
||||||
|
|
||||||
|
@ -226,43 +227,35 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac
|
||||||
albumAdapter.swapDataSet(artist.albums!!)
|
albumAdapter.swapDataSet(artist.albums!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadBiography(lang: String? = Locale.getDefault().language) {
|
private fun loadBiography(name: String,
|
||||||
|
lang: String? = Locale.getDefault().language) {
|
||||||
biography = null
|
biography = null
|
||||||
|
this.lang = lang
|
||||||
lastFMRestClient!!.apiService
|
artistDetailsPresenter.loadBiography(name, lang, null)
|
||||||
.getArtistInfo(getArtist().name, lang, null)
|
|
||||||
.enqueue(object : Callback<LastFmArtist> {
|
|
||||||
override fun onResponse(call: Call<LastFmArtist>,
|
|
||||||
response: Response<LastFmArtist>) {
|
|
||||||
val lastFmArtist = response.body()
|
|
||||||
if (lastFmArtist != null && lastFmArtist.artist != null) {
|
|
||||||
val bioContent = lastFmArtist.artist.bio.content
|
|
||||||
if (bioContent != null && !bioContent.trim { it <= ' ' }.isEmpty()) {
|
|
||||||
//TransitionManager.beginDelayedTransition(titleContainer);
|
|
||||||
biographyText.visibility = View.VISIBLE
|
|
||||||
biographyTitle.visibility = View.VISIBLE
|
|
||||||
biography = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
Html.fromHtml(bioContent, Html.FROM_HTML_MODE_LEGACY)
|
|
||||||
} else {
|
|
||||||
Html.fromHtml(bioContent)
|
|
||||||
}
|
|
||||||
biographyText.text = biography
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the "lang" parameter is set and no biography is given, retry with default language
|
|
||||||
if (biography == null && lang != null) {
|
|
||||||
loadBiography(null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(call: Call<LastFmArtist>, t: Throwable) {
|
|
||||||
t.printStackTrace()
|
|
||||||
biography = null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun artistInfo(lastFmArtist: LastFmArtist?) {
|
||||||
|
if (lastFmArtist != null && lastFmArtist.artist != null) {
|
||||||
|
val bioContent = lastFmArtist.artist.bio.content
|
||||||
|
if (bioContent != null && bioContent.trim { it <= ' ' }.isNotEmpty()) {
|
||||||
|
biographyText.visibility = View.VISIBLE
|
||||||
|
biographyTitle.visibility = View.VISIBLE
|
||||||
|
biography = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
Html.fromHtml(bioContent, Html.FROM_HTML_MODE_LEGACY)
|
||||||
|
} else {
|
||||||
|
Html.fromHtml(bioContent)
|
||||||
|
}
|
||||||
|
biographyText.text = biography
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the "lang" parameter is set and no biography is given, retry with default language
|
||||||
|
if (biography == null && lang != null) {
|
||||||
|
loadBiography(getArtist().name, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var lang: String? = null
|
||||||
|
|
||||||
private fun loadArtistImage() {
|
private fun loadArtistImage() {
|
||||||
GlideApp.with(this)
|
GlideApp.with(this)
|
||||||
|
@ -281,7 +274,7 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac
|
||||||
setColors(defaultFooterColor)
|
setColors(defaultFooterColor)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
forceDownload = false;
|
forceDownload = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setColors(color: Int) {
|
private fun setColors(color: Int) {
|
||||||
|
@ -351,8 +344,7 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reload() {
|
private fun reload() {
|
||||||
artistDetailsPresenter.unsubscribe()
|
artistDetailsPresenter.loadArtist(intent.extras!!.getInt(EXTRA_ARTIST_ID))
|
||||||
artistDetailsPresenter.subscribe()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -10,31 +10,34 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||||
|
import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
||||||
import code.name.monkey.retromusic.adapter.song.ShuffleButtonSongAdapter
|
import code.name.monkey.retromusic.adapter.song.ShuffleButtonSongAdapter
|
||||||
import code.name.monkey.retromusic.adapter.song.SongAdapter
|
|
||||||
import code.name.monkey.retromusic.extensions.applyToolbar
|
import code.name.monkey.retromusic.extensions.applyToolbar
|
||||||
import code.name.monkey.retromusic.helper.menu.GenreMenuHelper
|
import code.name.monkey.retromusic.helper.menu.GenreMenuHelper
|
||||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||||
import code.name.monkey.retromusic.model.Genre
|
import code.name.monkey.retromusic.model.Genre
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.mvp.contract.GenreDetailsContract
|
|
||||||
import code.name.monkey.retromusic.mvp.presenter.GenreDetailsPresenter
|
import code.name.monkey.retromusic.mvp.presenter.GenreDetailsPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.GenreDetailsView
|
||||||
import code.name.monkey.retromusic.util.RetroColorUtil
|
import code.name.monkey.retromusic.util.RetroColorUtil
|
||||||
import code.name.monkey.retromusic.util.ViewUtil
|
import code.name.monkey.retromusic.util.ViewUtil
|
||||||
import com.afollestad.materialcab.MaterialCab
|
import com.afollestad.materialcab.MaterialCab
|
||||||
import kotlinx.android.synthetic.main.activity_playlist_detail.*
|
import kotlinx.android.synthetic.main.activity_playlist_detail.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hemanth S (h4h13).
|
* @author Hemanth S (h4h13).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), GenreDetailsContract.GenreDetailsView, CabHolder {
|
class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), CabHolder, GenreDetailsView {
|
||||||
|
|
||||||
private var genre: Genre? = null
|
@Inject
|
||||||
private var presenter: GenreDetailsPresenter? = null
|
lateinit var genreDetailsPresenter: GenreDetailsPresenter
|
||||||
|
|
||||||
|
private lateinit var genre: Genre
|
||||||
private lateinit var songAdapter: ShuffleButtonSongAdapter
|
private lateinit var songAdapter: ShuffleButtonSongAdapter
|
||||||
private var cab: MaterialCab? = null
|
private var cab: MaterialCab? = null
|
||||||
|
|
||||||
|
@ -53,49 +56,45 @@ class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), GenreDetailsContrac
|
||||||
setLightStatusbar(ColorUtil.isColorLight(ThemeStore.primaryColor(this)))
|
setLightStatusbar(ColorUtil.isColorLight(ThemeStore.primaryColor(this)))
|
||||||
toggleBottomNavigationView(true)
|
toggleBottomNavigationView(true)
|
||||||
|
|
||||||
genre = intent?.extras?.getParcelable(EXTRA_GENRE_ID)
|
if (intent.extras != null) {
|
||||||
presenter = genre?.id?.let { GenreDetailsPresenter(this, it) }
|
genre = intent?.extras?.getParcelable(EXTRA_GENRE_ID)!!
|
||||||
|
} else {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
setUpToolBar()
|
setUpToolBar()
|
||||||
setupRecyclerView()
|
setupRecyclerView()
|
||||||
|
|
||||||
|
App.musicComponent.inject(this)
|
||||||
|
genreDetailsPresenter.attachView(this)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setUpToolBar() {
|
private fun setUpToolBar() {
|
||||||
val primaryColor = ThemeStore.primaryColor(this)
|
val primaryColor = ThemeStore.primaryColor(this)
|
||||||
appBarLayout.setBackgroundColor(primaryColor)
|
appBarLayout.setBackgroundColor(primaryColor)
|
||||||
applyToolbar(toolbar)
|
applyToolbar(toolbar)
|
||||||
|
title = genre.name
|
||||||
title = genre?.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
presenter?.subscribe()
|
genreDetailsPresenter.loadGenreSongs(genre.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onDestroy() {
|
||||||
super.onPause()
|
super.onDestroy()
|
||||||
presenter?.unsubscribe()
|
genreDetailsPresenter.detachView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createContentView(): View {
|
override fun createContentView(): View {
|
||||||
return wrapSlidingMusicPanel(R.layout.activity_playlist_detail)
|
return wrapSlidingMusicPanel(R.layout.activity_playlist_detail)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun loading() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showEmptyView() {
|
override fun showEmptyView() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun completed() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.menu_genre_detail, menu)
|
menuInflater.inflate(R.menu.menu_genre_detail, menu)
|
||||||
return super.onCreateOptionsMenu(menu)
|
return super.onCreateOptionsMenu(menu)
|
||||||
|
@ -105,7 +104,7 @@ class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), GenreDetailsContrac
|
||||||
if (item.itemId == android.R.id.home) {
|
if (item.itemId == android.R.id.home) {
|
||||||
onBackPressed()
|
onBackPressed()
|
||||||
}
|
}
|
||||||
return GenreMenuHelper.handleMenuClick(this, genre!!, item)
|
return GenreMenuHelper.handleMenuClick(this, genre, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupRecyclerView() {
|
private fun setupRecyclerView() {
|
||||||
|
@ -124,8 +123,8 @@ class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), GenreDetailsContrac
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showData(list: ArrayList<Song>) {
|
override fun songs(songs: ArrayList<Song>) {
|
||||||
songAdapter.swapDataSet(list)
|
songAdapter.swapDataSet(songs)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openCab(menuRes: Int, callback: MaterialCab.Callback): MaterialCab {
|
override fun openCab(menuRes: Int, callback: MaterialCab.Callback): MaterialCab {
|
||||||
|
@ -149,7 +148,7 @@ class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), GenreDetailsContrac
|
||||||
|
|
||||||
override fun onMediaStoreChanged() {
|
override fun onMediaStoreChanged() {
|
||||||
super.onMediaStoreChanged()
|
super.onMediaStoreChanged()
|
||||||
presenter?.subscribe()
|
genreDetailsPresenter.loadGenreSongs(genre.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||||
|
import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
||||||
import code.name.monkey.retromusic.adapter.song.OrderablePlaylistSongAdapter
|
import code.name.monkey.retromusic.adapter.song.OrderablePlaylistSongAdapter
|
||||||
|
@ -21,9 +22,8 @@ import code.name.monkey.retromusic.loaders.PlaylistLoader
|
||||||
import code.name.monkey.retromusic.model.AbsCustomPlaylist
|
import code.name.monkey.retromusic.model.AbsCustomPlaylist
|
||||||
import code.name.monkey.retromusic.model.Playlist
|
import code.name.monkey.retromusic.model.Playlist
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.mvp.contract.PlaylistSongsContract
|
|
||||||
import code.name.monkey.retromusic.mvp.contract.PlaylistSongsContract.*
|
|
||||||
import code.name.monkey.retromusic.mvp.presenter.PlaylistSongsPresenter
|
import code.name.monkey.retromusic.mvp.presenter.PlaylistSongsPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.PlaylistSongsView
|
||||||
import code.name.monkey.retromusic.util.PlaylistsUtil
|
import code.name.monkey.retromusic.util.PlaylistsUtil
|
||||||
import code.name.monkey.retromusic.util.RetroColorUtil
|
import code.name.monkey.retromusic.util.RetroColorUtil
|
||||||
import code.name.monkey.retromusic.util.ViewUtil
|
import code.name.monkey.retromusic.util.ViewUtil
|
||||||
|
@ -32,16 +32,19 @@ import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemA
|
||||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager
|
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager
|
||||||
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils
|
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils
|
||||||
import kotlinx.android.synthetic.main.activity_playlist_detail.*
|
import kotlinx.android.synthetic.main.activity_playlist_detail.*
|
||||||
import java.util.*
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, PlaylistSongsView {
|
class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, PlaylistSongsView {
|
||||||
|
|
||||||
private var playlist: Playlist? = null
|
@Inject
|
||||||
|
lateinit var playlistSongsPresenter: PlaylistSongsPresenter
|
||||||
|
|
||||||
|
private lateinit var playlist: Playlist
|
||||||
private var cab: MaterialCab? = null
|
private var cab: MaterialCab? = null
|
||||||
private lateinit var adapter: SongAdapter
|
private lateinit var adapter: SongAdapter
|
||||||
private var wrappedAdapter: RecyclerView.Adapter<*>? = null
|
private var wrappedAdapter: RecyclerView.Adapter<*>? = null
|
||||||
private var recyclerViewDragDropManager: RecyclerViewDragDropManager? = null
|
private var recyclerViewDragDropManager: RecyclerViewDragDropManager? = null
|
||||||
private var songsPresenter: PlaylistSongsPresenter? = null
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
setDrawUnderStatusBar()
|
setDrawUnderStatusBar()
|
||||||
|
@ -55,8 +58,15 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli
|
||||||
|
|
||||||
toggleBottomNavigationView(true)
|
toggleBottomNavigationView(true)
|
||||||
|
|
||||||
playlist = intent.extras!!.getParcelable(EXTRA_PLAYLIST)
|
if (intent.extras != null) {
|
||||||
songsPresenter = PlaylistSongsPresenter(this, playlist!!)
|
playlist = intent.extras!!.getParcelable(EXTRA_PLAYLIST)!!
|
||||||
|
} else {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
App.musicComponent.inject(this)
|
||||||
|
|
||||||
|
playlistSongsPresenter.attachView(this)
|
||||||
|
|
||||||
setUpToolBar()
|
setUpToolBar()
|
||||||
setUpRecyclerView()
|
setUpRecyclerView()
|
||||||
|
@ -78,7 +88,7 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli
|
||||||
adapter = OrderablePlaylistSongAdapter(this, ArrayList(), R.layout.item_list, false, this,
|
adapter = OrderablePlaylistSongAdapter(this, ArrayList(), R.layout.item_list, false, this,
|
||||||
object : OrderablePlaylistSongAdapter.OnMoveItemListener {
|
object : OrderablePlaylistSongAdapter.OnMoveItemListener {
|
||||||
override fun onMoveItem(fromPosition: Int, toPosition: Int) {
|
override fun onMoveItem(fromPosition: Int, toPosition: Int) {
|
||||||
if (PlaylistsUtil.moveItem(this@PlaylistDetailActivity, playlist!!.id, fromPosition, toPosition)) {
|
if (PlaylistsUtil.moveItem(this@PlaylistDetailActivity, playlist.id, fromPosition, toPosition)) {
|
||||||
val song = adapter.dataSet.removeAt(fromPosition)
|
val song = adapter.dataSet.removeAt(fromPosition)
|
||||||
adapter.dataSet.add(toPosition, song)
|
adapter.dataSet.add(toPosition, song)
|
||||||
adapter.notifyItemMoved(fromPosition, toPosition)
|
adapter.notifyItemMoved(fromPosition, toPosition)
|
||||||
|
@ -102,12 +112,12 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
songsPresenter!!.subscribe()
|
playlistSongsPresenter.loadPlaylistSongs(playlist)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setUpToolBar() {
|
private fun setUpToolBar() {
|
||||||
applyToolbar(toolbar)
|
applyToolbar(toolbar)
|
||||||
title = playlist!!.name
|
title = playlist.name
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
@ -116,14 +126,13 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
val id = item.itemId
|
when (item.itemId) {
|
||||||
when (id) {
|
|
||||||
android.R.id.home -> {
|
android.R.id.home -> {
|
||||||
onBackPressed()
|
onBackPressed()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return PlaylistMenuHelper.handleMenuClick(this, playlist!!, item)
|
return PlaylistMenuHelper.handleMenuClick(this, playlist, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openCab(menuRes: Int, callback: MaterialCab.Callback): MaterialCab {
|
override fun openCab(menuRes: Int, callback: MaterialCab.Callback): MaterialCab {
|
||||||
|
@ -153,19 +162,19 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli
|
||||||
|
|
||||||
if (playlist !is AbsCustomPlaylist) {
|
if (playlist !is AbsCustomPlaylist) {
|
||||||
// Playlist deleted
|
// Playlist deleted
|
||||||
if (!PlaylistsUtil.doesPlaylistExist(this, playlist!!.id)) {
|
if (!PlaylistsUtil.doesPlaylistExist(this, playlist.id)) {
|
||||||
finish()
|
finish()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Playlist renamed
|
// Playlist renamed
|
||||||
val playlistName = PlaylistsUtil.getNameForPlaylist(this, playlist!!.id.toLong())
|
val playlistName = PlaylistsUtil.getNameForPlaylist(this, playlist.id.toLong())
|
||||||
if (playlistName != playlist!!.name) {
|
if (playlistName != playlist.name) {
|
||||||
playlist = PlaylistLoader.getPlaylist(this, playlist!!.id)
|
playlist = PlaylistLoader.getPlaylist(this, playlist.id)
|
||||||
setToolbarTitle(playlist!!.name)
|
setToolbarTitle(playlist.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
songsPresenter!!.subscribe()
|
playlistSongsPresenter.loadPlaylistSongs(playlist)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setToolbarTitle(title: String) {
|
private fun setToolbarTitle(title: String) {
|
||||||
|
@ -182,7 +191,6 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli
|
||||||
recyclerViewDragDropManager!!.cancelDrag()
|
recyclerViewDragDropManager!!.cancelDrag()
|
||||||
}
|
}
|
||||||
super.onPause()
|
super.onPause()
|
||||||
songsPresenter!!.unsubscribe()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
@ -201,19 +209,16 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli
|
||||||
wrappedAdapter = null
|
wrappedAdapter = null
|
||||||
}
|
}
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
playlistSongsPresenter.detachView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loading() {}
|
|
||||||
|
|
||||||
override fun showEmptyView() {
|
override fun showEmptyView() {
|
||||||
empty.visibility = View.VISIBLE
|
empty.visibility = View.VISIBLE
|
||||||
emptyText.visibility = View.VISIBLE
|
emptyText.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun completed() {}
|
override fun songs(songs: ArrayList<Song>) {
|
||||||
|
adapter.swapDataSet(songs)
|
||||||
override fun showData(list: ArrayList<Song>) {
|
|
||||||
adapter.swapDataSet(list)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -21,19 +21,22 @@ import androidx.recyclerview.widget.RecyclerView
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||||
|
import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
|
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
|
||||||
import code.name.monkey.retromusic.adapter.SearchAdapter
|
import code.name.monkey.retromusic.adapter.SearchAdapter
|
||||||
import code.name.monkey.retromusic.mvp.contract.SearchContract
|
|
||||||
import code.name.monkey.retromusic.mvp.presenter.SearchPresenter
|
import code.name.monkey.retromusic.mvp.presenter.SearchPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.SearchView
|
||||||
import code.name.monkey.retromusic.util.RetroColorUtil
|
import code.name.monkey.retromusic.util.RetroColorUtil
|
||||||
import code.name.monkey.retromusic.util.RetroUtil
|
import code.name.monkey.retromusic.util.RetroUtil
|
||||||
import kotlinx.android.synthetic.main.activity_search.*
|
import kotlinx.android.synthetic.main.activity_search.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, SearchContract.SearchView, TextWatcher {
|
class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, TextWatcher, SearchView {
|
||||||
|
@Inject
|
||||||
|
lateinit var searchPresenter: SearchPresenter
|
||||||
|
|
||||||
private lateinit var searchPresenter: SearchPresenter
|
|
||||||
private var searchAdapter: SearchAdapter? = null
|
private var searchAdapter: SearchAdapter? = null
|
||||||
private var query: String? = null
|
private var query: String? = null
|
||||||
|
|
||||||
|
@ -42,7 +45,9 @@ class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, SearchCon
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_search)
|
setContentView(R.layout.activity_search)
|
||||||
|
|
||||||
searchPresenter = SearchPresenter(this)
|
App.musicComponent.inject(this)
|
||||||
|
|
||||||
|
searchPresenter.attachView(this)
|
||||||
|
|
||||||
setStatusbarColorAuto()
|
setStatusbarColorAuto()
|
||||||
setNavigationbarColorAuto()
|
setNavigationbarColorAuto()
|
||||||
|
@ -105,13 +110,12 @@ class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, SearchCon
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
searchPresenter.subscribe()
|
|
||||||
searchPresenter.search(query)
|
searchPresenter.search(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
searchPresenter.unsubscribe()
|
searchPresenter.detachView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
|
@ -158,18 +162,10 @@ class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, SearchCon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loading() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showEmptyView() {
|
override fun showEmptyView() {
|
||||||
searchAdapter!!.swapDataSet(ArrayList())
|
searchAdapter!!.swapDataSet(ArrayList())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun completed() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showData(list: MutableList<Any>) {
|
override fun showData(list: MutableList<Any>) {
|
||||||
searchAdapter!!.swapDataSet(list)
|
searchAdapter!!.swapDataSet(list)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Hemanth Savarala.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package code.name.monkey.retromusic.dagger
|
||||||
|
|
||||||
|
import code.name.monkey.retromusic.activities.*
|
||||||
|
import code.name.monkey.retromusic.dagger.module.*
|
||||||
|
import code.name.monkey.retromusic.fragments.mainactivity.*
|
||||||
|
import code.name.monkey.retromusic.fragments.mainactivity.home.BannerHomeFragment
|
||||||
|
import dagger.Component
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by hemanths on 2019-09-04.
|
||||||
|
*/
|
||||||
|
@Component(modules = [
|
||||||
|
RepositoryModule::class,
|
||||||
|
AlbumModule::class,
|
||||||
|
ArtistModule::class,
|
||||||
|
GenreModule::class,
|
||||||
|
HomeModule::class,
|
||||||
|
PlaylistModule::class,
|
||||||
|
SearchModule::class,
|
||||||
|
SongModule::class,
|
||||||
|
ActivityModule::class
|
||||||
|
])
|
||||||
|
interface MusicComponent {
|
||||||
|
|
||||||
|
fun inject(songsFragment: SongsFragment)
|
||||||
|
|
||||||
|
fun inject(albumsFragment: AlbumsFragment)
|
||||||
|
|
||||||
|
fun inject(artistsFragment: ArtistsFragment)
|
||||||
|
|
||||||
|
fun inject(genresFragment: GenresFragment)
|
||||||
|
|
||||||
|
fun inject(playlistsFragment: PlaylistsFragment)
|
||||||
|
|
||||||
|
fun inject(artistDetailActivity: ArtistDetailActivity)
|
||||||
|
|
||||||
|
fun inject(albumDetailsActivity: AlbumDetailsActivity)
|
||||||
|
|
||||||
|
fun inject(playlistDetailActivity: PlaylistDetailActivity)
|
||||||
|
|
||||||
|
fun inject(genreDetailsActivity: GenreDetailsActivity)
|
||||||
|
|
||||||
|
fun inject(searchActivity: SearchActivity)
|
||||||
|
|
||||||
|
fun inject(bannerHomeFragment: BannerHomeFragment)
|
||||||
|
}
|
|
@ -12,17 +12,21 @@
|
||||||
* See the GNU General Public License for more details.
|
* See the GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.contract
|
package code.name.monkey.retromusic.dagger.module
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Home
|
import android.app.Activity
|
||||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
|
||||||
|
|
||||||
interface HomeContract {
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
|
||||||
interface HomeView : BaseView<ArrayList<Home>>
|
/**
|
||||||
|
* Created by hemanths on 2019-09-04.
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
class ActivityModule(private val activity: Activity) {
|
||||||
|
|
||||||
interface HomePresenter : BasePresenter<HomeView> {
|
@Provides
|
||||||
fun homeSections()
|
fun provideActivity(): Activity {
|
||||||
|
return activity
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Hemanth Savarala.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package code.name.monkey.retromusic.dagger.module
|
||||||
|
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.AlbumDetailsPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.AlbumDetailsPresenter.AlbumDetailsPresenterImpl
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.AlbumsPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.AlbumsPresenter.AlbumsPresenterImpl
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by hemanths on 2019-09-04.
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
class AlbumModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun providesAlbumsPresenter(presenter: AlbumsPresenterImpl): AlbumsPresenter {
|
||||||
|
return presenter
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun providesAlbumDetailsPresenter(presenter: AlbumDetailsPresenterImpl): AlbumDetailsPresenter {
|
||||||
|
return presenter
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,21 +12,21 @@
|
||||||
* See the GNU General Public License for more details.
|
* See the GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.contract
|
package code.name.monkey.retromusic.dagger.module
|
||||||
|
|
||||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
import android.content.Context
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 20/08/17.
|
* Created by hemanths on 2019-09-04.
|
||||||
*/
|
*/
|
||||||
|
@Module
|
||||||
|
class AppModule(private val context: Context) {
|
||||||
|
|
||||||
interface SearchContract {
|
@Provides
|
||||||
interface SearchView : BaseView<MutableList<Any>>
|
fun provideContext(): Context {
|
||||||
|
return context
|
||||||
interface SearchPresenter : BasePresenter<SearchView> {
|
|
||||||
fun search(query: String?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Hemanth Savarala.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package code.name.monkey.retromusic.dagger.module
|
||||||
|
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.ArtistDetailsPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.ArtistsPresenter
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.ArtistDetailsPresenter.*
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.ArtistsPresenter.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by hemanths on 2019-09-04.
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
class ArtistModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun providesArtistDetailsPresenter(presenter: ArtistDetailsPresenterImpl): ArtistDetailsPresenter {
|
||||||
|
return presenter
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun providesArtistsPresenter(presenter: ArtistsPresenterImpl): ArtistsPresenter {
|
||||||
|
return presenter
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Hemanth Savarala.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package code.name.monkey.retromusic.dagger.module
|
||||||
|
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.GenreDetailsPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.GenreDetailsPresenter.GenreDetailsPresenterImpl
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.GenresPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.GenresPresenter.GenresPresenterImpl
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by hemanths on 2019-09-04.
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
class GenreModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun providesGenresPresenter(presenter: GenresPresenterImpl): GenresPresenter {
|
||||||
|
return presenter
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun providesGenreDetailsPresenter(presenter: GenreDetailsPresenterImpl): GenreDetailsPresenter {
|
||||||
|
return presenter
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,22 +12,22 @@
|
||||||
* See the GNU General Public License for more details.
|
* See the GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.contract
|
package code.name.monkey.retromusic.dagger.module
|
||||||
|
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Artist
|
|
||||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
|
||||||
|
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.HomePresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.HomePresenter.HomePresenterImpl
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 20/08/17.
|
* Created by hemanths on 2019-09-04.
|
||||||
*/
|
*/
|
||||||
|
@Module
|
||||||
|
class HomeModule {
|
||||||
|
|
||||||
interface ArtistDetailContract {
|
@Provides
|
||||||
interface ArtistsDetailsView : BaseView<Artist>
|
fun providesHomePresenter(presenter: HomePresenterImpl): HomePresenter {
|
||||||
|
return presenter
|
||||||
interface Presenter : BasePresenter<ArtistsDetailsView> {
|
|
||||||
fun loadArtistById()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Hemanth Savarala.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package code.name.monkey.retromusic.dagger.module
|
||||||
|
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.PlaylistSongsPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.PlaylistSongsPresenter.PlaylistSongsPresenterImpl
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.PlaylistsPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.PlaylistsPresenter.PlaylistsPresenterImpl
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by hemanths on 2019-09-04.
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
class PlaylistModule {
|
||||||
|
@Provides
|
||||||
|
fun providesPlaylistSongPresenter(presenter: PlaylistSongsPresenterImpl): PlaylistSongsPresenter {
|
||||||
|
return presenter
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun providesPlaylistsPresenter(presenter: PlaylistsPresenterImpl): PlaylistsPresenter {
|
||||||
|
return presenter
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,22 +12,23 @@
|
||||||
* See the GNU General Public License for more details.
|
* See the GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.contract
|
package code.name.monkey.retromusic.dagger.module
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
import android.content.Context
|
||||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
|
||||||
|
|
||||||
import java.util.ArrayList
|
import code.name.monkey.retromusic.providers.RepositoryImpl
|
||||||
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hemanth S (h4h13).
|
* Created by hemanths on 2019-09-04.
|
||||||
*/
|
*/
|
||||||
|
@Module(includes = [AppModule::class])
|
||||||
|
class RepositoryModule {
|
||||||
|
|
||||||
interface GenreDetailsContract {
|
@Provides
|
||||||
interface GenreDetailsView : BaseView<ArrayList<Song>>
|
fun providesRepository(context: Context): Repository {
|
||||||
|
return RepositoryImpl(context)
|
||||||
interface Presenter : BasePresenter<GenreDetailsView> {
|
|
||||||
fun loadGenre(genreId: Int)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,24 +12,22 @@
|
||||||
* See the GNU General Public License for more details.
|
* See the GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.contract
|
package code.name.monkey.retromusic.dagger.module
|
||||||
|
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Artist
|
|
||||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
|
||||||
|
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.SearchPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.SearchPresenter.SearchPresenterImpl
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 16/08/17.
|
* Created by hemanths on 2019-09-04.
|
||||||
*/
|
*/
|
||||||
|
@Module
|
||||||
|
class SearchModule {
|
||||||
|
|
||||||
interface ArtistContract {
|
@Provides
|
||||||
interface ArtistView : BaseView<ArrayList<Artist>>
|
fun providesSearchPresenter(presenter: SearchPresenterImpl): SearchPresenter {
|
||||||
|
return presenter
|
||||||
interface Presenter : BasePresenter<ArtistView> {
|
|
||||||
fun loadArtists()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -12,22 +12,20 @@
|
||||||
* See the GNU General Public License for more details.
|
* See the GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.contract
|
package code.name.monkey.retromusic.dagger.module
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Genre
|
import code.name.monkey.retromusic.mvp.presenter.SongPresenter
|
||||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
import code.name.monkey.retromusic.mvp.presenter.SongPresenter.SongPresenterImpl
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hemanth S (h4h13).
|
* Created by hemanths on 2019-09-04.
|
||||||
*/
|
*/
|
||||||
|
@Module
|
||||||
interface GenreContract {
|
class SongModule {
|
||||||
interface GenreView : BaseView<ArrayList<Genre>>
|
@Provides
|
||||||
|
fun providesSongPresenter(presenter: SongPresenterImpl): SongPresenter {
|
||||||
interface Presenter : BasePresenter<GenreView> {
|
return presenter
|
||||||
fun loadGenre()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,18 +2,23 @@ package code.name.monkey.retromusic.fragments.mainactivity
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.adapter.album.AlbumAdapter
|
import code.name.monkey.retromusic.adapter.album.AlbumAdapter
|
||||||
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment
|
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment
|
||||||
import code.name.monkey.retromusic.model.Album
|
import code.name.monkey.retromusic.model.Album
|
||||||
import code.name.monkey.retromusic.mvp.contract.AlbumContract
|
import code.name.monkey.retromusic.mvp.presenter.AlbumsPresenter
|
||||||
import code.name.monkey.retromusic.mvp.presenter.AlbumPresenter
|
import code.name.monkey.retromusic.mvp.presenter.AlbumsView
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridLayoutManager>(), AlbumContract.AlbumView {
|
open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridLayoutManager>(), AlbumsView {
|
||||||
|
override fun albums(albums: java.util.ArrayList<Album>) {
|
||||||
private lateinit var presenter: AlbumPresenter
|
adapter?.swapDataSet(albums)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var albumsPresenter: AlbumsPresenter
|
||||||
|
|
||||||
override val emptyMessage: Int
|
override val emptyMessage: Int
|
||||||
get() = R.string.no_albums
|
get() = R.string.no_albums
|
||||||
|
@ -26,15 +31,13 @@ open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Al
|
||||||
var itemLayoutRes = itemLayoutRes
|
var itemLayoutRes = itemLayoutRes
|
||||||
notifyLayoutResChanged(itemLayoutRes)
|
notifyLayoutResChanged(itemLayoutRes)
|
||||||
if (itemLayoutRes != R.layout.item_list) {
|
if (itemLayoutRes != R.layout.item_list) {
|
||||||
|
itemLayoutRes = PreferenceUtil.getInstance().getAlbumGridStyle(requireContext())
|
||||||
itemLayoutRes = PreferenceUtil.getInstance().getAlbumGridStyle(context!!)
|
|
||||||
}
|
}
|
||||||
val dataSet = if (adapter == null) ArrayList() else adapter!!.dataSet
|
val dataSet = if (adapter == null) ArrayList() else adapter!!.dataSet
|
||||||
return AlbumAdapter(libraryFragment.mainActivity, dataSet, itemLayoutRes, loadUsePalette(), libraryFragment)
|
return AlbumAdapter(libraryFragment.mainActivity, dataSet, itemLayoutRes, loadUsePalette(), libraryFragment)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun loadUsePalette(): Boolean {
|
public override fun loadUsePalette(): Boolean {
|
||||||
|
|
||||||
return PreferenceUtil.getInstance().albumColoredFooters()
|
return PreferenceUtil.getInstance().albumColoredFooters()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,13 +46,10 @@ open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Al
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setGridSize(gridSize: Int) {
|
override fun setGridSize(gridSize: Int) {
|
||||||
layoutManager!!.spanCount = gridSize
|
layoutManager?.spanCount = gridSize
|
||||||
adapter!!.notifyDataSetChanged()
|
adapter?.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setSortOrder(sortOrder: String) {
|
|
||||||
presenter.loadAlbums()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun loadSortOrder(): String {
|
override fun loadSortOrder(): String {
|
||||||
|
|
||||||
|
@ -86,38 +86,36 @@ open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Al
|
||||||
PreferenceUtil.getInstance().setAlbumColoredFooters(usePalette)
|
PreferenceUtil.getInstance().setAlbumColoredFooters(usePalette)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMediaStoreChanged() {
|
|
||||||
presenter.loadAlbums()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
presenter = AlbumPresenter(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
App.musicComponent.inject(this)
|
||||||
|
albumsPresenter.attachView(this)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
if (adapter!!.dataSet.isEmpty()) {
|
if (adapter!!.dataSet.isEmpty()) {
|
||||||
presenter.subscribe()
|
albumsPresenter.loadAlbums()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onMediaStoreChanged() {
|
||||||
super.onDestroy()
|
albumsPresenter.loadAlbums()
|
||||||
presenter.unsubscribe()
|
}
|
||||||
|
|
||||||
|
override fun setSortOrder(sortOrder: String) {
|
||||||
|
albumsPresenter.loadAlbums()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
super.onDestroyView()
|
||||||
|
albumsPresenter.detachView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loading() {}
|
|
||||||
|
|
||||||
override fun showEmptyView() {
|
override fun showEmptyView() {
|
||||||
adapter!!.swapDataSet(ArrayList())
|
adapter?.swapDataSet(ArrayList())
|
||||||
}
|
|
||||||
|
|
||||||
override fun completed() {}
|
|
||||||
|
|
||||||
override fun showData(list: ArrayList<Album>) {
|
|
||||||
adapter!!.swapDataSet(list)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -2,24 +2,46 @@ package code.name.monkey.retromusic.fragments.mainactivity
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.adapter.artist.ArtistAdapter
|
import code.name.monkey.retromusic.adapter.artist.ArtistAdapter
|
||||||
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment
|
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment
|
||||||
import code.name.monkey.retromusic.model.Artist
|
import code.name.monkey.retromusic.model.Artist
|
||||||
import code.name.monkey.retromusic.mvp.contract.ArtistContract
|
import code.name.monkey.retromusic.mvp.presenter.ArtistsPresenter
|
||||||
import code.name.monkey.retromusic.mvp.presenter.ArtistPresenter
|
import code.name.monkey.retromusic.mvp.presenter.ArtistsView
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import java.util.*
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<ArtistAdapter, GridLayoutManager>(), ArtistContract.ArtistView {
|
class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<ArtistAdapter, GridLayoutManager>(), ArtistsView {
|
||||||
private lateinit var presenter: ArtistPresenter
|
override fun artists(artists: ArrayList<Artist>) {
|
||||||
|
adapter?.swapDataSet(artists)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var artistsPresenter: ArtistsPresenter
|
||||||
|
|
||||||
override val emptyMessage: Int
|
override val emptyMessage: Int
|
||||||
get() = R.string.no_artists
|
get() = R.string.no_artists
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
presenter = ArtistPresenter(this)
|
App.musicComponent.inject(this)
|
||||||
|
artistsPresenter.attachView(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
if (adapter!!.dataSet.isEmpty()) {
|
||||||
|
artistsPresenter.loadArtists()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMediaStoreChanged() {
|
||||||
|
artistsPresenter.loadArtists()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setSortOrder(sortOrder: String) {
|
||||||
|
artistsPresenter.loadArtists()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createLayoutManager(): GridLayoutManager {
|
override fun createLayoutManager(): GridLayoutManager {
|
||||||
|
@ -30,15 +52,12 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
|
||||||
var itemLayoutRes = itemLayoutRes
|
var itemLayoutRes = itemLayoutRes
|
||||||
notifyLayoutResChanged(itemLayoutRes)
|
notifyLayoutResChanged(itemLayoutRes)
|
||||||
if (itemLayoutRes != R.layout.item_list) {
|
if (itemLayoutRes != R.layout.item_list) {
|
||||||
itemLayoutRes = PreferenceUtil.getInstance().getArtistGridStyle(context!!)
|
itemLayoutRes = PreferenceUtil.getInstance().getArtistGridStyle(requireContext())
|
||||||
}
|
}
|
||||||
val dataSet = if (adapter == null) ArrayList() else adapter!!.dataSet
|
val dataSet = if (adapter == null) ArrayList() else adapter!!.dataSet
|
||||||
return ArtistAdapter(libraryFragment.mainActivity, dataSet, itemLayoutRes, loadUsePalette(), libraryFragment)
|
return ArtistAdapter(libraryFragment.mainActivity, dataSet, itemLayoutRes, loadUsePalette(), libraryFragment)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMediaStoreChanged() {
|
|
||||||
presenter.loadArtists()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun loadGridSize(): Int {
|
override fun loadGridSize(): Int {
|
||||||
return PreferenceUtil.getInstance().getArtistGridSize(activity!!)
|
return PreferenceUtil.getInstance().getArtistGridSize(activity!!)
|
||||||
|
@ -65,12 +84,12 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setUsePalette(usePalette: Boolean) {
|
override fun setUsePalette(usePalette: Boolean) {
|
||||||
adapter!!.usePalette(usePalette)
|
adapter?.usePalette(usePalette)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setGridSize(gridSize: Int) {
|
override fun setGridSize(gridSize: Int) {
|
||||||
layoutManager!!.spanCount = gridSize
|
layoutManager?.spanCount = gridSize
|
||||||
adapter!!.notifyDataSetChanged()
|
adapter?.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,34 +101,13 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
|
||||||
PreferenceUtil.getInstance().artistSortOrder = sortOrder
|
PreferenceUtil.getInstance().artistSortOrder = sortOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setSortOrder(sortOrder: String) {
|
override fun onDestroyView() {
|
||||||
presenter.loadArtists()
|
super.onDestroyView()
|
||||||
|
artistsPresenter.detachView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
|
||||||
super.onResume()
|
|
||||||
if (adapter!!.dataSet.isEmpty()) {
|
|
||||||
presenter.subscribe()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
|
||||||
super.onDestroy()
|
|
||||||
presenter.unsubscribe()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun loading() {}
|
|
||||||
|
|
||||||
override fun showEmptyView() {
|
override fun showEmptyView() {
|
||||||
adapter!!.swapDataSet(ArrayList())
|
adapter?.swapDataSet(ArrayList())
|
||||||
}
|
|
||||||
|
|
||||||
override fun completed() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showData(list: ArrayList<Artist>) {
|
|
||||||
adapter!!.swapDataSet(list)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -125,5 +123,4 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
|
||||||
return fragment
|
return fragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,31 +16,25 @@ package code.name.monkey.retromusic.fragments.mainactivity
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.adapter.GenreAdapter
|
import code.name.monkey.retromusic.adapter.GenreAdapter
|
||||||
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewFragment
|
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewFragment
|
||||||
import code.name.monkey.retromusic.model.Genre
|
import code.name.monkey.retromusic.model.Genre
|
||||||
import code.name.monkey.retromusic.mvp.contract.GenreContract
|
import code.name.monkey.retromusic.mvp.presenter.GenresPresenter
|
||||||
import code.name.monkey.retromusic.mvp.presenter.GenrePresenter
|
import code.name.monkey.retromusic.mvp.presenter.GenresView
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
class GenresFragment : AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearLayoutManager>(), GenreContract.GenreView {
|
class GenresFragment : AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearLayoutManager>(), GenresView {
|
||||||
override fun loading() {
|
override fun genres(genres: ArrayList<Genre>) {
|
||||||
|
adapter?.swapDataSet(genres)
|
||||||
}
|
|
||||||
|
|
||||||
override fun showData(list: ArrayList<Genre>) {
|
|
||||||
adapter?.swapDataSet(list)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showEmptyView() {
|
override fun showEmptyView() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun completed() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun createLayoutManager(): LinearLayoutManager {
|
override fun createLayoutManager(): LinearLayoutManager {
|
||||||
return LinearLayoutManager(activity)
|
return LinearLayoutManager(activity)
|
||||||
}
|
}
|
||||||
|
@ -53,28 +47,31 @@ class GenresFragment : AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearL
|
||||||
override val emptyMessage: Int
|
override val emptyMessage: Int
|
||||||
get() = R.string.no_genres
|
get() = R.string.no_genres
|
||||||
|
|
||||||
private lateinit var presenter: GenrePresenter
|
|
||||||
|
@Inject
|
||||||
|
lateinit var genresPresenter: GenresPresenter
|
||||||
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
App.musicComponent.inject(this)
|
||||||
presenter = GenrePresenter(this)
|
genresPresenter.attachView(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
if (adapter!!.dataSet.isEmpty()) {
|
if (adapter!!.dataSet.isEmpty()) {
|
||||||
presenter.subscribe()
|
genresPresenter.loadGenres()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroyView() {
|
||||||
presenter.unsubscribe()
|
super.onDestroyView()
|
||||||
super.onDestroy()
|
genresPresenter.detachView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMediaStoreChanged() {
|
override fun onMediaStoreChanged() {
|
||||||
presenter.loadGenre()
|
genresPresenter.loadGenres()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -4,26 +4,28 @@ import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.adapter.playlist.PlaylistAdapter
|
import code.name.monkey.retromusic.adapter.playlist.PlaylistAdapter
|
||||||
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewFragment
|
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewFragment
|
||||||
import code.name.monkey.retromusic.model.Playlist
|
import code.name.monkey.retromusic.model.Playlist
|
||||||
import code.name.monkey.retromusic.mvp.contract.PlaylistContract
|
import code.name.monkey.retromusic.mvp.presenter.PlaylistView
|
||||||
import code.name.monkey.retromusic.mvp.presenter.PlaylistPresenter
|
import code.name.monkey.retromusic.mvp.presenter.PlaylistsPresenter
|
||||||
import java.util.*
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment<PlaylistAdapter, LinearLayoutManager>(), PlaylistContract.PlaylistView {
|
class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment<PlaylistAdapter, LinearLayoutManager>(), PlaylistView {
|
||||||
|
|
||||||
private lateinit var presenter: PlaylistPresenter
|
@Inject
|
||||||
|
lateinit var playlistsPresenter: PlaylistsPresenter
|
||||||
|
|
||||||
override val emptyMessage: Int
|
override val emptyMessage: Int
|
||||||
get() = R.string.no_playlists
|
get() = R.string.no_playlists
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setHasOptionsMenu(true)
|
App.musicComponent.inject(this)
|
||||||
presenter = PlaylistPresenter(this)
|
playlistsPresenter.attachView(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createLayoutManager(): LinearLayoutManager {
|
override fun createLayoutManager(): LinearLayoutManager {
|
||||||
|
@ -38,33 +40,25 @@ class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment<PlaylistAdapter, L
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
if (adapter!!.dataSet.isEmpty()) {
|
if (adapter!!.dataSet.isEmpty()) {
|
||||||
presenter.subscribe()
|
playlistsPresenter.playlists()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroyView() {
|
||||||
presenter.unsubscribe()
|
super.onDestroyView()
|
||||||
super.onDestroy()
|
playlistsPresenter.detachView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMediaStoreChanged() {
|
override fun onMediaStoreChanged() {
|
||||||
super.onMediaStoreChanged()
|
super.onMediaStoreChanged()
|
||||||
presenter.loadPlaylists()
|
playlistsPresenter.playlists()
|
||||||
}
|
|
||||||
|
|
||||||
override fun loading() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showEmptyView() {
|
override fun showEmptyView() {
|
||||||
adapter!!.swapDataSet(ArrayList())
|
adapter!!.swapDataSet(ArrayList())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun completed() {
|
override fun playlists(list: ArrayList<Playlist>) {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showData(list: ArrayList<Playlist>) {
|
|
||||||
adapter!!.swapDataSet(list)
|
adapter!!.swapDataSet(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,27 +2,32 @@ package code.name.monkey.retromusic.fragments.mainactivity
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.adapter.song.ShuffleButtonSongAdapter
|
import code.name.monkey.retromusic.adapter.song.ShuffleButtonSongAdapter
|
||||||
import code.name.monkey.retromusic.adapter.song.SongAdapter
|
import code.name.monkey.retromusic.adapter.song.SongAdapter
|
||||||
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment
|
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.mvp.contract.SongContract
|
|
||||||
import code.name.monkey.retromusic.mvp.presenter.SongPresenter
|
import code.name.monkey.retromusic.mvp.presenter.SongPresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.SongView
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdapter, GridLayoutManager>(), SongContract.SongView {
|
class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdapter, GridLayoutManager>(), SongView {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var songPresenter: SongPresenter
|
||||||
|
|
||||||
private lateinit var presenter: SongPresenter
|
|
||||||
|
|
||||||
override val emptyMessage: Int
|
override val emptyMessage: Int
|
||||||
get() = R.string.no_songs
|
get() = R.string.no_songs
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
presenter = SongPresenter(this)
|
App.musicComponent.inject(this)
|
||||||
|
|
||||||
|
songPresenter.attachView(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createLayoutManager(): GridLayoutManager {
|
override fun createLayoutManager(): GridLayoutManager {
|
||||||
|
@ -41,8 +46,12 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
|
||||||
} else SongAdapter(libraryFragment.mainActivity, dataSet, itemLayoutRes, usePalette, libraryFragment)
|
} else SongAdapter(libraryFragment.mainActivity, dataSet, itemLayoutRes, usePalette, libraryFragment)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun songs(songs: ArrayList<Song>) {
|
||||||
|
adapter?.swapDataSet(songs)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onMediaStoreChanged() {
|
override fun onMediaStoreChanged() {
|
||||||
presenter.loadSongs()
|
songPresenter.loadSongs()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadGridSize(): Int {
|
override fun loadGridSize(): Int {
|
||||||
|
@ -81,31 +90,19 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
if (adapter!!.dataSet.isEmpty()) {
|
if (adapter!!.dataSet.isEmpty()) {
|
||||||
presenter.subscribe()
|
songPresenter.loadSongs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroyView() {
|
||||||
presenter.unsubscribe()
|
super.onDestroyView()
|
||||||
super.onDestroy()
|
songPresenter.detachView()
|
||||||
}
|
|
||||||
|
|
||||||
override fun loading() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showData(list: ArrayList<Song>) {
|
|
||||||
adapter!!.swapDataSet(list)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showEmptyView() {
|
override fun showEmptyView() {
|
||||||
adapter!!.swapDataSet(ArrayList())
|
adapter!!.swapDataSet(ArrayList())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun completed() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun loadSortOrder(): String {
|
override fun loadSortOrder(): String {
|
||||||
return PreferenceUtil.getInstance().songSortOrder
|
return PreferenceUtil.getInstance().songSortOrder
|
||||||
}
|
}
|
||||||
|
@ -115,7 +112,7 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setSortOrder(sortOrder: String) {
|
override fun setSortOrder(sortOrder: String) {
|
||||||
presenter.loadSongs()
|
songPresenter.loadSongs()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import code.name.monkey.appthemehelper.ThemeStore
|
||||||
import code.name.monkey.appthemehelper.common.ATHToolbarActivity
|
import code.name.monkey.appthemehelper.common.ATHToolbarActivity
|
||||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||||
|
import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.Constants
|
import code.name.monkey.retromusic.Constants
|
||||||
import code.name.monkey.retromusic.Constants.USER_BANNER
|
import code.name.monkey.retromusic.Constants.USER_BANNER
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
|
@ -29,8 +30,8 @@ import code.name.monkey.retromusic.model.Home
|
||||||
import code.name.monkey.retromusic.model.smartplaylist.HistoryPlaylist
|
import code.name.monkey.retromusic.model.smartplaylist.HistoryPlaylist
|
||||||
import code.name.monkey.retromusic.model.smartplaylist.LastAddedPlaylist
|
import code.name.monkey.retromusic.model.smartplaylist.LastAddedPlaylist
|
||||||
import code.name.monkey.retromusic.model.smartplaylist.MyTopTracksPlaylist
|
import code.name.monkey.retromusic.model.smartplaylist.MyTopTracksPlaylist
|
||||||
import code.name.monkey.retromusic.mvp.contract.HomeContract
|
|
||||||
import code.name.monkey.retromusic.mvp.presenter.HomePresenter
|
import code.name.monkey.retromusic.mvp.presenter.HomePresenter
|
||||||
|
import code.name.monkey.retromusic.mvp.presenter.HomeView
|
||||||
import code.name.monkey.retromusic.util.*
|
import code.name.monkey.retromusic.util.*
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
@ -41,12 +42,29 @@ import kotlinx.android.synthetic.main.fragment_banner_home.*
|
||||||
import kotlinx.android.synthetic.main.home_content.*
|
import kotlinx.android.synthetic.main.home_content.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallbacks, HomeContract.HomeView {
|
class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallbacks, HomeView {
|
||||||
|
|
||||||
|
override fun sections(sections: ArrayList<Home>) {
|
||||||
|
val finalList = sections.sortedWith(compareBy { it.priority })
|
||||||
|
homeAdapter.swapData(finalList)
|
||||||
|
recyclerView.apply {
|
||||||
|
layoutManager = LinearLayoutManager(mainActivity)
|
||||||
|
adapter = homeAdapter
|
||||||
|
}
|
||||||
|
if (sections.isEmpty()) {
|
||||||
|
showEmptyView()
|
||||||
|
} else {
|
||||||
|
emptyContainer.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var homePresenter: HomePresenter
|
||||||
|
|
||||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
private lateinit var homePresenter: HomePresenter
|
|
||||||
private lateinit var toolbar: Toolbar
|
private lateinit var toolbar: Toolbar
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, viewGroup: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, viewGroup: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
@ -83,7 +101,8 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
homePresenter = HomePresenter(this)
|
App.musicComponent.inject(this)
|
||||||
|
homePresenter.attachView(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,22 +127,18 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
|
||||||
}
|
}
|
||||||
|
|
||||||
actionShuffle.setOnClickListener {
|
actionShuffle.setOnClickListener {
|
||||||
MusicPlayerRemote.openAndShuffleQueue(SongLoader.getAllSongs(requireActivity()) , true)
|
MusicPlayerRemote.openAndShuffleQueue(SongLoader.getAllSongs(requireActivity()), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
history.setOnClickListener {
|
history.setOnClickListener {
|
||||||
NavigationUtil.goToPlaylistNew(requireActivity(), HistoryPlaylist(requireActivity()))
|
NavigationUtil.goToPlaylistNew(requireActivity(), HistoryPlaylist(requireActivity()))
|
||||||
}
|
}
|
||||||
|
|
||||||
homePresenter = HomePresenter(this)
|
|
||||||
|
|
||||||
contentContainer.setBackgroundColor(ThemeStore.primaryColor(requireContext()))
|
contentContainer.setBackgroundColor(ThemeStore.primaryColor(requireContext()))
|
||||||
|
|
||||||
setupToolbar()
|
setupToolbar()
|
||||||
homeAdapter = HomeAdapter(mainActivity, ArrayList(), displayMetrics)
|
homeAdapter = HomeAdapter(mainActivity, ArrayList(), displayMetrics)
|
||||||
|
|
||||||
homePresenter.subscribe()
|
|
||||||
|
|
||||||
checkPadding()
|
checkPadding()
|
||||||
|
|
||||||
userInfoContainer.setOnClickListener {
|
userInfoContainer.setOnClickListener {
|
||||||
|
@ -131,6 +146,8 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
|
||||||
}
|
}
|
||||||
titleWelcome.setTextColor(ThemeStore.textColorPrimary(requireContext()))
|
titleWelcome.setTextColor(ThemeStore.textColorPrimary(requireContext()))
|
||||||
titleWelcome.text = String.format("%s", PreferenceUtil.getInstance().userName)
|
titleWelcome.text = String.format("%s", PreferenceUtil.getInstance().userName)
|
||||||
|
|
||||||
|
homePresenter.loadSections()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkPadding() {
|
private fun checkPadding() {
|
||||||
|
@ -177,21 +194,13 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
disposable.dispose()
|
disposable.dispose()
|
||||||
homePresenter.unsubscribe()
|
homePresenter.detachView()
|
||||||
}
|
|
||||||
|
|
||||||
override fun loading() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showEmptyView() {
|
override fun showEmptyView() {
|
||||||
emptyContainer.show()
|
emptyContainer.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun completed() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onServiceConnected() {
|
override fun onServiceConnected() {
|
||||||
super.onServiceConnected()
|
super.onServiceConnected()
|
||||||
checkPadding()
|
checkPadding()
|
||||||
|
@ -204,20 +213,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
|
||||||
|
|
||||||
private lateinit var homeAdapter: HomeAdapter
|
private lateinit var homeAdapter: HomeAdapter
|
||||||
|
|
||||||
override fun showData(list: ArrayList<Home>) {
|
|
||||||
val finalList = list.sortedWith(compareBy { it.priority })
|
|
||||||
homeAdapter.swapData(finalList)
|
|
||||||
recyclerView.apply {
|
|
||||||
layoutManager = LinearLayoutManager(mainActivity)
|
|
||||||
adapter = homeAdapter
|
|
||||||
}
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
showEmptyView()
|
|
||||||
} else {
|
|
||||||
emptyContainer.hide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
super.onCreateOptionsMenu(menu, inflater)
|
super.onCreateOptionsMenu(menu, inflater)
|
||||||
inflater.inflate(R.menu.menu_search, menu)
|
inflater.inflate(R.menu.menu_search, menu)
|
||||||
|
|
|
@ -18,12 +18,6 @@ package code.name.monkey.retromusic.mvp
|
||||||
* Created by hemanths on 09/08/17.
|
* Created by hemanths on 09/08/17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface BaseView<T> {
|
interface BaseView {
|
||||||
fun loading()
|
|
||||||
|
|
||||||
fun showData(list: T)
|
|
||||||
|
|
||||||
fun showEmptyView()
|
fun showEmptyView()
|
||||||
|
|
||||||
fun completed()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,17 +14,13 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp
|
package code.name.monkey.retromusic.mvp
|
||||||
|
|
||||||
import code.name.monkey.retromusic.Injection
|
|
||||||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
|
||||||
import code.name.monkey.retromusic.util.schedulers.BaseSchedulerProvider
|
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 16/08/17.
|
* Created by hemanths on 16/08/17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
open class Presenter {
|
|
||||||
protected var repository: Repository = Injection.provideRepository()
|
interface Presenter<T> {
|
||||||
protected var disposable: CompositeDisposable = CompositeDisposable()
|
fun attachView(view: T)
|
||||||
protected var schedulerProvider: BaseSchedulerProvider = Injection.provideSchedulerProvider()
|
|
||||||
|
fun detachView()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,15 +12,19 @@
|
||||||
* See the GNU General Public License for more details.
|
* See the GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp
|
package code.name.monkey.retromusic.mvp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 09/08/17.
|
* Created by hemanths on 2019-09-04.
|
||||||
*/
|
*/
|
||||||
|
public abstract class PresenterImpl<T> {
|
||||||
|
protected T view;
|
||||||
|
|
||||||
interface BasePresenter<T> {
|
public void attachView(T view) {
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
fun subscribe()
|
public void detachView() {
|
||||||
|
view = null;
|
||||||
fun unsubscribe()
|
}
|
||||||
}
|
}
|
|
@ -1,31 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Hemanth Savarala.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.contract
|
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Album
|
|
||||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
interface AlbumContract {
|
|
||||||
|
|
||||||
interface AlbumView : BaseView<ArrayList<Album>>
|
|
||||||
|
|
||||||
interface Presenter : BasePresenter<AlbumView> {
|
|
||||||
|
|
||||||
fun loadAlbums()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Hemanth Savarala.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.contract
|
|
||||||
|
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Album
|
|
||||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
|
||||||
|
|
||||||
interface AlbumDetailsContract {
|
|
||||||
|
|
||||||
interface AlbumDetailsView : BaseView<Album>
|
|
||||||
|
|
||||||
interface Presenter : BasePresenter<AlbumDetailsView> {
|
|
||||||
|
|
||||||
fun loadAlbumSongs(albumId: Int)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Hemanth Savarala.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.contract
|
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Playlist
|
|
||||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
|
||||||
|
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by hemanths on 19/08/17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
interface PlaylistContract {
|
|
||||||
interface PlaylistView : BaseView<ArrayList<Playlist>>
|
|
||||||
|
|
||||||
interface Presenter : BasePresenter<PlaylistView> {
|
|
||||||
fun loadPlaylists()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Hemanth Savarala.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.contract
|
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Playlist
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
|
||||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
|
||||||
|
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by hemanths on 20/08/17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
interface PlaylistSongsContract {
|
|
||||||
interface PlaylistSongsView : BaseView<ArrayList<Song>>
|
|
||||||
|
|
||||||
interface Presenter : BasePresenter<PlaylistSongsView> {
|
|
||||||
fun loadSongs(playlist: Playlist)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Hemanth Savarala.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.contract
|
|
||||||
|
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
|
||||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
|
||||||
|
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by hemanths on 10/08/17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
interface SongContract {
|
|
||||||
|
|
||||||
interface SongView : BaseView<ArrayList<Song>>
|
|
||||||
|
|
||||||
interface Presenter : BasePresenter<SongView> {
|
|
||||||
fun loadSongs()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,37 +15,71 @@
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Album
|
import code.name.monkey.retromusic.model.Album
|
||||||
|
import code.name.monkey.retromusic.model.Artist
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.contract.AlbumDetailsContract
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 20/08/17.
|
* Created by hemanths on 20/08/17.
|
||||||
*/
|
*/
|
||||||
|
interface AlbumDetailsView {
|
||||||
|
fun album(album: Album)
|
||||||
|
|
||||||
class AlbumDetailsPresenter(private val view: AlbumDetailsContract.AlbumDetailsView, private val albumId: Int) : Presenter(), AlbumDetailsContract.Presenter {
|
fun complete()
|
||||||
|
|
||||||
override fun subscribe() {
|
fun loadArtistImage(artist: Artist)
|
||||||
loadAlbumSongs(albumId)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun unsubscribe() {
|
fun moreAlbums(albums: ArrayList<Album>)
|
||||||
disposable.clear()
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun loadAlbumSongs(albumId: Int) {
|
interface AlbumDetailsPresenter : Presenter<AlbumDetailsView> {
|
||||||
disposable.add(repository.getAlbumFlowable(albumId)
|
fun loadAlbum(albumId: Int)
|
||||||
.doOnSubscribe { view.loading() }
|
|
||||||
.subscribe({ this.showAlbum(it) },
|
|
||||||
{ view.showEmptyView() },
|
|
||||||
{ view.completed() }))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showAlbum(album: Album?) {
|
fun loadMore(artistId: Int)
|
||||||
if (album != null) {
|
|
||||||
view.showData(album)
|
class AlbumDetailsPresenterImpl @Inject constructor(
|
||||||
} else {
|
private val repository: Repository
|
||||||
view.showEmptyView()
|
) : PresenterImpl<AlbumDetailsView>(), AlbumDetailsPresenter {
|
||||||
|
|
||||||
|
private lateinit var album: Album
|
||||||
|
|
||||||
|
override fun loadMore(artistId: Int) {
|
||||||
|
disposable = repository.getArtistByIdFlowable(artistId)
|
||||||
|
.map {
|
||||||
|
view.loadArtistImage(it)
|
||||||
|
return@map it.albums
|
||||||
|
}
|
||||||
|
.map {
|
||||||
|
it.filter { filterAlbum -> album.id != filterAlbum.id }
|
||||||
|
}
|
||||||
|
.subscribe {
|
||||||
|
if (it.isEmpty()) {
|
||||||
|
return@subscribe
|
||||||
|
}
|
||||||
|
view.moreAlbums(ArrayList(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var disposable: Disposable? = null
|
||||||
|
|
||||||
|
override fun loadAlbum(albumId: Int) {
|
||||||
|
disposable = repository.getAlbumFlowable(albumId)
|
||||||
|
.doOnComplete {
|
||||||
|
view.complete()
|
||||||
|
}
|
||||||
|
.subscribe {
|
||||||
|
album = it
|
||||||
|
view.album(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun detachView() {
|
||||||
|
super.detachView()
|
||||||
|
disposable?.dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,34 +15,43 @@
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Album
|
import code.name.monkey.retromusic.model.Album
|
||||||
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.contract.AlbumContract
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 12/08/17.
|
* Created by hemanths on 12/08/17.
|
||||||
*/
|
*/
|
||||||
|
interface AlbumsView : BaseView {
|
||||||
class AlbumPresenter(private val view: AlbumContract.AlbumView) : Presenter(), AlbumContract.Presenter {
|
fun albums(albums: ArrayList<Album>)
|
||||||
|
|
||||||
override fun subscribe() {
|
|
||||||
loadAlbums()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun unsubscribe() {
|
|
||||||
disposable.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showList(albums: ArrayList<Album>) {
|
|
||||||
view.showData(albums)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun loadAlbums() {
|
|
||||||
disposable.add(repository.allAlbumsFlowable
|
|
||||||
.doOnSubscribe { view.loading() }
|
|
||||||
.subscribe({ this.showList(it) },
|
|
||||||
{ view.showEmptyView() },
|
|
||||||
{ view.completed() }))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface AlbumsPresenter : Presenter<AlbumsView> {
|
||||||
|
|
||||||
|
fun loadAlbums()
|
||||||
|
|
||||||
|
class AlbumsPresenterImpl @Inject constructor(
|
||||||
|
private val repository: Repository
|
||||||
|
) : PresenterImpl<AlbumsView>(), AlbumsPresenter {
|
||||||
|
|
||||||
|
private var disposable: Disposable? = null
|
||||||
|
|
||||||
|
private fun showList(albums: ArrayList<Album>) {
|
||||||
|
if (albums.isNotEmpty()) view.albums(albums) else view.showEmptyView()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun detachView() {
|
||||||
|
super.detachView()
|
||||||
|
disposable?.dispose()
|
||||||
|
}
|
||||||
|
override fun loadAlbums() {
|
||||||
|
disposable = repository.allAlbumsFlowable
|
||||||
|
.subscribe { this.showList(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,41 +14,62 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import code.name.monkey.retromusic.model.Artist
|
import code.name.monkey.retromusic.model.Artist
|
||||||
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.contract.ArtistDetailContract
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
import code.name.monkey.retromusic.activities.ArtistDetailActivity
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
|
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 20/08/17.
|
* Created by hemanths on 20/08/17.
|
||||||
*/
|
*/
|
||||||
|
interface ArtistDetailsView : BaseView {
|
||||||
|
fun artist(artist: Artist)
|
||||||
|
fun artistInfo(lastFmArtist: LastFmArtist?)
|
||||||
|
fun complete()
|
||||||
|
}
|
||||||
|
|
||||||
class ArtistDetailsPresenter(private val view: ArtistDetailContract.ArtistsDetailsView,
|
interface ArtistDetailsPresenter : Presenter<ArtistDetailsView> {
|
||||||
private val bundle: Bundle) : Presenter(), ArtistDetailContract.Presenter {
|
|
||||||
|
|
||||||
override fun subscribe() {
|
fun loadArtist(artistId: Int)
|
||||||
loadArtistById()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun unsubscribe() {
|
fun loadBiography(name: String,
|
||||||
disposable.clear()
|
lang: String? = Locale.getDefault().language,
|
||||||
}
|
cache: String?)
|
||||||
|
|
||||||
override fun loadArtistById() {
|
class ArtistDetailsPresenterImpl @Inject constructor(
|
||||||
disposable.add(repository.getArtistByIdFlowable(bundle.getInt(ArtistDetailActivity.EXTRA_ARTIST_ID))
|
private val repository: Repository
|
||||||
.doOnSubscribe { view.loading() }
|
) : PresenterImpl<ArtistDetailsView>(), ArtistDetailsPresenter {
|
||||||
.subscribe({ this.showArtist(it) },
|
|
||||||
{ view.showEmptyView() },
|
|
||||||
{ view.completed() }))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showArtist(album: Artist?) {
|
override fun loadBiography(name: String,
|
||||||
if (album != null) {
|
lang: String?,
|
||||||
view.showData(album)
|
cache: String?) {
|
||||||
} else {
|
disposable = repository.artistInfoFloable(name, lang, cache)
|
||||||
view.showEmptyView()
|
.subscribe {
|
||||||
|
view.artistInfo(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var disposable: Disposable? = null
|
||||||
|
|
||||||
|
override fun loadArtist(artistId: Int) {
|
||||||
|
disposable = repository.getArtistByIdFlowable(artistId)
|
||||||
|
.doOnComplete {
|
||||||
|
view.complete()
|
||||||
|
}
|
||||||
|
.subscribe {
|
||||||
|
this.showArtist(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun showArtist(artist: Artist) {
|
||||||
|
view.artist(artist)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,34 +14,49 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
|
import code.name.monkey.retromusic.helper.SearchQueryHelper.songs
|
||||||
import code.name.monkey.retromusic.model.Artist
|
import code.name.monkey.retromusic.model.Artist
|
||||||
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.contract.ArtistContract
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
import java.util.*
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
|
import io.reactivex.functions.Consumer
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ArtistPresenter(private val mView: ArtistContract.ArtistView) : Presenter(), ArtistContract.Presenter {
|
interface ArtistsView : BaseView {
|
||||||
|
fun artists(artists: ArrayList<Artist>)
|
||||||
|
}
|
||||||
|
|
||||||
override fun subscribe() {
|
interface ArtistsPresenter : Presenter<ArtistsView> {
|
||||||
loadArtists()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun unsubscribe() {
|
fun loadArtists()
|
||||||
disposable.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showList(songs: ArrayList<Artist>) {
|
class ArtistsPresenterImpl @Inject constructor(
|
||||||
if (songs.isEmpty()) {
|
private val repository: Repository
|
||||||
mView.showEmptyView()
|
) : PresenterImpl<ArtistsView>(), ArtistsPresenter {
|
||||||
} else {
|
|
||||||
mView.showData(songs)
|
private var disposable: Disposable? = null
|
||||||
|
|
||||||
|
private fun showList(artists: ArrayList<Artist>) {
|
||||||
|
if (songs.isNotEmpty())
|
||||||
|
view.artists(artists)
|
||||||
|
else
|
||||||
|
view.showEmptyView()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun detachView() {
|
||||||
|
super.detachView()
|
||||||
|
disposable?.dispose()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun loadArtists() {
|
||||||
|
disposable = repository.allArtistsFlowable
|
||||||
|
.subscribe({
|
||||||
|
view.artists(it)
|
||||||
|
}, {
|
||||||
|
println(it)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadArtists() {
|
|
||||||
disposable.add(repository.allArtistsFlowable
|
|
||||||
.doOnSubscribe { mView.loading() }
|
|
||||||
.subscribe({ this.showList(it) },
|
|
||||||
{ mView.showEmptyView() },
|
|
||||||
{ mView.completed() }))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,39 +15,51 @@
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.contract.GenreDetailsContract
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 20/08/17.
|
* Created by hemanths on 20/08/17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class GenreDetailsPresenter(private val view: GenreDetailsContract.GenreDetailsView,
|
interface GenreDetailsView : BaseView {
|
||||||
private val genreId: Int) : Presenter(), GenreDetailsContract.Presenter {
|
fun songs(songs: ArrayList<Song>)
|
||||||
|
}
|
||||||
|
|
||||||
override fun subscribe() {
|
interface GenreDetailsPresenter : Presenter<GenreDetailsView> {
|
||||||
loadGenre(genreId)
|
fun loadGenreSongs(genreId: Int)
|
||||||
}
|
|
||||||
|
|
||||||
override fun unsubscribe() {
|
class GenreDetailsPresenterImpl @Inject constructor(
|
||||||
disposable.clear()
|
private val repository: Repository
|
||||||
}
|
) : PresenterImpl<GenreDetailsView>(), GenreDetailsPresenter {
|
||||||
|
|
||||||
override fun loadGenre(genreId: Int) {
|
override fun detachView() {
|
||||||
disposable.add(repository.getGenreFlowable(genreId)
|
super.detachView()
|
||||||
.doOnSubscribe { view.loading() }
|
disposable?.dispose()
|
||||||
.subscribe({ this.showGenre(it) },
|
}
|
||||||
{ view.showEmptyView() },
|
|
||||||
{ view.completed() }))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showGenre(songs: ArrayList<Song>?) {
|
private var disposable: Disposable? = null
|
||||||
if (songs != null) {
|
|
||||||
view.showData(songs)
|
override fun loadGenreSongs(genreId: Int) {
|
||||||
} else {
|
disposable = repository.getGenreFlowable(genreId)
|
||||||
view.showEmptyView()
|
.subscribe {
|
||||||
|
showGenre(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showGenre(songs: ArrayList<Song>) {
|
||||||
|
if (songs.isNotEmpty()) {
|
||||||
|
view.songs(songs)
|
||||||
|
} else {
|
||||||
|
view.showEmptyView()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,38 +15,42 @@
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Genre
|
import code.name.monkey.retromusic.model.Genre
|
||||||
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.contract.GenreContract
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
|
import code.name.monkey.retromusic.providers.RepositoryImpl
|
||||||
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hemanth S (h4h13).
|
* @author Hemanth S (h4h13).
|
||||||
*/
|
*/
|
||||||
|
interface GenresView : BaseView {
|
||||||
|
fun genres(genres: ArrayList<Genre>)
|
||||||
|
}
|
||||||
|
|
||||||
class GenrePresenter(
|
interface GenresPresenter : Presenter<GenresView> {
|
||||||
private val view: GenreContract.GenreView) : Presenter(), GenreContract.Presenter {
|
fun loadGenres()
|
||||||
|
|
||||||
override fun subscribe() {
|
class GenresPresenterImpl @Inject constructor(
|
||||||
loadGenre()
|
private val repository: Repository
|
||||||
}
|
) : PresenterImpl<GenresView>(), GenresPresenter {
|
||||||
|
|
||||||
override fun unsubscribe() {
|
private var disposable: Disposable? = null
|
||||||
disposable.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun loadGenre() {
|
override fun loadGenres() {
|
||||||
disposable.add(repository.allGenresFlowable
|
disposable = repository.allGenresFlowable
|
||||||
.doOnSubscribe { view.loading() }
|
.subscribe { this.showList(it) }
|
||||||
.subscribe({ this.showList(it) },
|
}
|
||||||
{ view.showEmptyView() },
|
|
||||||
{ view.completed() }))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showList(genres: ArrayList<Genre>) {
|
private fun showList(genres: ArrayList<Genre>) {
|
||||||
if (genres.isEmpty()) {
|
if (genres.isNotEmpty()) {
|
||||||
view.showEmptyView()
|
view.genres(genres)
|
||||||
} else {
|
} else {
|
||||||
view.showData(genres)
|
view.showEmptyView()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,25 +15,135 @@
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.adapter.HomeAdapter.Companion.GENRES
|
|
||||||
import code.name.monkey.retromusic.adapter.HomeAdapter.Companion.PLAYLISTS
|
import code.name.monkey.retromusic.adapter.HomeAdapter.Companion.PLAYLISTS
|
||||||
import code.name.monkey.retromusic.adapter.HomeAdapter.Companion.RECENT_ALBUMS
|
import code.name.monkey.retromusic.adapter.HomeAdapter.Companion.RECENT_ALBUMS
|
||||||
import code.name.monkey.retromusic.adapter.HomeAdapter.Companion.RECENT_ARTISTS
|
import code.name.monkey.retromusic.adapter.HomeAdapter.Companion.RECENT_ARTISTS
|
||||||
import code.name.monkey.retromusic.adapter.HomeAdapter.Companion.TOP_ALBUMS
|
import code.name.monkey.retromusic.adapter.HomeAdapter.Companion.TOP_ALBUMS
|
||||||
import code.name.monkey.retromusic.adapter.HomeAdapter.Companion.TOP_ARTISTS
|
import code.name.monkey.retromusic.adapter.HomeAdapter.Companion.TOP_ARTISTS
|
||||||
import code.name.monkey.retromusic.model.Home
|
import code.name.monkey.retromusic.model.Home
|
||||||
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.contract.HomeContract
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
operator fun CompositeDisposable.plusAssign(disposable: Disposable) {
|
operator fun CompositeDisposable.plusAssign(disposable: Disposable) {
|
||||||
add(disposable)
|
add(disposable)
|
||||||
}
|
}
|
||||||
|
|
||||||
class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), HomeContract.HomePresenter {
|
interface HomeView : BaseView {
|
||||||
|
fun sections(sections: ArrayList<Home>)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface HomePresenter : Presenter<HomeView> {
|
||||||
|
fun loadSections()
|
||||||
|
|
||||||
|
class HomePresenterImpl @Inject constructor(
|
||||||
|
private val repository: Repository
|
||||||
|
) : PresenterImpl<HomeView>(), HomePresenter {
|
||||||
|
override fun loadSections() {
|
||||||
|
loadRecentArtists()
|
||||||
|
loadRecentAlbums()
|
||||||
|
loadTopArtists()
|
||||||
|
loadATopAlbums()
|
||||||
|
loadFavorite()
|
||||||
|
}
|
||||||
|
|
||||||
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
|
private val hashSet: HashSet<Home> = HashSet()
|
||||||
|
|
||||||
|
private fun showData(sections: ArrayList<Home>) {
|
||||||
|
if (sections.isEmpty()) {
|
||||||
|
view.showEmptyView()
|
||||||
|
} else {
|
||||||
|
view.sections(sections)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadRecentArtists() {
|
||||||
|
disposable += repository.recentArtistsFlowable
|
||||||
|
.subscribe {
|
||||||
|
if (it.isNotEmpty()) hashSet.add(
|
||||||
|
Home(0,
|
||||||
|
R.string.recent_artists,
|
||||||
|
0,
|
||||||
|
it,
|
||||||
|
RECENT_ARTISTS,
|
||||||
|
R.drawable.ic_artist_white_24dp
|
||||||
|
))
|
||||||
|
showData(ArrayList(hashSet))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadRecentAlbums() {
|
||||||
|
disposable += repository.recentAlbumsFlowable
|
||||||
|
.subscribe {
|
||||||
|
if (it.isNotEmpty()) hashSet.add(
|
||||||
|
Home(1,
|
||||||
|
R.string.recent_albums,
|
||||||
|
0,
|
||||||
|
it,
|
||||||
|
RECENT_ALBUMS,
|
||||||
|
R.drawable.ic_album_white_24dp
|
||||||
|
))
|
||||||
|
showData(ArrayList(hashSet))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadTopArtists() {
|
||||||
|
disposable += repository.topArtistsFlowable
|
||||||
|
.subscribe {
|
||||||
|
if (it.isNotEmpty()) hashSet.add(
|
||||||
|
Home(2,
|
||||||
|
R.string.top_artists,
|
||||||
|
0,
|
||||||
|
it,
|
||||||
|
TOP_ARTISTS,
|
||||||
|
R.drawable.ic_artist_white_24dp
|
||||||
|
))
|
||||||
|
showData(ArrayList(hashSet))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadATopAlbums() {
|
||||||
|
disposable += repository.topAlbumsFlowable
|
||||||
|
.subscribe {
|
||||||
|
if (it.isNotEmpty()) hashSet.add(
|
||||||
|
Home(3,
|
||||||
|
R.string.top_albums,
|
||||||
|
0,
|
||||||
|
it,
|
||||||
|
TOP_ALBUMS,
|
||||||
|
R.drawable.ic_album_white_24dp
|
||||||
|
))
|
||||||
|
showData(ArrayList(hashSet))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadFavorite() {
|
||||||
|
disposable += repository.favoritePlaylistFlowable
|
||||||
|
.subscribe {
|
||||||
|
if (it.isNotEmpty()) hashSet.add(
|
||||||
|
Home(4,
|
||||||
|
R.string.favorites,
|
||||||
|
0,
|
||||||
|
it,
|
||||||
|
PLAYLISTS,
|
||||||
|
R.drawable.ic_favorite_white_24dp
|
||||||
|
))
|
||||||
|
showData(ArrayList(hashSet))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*class HomePresenter(
|
||||||
|
private val view: HomeContract.HomeView,
|
||||||
|
private val repositoryImpl: RepositoryImpl
|
||||||
|
) : Presenter(), HomeContract.HomePresenter {
|
||||||
private val hashSet: HashSet<Home> = HashSet()
|
private val hashSet: HashSet<Home> = HashSet()
|
||||||
|
|
||||||
override fun homeSections() {
|
override fun homeSections() {
|
||||||
|
@ -53,7 +163,7 @@ class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), Home
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadRecentArtists() {
|
private fun loadRecentArtists() {
|
||||||
disposable += repository.recentArtistsFlowable
|
disposable += repositoryImpl.recentArtistsFlowable
|
||||||
.subscribe({
|
.subscribe({
|
||||||
if (it.isNotEmpty()) hashSet.add(Home(0, R.string.recent_artists, 0, it, RECENT_ARTISTS, R.drawable.ic_artist_white_24dp))
|
if (it.isNotEmpty()) hashSet.add(Home(0, R.string.recent_artists, 0, it, RECENT_ARTISTS, R.drawable.ic_artist_white_24dp))
|
||||||
view.showData(ArrayList(hashSet))
|
view.showData(ArrayList(hashSet))
|
||||||
|
@ -63,7 +173,7 @@ class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), Home
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadRecentAlbums() {
|
private fun loadRecentAlbums() {
|
||||||
disposable += repository.recentAlbumsFlowable
|
disposable += repositoryImpl.recentAlbumsFlowable
|
||||||
.subscribe({
|
.subscribe({
|
||||||
if (it.isNotEmpty()) hashSet.add(Home(1, R.string.recent_albums, 0, it, RECENT_ALBUMS, R.drawable.ic_album_white_24dp))
|
if (it.isNotEmpty()) hashSet.add(Home(1, R.string.recent_albums, 0, it, RECENT_ALBUMS, R.drawable.ic_album_white_24dp))
|
||||||
view.showData(ArrayList(hashSet))
|
view.showData(ArrayList(hashSet))
|
||||||
|
@ -73,7 +183,7 @@ class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), Home
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadATopAlbums() {
|
private fun loadATopAlbums() {
|
||||||
disposable += repository.topAlbumsFlowable
|
disposable += repositoryImpl.topAlbumsFlowable
|
||||||
.subscribe({
|
.subscribe({
|
||||||
if (it.isNotEmpty()) hashSet.add(Home(3, R.string.top_albums, 0, it, TOP_ALBUMS, R.drawable.ic_album_white_24dp))
|
if (it.isNotEmpty()) hashSet.add(Home(3, R.string.top_albums, 0, it, TOP_ALBUMS, R.drawable.ic_album_white_24dp))
|
||||||
view.showData(ArrayList(hashSet))
|
view.showData(ArrayList(hashSet))
|
||||||
|
@ -83,7 +193,7 @@ class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), Home
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadTopArtists() {
|
private fun loadTopArtists() {
|
||||||
disposable += repository.topArtistsFlowable
|
disposable += repositoryImpl.topArtistsFlowable
|
||||||
.subscribe({
|
.subscribe({
|
||||||
if (it.isNotEmpty()) hashSet.add(Home(2, R.string.top_artists, 0, it, TOP_ARTISTS, R.drawable.ic_artist_white_24dp))
|
if (it.isNotEmpty()) hashSet.add(Home(2, R.string.top_artists, 0, it, TOP_ARTISTS, R.drawable.ic_artist_white_24dp))
|
||||||
view.showData(ArrayList(hashSet))
|
view.showData(ArrayList(hashSet))
|
||||||
|
@ -93,7 +203,7 @@ class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), Home
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadFavorite() {
|
private fun loadFavorite() {
|
||||||
disposable += repository.favoritePlaylistFlowable
|
disposable += repositoryImpl.favoritePlaylistFlowable
|
||||||
.subscribe({
|
.subscribe({
|
||||||
if (it.isNotEmpty()) hashSet.add(Home(4, R.string.favorites, 0, it, PLAYLISTS, R.drawable.ic_favorite_white_24dp))
|
if (it.isNotEmpty()) hashSet.add(Home(4, R.string.favorites, 0, it, PLAYLISTS, R.drawable.ic_favorite_white_24dp))
|
||||||
view.showData(ArrayList(hashSet))
|
view.showData(ArrayList(hashSet))
|
||||||
|
@ -101,4 +211,4 @@ class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), Home
|
||||||
view.showEmptyView()
|
view.showEmptyView()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
|
@ -15,38 +15,45 @@
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Playlist
|
import code.name.monkey.retromusic.model.Playlist
|
||||||
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.contract.PlaylistContract
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
import java.util.*
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 19/08/17.
|
* Created by hemanths on 19/08/17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class PlaylistPresenter(private val view: PlaylistContract.PlaylistView) : Presenter(), PlaylistContract.Presenter {
|
interface PlaylistView : BaseView {
|
||||||
|
fun playlists(playlists: ArrayList<Playlist>)
|
||||||
|
}
|
||||||
|
|
||||||
override fun subscribe() {
|
interface PlaylistsPresenter : Presenter<PlaylistView> {
|
||||||
loadPlaylists()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun unsubscribe() {
|
fun playlists()
|
||||||
disposable.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun loadPlaylists() {
|
class PlaylistsPresenterImpl @Inject constructor(
|
||||||
disposable.add(repository.allPlaylistsFlowable
|
private val repository: Repository
|
||||||
.doOnSubscribe { view.loading() }
|
) : PresenterImpl<PlaylistView>(), PlaylistsPresenter {
|
||||||
.subscribe({ this.showList(it) },
|
|
||||||
{ view.showEmptyView() },
|
|
||||||
{ view.completed() }))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showList(songs: ArrayList<Playlist>) {
|
private var disposable: Disposable? = null
|
||||||
if (songs.isEmpty()) {
|
|
||||||
view.showEmptyView()
|
override fun playlists() {
|
||||||
} else {
|
disposable = repository.allPlaylistsFlowable
|
||||||
view.showData(songs)
|
.subscribe { this.showList(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showList(arrayList: ArrayList<Playlist>) {
|
||||||
|
if (arrayList.isEmpty()) {
|
||||||
|
view.showEmptyView()
|
||||||
|
} else {
|
||||||
|
view.playlists(arrayList)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,30 +15,45 @@
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Playlist
|
import code.name.monkey.retromusic.model.Playlist
|
||||||
|
import code.name.monkey.retromusic.model.Song
|
||||||
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.contract.PlaylistSongsContract
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 20/08/17.
|
* Created by hemanths on 20/08/17.
|
||||||
*/
|
*/
|
||||||
|
interface PlaylistSongsView : BaseView {
|
||||||
class PlaylistSongsPresenter(private val view: PlaylistSongsContract.PlaylistSongsView,
|
fun songs(songs: ArrayList<Song>)
|
||||||
private val mPlaylist: Playlist) : Presenter(), PlaylistSongsContract.Presenter {
|
|
||||||
|
|
||||||
|
|
||||||
override fun subscribe() {
|
|
||||||
loadSongs(mPlaylist)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun unsubscribe() {
|
|
||||||
disposable.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun loadSongs(playlist: Playlist) {
|
|
||||||
disposable.add(repository.getPlaylistSongsFlowable(playlist)
|
|
||||||
.doOnSubscribe { view.loading() }
|
|
||||||
.subscribe({ songs -> view.showData(songs) },
|
|
||||||
{ view.showEmptyView() },
|
|
||||||
{ view.completed() }))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PlaylistSongsPresenter : Presenter<PlaylistSongsView> {
|
||||||
|
fun loadPlaylistSongs(playlist: Playlist)
|
||||||
|
|
||||||
|
class PlaylistSongsPresenterImpl @Inject constructor(
|
||||||
|
private val repository: Repository
|
||||||
|
) : PresenterImpl<PlaylistSongsView>(), PlaylistSongsPresenter {
|
||||||
|
|
||||||
|
private var disposable: Disposable? = null
|
||||||
|
|
||||||
|
override fun loadPlaylistSongs(playlist: Playlist) {
|
||||||
|
disposable = repository.getPlaylistSongsFlowable(playlist)
|
||||||
|
.subscribe {
|
||||||
|
view.songs(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun detachView() {
|
||||||
|
super.detachView()
|
||||||
|
disposable?.dispose()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun attachView(view: PlaylistSongsView) {
|
||||||
|
super.attachView(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,33 +15,40 @@
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.contract.SearchContract
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
import java.util.*
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
import java.util.concurrent.TimeUnit
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 20/08/17.
|
* Created by hemanths on 20/08/17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class SearchPresenter(private val view: SearchContract.SearchView) : Presenter(), SearchContract.SearchPresenter {
|
interface SearchView {
|
||||||
|
fun showData(data: MutableList<Any>)
|
||||||
|
|
||||||
override fun subscribe() {
|
fun showEmptyView()
|
||||||
search("")
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun unsubscribe() {
|
interface SearchPresenter : Presenter<SearchView> {
|
||||||
disposable.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showList(albums: ArrayList<Any>) {
|
fun search(query: String?)
|
||||||
if (albums.isEmpty()) {
|
|
||||||
view.showEmptyView()
|
class SearchPresenterImpl @Inject constructor(
|
||||||
} else {
|
private val repository: Repository
|
||||||
view.showData(albums)
|
) : PresenterImpl<SearchView>(), SearchPresenter {
|
||||||
|
|
||||||
|
override fun attachView(view: SearchView) {
|
||||||
|
super.attachView(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun detachView() {
|
||||||
|
super.detachView()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun search(query: String?) {
|
||||||
|
view.showData(repository.search(query))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun search(query: String?) {
|
|
||||||
view.showData(repository.search(query))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,36 +16,42 @@ package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.contract.SongContract
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 10/08/17.
|
* Created by hemanths on 10/08/17.
|
||||||
*/
|
*/
|
||||||
|
interface SongView {
|
||||||
|
fun songs(songs: ArrayList<Song>)
|
||||||
|
|
||||||
class SongPresenter(private val view: SongContract.SongView) : Presenter(), SongContract.Presenter {
|
fun showEmptyView()
|
||||||
|
}
|
||||||
|
|
||||||
override fun loadSongs() {
|
interface SongPresenter : Presenter<SongView> {
|
||||||
disposable.add(repository.allSongsFlowable
|
fun loadSongs()
|
||||||
.doOnSubscribe { view.loading() }
|
|
||||||
.subscribe({ this.showList(it) },
|
|
||||||
{ view.showEmptyView() },
|
|
||||||
{ view.completed() }))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun subscribe() {
|
class SongPresenterImpl @Inject constructor(
|
||||||
loadSongs()
|
private val repository: Repository
|
||||||
}
|
) : PresenterImpl<SongView>(), SongPresenter {
|
||||||
|
|
||||||
private fun showList(songs: ArrayList<Song>) {
|
private var disposable: Disposable? = null
|
||||||
if (songs.isEmpty()) {
|
|
||||||
view.showEmptyView()
|
override fun loadSongs() {
|
||||||
} else {
|
disposable = repository.allSongsFlowable
|
||||||
view.showData(songs)
|
.subscribe {
|
||||||
|
view.songs(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun detachView() {
|
||||||
|
super.detachView()
|
||||||
|
disposable?.dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unsubscribe() {
|
|
||||||
disposable.clear()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,23 @@ import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.loaders.*
|
import code.name.monkey.retromusic.loaders.*
|
||||||
import code.name.monkey.retromusic.model.*
|
import code.name.monkey.retromusic.model.*
|
||||||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
|
import code.name.monkey.retromusic.rest.LastFMRestClient
|
||||||
|
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
|
|
||||||
class RepositoryImpl(private val context: Context) : Repository {
|
class RepositoryImpl(private val context: Context) : Repository {
|
||||||
|
override fun artistInfoFloable(
|
||||||
|
name: String,
|
||||||
|
lang: String?,
|
||||||
|
cache: String?
|
||||||
|
): Observable<LastFmArtist> {
|
||||||
|
return LastFMRestClient(context).apiService.getArtistInfoFloable(name, lang, cache)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
}
|
||||||
|
|
||||||
override fun search(query: String?): MutableList<Any> {
|
override fun search(query: String?): MutableList<Any> {
|
||||||
return SearchLoader.searchAll(context, query)
|
return SearchLoader.searchAll(context, query)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package code.name.monkey.retromusic.providers.interfaces
|
package code.name.monkey.retromusic.providers.interfaces
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.*
|
import code.name.monkey.retromusic.model.*
|
||||||
|
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,4 +88,7 @@ interface Repository {
|
||||||
|
|
||||||
val favoritePlaylist: ArrayList<Playlist>
|
val favoritePlaylist: ArrayList<Playlist>
|
||||||
|
|
||||||
|
fun artistInfoFloable(name: String,
|
||||||
|
lang: String?,
|
||||||
|
cache: String?): Observable<LastFmArtist>
|
||||||
}
|
}
|
|
@ -16,11 +16,12 @@ package code.name.monkey.retromusic.rest;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import code.name.monkey.retromusic.rest.service.LastFMService;
|
import code.name.monkey.retromusic.rest.service.LastFMService;
|
||||||
import okhttp3.Cache;
|
import okhttp3.Cache;
|
||||||
import okhttp3.Call;
|
import okhttp3.Call;
|
||||||
|
@ -43,7 +44,7 @@ public class LastFMRestClient {
|
||||||
this(createDefaultOkHttpClientBuilder(context).build());
|
this(createDefaultOkHttpClientBuilder(context).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public LastFMRestClient(@NonNull Call.Factory client) {
|
private LastFMRestClient(@NonNull Call.Factory client) {
|
||||||
Retrofit restAdapter = new Retrofit.Builder()
|
Retrofit restAdapter = new Retrofit.Builder()
|
||||||
.baseUrl(BASE_URL)
|
.baseUrl(BASE_URL)
|
||||||
.callFactory(client)
|
.callFactory(client)
|
||||||
|
@ -72,7 +73,8 @@ public class LastFMRestClient {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OkHttpClient.Builder createDefaultOkHttpClientBuilder(Context context) {
|
@NonNull
|
||||||
|
private static OkHttpClient.Builder createDefaultOkHttpClientBuilder(@NonNull Context context) {
|
||||||
return new OkHttpClient.Builder()
|
return new OkHttpClient.Builder()
|
||||||
.connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
|
.connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
|
||||||
.retryOnConnectionFailure(true)
|
.retryOnConnectionFailure(true)
|
||||||
|
@ -83,6 +85,7 @@ public class LastFMRestClient {
|
||||||
.addInterceptor(createCacheControlInterceptor());
|
.addInterceptor(createCacheControlInterceptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public LastFMService getApiService() {
|
public LastFMService getApiService() {
|
||||||
return apiService;
|
return apiService;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,9 @@ package code.name.monkey.retromusic.rest.service;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import code.name.monkey.retromusic.rest.model.LastFmAlbum;
|
import code.name.monkey.retromusic.rest.model.LastFmAlbum;
|
||||||
import code.name.monkey.retromusic.rest.model.LastFmArtist;
|
import code.name.monkey.retromusic.rest.model.LastFmArtist;
|
||||||
import code.name.monkey.retromusic.rest.model.LastFmTrack;
|
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
|
@ -37,12 +37,11 @@ public interface LastFMService {
|
||||||
Observable<LastFmAlbum> getAlbumInfo(@Query("album") @NonNull String albumName, @Query("artist") @NonNull String artistName, @Nullable @Query("lang") String language);
|
Observable<LastFmAlbum> getAlbumInfo(@Query("album") @NonNull String albumName, @Query("artist") @NonNull String artistName, @Nullable @Query("lang") String language);
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@GET("?api_key=" + API_KEY + "&format=json&autocorrect=1" + "&method=" + METHOD_TRACK)
|
@GET(BASE_QUERY_PARAMETERS + "&method=artist.getinfo")
|
||||||
Observable<LastFmTrack> getTrackInfo(@Query("artist") @NonNull String artist, @Query("track") @NonNull String track);
|
Call<LastFmArtist> getArtistInfo(@Query("artist") @NonNull String artistName, @Nullable @Query("lang") String language, @Nullable @Header("Cache-Control") String cacheControl);
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@GET(BASE_QUERY_PARAMETERS + "&method=artist.getinfo")
|
@GET(BASE_QUERY_PARAMETERS + "&method=artist.getinfo")
|
||||||
default Call<LastFmArtist> getArtistInfo(@Query("artist") @NonNull String artistName, @Nullable @Query("lang") String language, @Nullable @Header("Cache-Control") String cacheControl) {
|
Observable<LastFmArtist> getArtistInfoFloable(@Query("artist") @NonNull String artistName, @Nullable @Query("lang") String language, @Nullable @Header("Cache-Control") String cacheControl);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue