Code refactor ArrayList to List

This commit is contained in:
h4h13 2020-02-17 16:50:08 +05:30
parent 67f4b4ecf2
commit 87954b43f2
43 changed files with 236 additions and 305 deletions

View file

@ -19,5 +19,6 @@ package code.name.monkey.retromusic.mvp
*/
interface BaseView {
fun showEmptyView()
}

View file

@ -40,9 +40,7 @@ interface AlbumDetailsView {
fun loadArtistImage(artist: Artist)
fun moreAlbums(
albums: ArrayList<Album>
)
fun moreAlbums(albums: List<Album>)
fun aboutAlbum(lastFmAlbum: LastFmAlbum)
}
@ -51,6 +49,7 @@ interface AlbumDetailsPresenter : Presenter<AlbumDetailsView> {
fun loadAlbum(albumId: Int)
fun loadMore(artistId: Int)
fun aboutAlbum(artist: String, album: String)
class AlbumDetailsPresenterImpl @Inject constructor(

View file

@ -14,7 +14,8 @@
package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
import code.name.monkey.retromusic.model.Album
import code.name.monkey.retromusic.mvp.BaseView
import code.name.monkey.retromusic.mvp.Presenter
@ -25,7 +26,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.ArrayList
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
@ -33,35 +33,35 @@ import kotlin.coroutines.CoroutineContext
* Created by hemanths on 12/08/17.
*/
interface AlbumsView : BaseView {
fun albums(albums: ArrayList<Album>)
fun albums(albums: List<Album>)
}
interface AlbumsPresenter : Presenter<AlbumsView> {
fun loadAlbums()
fun loadAlbums()
class AlbumsPresenterImpl @Inject constructor(
class AlbumsPresenterImpl @Inject constructor(
private val repository: Repository
) : PresenterImpl<AlbumsView>(), AlbumsPresenter, CoroutineScope {
private val job = Job()
) : PresenterImpl<AlbumsView>(), AlbumsPresenter, CoroutineScope {
override val coroutineContext: CoroutineContext
get() = Dispatchers.IO + job
private val job = Job()
override fun detachView() {
super.detachView()
job.cancel()
}
override val coroutineContext: CoroutineContext
get() = Dispatchers.IO + job
override fun loadAlbums() {
launch {
when (val result = repository.allAlbums()) {
is Result.Success -> withContext(Dispatchers.Main) {
view?.albums(result.data)
}
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
}
}
}
override fun detachView() {
super.detachView()
job.cancel()
}
override fun loadAlbums() {
launch {
when (val result = repository.allAlbums()) {
is Success -> withContext(Dispatchers.Main) { view?.albums(result.data) }
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
}
}
}
}

View file

@ -14,7 +14,8 @@
package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
import code.name.monkey.retromusic.model.Artist
import code.name.monkey.retromusic.mvp.BaseView
import code.name.monkey.retromusic.mvp.Presenter
@ -36,7 +37,9 @@ import kotlin.coroutines.CoroutineContext
interface ArtistDetailsView : BaseView {
fun artist(artist: Artist)
fun artistInfo(lastFmArtist: LastFmArtist?)
fun complete()
}
@ -62,12 +65,8 @@ interface ArtistDetailsPresenter : Presenter<ArtistDetailsView> {
override fun loadBiography(name: String, lang: String?, cache: String?) {
launch {
when (val result = repository.artistInfo(name, lang, cache)) {
is Result.Success -> withContext(Dispatchers.Main) {
view?.artistInfo(result.data)
}
is Result.Error -> withContext(Dispatchers.Main) {
}
is Success -> withContext(Dispatchers.Main) { view?.artistInfo(result.data) }
is Error -> withContext(Dispatchers.Main) {}
}
}
}
@ -75,13 +74,8 @@ interface ArtistDetailsPresenter : Presenter<ArtistDetailsView> {
override fun loadArtist(artistId: Int) {
launch {
when (val result = repository.artistById(artistId)) {
is Result.Success -> withContext(Dispatchers.Main) {
view?.artist(result.data)
}
is Result.Error -> withContext(Dispatchers.Main) {
view?.showEmptyView()
}
is Success -> withContext(Dispatchers.Main) { view?.artist(result.data) }
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
}
}

View file

@ -14,18 +14,23 @@
package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
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.PresenterImpl
import code.name.monkey.retromusic.providers.interfaces.Repository
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
interface ArtistsView : BaseView {
fun artists(artists: ArrayList<Artist>)
fun artists(artists: List<Artist>)
}
interface ArtistsPresenter : Presenter<ArtistsView> {
@ -33,8 +38,9 @@ interface ArtistsPresenter : Presenter<ArtistsView> {
fun loadArtists()
class ArtistsPresenterImpl @Inject constructor(
private val repository: Repository
private val repository: Repository
) : PresenterImpl<ArtistsView>(), ArtistsPresenter, CoroutineScope {
private val job = Job()
override val coroutineContext: CoroutineContext
@ -48,8 +54,8 @@ interface ArtistsPresenter : Presenter<ArtistsView> {
override fun loadArtists() {
launch {
when (val result = repository.allArtists()) {
is Result.Success -> withContext(Dispatchers.Main) { view?.artists(result.data) }
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
is Success -> withContext(Dispatchers.Main) { view?.artists(result.data) }
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
}
}

View file

@ -14,32 +14,37 @@
package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
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.PresenterImpl
import code.name.monkey.retromusic.providers.interfaces.Repository
import kotlinx.coroutines.*
import java.util.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
/**
* Created by hemanths on 20/08/17.
*/
interface GenreDetailsView : BaseView {
fun songs(songs: ArrayList<Song>)
fun songs(songs: List<Song>)
}
interface GenreDetailsPresenter : Presenter<GenreDetailsView> {
fun loadGenreSongs(genreId: Int)
class GenreDetailsPresenterImpl @Inject constructor(
private val repository: Repository
private val repository: Repository
) : PresenterImpl<GenreDetailsView>(), GenreDetailsPresenter, CoroutineScope {
private val job = Job()
override val coroutineContext: CoroutineContext
@ -50,16 +55,11 @@ interface GenreDetailsPresenter : Presenter<GenreDetailsView> {
job.cancel()
}
override fun loadGenreSongs(genreId: Int) {
launch {
when (val result = repository.getGenre(genreId)) {
is Result.Success -> withContext(Dispatchers.Main) {
view?.songs(result.data)
}
is Result.Error -> withContext(Dispatchers.Main) {
view?.showEmptyView()
}
is Success -> withContext(Dispatchers.Main) { view?.songs(result.data) }
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
}
}

View file

@ -14,14 +14,18 @@
package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
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.PresenterImpl
import code.name.monkey.retromusic.providers.interfaces.Repository
import kotlinx.coroutines.*
import java.util.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
@ -29,15 +33,17 @@ import kotlin.coroutines.CoroutineContext
* @author Hemanth S (h4h13).
*/
interface GenresView : BaseView {
fun genres(genres: ArrayList<Genre>)
fun genres(genres: List<Genre>)
}
interface GenresPresenter : Presenter<GenresView> {
fun loadGenres()
class GenresPresenterImpl @Inject constructor(
private val repository: Repository
private val repository: Repository
) : PresenterImpl<GenresView>(), GenresPresenter, CoroutineScope {
private val job = Job()
override val coroutineContext: CoroutineContext
@ -51,10 +57,8 @@ interface GenresPresenter : Presenter<GenresView> {
override fun loadGenres() {
launch {
when (val result = repository.allGenres()) {
is Result.Success -> withContext(Dispatchers.Main) {
view?.genres(result.data)
}
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
is Success -> withContext(Dispatchers.Main) { view?.genres(result.data) }
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
}
}

View file

@ -29,7 +29,7 @@ import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
interface HomeView : BaseView {
fun sections(sections: ArrayList<Home>)
fun sections(sections: List<Home>)
}
interface HomePresenter : Presenter<HomeView> {

View file

@ -16,19 +16,25 @@ package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.model.Playlist
import code.name.monkey.retromusic.mvp.*
import code.name.monkey.retromusic.mvp.BaseView
import code.name.monkey.retromusic.mvp.Presenter
import code.name.monkey.retromusic.mvp.PresenterImpl
import code.name.monkey.retromusic.providers.interfaces.Repository
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
/**
* Created by hemanths on 19/08/17.
*/
interface PlaylistView : BaseView {
fun playlists(playlists: ArrayList<Playlist>)
fun playlists(playlists: List<Playlist>)
}
interface PlaylistsPresenter : Presenter<PlaylistView> {
@ -36,7 +42,7 @@ interface PlaylistsPresenter : Presenter<PlaylistView> {
fun playlists()
class PlaylistsPresenterImpl @Inject constructor(
private val repository: Repository
private val repository: Repository
) : PresenterImpl<PlaylistView>(), PlaylistsPresenter, CoroutineScope {
private val job = Job()
@ -52,9 +58,7 @@ interface PlaylistsPresenter : Presenter<PlaylistView> {
override fun playlists() {
launch {
when (val result = repository.allPlaylists()) {
is Result.Success -> withContext(Dispatchers.Main) {
view?.playlists(result.data)
}
is Result.Success -> withContext(Dispatchers.Main) { view?.playlists(result.data) }
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
}

View file

@ -14,11 +14,19 @@
package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.model.*
import code.name.monkey.retromusic.mvp.*
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
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.PresenterImpl
import code.name.monkey.retromusic.providers.interfaces.Repository
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
@ -26,14 +34,15 @@ import kotlin.coroutines.CoroutineContext
* Created by hemanths on 20/08/17.
*/
interface PlaylistSongsView : BaseView {
fun songs(songs: ArrayList<Song>)
fun songs(songs: List<Song>)
}
interface PlaylistSongsPresenter : Presenter<PlaylistSongsView> {
fun loadPlaylistSongs(playlist: Playlist)
class PlaylistSongsPresenterImpl @Inject constructor(
private val repository: Repository
private val repository: Repository
) : PresenterImpl<PlaylistSongsView>(), PlaylistSongsPresenter, CoroutineScope {
private var job: Job = Job()
@ -44,10 +53,8 @@ interface PlaylistSongsPresenter : Presenter<PlaylistSongsView> {
override fun loadPlaylistSongs(playlist: Playlist) {
launch {
when (val songs = repository.getPlaylistSongs(playlist)) {
is Result.Success -> withContext(Dispatchers.Main) {
view?.songs(songs.data)
}
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
is Success -> withContext(Dispatchers.Main) { view?.songs(songs.data) }
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
}
}

View file

@ -16,10 +16,14 @@ package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.mvp.*
import code.name.monkey.retromusic.mvp.Presenter
import code.name.monkey.retromusic.mvp.PresenterImpl
import code.name.monkey.retromusic.providers.interfaces.Repository
import kotlinx.coroutines.*
import java.util.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
@ -27,36 +31,39 @@ import kotlin.coroutines.CoroutineContext
* Created by hemanths on 10/08/17.
*/
interface SongView {
fun songs(songs: ArrayList<Song>)
fun showEmptyView()
fun songs(songs: List<Song>)
fun showEmptyView()
}
interface SongPresenter : Presenter<SongView> {
fun loadSongs()
class SongPresenterImpl @Inject constructor(
private val repository: Repository
) : PresenterImpl<SongView>(), SongPresenter, CoroutineScope {
private var job: Job = Job()
fun loadSongs()
override val coroutineContext: CoroutineContext
get() = Dispatchers.IO + job
class SongPresenterImpl @Inject constructor(
private val repository: Repository
) : PresenterImpl<SongView>(), SongPresenter, CoroutineScope {
override fun loadSongs() {
launch {
when (val songs = repository.allSongs()) {
is Result.Success -> withContext(Dispatchers.Main) { view?.songs(songs.data) }
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
}
}
private var job: Job = Job()
override fun detachView() {
super.detachView()
job.cancel();
}
}
override val coroutineContext: CoroutineContext
get() = Dispatchers.IO + job
override fun loadSongs() {
launch {
when (val songs = repository.allSongs()) {
is Result.Success -> withContext(Dispatchers.Main) { view?.songs(songs.data) }
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
}
}
override fun detachView() {
super.detachView()
job.cancel()
}
}
}