From 6cdea143164e266841ef4c3b3d07a41ffc7ea500 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Thu, 5 Sep 2019 01:00:24 +0530 Subject: [PATCH] Added Dagger --- app/build.gradle | 7 +- .../java/code/name/monkey/retromusic/App.kt | 11 ++ .../activities/AlbumDetailsActivity.kt | 93 ++++++------ .../activities/ArtistDetailActivity.kt | 116 +++++++-------- .../activities/GenreDetailsActivity.kt | 51 ++++--- .../activities/PlaylistDetailActivity.kt | 57 ++++---- .../retromusic/activities/SearchActivity.kt | 24 ++-- .../retromusic/dagger/MusicComponent.kt | 60 ++++++++ .../module/ActivityModule.kt} | 22 +-- .../retromusic/dagger/module/AlbumModule.kt | 39 ++++++ .../module/AppModule.kt} | 20 +-- .../retromusic/dagger/module/ArtistModule.kt | 40 ++++++ .../retromusic/dagger/module/GenreModule.kt | 40 ++++++ .../module/HomeModule.kt} | 24 ++-- .../dagger/module/PlaylistModule.kt | 38 +++++ .../module/RepositoryModule.kt} | 23 +-- .../module/SearchModule.kt} | 26 ++-- .../module/SongModule.kt} | 24 ++-- .../fragments/mainactivity/AlbumsFragment.kt | 60 ++++---- .../fragments/mainactivity/ArtistsFragment.kt | 75 +++++----- .../fragments/mainactivity/GenresFragment.kt | 39 +++--- .../mainactivity/PlaylistsFragment.kt | 36 ++--- .../fragments/mainactivity/SongsFragment.kt | 41 +++--- .../mainactivity/home/BannerHomeFragment.kt | 59 ++++---- .../name/monkey/retromusic/mvp/BaseView.kt | 8 +- .../name/monkey/retromusic/mvp/Presenter.kt | 14 +- .../{BasePresenter.kt => PresenterImpl.java} | 16 ++- .../retromusic/mvp/contract/AlbumContract.kt | 31 ---- .../mvp/contract/AlbumDetailsContract.kt | 30 ---- .../mvp/contract/PlaylistContract.kt | 33 ----- .../mvp/contract/PlaylistSongsContract.kt | 35 ----- .../retromusic/mvp/contract/SongContract.kt | 36 ----- .../mvp/presenter/AlbumDetailsPresenter.kt | 76 +++++++--- .../mvp/presenter/AlbumPresenter.kt | 55 +++++--- .../mvp/presenter/ArtistDetailsPresenter.kt | 69 +++++---- .../mvp/presenter/ArtistPresenter.kt | 59 +++++--- .../mvp/presenter/GenreDetailsPresenter.kt | 54 ++++--- .../mvp/presenter/GenrePresenter.kt | 46 +++--- .../retromusic/mvp/presenter/HomePresenter.kt | 132 ++++++++++++++++-- .../mvp/presenter/PlaylistPresenter.kt | 49 ++++--- .../mvp/presenter/PlaylistSongsPresenter.kt | 57 +++++--- .../mvp/presenter/SearchPresenter.kt | 45 +++--- .../retromusic/mvp/presenter/SongPresenter.kt | 48 ++++--- .../retromusic/providers/RepositoryImpl.kt | 12 ++ .../providers/interfaces/Repository.kt | 4 + .../retromusic/rest/LastFMRestClient.java | 11 +- .../rest/service/LastFMService.java | 11 +- 47 files changed, 1130 insertions(+), 826 deletions(-) create mode 100644 app/src/main/java/code/name/monkey/retromusic/dagger/MusicComponent.kt rename app/src/main/java/code/name/monkey/retromusic/{mvp/contract/HomeContract.kt => dagger/module/ActivityModule.kt} (62%) create mode 100644 app/src/main/java/code/name/monkey/retromusic/dagger/module/AlbumModule.kt rename app/src/main/java/code/name/monkey/retromusic/{mvp/contract/SearchContract.kt => dagger/module/AppModule.kt} (61%) create mode 100644 app/src/main/java/code/name/monkey/retromusic/dagger/module/ArtistModule.kt create mode 100644 app/src/main/java/code/name/monkey/retromusic/dagger/module/GenreModule.kt rename app/src/main/java/code/name/monkey/retromusic/{mvp/contract/ArtistDetailContract.kt => dagger/module/HomeModule.kt} (59%) create mode 100644 app/src/main/java/code/name/monkey/retromusic/dagger/module/PlaylistModule.kt rename app/src/main/java/code/name/monkey/retromusic/{mvp/contract/GenreDetailsContract.kt => dagger/module/RepositoryModule.kt} (56%) rename app/src/main/java/code/name/monkey/retromusic/{mvp/contract/ArtistContract.kt => dagger/module/SearchModule.kt} (58%) rename app/src/main/java/code/name/monkey/retromusic/{mvp/contract/GenreContract.kt => dagger/module/SongModule.kt} (59%) rename app/src/main/java/code/name/monkey/retromusic/mvp/{BasePresenter.kt => PresenterImpl.java} (69%) delete mode 100644 app/src/main/java/code/name/monkey/retromusic/mvp/contract/AlbumContract.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/mvp/contract/AlbumDetailsContract.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/mvp/contract/PlaylistContract.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/mvp/contract/PlaylistSongsContract.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/mvp/contract/SongContract.kt diff --git a/app/build.gradle b/app/build.gradle index c3d5b6ed..3df0e6da 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -75,7 +75,9 @@ android { androidExtensions { experimental = true } - + kapt { + generateStubs = true + } } def getProperties(String fileName) { @@ -150,6 +152,9 @@ dependencies { implementation 'com.r0adkll:slidableactivity:2.1.0' 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') } diff --git a/app/src/main/java/code/name/monkey/retromusic/App.kt b/app/src/main/java/code/name/monkey/retromusic/App.kt index 50f624dd..90967174 100644 --- a/app/src/main/java/code/name/monkey/retromusic/App.kt +++ b/app/src/main/java/code/name/monkey/retromusic/App.kt @@ -20,6 +20,9 @@ import androidx.multidex.MultiDexApplication import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.VersionUtils 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.TransactionDetails @@ -32,6 +35,11 @@ class App : MultiDexApplication() { super.onCreate() instance = this + + musicComponent = DaggerMusicComponent.builder() + .appModule(AppModule(this)) + .build() + // default theme if (!ThemeStore.isConfigured(this, 3)) { ThemeStore.editTheme(this) @@ -65,6 +73,9 @@ class App : MultiDexApplication() { companion object { + + lateinit var musicComponent: MusicComponent + const val PRO_VERSION_PRODUCT_ID = "pro_version" lateinit var instance: App diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt index 191ca116..d553dea2 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt @@ -18,6 +18,7 @@ import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialUtil import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper +import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity 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.dialogs.AddToPlaylistDialog 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.RetroGlideExtension 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.misc.AppBarStateChangeListener 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.AlbumDetailsView import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.NavigationUtil 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_content.* 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 var disposable = CompositeDisposable() @@ -67,6 +70,9 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac window.enterTransition = slide } + @Inject + lateinit var albumDetailsPresenter: AlbumDetailsPresenter + override fun onCreate(savedInstanceState: Bundle?) { setDrawUnderStatusBar() setupWindowTransition() @@ -81,10 +87,6 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac artistImage = findViewById(R.id.artistImage) - val albumId = intent.getIntExtra(EXTRA_ALBUM_ID, -1) - albumDetailsPresenter = AlbumDetailsPresenter(this, albumId) - albumDetailsPresenter.subscribe() - setupRecyclerView() setupToolbarMarginHeight() @@ -98,6 +100,15 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac shuffleAction.apply { 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() { @@ -151,42 +162,31 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac } } - override fun onPause() { - super.onPause() - albumDetailsPresenter.unsubscribe() - } - override fun onDestroy() { super.onDestroy() disposable.dispose() + albumDetailsPresenter.detachView() } - override fun loading() { - - } - - override fun showEmptyView() { - - } - - override fun completed() { + override fun complete() { ActivityCompat.startPostponedEnterTransition(this) } - override fun showData(list: Album) { - if (list.songs!!.isEmpty()) { + override fun album(album: Album) { + + if (album.songs!!.isEmpty()) { finish() return } - this.album = list + this.album = album - albumTitle.text = list.title - albumText.text = String.format("%s • %s • %s", list.artistName, MusicUtil.getYearString(list.year), MusicUtil.getReadableDurationString(MusicUtil.getTotalDuration(this, list.songs))) + albumTitle.text = album.title + albumText.text = String.format("%s • %s • %s", album.artistName, MusicUtil.getYearString(album.year), MusicUtil.getReadableDurationString(MusicUtil.getTotalDuration(this, album.songs))) loadAlbumCover() - loadMoreFrom(list) + simpleSongAdapter.swapDataSet(album.songs) - simpleSongAdapter.swapDataSet(list.songs) + albumDetailsPresenter.loadMore(album.artistId) } private lateinit var artistImage: ImageView @@ -194,17 +194,7 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac private fun loadMoreFrom(album: Album) { disposable.add(ArtistLoader.getArtistFlowable(this, album.artistId) .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!! } .map { it.filter { albumSearch -> albumSearch.id != album.id } } @@ -227,6 +217,30 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac }) } + override fun moreAlbums(albums: ArrayList) { + 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() { GlideApp.with(this) .asBitmapPalette() @@ -238,7 +252,6 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac override fun onColorReady(color: Int) { setColors(color) } - }) } @@ -337,7 +350,7 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsContrac } private fun reload() { - albumDetailsPresenter.subscribe() + albumDetailsPresenter.loadAlbum(intent.extras!!.getInt(ArtistDetailActivity.EXTRA_ARTIST_ID)) } companion object { diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/ArtistDetailActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/ArtistDetailActivity.kt index c81a2614..06cd0c27 100755 --- a/app/src/main/java/code/name/monkey/retromusic/activities/ArtistDetailActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/ArtistDetailActivity.kt @@ -22,6 +22,7 @@ import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialUtil import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper +import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity 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.misc.AppBarStateChangeListener 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.ArtistDetailsView import code.name.monkey.retromusic.rest.LastFMRestClient import code.name.monkey.retromusic.rest.model.LastFmArtist import code.name.monkey.retromusic.util.* import com.google.android.material.appbar.AppBarLayout import kotlinx.android.synthetic.main.activity_artist_content.* import kotlinx.android.synthetic.main.activity_artist_details.* -import retrofit2.Call -import retrofit2.Callback -import retrofit2.Response import java.util.* +import javax.inject.Inject import kotlin.collections.ArrayList -class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContract.ArtistsDetailsView { +class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView { private var biography: Spanned? = null private lateinit var artist: Artist private var lastFMRestClient: LastFMRestClient? = null - private lateinit var artistDetailsPresenter: ArtistDetailsPresenter private lateinit var songAdapter: SimpleSongAdapter private lateinit var albumAdapter: AlbumAdapter private var forceDownload: Boolean = false @@ -68,11 +66,13 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac return wrapSlidingMusicPanel(R.layout.activity_artist_details) } + @Inject + lateinit var artistDetailsPresenter: ArtistDetailsPresenter + override fun onCreate(savedInstanceState: Bundle?) { setDrawUnderStatusBar() setupWindowTransitions() super.onCreate(savedInstanceState) - //collapsingToolbarLayout?.setBackgroundColor(ThemeStore.primaryColor(this)) contentContainer?.setCardBackgroundColor(ColorStateList.valueOf(ThemeStore.primaryColor(this))) toggleBottomNavigationView(true) setNavigationbarColorAuto() @@ -80,13 +80,20 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac 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) setUpViews() - artistDetailsPresenter = ArtistDetailsPresenter(this, intent.extras!!) - artistDetailsPresenter.subscribe() - playAction.apply { setOnClickListener { MusicPlayerRemote.openQueue(artist.songs, 0, true) } } @@ -110,10 +117,10 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac } private fun setupContainerHeight() { - if (imageContainer != null) { - val params = imageContainer!!.layoutParams + imageContainer?.let { + val params = it.layoutParams 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) setSupportActionBar(toolbar) - supportActionBar!!.title = null + supportActionBar?.title = null if (toolbar != null && !PreferenceUtil.getInstance().fullScreenMode) { 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 completed() { + override fun complete() { ActivityCompat.startPostponedEnterTransition(this) } - override fun showData(list: Artist) { - setArtist(list) + override fun artist(artist: Artist) { + setArtist(artist) } private fun getArtist(): Artist { @@ -214,11 +214,12 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac loadArtistImage() if (RetroUtil.isAllowedToDownloadMetadata(this)) { - loadBiography() + loadBiography(artist.name) } artistTitle.text = artist.name text.text = String.format("%s • %s", MusicUtil.getArtistInfoString(this, artist), MusicUtil .getReadableDurationString(MusicUtil.getTotalDuration(this, artist.songs))) + //val songs = artist.songs.sortedWith(compareBy { it.title }) as ArrayList songAdapter.swapDataSet(artist.songs) @@ -226,43 +227,35 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac albumAdapter.swapDataSet(artist.albums!!) } - private fun loadBiography(lang: String? = Locale.getDefault().language) { + private fun loadBiography(name: String, + lang: String? = Locale.getDefault().language) { biography = null - - lastFMRestClient!!.apiService - .getArtistInfo(getArtist().name, lang, null) - .enqueue(object : Callback { - override fun onResponse(call: Call, - response: Response) { - 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, t: Throwable) { - t.printStackTrace() - biography = null - } - }) + this.lang = lang + artistDetailsPresenter.loadBiography(name, lang, 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() { GlideApp.with(this) @@ -281,7 +274,7 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac setColors(defaultFooterColor) } }) - forceDownload = false; + forceDownload = false } private fun setColors(color: Int) { @@ -351,8 +344,7 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailContrac } private fun reload() { - artistDetailsPresenter.unsubscribe() - artistDetailsPresenter.subscribe() + artistDetailsPresenter.loadArtist(intent.extras!!.getInt(EXTRA_ARTIST_ID)) } companion object { diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/GenreDetailsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/GenreDetailsActivity.kt index eba3df0d..995c6f98 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/GenreDetailsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/GenreDetailsActivity.kt @@ -10,31 +10,34 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.ColorUtil +import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity 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.helper.menu.GenreMenuHelper import code.name.monkey.retromusic.interfaces.CabHolder import code.name.monkey.retromusic.model.Genre 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.GenreDetailsView import code.name.monkey.retromusic.util.RetroColorUtil import code.name.monkey.retromusic.util.ViewUtil import com.afollestad.materialcab.MaterialCab import kotlinx.android.synthetic.main.activity_playlist_detail.* import java.util.* +import javax.inject.Inject /** * @author Hemanth S (h4h13). */ -class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), GenreDetailsContract.GenreDetailsView, CabHolder { +class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), CabHolder, GenreDetailsView { - private var genre: Genre? = null - private var presenter: GenreDetailsPresenter? = null + @Inject + lateinit var genreDetailsPresenter: GenreDetailsPresenter + + private lateinit var genre: Genre private lateinit var songAdapter: ShuffleButtonSongAdapter private var cab: MaterialCab? = null @@ -53,49 +56,45 @@ class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), GenreDetailsContrac setLightStatusbar(ColorUtil.isColorLight(ThemeStore.primaryColor(this))) toggleBottomNavigationView(true) - genre = intent?.extras?.getParcelable(EXTRA_GENRE_ID) - presenter = genre?.id?.let { GenreDetailsPresenter(this, it) } + if (intent.extras != null) { + genre = intent?.extras?.getParcelable(EXTRA_GENRE_ID)!! + } else { + finish() + } setUpToolBar() setupRecyclerView() + App.musicComponent.inject(this) + genreDetailsPresenter.attachView(this) + } private fun setUpToolBar() { val primaryColor = ThemeStore.primaryColor(this) appBarLayout.setBackgroundColor(primaryColor) applyToolbar(toolbar) - - title = genre?.name + title = genre.name } override fun onResume() { super.onResume() - presenter?.subscribe() + genreDetailsPresenter.loadGenreSongs(genre.id) } - override fun onPause() { - super.onPause() - presenter?.unsubscribe() + override fun onDestroy() { + super.onDestroy() + genreDetailsPresenter.detachView() } override fun createContentView(): View { return wrapSlidingMusicPanel(R.layout.activity_playlist_detail) } - - override fun loading() { - - } - override fun showEmptyView() { } - override fun completed() { - - } - override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_genre_detail, menu) return super.onCreateOptionsMenu(menu) @@ -105,7 +104,7 @@ class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), GenreDetailsContrac if (item.itemId == android.R.id.home) { onBackPressed() } - return GenreMenuHelper.handleMenuClick(this, genre!!, item) + return GenreMenuHelper.handleMenuClick(this, genre, item) } private fun setupRecyclerView() { @@ -124,8 +123,8 @@ class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), GenreDetailsContrac }) } - override fun showData(list: ArrayList) { - songAdapter.swapDataSet(list) + override fun songs(songs: ArrayList) { + songAdapter.swapDataSet(songs) } override fun openCab(menuRes: Int, callback: MaterialCab.Callback): MaterialCab { @@ -149,7 +148,7 @@ class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), GenreDetailsContrac override fun onMediaStoreChanged() { super.onMediaStoreChanged() - presenter?.subscribe() + genreDetailsPresenter.loadGenreSongs(genre.id) } companion object { diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/PlaylistDetailActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/PlaylistDetailActivity.kt index fb63bfed..67eeafa1 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/PlaylistDetailActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/PlaylistDetailActivity.kt @@ -9,6 +9,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.ColorUtil +import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity 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.Playlist 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.PlaylistSongsView import code.name.monkey.retromusic.util.PlaylistsUtil import code.name.monkey.retromusic.util.RetroColorUtil 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.utils.WrapperAdapterUtils import kotlinx.android.synthetic.main.activity_playlist_detail.* -import java.util.* +import javax.inject.Inject + 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 lateinit var adapter: SongAdapter private var wrappedAdapter: RecyclerView.Adapter<*>? = null private var recyclerViewDragDropManager: RecyclerViewDragDropManager? = null - private var songsPresenter: PlaylistSongsPresenter? = null override fun onCreate(savedInstanceState: Bundle?) { setDrawUnderStatusBar() @@ -55,8 +58,15 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli toggleBottomNavigationView(true) - playlist = intent.extras!!.getParcelable(EXTRA_PLAYLIST) - songsPresenter = PlaylistSongsPresenter(this, playlist!!) + if (intent.extras != null) { + playlist = intent.extras!!.getParcelable(EXTRA_PLAYLIST)!! + } else { + finish() + } + + App.musicComponent.inject(this) + + playlistSongsPresenter.attachView(this) setUpToolBar() setUpRecyclerView() @@ -78,7 +88,7 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli adapter = OrderablePlaylistSongAdapter(this, ArrayList(), R.layout.item_list, false, this, object : OrderablePlaylistSongAdapter.OnMoveItemListener { 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) adapter.dataSet.add(toPosition, song) adapter.notifyItemMoved(fromPosition, toPosition) @@ -102,12 +112,12 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli override fun onResume() { super.onResume() - songsPresenter!!.subscribe() + playlistSongsPresenter.loadPlaylistSongs(playlist) } private fun setUpToolBar() { applyToolbar(toolbar) - title = playlist!!.name + title = playlist.name } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -116,14 +126,13 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli } override fun onOptionsItemSelected(item: MenuItem): Boolean { - val id = item.itemId - when (id) { + when (item.itemId) { android.R.id.home -> { onBackPressed() return true } } - return PlaylistMenuHelper.handleMenuClick(this, playlist!!, item) + return PlaylistMenuHelper.handleMenuClick(this, playlist, item) } override fun openCab(menuRes: Int, callback: MaterialCab.Callback): MaterialCab { @@ -153,19 +162,19 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli if (playlist !is AbsCustomPlaylist) { // Playlist deleted - if (!PlaylistsUtil.doesPlaylistExist(this, playlist!!.id)) { + if (!PlaylistsUtil.doesPlaylistExist(this, playlist.id)) { finish() return } // Playlist renamed - val playlistName = PlaylistsUtil.getNameForPlaylist(this, playlist!!.id.toLong()) - if (playlistName != playlist!!.name) { - playlist = PlaylistLoader.getPlaylist(this, playlist!!.id) - setToolbarTitle(playlist!!.name) + val playlistName = PlaylistsUtil.getNameForPlaylist(this, playlist.id.toLong()) + if (playlistName != playlist.name) { + playlist = PlaylistLoader.getPlaylist(this, playlist.id) + setToolbarTitle(playlist.name) } } - songsPresenter!!.subscribe() + playlistSongsPresenter.loadPlaylistSongs(playlist) } private fun setToolbarTitle(title: String) { @@ -182,7 +191,6 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli recyclerViewDragDropManager!!.cancelDrag() } super.onPause() - songsPresenter!!.unsubscribe() } override fun onDestroy() { @@ -201,19 +209,16 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli wrappedAdapter = null } super.onDestroy() + playlistSongsPresenter.detachView() } - override fun loading() {} - override fun showEmptyView() { empty.visibility = View.VISIBLE emptyText.visibility = View.VISIBLE } - override fun completed() {} - - override fun showData(list: ArrayList) { - adapter.swapDataSet(list) + override fun songs(songs: ArrayList) { + adapter.swapDataSet(songs) } companion object { diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/SearchActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/SearchActivity.kt index 099b57c1..2f35e284 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/SearchActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/SearchActivity.kt @@ -21,19 +21,22 @@ import androidx.recyclerview.widget.RecyclerView import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper +import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity 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.SearchView import code.name.monkey.retromusic.util.RetroColorUtil import code.name.monkey.retromusic.util.RetroUtil import kotlinx.android.synthetic.main.activity_search.* 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 query: String? = null @@ -42,7 +45,9 @@ class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, SearchCon super.onCreate(savedInstanceState) setContentView(R.layout.activity_search) - searchPresenter = SearchPresenter(this) + App.musicComponent.inject(this) + + searchPresenter.attachView(this) setStatusbarColorAuto() setNavigationbarColorAuto() @@ -105,13 +110,12 @@ class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, SearchCon override fun onResume() { super.onResume() - searchPresenter.subscribe() searchPresenter.search(query) } override fun onDestroy() { super.onDestroy() - searchPresenter.unsubscribe() + searchPresenter.detachView() } override fun onSaveInstanceState(outState: Bundle) { @@ -158,18 +162,10 @@ class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, SearchCon } } - override fun loading() { - - } - override fun showEmptyView() { searchAdapter!!.swapDataSet(ArrayList()) } - override fun completed() { - - } - override fun showData(list: MutableList) { searchAdapter!!.swapDataSet(list) } diff --git a/app/src/main/java/code/name/monkey/retromusic/dagger/MusicComponent.kt b/app/src/main/java/code/name/monkey/retromusic/dagger/MusicComponent.kt new file mode 100644 index 00000000..c97b929e --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/dagger/MusicComponent.kt @@ -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) +} diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/HomeContract.kt b/app/src/main/java/code/name/monkey/retromusic/dagger/module/ActivityModule.kt similarity index 62% rename from app/src/main/java/code/name/monkey/retromusic/mvp/contract/HomeContract.kt rename to app/src/main/java/code/name/monkey/retromusic/dagger/module/ActivityModule.kt index 73e45e44..50200c8e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/HomeContract.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dagger/module/ActivityModule.kt @@ -12,17 +12,21 @@ * 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 code.name.monkey.retromusic.mvp.BasePresenter -import code.name.monkey.retromusic.mvp.BaseView +import android.app.Activity -interface HomeContract { +import dagger.Module +import dagger.Provides - interface HomeView : BaseView> +/** + * Created by hemanths on 2019-09-04. + */ +@Module +class ActivityModule(private val activity: Activity) { - interface HomePresenter : BasePresenter { - fun homeSections() + @Provides + fun provideActivity(): Activity { + return activity } -} \ No newline at end of file +} diff --git a/app/src/main/java/code/name/monkey/retromusic/dagger/module/AlbumModule.kt b/app/src/main/java/code/name/monkey/retromusic/dagger/module/AlbumModule.kt new file mode 100644 index 00000000..80fcd1ca --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/dagger/module/AlbumModule.kt @@ -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 + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/SearchContract.kt b/app/src/main/java/code/name/monkey/retromusic/dagger/module/AppModule.kt similarity index 61% rename from app/src/main/java/code/name/monkey/retromusic/mvp/contract/SearchContract.kt rename to app/src/main/java/code/name/monkey/retromusic/dagger/module/AppModule.kt index 1fbf0273..2e5d7085 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/SearchContract.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dagger/module/AppModule.kt @@ -12,21 +12,21 @@ * 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 code.name.monkey.retromusic.mvp.BaseView -import java.util.* +import android.content.Context +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 { - interface SearchView : BaseView> - - interface SearchPresenter : BasePresenter { - fun search(query: String?) + @Provides + fun provideContext(): Context { + return context } } diff --git a/app/src/main/java/code/name/monkey/retromusic/dagger/module/ArtistModule.kt b/app/src/main/java/code/name/monkey/retromusic/dagger/module/ArtistModule.kt new file mode 100644 index 00000000..26cc9c0e --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/dagger/module/ArtistModule.kt @@ -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 + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/dagger/module/GenreModule.kt b/app/src/main/java/code/name/monkey/retromusic/dagger/module/GenreModule.kt new file mode 100644 index 00000000..6fc027cc --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/dagger/module/GenreModule.kt @@ -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 + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/ArtistDetailContract.kt b/app/src/main/java/code/name/monkey/retromusic/dagger/module/HomeModule.kt similarity index 59% rename from app/src/main/java/code/name/monkey/retromusic/mvp/contract/ArtistDetailContract.kt rename to app/src/main/java/code/name/monkey/retromusic/dagger/module/HomeModule.kt index 548399e0..51b6eadd 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/ArtistDetailContract.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dagger/module/HomeModule.kt @@ -12,22 +12,22 @@ * See the GNU General Public License for more details. */ -package code.name.monkey.retromusic.mvp.contract - - -import code.name.monkey.retromusic.model.Artist -import code.name.monkey.retromusic.mvp.BasePresenter -import code.name.monkey.retromusic.mvp.BaseView +package code.name.monkey.retromusic.dagger.module +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 { - interface ArtistsDetailsView : BaseView - - interface Presenter : BasePresenter { - fun loadArtistById() + @Provides + fun providesHomePresenter(presenter: HomePresenterImpl): HomePresenter { + return presenter } + } diff --git a/app/src/main/java/code/name/monkey/retromusic/dagger/module/PlaylistModule.kt b/app/src/main/java/code/name/monkey/retromusic/dagger/module/PlaylistModule.kt new file mode 100644 index 00000000..2995fe5d --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/dagger/module/PlaylistModule.kt @@ -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 + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/GenreDetailsContract.kt b/app/src/main/java/code/name/monkey/retromusic/dagger/module/RepositoryModule.kt similarity index 56% rename from app/src/main/java/code/name/monkey/retromusic/mvp/contract/GenreDetailsContract.kt rename to app/src/main/java/code/name/monkey/retromusic/dagger/module/RepositoryModule.kt index 4344623d..0586a885 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/GenreDetailsContract.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dagger/module/RepositoryModule.kt @@ -12,22 +12,23 @@ * 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 code.name.monkey.retromusic.mvp.BasePresenter -import code.name.monkey.retromusic.mvp.BaseView +import android.content.Context -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 { - interface GenreDetailsView : BaseView> - - interface Presenter : BasePresenter { - fun loadGenre(genreId: Int) + @Provides + fun providesRepository(context: Context): Repository { + return RepositoryImpl(context) } } diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/ArtistContract.kt b/app/src/main/java/code/name/monkey/retromusic/dagger/module/SearchModule.kt similarity index 58% rename from app/src/main/java/code/name/monkey/retromusic/mvp/contract/ArtistContract.kt rename to app/src/main/java/code/name/monkey/retromusic/dagger/module/SearchModule.kt index e92fbd98..0eafe55a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/ArtistContract.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dagger/module/SearchModule.kt @@ -12,24 +12,22 @@ * See the GNU General Public License for more details. */ -package code.name.monkey.retromusic.mvp.contract - - -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 +package code.name.monkey.retromusic.dagger.module +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 { - interface ArtistView : BaseView> - - interface Presenter : BasePresenter { - fun loadArtists() + @Provides + fun providesSearchPresenter(presenter: SearchPresenterImpl): SearchPresenter { + return presenter } + } diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/GenreContract.kt b/app/src/main/java/code/name/monkey/retromusic/dagger/module/SongModule.kt similarity index 59% rename from app/src/main/java/code/name/monkey/retromusic/mvp/contract/GenreContract.kt rename to app/src/main/java/code/name/monkey/retromusic/dagger/module/SongModule.kt index 25bc9e35..a78a864e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/GenreContract.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dagger/module/SongModule.kt @@ -12,22 +12,20 @@ * 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.BasePresenter -import code.name.monkey.retromusic.mvp.BaseView - -import java.util.ArrayList +import code.name.monkey.retromusic.mvp.presenter.SongPresenter +import code.name.monkey.retromusic.mvp.presenter.SongPresenter.SongPresenterImpl +import dagger.Module +import dagger.Provides /** - * @author Hemanth S (h4h13). + * Created by hemanths on 2019-09-04. */ - -interface GenreContract { - interface GenreView : BaseView> - - interface Presenter : BasePresenter { - fun loadGenre() +@Module +class SongModule { + @Provides + fun providesSongPresenter(presenter: SongPresenterImpl): SongPresenter { + return presenter } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/AlbumsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/AlbumsFragment.kt index 01cc1639..69753814 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/AlbumsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/AlbumsFragment.kt @@ -2,18 +2,23 @@ package code.name.monkey.retromusic.fragments.mainactivity import android.os.Bundle import androidx.recyclerview.widget.GridLayoutManager +import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.album.AlbumAdapter import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment import code.name.monkey.retromusic.model.Album -import code.name.monkey.retromusic.mvp.contract.AlbumContract -import code.name.monkey.retromusic.mvp.presenter.AlbumPresenter +import code.name.monkey.retromusic.mvp.presenter.AlbumsPresenter +import code.name.monkey.retromusic.mvp.presenter.AlbumsView import code.name.monkey.retromusic.util.PreferenceUtil +import javax.inject.Inject -open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment(), AlbumContract.AlbumView { - - private lateinit var presenter: AlbumPresenter +open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment(), AlbumsView { + override fun albums(albums: java.util.ArrayList) { + adapter?.swapDataSet(albums) + } + @Inject + lateinit var albumsPresenter: AlbumsPresenter override val emptyMessage: Int get() = R.string.no_albums @@ -26,15 +31,13 @@ open class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment) { - adapter!!.swapDataSet(list) + adapter?.swapDataSet(ArrayList()) } companion object { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/ArtistsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/ArtistsFragment.kt index 4db0e35f..36eb5820 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/ArtistsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/ArtistsFragment.kt @@ -2,24 +2,46 @@ package code.name.monkey.retromusic.fragments.mainactivity import android.os.Bundle import androidx.recyclerview.widget.GridLayoutManager +import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.artist.ArtistAdapter import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment import code.name.monkey.retromusic.model.Artist -import code.name.monkey.retromusic.mvp.contract.ArtistContract -import code.name.monkey.retromusic.mvp.presenter.ArtistPresenter +import code.name.monkey.retromusic.mvp.presenter.ArtistsPresenter +import code.name.monkey.retromusic.mvp.presenter.ArtistsView import code.name.monkey.retromusic.util.PreferenceUtil -import java.util.* +import javax.inject.Inject -class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment(), ArtistContract.ArtistView { - private lateinit var presenter: ArtistPresenter +class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment(), ArtistsView { + override fun artists(artists: ArrayList) { + adapter?.swapDataSet(artists) + } + + @Inject + lateinit var artistsPresenter: ArtistsPresenter override val emptyMessage: Int get() = R.string.no_artists override fun onCreate(savedInstanceState: Bundle?) { 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 { @@ -30,15 +52,12 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment) { - adapter!!.swapDataSet(list) + adapter?.swapDataSet(ArrayList()) } companion object { @@ -125,5 +123,4 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment(), GenreContract.GenreView { - override fun loading() { - - } - - override fun showData(list: ArrayList) { - adapter?.swapDataSet(list) +class GenresFragment : AbsLibraryPagerRecyclerViewFragment(), GenresView { + override fun genres(genres: ArrayList) { + adapter?.swapDataSet(genres) } override fun showEmptyView() { } - override fun completed() { - - } - override fun createLayoutManager(): LinearLayoutManager { return LinearLayoutManager(activity) } @@ -53,28 +47,31 @@ class GenresFragment : AbsLibraryPagerRecyclerViewFragment(), PlaylistContract.PlaylistView { +class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment(), PlaylistView { - private lateinit var presenter: PlaylistPresenter + @Inject + lateinit var playlistsPresenter: PlaylistsPresenter override val emptyMessage: Int get() = R.string.no_playlists override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setHasOptionsMenu(true) - presenter = PlaylistPresenter(this) + App.musicComponent.inject(this) + playlistsPresenter.attachView(this) } override fun createLayoutManager(): LinearLayoutManager { @@ -38,33 +40,25 @@ class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment) { + override fun playlists(list: ArrayList) { adapter!!.swapDataSet(list) } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/SongsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/SongsFragment.kt index 5c55e8aa..d06b73fa 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/SongsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/SongsFragment.kt @@ -2,27 +2,32 @@ package code.name.monkey.retromusic.fragments.mainactivity import android.os.Bundle import androidx.recyclerview.widget.GridLayoutManager +import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.song.ShuffleButtonSongAdapter import code.name.monkey.retromusic.adapter.song.SongAdapter import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment 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.SongView import code.name.monkey.retromusic.util.PreferenceUtil import java.util.* +import javax.inject.Inject -class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment(), SongContract.SongView { +class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment(), SongView { + @Inject + lateinit var songPresenter: SongPresenter - private lateinit var presenter: SongPresenter override val emptyMessage: Int get() = R.string.no_songs override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - presenter = SongPresenter(this) + App.musicComponent.inject(this) + + songPresenter.attachView(this) } override fun createLayoutManager(): GridLayoutManager { @@ -41,8 +46,12 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment) { + adapter?.swapDataSet(songs) + } + override fun onMediaStoreChanged() { - presenter.loadSongs() + songPresenter.loadSongs() } override fun loadGridSize(): Int { @@ -81,31 +90,19 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment) { - adapter!!.swapDataSet(list) + override fun onDestroyView() { + super.onDestroyView() + songPresenter.detachView() } override fun showEmptyView() { adapter!!.swapDataSet(ArrayList()) } - override fun completed() { - - } - override fun loadSortOrder(): String { return PreferenceUtil.getInstance().songSortOrder } @@ -115,7 +112,7 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment) { + 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 lateinit var homePresenter: HomePresenter private lateinit var toolbar: Toolbar override fun onCreateView(inflater: LayoutInflater, viewGroup: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -83,7 +101,8 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - homePresenter = HomePresenter(this) + App.musicComponent.inject(this) + homePresenter.attachView(this) } @@ -108,22 +127,18 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba } actionShuffle.setOnClickListener { - MusicPlayerRemote.openAndShuffleQueue(SongLoader.getAllSongs(requireActivity()) , true) + MusicPlayerRemote.openAndShuffleQueue(SongLoader.getAllSongs(requireActivity()), true) } history.setOnClickListener { NavigationUtil.goToPlaylistNew(requireActivity(), HistoryPlaylist(requireActivity())) } - homePresenter = HomePresenter(this) - contentContainer.setBackgroundColor(ThemeStore.primaryColor(requireContext())) setupToolbar() homeAdapter = HomeAdapter(mainActivity, ArrayList(), displayMetrics) - homePresenter.subscribe() - checkPadding() userInfoContainer.setOnClickListener { @@ -131,6 +146,8 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba } titleWelcome.setTextColor(ThemeStore.textColorPrimary(requireContext())) titleWelcome.text = String.format("%s", PreferenceUtil.getInstance().userName) + + homePresenter.loadSections() } private fun checkPadding() { @@ -177,21 +194,13 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba override fun onDestroyView() { super.onDestroyView() disposable.dispose() - homePresenter.unsubscribe() - } - - override fun loading() { - + homePresenter.detachView() } override fun showEmptyView() { emptyContainer.show() } - override fun completed() { - - } - override fun onServiceConnected() { super.onServiceConnected() checkPadding() @@ -204,20 +213,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba private lateinit var homeAdapter: HomeAdapter - override fun showData(list: ArrayList) { - 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) { super.onCreateOptionsMenu(menu, inflater) inflater.inflate(R.menu.menu_search, menu) diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/BaseView.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/BaseView.kt index b54e55dc..818853fc 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/BaseView.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/BaseView.kt @@ -18,12 +18,6 @@ package code.name.monkey.retromusic.mvp * Created by hemanths on 09/08/17. */ -interface BaseView { - fun loading() - - fun showData(list: T) - +interface BaseView { fun showEmptyView() - - fun completed() } diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/Presenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/Presenter.kt index c7e6823e..1772b347 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/Presenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/Presenter.kt @@ -14,17 +14,13 @@ 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. */ -open class Presenter { - protected var repository: Repository = Injection.provideRepository() - protected var disposable: CompositeDisposable = CompositeDisposable() - protected var schedulerProvider: BaseSchedulerProvider = Injection.provideSchedulerProvider() + +interface Presenter { + fun attachView(view: T) + + fun detachView() } diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/BasePresenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/PresenterImpl.java similarity index 69% rename from app/src/main/java/code/name/monkey/retromusic/mvp/BasePresenter.kt rename to app/src/main/java/code/name/monkey/retromusic/mvp/PresenterImpl.java index ea7f27f9..82d9950b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/BasePresenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/PresenterImpl.java @@ -12,15 +12,19 @@ * 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 { + protected T view; -interface BasePresenter { + public void attachView(T view) { + this.view = view; + } - fun subscribe() - - fun unsubscribe() + public void detachView() { + view = null; + } } diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/AlbumContract.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/contract/AlbumContract.kt deleted file mode 100644 index c5a04136..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/AlbumContract.kt +++ /dev/null @@ -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> - - interface Presenter : BasePresenter { - - fun loadAlbums() - } - -} diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/AlbumDetailsContract.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/contract/AlbumDetailsContract.kt deleted file mode 100644 index f94af5ab..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/AlbumDetailsContract.kt +++ /dev/null @@ -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 - - interface Presenter : BasePresenter { - - fun loadAlbumSongs(albumId: Int) - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/PlaylistContract.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/contract/PlaylistContract.kt deleted file mode 100644 index 42f93d29..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/PlaylistContract.kt +++ /dev/null @@ -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> - - interface Presenter : BasePresenter { - fun loadPlaylists() - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/PlaylistSongsContract.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/contract/PlaylistSongsContract.kt deleted file mode 100644 index 46ddd125..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/PlaylistSongsContract.kt +++ /dev/null @@ -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> - - interface Presenter : BasePresenter { - fun loadSongs(playlist: Playlist) - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/SongContract.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/contract/SongContract.kt deleted file mode 100644 index 2c86ae4c..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/contract/SongContract.kt +++ /dev/null @@ -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> - - interface Presenter : BasePresenter { - fun loadSongs() - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/AlbumDetailsPresenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/AlbumDetailsPresenter.kt index 6ae47252..7d08620d 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/AlbumDetailsPresenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/AlbumDetailsPresenter.kt @@ -15,37 +15,71 @@ package code.name.monkey.retromusic.mvp.presenter 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.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. */ +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() { - loadAlbumSongs(albumId) - } + fun loadArtistImage(artist: Artist) - override fun unsubscribe() { - disposable.clear() - } + fun moreAlbums(albums: ArrayList) +} - override fun loadAlbumSongs(albumId: Int) { - disposable.add(repository.getAlbumFlowable(albumId) - .doOnSubscribe { view.loading() } - .subscribe({ this.showAlbum(it) }, - { view.showEmptyView() }, - { view.completed() })) - } +interface AlbumDetailsPresenter : Presenter { + fun loadAlbum(albumId: Int) - private fun showAlbum(album: Album?) { - if (album != null) { - view.showData(album) - } else { - view.showEmptyView() + fun loadMore(artistId: Int) + + class AlbumDetailsPresenterImpl @Inject constructor( + private val repository: Repository + ) : PresenterImpl(), 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() } } -} +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/AlbumPresenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/AlbumPresenter.kt index 7ea2bcd8..bbb2027f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/AlbumPresenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/AlbumPresenter.kt @@ -15,34 +15,43 @@ package code.name.monkey.retromusic.mvp.presenter 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.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 javax.inject.Inject /** * Created by hemanths on 12/08/17. */ - -class AlbumPresenter(private val view: AlbumContract.AlbumView) : Presenter(), AlbumContract.Presenter { - - override fun subscribe() { - loadAlbums() - } - - override fun unsubscribe() { - disposable.clear() - } - - private fun showList(albums: ArrayList) { - view.showData(albums) - } - - override fun loadAlbums() { - disposable.add(repository.allAlbumsFlowable - .doOnSubscribe { view.loading() } - .subscribe({ this.showList(it) }, - { view.showEmptyView() }, - { view.completed() })) - } +interface AlbumsView : BaseView { + fun albums(albums: ArrayList) } + +interface AlbumsPresenter : Presenter { + + fun loadAlbums() + + class AlbumsPresenterImpl @Inject constructor( + private val repository: Repository + ) : PresenterImpl(), AlbumsPresenter { + + private var disposable: Disposable? = null + + private fun showList(albums: ArrayList) { + 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) } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/ArtistDetailsPresenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/ArtistDetailsPresenter.kt index a627ae7f..d1c17dc1 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/ArtistDetailsPresenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/ArtistDetailsPresenter.kt @@ -14,41 +14,62 @@ package code.name.monkey.retromusic.mvp.presenter -import android.os.Bundle 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.contract.ArtistDetailContract -import code.name.monkey.retromusic.activities.ArtistDetailActivity +import code.name.monkey.retromusic.mvp.PresenterImpl +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. */ +interface ArtistDetailsView : BaseView { + fun artist(artist: Artist) + fun artistInfo(lastFmArtist: LastFmArtist?) + fun complete() +} -class ArtistDetailsPresenter(private val view: ArtistDetailContract.ArtistsDetailsView, - private val bundle: Bundle) : Presenter(), ArtistDetailContract.Presenter { +interface ArtistDetailsPresenter : Presenter { - override fun subscribe() { - loadArtistById() - } + fun loadArtist(artistId: Int) - override fun unsubscribe() { - disposable.clear() - } + fun loadBiography(name: String, + lang: String? = Locale.getDefault().language, + cache: String?) - override fun loadArtistById() { - disposable.add(repository.getArtistByIdFlowable(bundle.getInt(ArtistDetailActivity.EXTRA_ARTIST_ID)) - .doOnSubscribe { view.loading() } - .subscribe({ this.showArtist(it) }, - { view.showEmptyView() }, - { view.completed() })) - } + class ArtistDetailsPresenterImpl @Inject constructor( + private val repository: Repository + ) : PresenterImpl(), ArtistDetailsPresenter { - private fun showArtist(album: Artist?) { - if (album != null) { - view.showData(album) - } else { - view.showEmptyView() + override fun loadBiography(name: String, + lang: String?, + cache: String?) { + disposable = repository.artistInfoFloable(name, lang, cache) + .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) } } -} +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/ArtistPresenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/ArtistPresenter.kt index f80d263f..eeae3f48 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/ArtistPresenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/ArtistPresenter.kt @@ -14,34 +14,49 @@ 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.mvp.BaseView import code.name.monkey.retromusic.mvp.Presenter -import code.name.monkey.retromusic.mvp.contract.ArtistContract -import java.util.* +import code.name.monkey.retromusic.mvp.PresenterImpl +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) +} - override fun subscribe() { - loadArtists() - } +interface ArtistsPresenter : Presenter { - override fun unsubscribe() { - disposable.clear() - } + fun loadArtists() - private fun showList(songs: ArrayList) { - if (songs.isEmpty()) { - mView.showEmptyView() - } else { - mView.showData(songs) + class ArtistsPresenterImpl @Inject constructor( + private val repository: Repository + ) : PresenterImpl(), ArtistsPresenter { + + private var disposable: Disposable? = null + + private fun showList(artists: ArrayList) { + 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() })) - } } diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/GenreDetailsPresenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/GenreDetailsPresenter.kt index 2a92f481..ecb1f07d 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/GenreDetailsPresenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/GenreDetailsPresenter.kt @@ -15,39 +15,51 @@ package code.name.monkey.retromusic.mvp.presenter 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.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 javax.inject.Inject /** * Created by hemanths on 20/08/17. */ -class GenreDetailsPresenter(private val view: GenreDetailsContract.GenreDetailsView, - private val genreId: Int) : Presenter(), GenreDetailsContract.Presenter { +interface GenreDetailsView : BaseView { + fun songs(songs: ArrayList) +} - override fun subscribe() { - loadGenre(genreId) - } +interface GenreDetailsPresenter : Presenter { + fun loadGenreSongs(genreId: Int) - override fun unsubscribe() { - disposable.clear() - } + class GenreDetailsPresenterImpl @Inject constructor( + private val repository: Repository + ) : PresenterImpl(), GenreDetailsPresenter { - override fun loadGenre(genreId: Int) { - disposable.add(repository.getGenreFlowable(genreId) - .doOnSubscribe { view.loading() } - .subscribe({ this.showGenre(it) }, - { view.showEmptyView() }, - { view.completed() })) - } + override fun detachView() { + super.detachView() + disposable?.dispose() + } - private fun showGenre(songs: ArrayList?) { - if (songs != null) { - view.showData(songs) - } else { - view.showEmptyView() + private var disposable: Disposable? = null + + override fun loadGenreSongs(genreId: Int) { + disposable = repository.getGenreFlowable(genreId) + .subscribe { + showGenre(it) + } + + } + + private fun showGenre(songs: ArrayList) { + if (songs.isNotEmpty()) { + view.songs(songs) + } else { + view.showEmptyView() + } } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/GenrePresenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/GenrePresenter.kt index da0b1026..afc25c5f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/GenrePresenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/GenrePresenter.kt @@ -15,38 +15,42 @@ package code.name.monkey.retromusic.mvp.presenter 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.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 javax.inject.Inject /** * @author Hemanth S (h4h13). */ +interface GenresView : BaseView { + fun genres(genres: ArrayList) +} -class GenrePresenter( - private val view: GenreContract.GenreView) : Presenter(), GenreContract.Presenter { +interface GenresPresenter : Presenter { + fun loadGenres() - override fun subscribe() { - loadGenre() - } + class GenresPresenterImpl @Inject constructor( + private val repository: Repository + ) : PresenterImpl(), GenresPresenter { - override fun unsubscribe() { - disposable.clear() - } + private var disposable: Disposable? = null - override fun loadGenre() { - disposable.add(repository.allGenresFlowable - .doOnSubscribe { view.loading() } - .subscribe({ this.showList(it) }, - { view.showEmptyView() }, - { view.completed() })) - } + override fun loadGenres() { + disposable = repository.allGenresFlowable + .subscribe { this.showList(it) } + } - private fun showList(genres: ArrayList) { - if (genres.isEmpty()) { - view.showEmptyView() - } else { - view.showData(genres) + private fun showList(genres: ArrayList) { + if (genres.isNotEmpty()) { + view.genres(genres) + } else { + view.showEmptyView() + } } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/HomePresenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/HomePresenter.kt index ab39d83d..e8146dfc 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/HomePresenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/HomePresenter.kt @@ -15,25 +15,135 @@ package code.name.monkey.retromusic.mvp.presenter 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.RECENT_ALBUMS 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_ARTISTS 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.contract.HomeContract -import code.name.monkey.retromusic.util.PreferenceUtil -import io.reactivex.android.schedulers.AndroidSchedulers +import code.name.monkey.retromusic.mvp.PresenterImpl +import code.name.monkey.retromusic.providers.interfaces.Repository import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.Disposable +import javax.inject.Inject operator fun CompositeDisposable.plusAssign(disposable: Disposable) { add(disposable) } -class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), HomeContract.HomePresenter { +interface HomeView : BaseView { + fun sections(sections: ArrayList) +} + +interface HomePresenter : Presenter { + fun loadSections() + + class HomePresenterImpl @Inject constructor( + private val repository: Repository + ) : PresenterImpl(), HomePresenter { + override fun loadSections() { + loadRecentArtists() + loadRecentAlbums() + loadTopArtists() + loadATopAlbums() + loadFavorite() + } + + private var disposable: CompositeDisposable = CompositeDisposable() + private val hashSet: HashSet = HashSet() + + private fun showData(sections: ArrayList) { + 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 = HashSet() override fun homeSections() { @@ -53,7 +163,7 @@ class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), Home } private fun loadRecentArtists() { - disposable += repository.recentArtistsFlowable + disposable += repositoryImpl.recentArtistsFlowable .subscribe({ 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)) @@ -63,7 +173,7 @@ class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), Home } private fun loadRecentAlbums() { - disposable += repository.recentAlbumsFlowable + disposable += repositoryImpl.recentAlbumsFlowable .subscribe({ 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)) @@ -73,7 +183,7 @@ class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), Home } private fun loadATopAlbums() { - disposable += repository.topAlbumsFlowable + disposable += repositoryImpl.topAlbumsFlowable .subscribe({ 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)) @@ -83,7 +193,7 @@ class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), Home } private fun loadTopArtists() { - disposable += repository.topArtistsFlowable + disposable += repositoryImpl.topArtistsFlowable .subscribe({ 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)) @@ -93,7 +203,7 @@ class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), Home } private fun loadFavorite() { - disposable += repository.favoritePlaylistFlowable + disposable += repositoryImpl.favoritePlaylistFlowable .subscribe({ if (it.isNotEmpty()) hashSet.add(Home(4, R.string.favorites, 0, it, PLAYLISTS, R.drawable.ic_favorite_white_24dp)) view.showData(ArrayList(hashSet)) @@ -101,4 +211,4 @@ class HomePresenter(private val view: HomeContract.HomeView) : Presenter(), Home view.showEmptyView() }) } -} +}*/ diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/PlaylistPresenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/PlaylistPresenter.kt index 916093f2..4a64d56c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/PlaylistPresenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/PlaylistPresenter.kt @@ -15,38 +15,45 @@ package code.name.monkey.retromusic.mvp.presenter 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.contract.PlaylistContract -import java.util.* +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 19/08/17. */ -class PlaylistPresenter(private val view: PlaylistContract.PlaylistView) : Presenter(), PlaylistContract.Presenter { +interface PlaylistView : BaseView { + fun playlists(playlists: ArrayList) +} - override fun subscribe() { - loadPlaylists() - } +interface PlaylistsPresenter : Presenter { - override fun unsubscribe() { - disposable.clear() - } + fun playlists() - override fun loadPlaylists() { - disposable.add(repository.allPlaylistsFlowable - .doOnSubscribe { view.loading() } - .subscribe({ this.showList(it) }, - { view.showEmptyView() }, - { view.completed() })) - } + class PlaylistsPresenterImpl @Inject constructor( + private val repository: Repository + ) : PresenterImpl(), PlaylistsPresenter { - private fun showList(songs: ArrayList) { - if (songs.isEmpty()) { - view.showEmptyView() - } else { - view.showData(songs) + private var disposable: Disposable? = null + + override fun playlists() { + disposable = repository.allPlaylistsFlowable + .subscribe { this.showList(it) } + } + + private fun showList(arrayList: ArrayList) { + if (arrayList.isEmpty()) { + view.showEmptyView() + } else { + view.playlists(arrayList) + } } } } + + diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/PlaylistSongsPresenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/PlaylistSongsPresenter.kt index 47e37a5f..c651689f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/PlaylistSongsPresenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/PlaylistSongsPresenter.kt @@ -15,30 +15,45 @@ package code.name.monkey.retromusic.mvp.presenter 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.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. */ - -class PlaylistSongsPresenter(private val view: PlaylistSongsContract.PlaylistSongsView, - 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 PlaylistSongsView : BaseView { + fun songs(songs: ArrayList) } + +interface PlaylistSongsPresenter : Presenter { + fun loadPlaylistSongs(playlist: Playlist) + + class PlaylistSongsPresenterImpl @Inject constructor( + private val repository: Repository + ) : PresenterImpl(), 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) + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/SearchPresenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/SearchPresenter.kt index e3681d93..42e527a0 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/SearchPresenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/SearchPresenter.kt @@ -15,33 +15,40 @@ package code.name.monkey.retromusic.mvp.presenter import code.name.monkey.retromusic.mvp.Presenter -import code.name.monkey.retromusic.mvp.contract.SearchContract -import java.util.* -import java.util.concurrent.TimeUnit +import code.name.monkey.retromusic.mvp.PresenterImpl +import code.name.monkey.retromusic.providers.interfaces.Repository +import javax.inject.Inject /** * Created by hemanths on 20/08/17. */ -class SearchPresenter(private val view: SearchContract.SearchView) : Presenter(), SearchContract.SearchPresenter { +interface SearchView { + fun showData(data: MutableList) - override fun subscribe() { - search("") - } + fun showEmptyView() +} - override fun unsubscribe() { - disposable.clear() - } +interface SearchPresenter : Presenter { - private fun showList(albums: ArrayList) { - if (albums.isEmpty()) { - view.showEmptyView() - } else { - view.showData(albums) + fun search(query: String?) + + class SearchPresenterImpl @Inject constructor( + private val repository: Repository + ) : PresenterImpl(), 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)) - } } + + diff --git a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/SongPresenter.kt b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/SongPresenter.kt index 9cb4c1a4..93af6393 100644 --- a/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/SongPresenter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/mvp/presenter/SongPresenter.kt @@ -16,36 +16,42 @@ package code.name.monkey.retromusic.mvp.presenter import code.name.monkey.retromusic.model.Song 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 javax.inject.Inject /** * Created by hemanths on 10/08/17. */ +interface SongView { + fun songs(songs: ArrayList) -class SongPresenter(private val view: SongContract.SongView) : Presenter(), SongContract.Presenter { + fun showEmptyView() +} - override fun loadSongs() { - disposable.add(repository.allSongsFlowable - .doOnSubscribe { view.loading() } - .subscribe({ this.showList(it) }, - { view.showEmptyView() }, - { view.completed() })) - } +interface SongPresenter : Presenter { + fun loadSongs() - override fun subscribe() { - loadSongs() - } + class SongPresenterImpl @Inject constructor( + private val repository: Repository + ) : PresenterImpl(), SongPresenter { - private fun showList(songs: ArrayList) { - if (songs.isEmpty()) { - view.showEmptyView() - } else { - view.showData(songs) + private var disposable: Disposable? = null + + override fun loadSongs() { + disposable = repository.allSongsFlowable + .subscribe { + view.songs(it) + } + } + + override fun detachView() { + super.detachView() + disposable?.dispose() } } - - override fun unsubscribe() { - disposable.clear() - } } + + diff --git a/app/src/main/java/code/name/monkey/retromusic/providers/RepositoryImpl.kt b/app/src/main/java/code/name/monkey/retromusic/providers/RepositoryImpl.kt index bbf38f70..389987de 100644 --- a/app/src/main/java/code/name/monkey/retromusic/providers/RepositoryImpl.kt +++ b/app/src/main/java/code/name/monkey/retromusic/providers/RepositoryImpl.kt @@ -19,11 +19,23 @@ import code.name.monkey.retromusic.App import code.name.monkey.retromusic.loaders.* import code.name.monkey.retromusic.model.* 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.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers class RepositoryImpl(private val context: Context) : Repository { + override fun artistInfoFloable( + name: String, + lang: String?, + cache: String? + ): Observable { + return LastFMRestClient(context).apiService.getArtistInfoFloable(name, lang, cache) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + } + override fun search(query: String?): MutableList { return SearchLoader.searchAll(context, query) } diff --git a/app/src/main/java/code/name/monkey/retromusic/providers/interfaces/Repository.kt b/app/src/main/java/code/name/monkey/retromusic/providers/interfaces/Repository.kt index cc575525..7ecf90a7 100644 --- a/app/src/main/java/code/name/monkey/retromusic/providers/interfaces/Repository.kt +++ b/app/src/main/java/code/name/monkey/retromusic/providers/interfaces/Repository.kt @@ -15,6 +15,7 @@ package code.name.monkey.retromusic.providers.interfaces import code.name.monkey.retromusic.model.* +import code.name.monkey.retromusic.rest.model.LastFmArtist import io.reactivex.Observable /** @@ -87,4 +88,7 @@ interface Repository { val favoritePlaylist: ArrayList + fun artistInfoFloable(name: String, + lang: String?, + cache: String?): Observable } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/rest/LastFMRestClient.java b/app/src/main/java/code/name/monkey/retromusic/rest/LastFMRestClient.java index c6afb36c..77d0cb95 100644 --- a/app/src/main/java/code/name/monkey/retromusic/rest/LastFMRestClient.java +++ b/app/src/main/java/code/name/monkey/retromusic/rest/LastFMRestClient.java @@ -16,11 +16,12 @@ package code.name.monkey.retromusic.rest; import android.content.Context; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import java.io.File; import java.util.concurrent.TimeUnit; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import code.name.monkey.retromusic.rest.service.LastFMService; import okhttp3.Cache; import okhttp3.Call; @@ -43,7 +44,7 @@ public class LastFMRestClient { this(createDefaultOkHttpClientBuilder(context).build()); } - public LastFMRestClient(@NonNull Call.Factory client) { + private LastFMRestClient(@NonNull Call.Factory client) { Retrofit restAdapter = new Retrofit.Builder() .baseUrl(BASE_URL) .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() .connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS)) .retryOnConnectionFailure(true) @@ -83,6 +85,7 @@ public class LastFMRestClient { .addInterceptor(createCacheControlInterceptor()); } + @NonNull public LastFMService getApiService() { return apiService; } diff --git a/app/src/main/java/code/name/monkey/retromusic/rest/service/LastFMService.java b/app/src/main/java/code/name/monkey/retromusic/rest/service/LastFMService.java index 99eae3a7..f8b24725 100644 --- a/app/src/main/java/code/name/monkey/retromusic/rest/service/LastFMService.java +++ b/app/src/main/java/code/name/monkey/retromusic/rest/service/LastFMService.java @@ -16,9 +16,9 @@ package code.name.monkey.retromusic.rest.service; import androidx.annotation.NonNull; import androidx.annotation.Nullable; + import code.name.monkey.retromusic.rest.model.LastFmAlbum; import code.name.monkey.retromusic.rest.model.LastFmArtist; -import code.name.monkey.retromusic.rest.model.LastFmTrack; import io.reactivex.Observable; import retrofit2.Call; import retrofit2.http.GET; @@ -37,12 +37,11 @@ public interface LastFMService { Observable getAlbumInfo(@Query("album") @NonNull String albumName, @Query("artist") @NonNull String artistName, @Nullable @Query("lang") String language); @NonNull - @GET("?api_key=" + API_KEY + "&format=json&autocorrect=1" + "&method=" + METHOD_TRACK) - Observable getTrackInfo(@Query("artist") @NonNull String artist, @Query("track") @NonNull String track); + @GET(BASE_QUERY_PARAMETERS + "&method=artist.getinfo") + Call getArtistInfo(@Query("artist") @NonNull String artistName, @Nullable @Query("lang") String language, @Nullable @Header("Cache-Control") String cacheControl); @NonNull @GET(BASE_QUERY_PARAMETERS + "&method=artist.getinfo") - default Call getArtistInfo(@Query("artist") @NonNull String artistName, @Nullable @Query("lang") String language, @Nullable @Header("Cache-Control") String cacheControl) { - return null; - } + Observable getArtistInfoFloable(@Query("artist") @NonNull String artistName, @Nullable @Query("lang") String language, @Nullable @Header("Cache-Control") String cacheControl); + } \ No newline at end of file