Added Dagger
This commit is contained in:
parent
074298dcb0
commit
6cdea14316
47 changed files with 1130 additions and 826 deletions
|
@ -18,12 +18,6 @@ package code.name.monkey.retromusic.mvp
|
|||
* Created by hemanths on 09/08/17.
|
||||
*/
|
||||
|
||||
interface BaseView<T> {
|
||||
fun loading()
|
||||
|
||||
fun showData(list: T)
|
||||
|
||||
interface BaseView {
|
||||
fun showEmptyView()
|
||||
|
||||
fun completed()
|
||||
}
|
||||
|
|
|
@ -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<T> {
|
||||
fun attachView(view: T)
|
||||
|
||||
fun detachView()
|
||||
}
|
||||
|
|
|
@ -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<T> {
|
||||
protected T view;
|
||||
|
||||
interface BasePresenter<T> {
|
||||
public void attachView(T view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
fun subscribe()
|
||||
|
||||
fun unsubscribe()
|
||||
public void detachView() {
|
||||
view = 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<ArrayList<Album>>
|
||||
|
||||
interface Presenter : BasePresenter<AlbumView> {
|
||||
|
||||
fun loadAlbums()
|
||||
}
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Hemanth Savarala.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
package code.name.monkey.retromusic.mvp.contract
|
||||
|
||||
|
||||
import code.name.monkey.retromusic.model.Album
|
||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
||||
import code.name.monkey.retromusic.mvp.BaseView
|
||||
|
||||
interface AlbumDetailsContract {
|
||||
|
||||
interface AlbumDetailsView : BaseView<Album>
|
||||
|
||||
interface Presenter : BasePresenter<AlbumDetailsView> {
|
||||
|
||||
fun loadAlbumSongs(albumId: Int)
|
||||
}
|
||||
}
|
|
@ -1,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.Artist
|
||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
||||
import code.name.monkey.retromusic.mvp.BaseView
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
|
||||
/**
|
||||
* Created by hemanths on 16/08/17.
|
||||
*/
|
||||
|
||||
interface ArtistContract {
|
||||
interface ArtistView : BaseView<ArrayList<Artist>>
|
||||
|
||||
interface Presenter : BasePresenter<ArtistView> {
|
||||
fun loadArtists()
|
||||
}
|
||||
}
|
|
@ -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.Artist
|
||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
||||
import code.name.monkey.retromusic.mvp.BaseView
|
||||
|
||||
|
||||
/**
|
||||
* Created by hemanths on 20/08/17.
|
||||
*/
|
||||
|
||||
interface ArtistDetailContract {
|
||||
interface ArtistsDetailsView : BaseView<Artist>
|
||||
|
||||
interface Presenter : BasePresenter<ArtistsDetailsView> {
|
||||
fun loadArtistById()
|
||||
}
|
||||
}
|
|
@ -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.Genre
|
||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
||||
import code.name.monkey.retromusic.mvp.BaseView
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
/**
|
||||
* @author Hemanth S (h4h13).
|
||||
*/
|
||||
|
||||
interface GenreContract {
|
||||
interface GenreView : BaseView<ArrayList<Genre>>
|
||||
|
||||
interface Presenter : BasePresenter<GenreView> {
|
||||
fun loadGenre()
|
||||
}
|
||||
}
|
|
@ -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.Song
|
||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
||||
import code.name.monkey.retromusic.mvp.BaseView
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
/**
|
||||
* @author Hemanth S (h4h13).
|
||||
*/
|
||||
|
||||
interface GenreDetailsContract {
|
||||
interface GenreDetailsView : BaseView<ArrayList<Song>>
|
||||
|
||||
interface Presenter : BasePresenter<GenreDetailsView> {
|
||||
fun loadGenre(genreId: Int)
|
||||
}
|
||||
}
|
|
@ -1,28 +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.Home
|
||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
||||
import code.name.monkey.retromusic.mvp.BaseView
|
||||
|
||||
interface HomeContract {
|
||||
|
||||
interface HomeView : BaseView<ArrayList<Home>>
|
||||
|
||||
interface HomePresenter : BasePresenter<HomeView> {
|
||||
fun homeSections()
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Hemanth Savarala.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
package code.name.monkey.retromusic.mvp.contract
|
||||
|
||||
import code.name.monkey.retromusic.model.Playlist
|
||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
||||
import code.name.monkey.retromusic.mvp.BaseView
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
/**
|
||||
* Created by hemanths on 19/08/17.
|
||||
*/
|
||||
|
||||
interface PlaylistContract {
|
||||
interface PlaylistView : BaseView<ArrayList<Playlist>>
|
||||
|
||||
interface Presenter : BasePresenter<PlaylistView> {
|
||||
fun loadPlaylists()
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Hemanth Savarala.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
package code.name.monkey.retromusic.mvp.contract
|
||||
|
||||
import code.name.monkey.retromusic.model.Playlist
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
||||
import code.name.monkey.retromusic.mvp.BaseView
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
|
||||
/**
|
||||
* Created by hemanths on 20/08/17.
|
||||
*/
|
||||
|
||||
interface PlaylistSongsContract {
|
||||
interface PlaylistSongsView : BaseView<ArrayList<Song>>
|
||||
|
||||
interface Presenter : BasePresenter<PlaylistSongsView> {
|
||||
fun loadSongs(playlist: Playlist)
|
||||
}
|
||||
}
|
|
@ -1,32 +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.mvp.BasePresenter
|
||||
import code.name.monkey.retromusic.mvp.BaseView
|
||||
import java.util.*
|
||||
|
||||
|
||||
/**
|
||||
* Created by hemanths on 20/08/17.
|
||||
*/
|
||||
|
||||
interface SearchContract {
|
||||
interface SearchView : BaseView<MutableList<Any>>
|
||||
|
||||
interface SearchPresenter : BasePresenter<SearchView> {
|
||||
fun search(query: String?)
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Hemanth Savarala.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
package code.name.monkey.retromusic.mvp.contract
|
||||
|
||||
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.mvp.BasePresenter
|
||||
import code.name.monkey.retromusic.mvp.BaseView
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
|
||||
/**
|
||||
* Created by hemanths on 10/08/17.
|
||||
*/
|
||||
|
||||
interface SongContract {
|
||||
|
||||
interface SongView : BaseView<ArrayList<Song>>
|
||||
|
||||
interface Presenter : BasePresenter<SongView> {
|
||||
fun loadSongs()
|
||||
}
|
||||
}
|
|
@ -15,37 +15,71 @@
|
|||
package code.name.monkey.retromusic.mvp.presenter
|
||||
|
||||
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<Album>)
|
||||
}
|
||||
|
||||
override fun loadAlbumSongs(albumId: Int) {
|
||||
disposable.add(repository.getAlbumFlowable(albumId)
|
||||
.doOnSubscribe { view.loading() }
|
||||
.subscribe({ this.showAlbum(it) },
|
||||
{ view.showEmptyView() },
|
||||
{ view.completed() }))
|
||||
}
|
||||
interface AlbumDetailsPresenter : Presenter<AlbumDetailsView> {
|
||||
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<AlbumDetailsView>(), AlbumDetailsPresenter {
|
||||
|
||||
private lateinit var album: Album
|
||||
|
||||
override fun loadMore(artistId: Int) {
|
||||
disposable = repository.getArtistByIdFlowable(artistId)
|
||||
.map {
|
||||
view.loadArtistImage(it)
|
||||
return@map it.albums
|
||||
}
|
||||
.map {
|
||||
it.filter { filterAlbum -> album.id != filterAlbum.id }
|
||||
}
|
||||
.subscribe {
|
||||
if (it.isEmpty()) {
|
||||
return@subscribe
|
||||
}
|
||||
view.moreAlbums(ArrayList(it))
|
||||
}
|
||||
}
|
||||
|
||||
private var disposable: Disposable? = null
|
||||
|
||||
override fun loadAlbum(albumId: Int) {
|
||||
disposable = repository.getAlbumFlowable(albumId)
|
||||
.doOnComplete {
|
||||
view.complete()
|
||||
}
|
||||
.subscribe {
|
||||
album = it
|
||||
view.album(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun detachView() {
|
||||
super.detachView()
|
||||
disposable?.dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,34 +15,43 @@
|
|||
package code.name.monkey.retromusic.mvp.presenter
|
||||
|
||||
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<Album>) {
|
||||
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<Album>)
|
||||
}
|
||||
|
||||
interface AlbumsPresenter : Presenter<AlbumsView> {
|
||||
|
||||
fun loadAlbums()
|
||||
|
||||
class AlbumsPresenterImpl @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : PresenterImpl<AlbumsView>(), AlbumsPresenter {
|
||||
|
||||
private var disposable: Disposable? = null
|
||||
|
||||
private fun showList(albums: ArrayList<Album>) {
|
||||
if (albums.isNotEmpty()) view.albums(albums) else view.showEmptyView()
|
||||
}
|
||||
|
||||
override fun detachView() {
|
||||
super.detachView()
|
||||
disposable?.dispose()
|
||||
}
|
||||
override fun loadAlbums() {
|
||||
disposable = repository.allAlbumsFlowable
|
||||
.subscribe { this.showList(it) }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,41 +14,62 @@
|
|||
|
||||
package code.name.monkey.retromusic.mvp.presenter
|
||||
|
||||
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<ArtistDetailsView> {
|
||||
|
||||
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<ArtistDetailsView>(), 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<Artist>)
|
||||
}
|
||||
|
||||
override fun subscribe() {
|
||||
loadArtists()
|
||||
}
|
||||
interface ArtistsPresenter : Presenter<ArtistsView> {
|
||||
|
||||
override fun unsubscribe() {
|
||||
disposable.clear()
|
||||
}
|
||||
fun loadArtists()
|
||||
|
||||
private fun showList(songs: ArrayList<Artist>) {
|
||||
if (songs.isEmpty()) {
|
||||
mView.showEmptyView()
|
||||
} else {
|
||||
mView.showData(songs)
|
||||
class ArtistsPresenterImpl @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : PresenterImpl<ArtistsView>(), ArtistsPresenter {
|
||||
|
||||
private var disposable: Disposable? = null
|
||||
|
||||
private fun showList(artists: ArrayList<Artist>) {
|
||||
if (songs.isNotEmpty())
|
||||
view.artists(artists)
|
||||
else
|
||||
view.showEmptyView()
|
||||
}
|
||||
|
||||
override fun detachView() {
|
||||
super.detachView()
|
||||
disposable?.dispose()
|
||||
}
|
||||
|
||||
override fun loadArtists() {
|
||||
disposable = repository.allArtistsFlowable
|
||||
.subscribe({
|
||||
view.artists(it)
|
||||
}, {
|
||||
println(it)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadArtists() {
|
||||
disposable.add(repository.allArtistsFlowable
|
||||
.doOnSubscribe { mView.loading() }
|
||||
.subscribe({ this.showList(it) },
|
||||
{ mView.showEmptyView() },
|
||||
{ mView.completed() }))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,39 +15,51 @@
|
|||
package code.name.monkey.retromusic.mvp.presenter
|
||||
|
||||
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<Song>)
|
||||
}
|
||||
|
||||
override fun subscribe() {
|
||||
loadGenre(genreId)
|
||||
}
|
||||
interface GenreDetailsPresenter : Presenter<GenreDetailsView> {
|
||||
fun loadGenreSongs(genreId: Int)
|
||||
|
||||
override fun unsubscribe() {
|
||||
disposable.clear()
|
||||
}
|
||||
class GenreDetailsPresenterImpl @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : PresenterImpl<GenreDetailsView>(), 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<Song>?) {
|
||||
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<Song>) {
|
||||
if (songs.isNotEmpty()) {
|
||||
view.songs(songs)
|
||||
} else {
|
||||
view.showEmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Genre>)
|
||||
}
|
||||
|
||||
class GenrePresenter(
|
||||
private val view: GenreContract.GenreView) : Presenter(), GenreContract.Presenter {
|
||||
interface GenresPresenter : Presenter<GenresView> {
|
||||
fun loadGenres()
|
||||
|
||||
override fun subscribe() {
|
||||
loadGenre()
|
||||
}
|
||||
class GenresPresenterImpl @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : PresenterImpl<GenresView>(), 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<Genre>) {
|
||||
if (genres.isEmpty()) {
|
||||
view.showEmptyView()
|
||||
} else {
|
||||
view.showData(genres)
|
||||
private fun showList(genres: ArrayList<Genre>) {
|
||||
if (genres.isNotEmpty()) {
|
||||
view.genres(genres)
|
||||
} else {
|
||||
view.showEmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Home>)
|
||||
}
|
||||
|
||||
interface HomePresenter : Presenter<HomeView> {
|
||||
fun loadSections()
|
||||
|
||||
class HomePresenterImpl @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : PresenterImpl<HomeView>(), HomePresenter {
|
||||
override fun loadSections() {
|
||||
loadRecentArtists()
|
||||
loadRecentAlbums()
|
||||
loadTopArtists()
|
||||
loadATopAlbums()
|
||||
loadFavorite()
|
||||
}
|
||||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
private val hashSet: HashSet<Home> = HashSet()
|
||||
|
||||
private fun showData(sections: ArrayList<Home>) {
|
||||
if (sections.isEmpty()) {
|
||||
view.showEmptyView()
|
||||
} else {
|
||||
view.sections(sections)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadRecentArtists() {
|
||||
disposable += repository.recentArtistsFlowable
|
||||
.subscribe {
|
||||
if (it.isNotEmpty()) hashSet.add(
|
||||
Home(0,
|
||||
R.string.recent_artists,
|
||||
0,
|
||||
it,
|
||||
RECENT_ARTISTS,
|
||||
R.drawable.ic_artist_white_24dp
|
||||
))
|
||||
showData(ArrayList(hashSet))
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadRecentAlbums() {
|
||||
disposable += repository.recentAlbumsFlowable
|
||||
.subscribe {
|
||||
if (it.isNotEmpty()) hashSet.add(
|
||||
Home(1,
|
||||
R.string.recent_albums,
|
||||
0,
|
||||
it,
|
||||
RECENT_ALBUMS,
|
||||
R.drawable.ic_album_white_24dp
|
||||
))
|
||||
showData(ArrayList(hashSet))
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadTopArtists() {
|
||||
disposable += repository.topArtistsFlowable
|
||||
.subscribe {
|
||||
if (it.isNotEmpty()) hashSet.add(
|
||||
Home(2,
|
||||
R.string.top_artists,
|
||||
0,
|
||||
it,
|
||||
TOP_ARTISTS,
|
||||
R.drawable.ic_artist_white_24dp
|
||||
))
|
||||
showData(ArrayList(hashSet))
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadATopAlbums() {
|
||||
disposable += repository.topAlbumsFlowable
|
||||
.subscribe {
|
||||
if (it.isNotEmpty()) hashSet.add(
|
||||
Home(3,
|
||||
R.string.top_albums,
|
||||
0,
|
||||
it,
|
||||
TOP_ALBUMS,
|
||||
R.drawable.ic_album_white_24dp
|
||||
))
|
||||
showData(ArrayList(hashSet))
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadFavorite() {
|
||||
disposable += repository.favoritePlaylistFlowable
|
||||
.subscribe {
|
||||
if (it.isNotEmpty()) hashSet.add(
|
||||
Home(4,
|
||||
R.string.favorites,
|
||||
0,
|
||||
it,
|
||||
PLAYLISTS,
|
||||
R.drawable.ic_favorite_white_24dp
|
||||
))
|
||||
showData(ArrayList(hashSet))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*class HomePresenter(
|
||||
private val view: HomeContract.HomeView,
|
||||
private val repositoryImpl: RepositoryImpl
|
||||
) : Presenter(), HomeContract.HomePresenter {
|
||||
private val hashSet: HashSet<Home> = HashSet()
|
||||
|
||||
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()
|
||||
})
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
|
|
@ -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<Playlist>)
|
||||
}
|
||||
|
||||
override fun subscribe() {
|
||||
loadPlaylists()
|
||||
}
|
||||
interface PlaylistsPresenter : Presenter<PlaylistView> {
|
||||
|
||||
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<PlaylistView>(), PlaylistsPresenter {
|
||||
|
||||
private fun showList(songs: ArrayList<Playlist>) {
|
||||
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<Playlist>) {
|
||||
if (arrayList.isEmpty()) {
|
||||
view.showEmptyView()
|
||||
} else {
|
||||
view.playlists(arrayList)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<Song>)
|
||||
}
|
||||
|
||||
interface PlaylistSongsPresenter : Presenter<PlaylistSongsView> {
|
||||
fun loadPlaylistSongs(playlist: Playlist)
|
||||
|
||||
class PlaylistSongsPresenterImpl @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : PresenterImpl<PlaylistSongsView>(), PlaylistSongsPresenter {
|
||||
|
||||
private var disposable: Disposable? = null
|
||||
|
||||
override fun loadPlaylistSongs(playlist: Playlist) {
|
||||
disposable = repository.getPlaylistSongsFlowable(playlist)
|
||||
.subscribe {
|
||||
view.songs(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun detachView() {
|
||||
super.detachView()
|
||||
disposable?.dispose()
|
||||
}
|
||||
|
||||
override fun attachView(view: PlaylistSongsView) {
|
||||
super.attachView(view)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -15,33 +15,40 @@
|
|||
package code.name.monkey.retromusic.mvp.presenter
|
||||
|
||||
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<Any>)
|
||||
|
||||
override fun subscribe() {
|
||||
search("")
|
||||
}
|
||||
fun showEmptyView()
|
||||
}
|
||||
|
||||
override fun unsubscribe() {
|
||||
disposable.clear()
|
||||
}
|
||||
interface SearchPresenter : Presenter<SearchView> {
|
||||
|
||||
private fun showList(albums: ArrayList<Any>) {
|
||||
if (albums.isEmpty()) {
|
||||
view.showEmptyView()
|
||||
} else {
|
||||
view.showData(albums)
|
||||
fun search(query: String?)
|
||||
|
||||
class SearchPresenterImpl @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : PresenterImpl<SearchView>(), SearchPresenter {
|
||||
|
||||
override fun attachView(view: SearchView) {
|
||||
super.attachView(view)
|
||||
}
|
||||
|
||||
override fun detachView() {
|
||||
super.detachView()
|
||||
}
|
||||
|
||||
override fun search(query: String?) {
|
||||
view.showData(repository.search(query))
|
||||
}
|
||||
}
|
||||
|
||||
override fun search(query: String?) {
|
||||
view.showData(repository.search(query))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,36 +16,42 @@ package code.name.monkey.retromusic.mvp.presenter
|
|||
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.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<Song>)
|
||||
|
||||
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<SongView> {
|
||||
fun loadSongs()
|
||||
|
||||
override fun subscribe() {
|
||||
loadSongs()
|
||||
}
|
||||
class SongPresenterImpl @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : PresenterImpl<SongView>(), SongPresenter {
|
||||
|
||||
private fun showList(songs: ArrayList<Song>) {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue