diff --git a/app/build.gradle b/app/build.gradle index 9625c80..fa0e4c4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -60,7 +60,6 @@ dependencies { compile "com.android.support:cardview-v7:$supportVersion" compile "com.android.support:palette-v7:$supportVersion" compile "com.android.support:design:$supportVersion" - compile "de.greenrobot:eventbus:2.4.1" compile "com.squareup.picasso:picasso:2.5.2" compile "com.squareup.okhttp3:okhttp:$okhttpVersion" compile "com.squareup.okhttp3:logging-interceptor:$okhttpVersion" @@ -69,7 +68,6 @@ dependencies { exclude module: 'okhttp' } compile "com.squareup.retrofit2:converter-gson:$retrofitVersion" - compile "com.birbit:android-priority-jobqueue:2.0.1" compile "org.jetbrains.anko:anko-sdk15:$parent.ext.ankoVersion" compile "org.jetbrains.anko:anko-support-v4:$parent.ext.ankoVersion" kapt "com.google.dagger:dagger-compiler:$daggerVersion" diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/data/CloudAlbumDataSource.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/data/CloudAlbumDataSource.kt index 322e5aa..57e3760 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/data/CloudAlbumDataSource.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/data/CloudAlbumDataSource.kt @@ -18,10 +18,10 @@ package com.antonioleiva.bandhookkotlin.data import com.antonioleiva.bandhookkotlin.Result import com.antonioleiva.bandhookkotlin.data.lastfm.LastFmService -import com.antonioleiva.bandhookkotlin.data.lastfm.model.LastFmResponse import com.antonioleiva.bandhookkotlin.data.mapper.AlbumMapper import com.antonioleiva.bandhookkotlin.domain.entity.Album import com.antonioleiva.bandhookkotlin.domain.entity.BizException.AlbumNotFound +import com.antonioleiva.bandhookkotlin.domain.entity.BizException.TopAlbumsNotFound import com.antonioleiva.bandhookkotlin.left import com.antonioleiva.bandhookkotlin.repository.datasource.AlbumDataSource import com.antonioleiva.bandhookkotlin.right @@ -29,7 +29,7 @@ import com.antonioleiva.bandhookkotlin.right class CloudAlbumDataSource(val lastFmService: LastFmService) : AlbumDataSource { override fun get(id: String): Result { - return lastFmService.requestAlbum(id).asResult { + return lastFmService.requestAlbum(id).asResult { AlbumMapper().transform(album).fold( { AlbumNotFound(id).left() }, { it.right() } @@ -37,17 +37,19 @@ class CloudAlbumDataSource(val lastFmService: LastFmService) : AlbumDataSource { } } - override fun requestTopAlbums(artistId: String?, artistName: String?): List { - val mbid = artistId ?: "" - val name = artistName ?: "" - - if (!mbid.isEmpty() || !name.isEmpty()) { - return lastFmService.requestAlbums(mbid, name).unwrapCall { - AlbumMapper().transform(topAlbums.albums) - } - } - - return emptyList() + override fun requestTopAlbums(artistId: String?, artistName: String?): + Result> { +// val mbid = artistId ?: "" +// val name = artistName ?: "" +// +// if (!mbid.isEmpty() || !name.isEmpty()) { +// return lastFmService.requestAlbums(mbid, name).unwrapCall { +// AlbumMapper().transform(topAlbums.albums) +// } +// } +// +// return emptyList() + return Result.pure(emptyList()) } } diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/data/lastfm/LastFmService.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/data/lastfm/LastFmService.kt index 477c20d..4832e7e 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/data/lastfm/LastFmService.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/data/lastfm/LastFmService.kt @@ -37,4 +37,5 @@ interface LastFmService { @GET("/2.0/?method=album.getInfo") fun requestAlbum(@Query("mbid") id: String): Call -} \ No newline at end of file + +} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/data/mapper/AlbumMapper.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/data/mapper/AlbumMapper.kt index a5f874f..1c19d98 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/data/mapper/AlbumMapper.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/data/mapper/AlbumMapper.kt @@ -26,8 +26,8 @@ import org.funktionale.option.toOption class AlbumMapper(val artistMapper: ArtistMapper = ArtistMapper(), val imageMapper: ImageMapper = ImageMapper(), val trackMapper: TrackMapper = TrackMapper()) { - fun transform(albums: List): List { - return albums.filter { albumHasQualityInfo(it) }.mapNotNull { transform(it) } + fun transform(albums: List): Option> { + return albums.filter { albumHasQualityInfo(it) }.mapNotNull { transform(it) }.toOption() } private fun albumHasQualityInfo(album: LastFmAlbum): Boolean { diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/di/ApplicationModule.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/di/ApplicationModule.kt index 5e4321b..905c9cb 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/di/ApplicationModule.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/di/ApplicationModule.kt @@ -4,12 +4,6 @@ import android.content.Context import com.antonioleiva.bandhookkotlin.App import com.antonioleiva.bandhookkotlin.di.qualifier.ApplicationQualifier import com.antonioleiva.bandhookkotlin.di.qualifier.LanguageSelection -import com.antonioleiva.bandhookkotlin.domain.BusImpl -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Bus -import com.antonioleiva.bandhookkotlin.domain.interactor.base.CustomJobManager -import com.antonioleiva.bandhookkotlin.domain.interactor.base.InteractorExecutor -import com.antonioleiva.bandhookkotlin.domain.interactor.base.InteractorExecutorImpl -import com.birbit.android.jobqueue.JobManager import com.squareup.picasso.Picasso import dagger.Module import dagger.Provides @@ -25,18 +19,10 @@ class ApplicationModule(private val app: App) { @Provides @Singleton @ApplicationQualifier fun provideApplicationContext(): Context = app - @Provides @Singleton - fun provideBus(): Bus = BusImpl() - @Provides @Singleton fun providePicasso(@ApplicationQualifier context: Context): Picasso = Picasso.Builder(context).build() - @Provides @Singleton - fun provideJobManager(@ApplicationQualifier context: Context): JobManager = CustomJobManager(context) - - @Provides @Singleton - fun provideInteractorExecutor(jobManager: JobManager, bus: Bus): InteractorExecutor = InteractorExecutorImpl(jobManager, bus) - @Provides @Singleton @LanguageSelection fun provideLanguageSelection(): String = Locale.getDefault().language + } diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/di/subcomponent/album/AlbumActivityModule.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/di/subcomponent/album/AlbumActivityModule.kt index 01c1ca3..e923428 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/di/subcomponent/album/AlbumActivityModule.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/di/subcomponent/album/AlbumActivityModule.kt @@ -5,7 +5,6 @@ import android.support.v7.widget.LinearLayoutManager import com.antonioleiva.bandhookkotlin.di.ActivityModule import com.antonioleiva.bandhookkotlin.di.scope.ActivityScope import com.antonioleiva.bandhookkotlin.domain.interactor.GetAlbumDetailInteractor -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Bus import com.antonioleiva.bandhookkotlin.ui.adapter.TracksAdapter import com.antonioleiva.bandhookkotlin.ui.entity.mapper.AlbumDetailDataMapper import com.antonioleiva.bandhookkotlin.ui.entity.mapper.TrackDataMapper @@ -35,8 +34,7 @@ class AlbumActivityModule(activity: AlbumActivity) : ActivityModule(activity) { @Provides @ActivityScope fun provideAlbumPresenter(view: AlbumView, - bus: Bus, albumInteractor: GetAlbumDetailInteractor, albumDetailDataMapper: AlbumDetailDataMapper) - = AlbumPresenter(view, bus, albumInteractor, albumDetailDataMapper) + = AlbumPresenter(view, albumInteractor, albumDetailDataMapper) } diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/di/subcomponent/detail/ArtistActivityModule.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/di/subcomponent/detail/ArtistActivityModule.kt index 6f6a27c..744d15e 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/di/subcomponent/detail/ArtistActivityModule.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/di/subcomponent/detail/ArtistActivityModule.kt @@ -4,8 +4,6 @@ import com.antonioleiva.bandhookkotlin.di.ActivityModule import com.antonioleiva.bandhookkotlin.di.scope.ActivityScope import com.antonioleiva.bandhookkotlin.domain.interactor.GetArtistDetailInteractor import com.antonioleiva.bandhookkotlin.domain.interactor.GetTopAlbumsInteractor -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Bus -import com.antonioleiva.bandhookkotlin.domain.interactor.base.InteractorExecutor import com.antonioleiva.bandhookkotlin.ui.entity.mapper.ArtistDetailDataMapper import com.antonioleiva.bandhookkotlin.ui.entity.mapper.ImageTitleDataMapper import com.antonioleiva.bandhookkotlin.ui.presenter.ArtistPresenter @@ -30,18 +28,17 @@ class ArtistActivityModule(activity: ArtistActivity) : ActivityModule(activity) @Provides @ActivityScope fun provideActivityPresenter(view: ArtistView, - bus: Bus, artistDetailInteractor: GetArtistDetailInteractor, topAlbumsInteractor: GetTopAlbumsInteractor, - interactorExecutor: InteractorExecutor, detailDataMapper: ArtistDetailDataMapper, imageTitleDataMapper: ImageTitleDataMapper) - = ArtistPresenter(view, bus, artistDetailInteractor, topAlbumsInteractor, - interactorExecutor, detailDataMapper, imageTitleDataMapper) + = ArtistPresenter(view, artistDetailInteractor, topAlbumsInteractor, + detailDataMapper, imageTitleDataMapper) @Provides @ActivityScope fun provideAlbumsFragment() = AlbumsFragment() @Provides @ActivityScope fun provideBiographyFragment() = BiographyFragment() -} \ No newline at end of file + +} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/di/subcomponent/main/MainActivityModule.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/di/subcomponent/main/MainActivityModule.kt index 24b424d..5225507 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/di/subcomponent/main/MainActivityModule.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/di/subcomponent/main/MainActivityModule.kt @@ -3,8 +3,6 @@ package com.antonioleiva.bandhookkotlin.di.subcomponent.main import com.antonioleiva.bandhookkotlin.di.ActivityModule import com.antonioleiva.bandhookkotlin.di.scope.ActivityScope import com.antonioleiva.bandhookkotlin.domain.interactor.GetRecommendedArtistsInteractor -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Bus -import com.antonioleiva.bandhookkotlin.domain.interactor.base.InteractorExecutor import com.antonioleiva.bandhookkotlin.ui.adapter.ImageTitleAdapter import com.antonioleiva.bandhookkotlin.ui.entity.mapper.ImageTitleDataMapper import com.antonioleiva.bandhookkotlin.ui.presenter.MainPresenter @@ -23,14 +21,12 @@ class MainActivityModule(activity: MainActivity) : ActivityModule(activity) { fun provideImageTitleMapper() = ImageTitleDataMapper() @Provides @ActivityScope - fun provideMainPresenter(view: MainView, bus: Bus, + fun provideMainPresenter(view: MainView, recommendedArtistsInteractor: GetRecommendedArtistsInteractor, - interactorExecutor: InteractorExecutor, - imageMapper: ImageTitleDataMapper) = MainPresenter(view, bus, recommendedArtistsInteractor, - interactorExecutor, imageMapper) + imageMapper: ImageTitleDataMapper) + = MainPresenter(view, recommendedArtistsInteractor, imageMapper) @Provides @ActivityScope fun provideAdapter() = ImageTitleAdapter() - -} \ No newline at end of file +} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/BusImpl.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/BusImpl.kt deleted file mode 100644 index 7cc01e7..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/BusImpl.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2015 Antonio Leiva - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain - -import android.os.Handler -import android.os.Looper -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Bus -import de.greenrobot.event.EventBus - -class BusImpl : EventBus(), Bus { - - val mainThread = Handler(Looper.getMainLooper()) - - override fun post(event: Any) { - mainThread.post({ super.post(event) }) - } - -} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/entity/Exceptions.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/entity/Exceptions.kt index f3991f5..32a74f0 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/entity/Exceptions.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/entity/Exceptions.kt @@ -4,4 +4,5 @@ sealed class BizException { class AlbumNotFound(val id: String) : BizException() class ArtistNotFound(val id: String) : BizException() object RecomendationsNotFound : BizException() -} \ No newline at end of file + class TopAlbumsNotFound(val artistId: String?, val artistName: String?) : BizException() +} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetAlbumDetailInteractor.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetAlbumDetailInteractor.kt index f51de92..3336a03 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetAlbumDetailInteractor.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetAlbumDetailInteractor.kt @@ -18,12 +18,12 @@ package com.antonioleiva.bandhookkotlin.domain.interactor import com.antonioleiva.bandhookkotlin.Result import com.antonioleiva.bandhookkotlin.domain.entity.Album -import com.antonioleiva.bandhookkotlin.domain.entity.BizException.* +import com.antonioleiva.bandhookkotlin.domain.entity.BizException.AlbumNotFound import com.antonioleiva.bandhookkotlin.domain.repository.AlbumRepository class GetAlbumDetailInteractor(val albumRepository: AlbumRepository) { fun getAlbum(albumId: String): Result = - albumRepository.get(albumId) + albumRepository.getAlbum(albumId) } diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetArtistDetailInteractor.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetArtistDetailInteractor.kt index 7b9f258..e1cf20c 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetArtistDetailInteractor.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetArtistDetailInteractor.kt @@ -20,6 +20,6 @@ import com.antonioleiva.bandhookkotlin.domain.repository.ArtistRepository class GetArtistDetailInteractor(val artistRepository: ArtistRepository) { - fun getArtist(artistId: String) = artistRepository.get(artistId) + fun getArtist(artistId: String) = artistRepository.getArtist(artistId) -} \ No newline at end of file +} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetRecommendedArtistsInteractor.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetRecommendedArtistsInteractor.kt index 279320c..ac47967 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetRecommendedArtistsInteractor.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetRecommendedArtistsInteractor.kt @@ -19,7 +19,7 @@ package com.antonioleiva.bandhookkotlin.domain.interactor import com.antonioleiva.bandhookkotlin.NonEmptyList import com.antonioleiva.bandhookkotlin.Result import com.antonioleiva.bandhookkotlin.domain.entity.Artist -import com.antonioleiva.bandhookkotlin.domain.entity.BizException.* +import com.antonioleiva.bandhookkotlin.domain.entity.BizException.RecomendationsNotFound import com.antonioleiva.bandhookkotlin.domain.repository.ArtistRepository class GetRecommendedArtistsInteractor(val artistRepository: ArtistRepository) { @@ -27,4 +27,4 @@ class GetRecommendedArtistsInteractor(val artistRepository: ArtistRepository) { fun getRecommendedArtists(): Result> = artistRepository.getRecommendedArtists() -} \ No newline at end of file +} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetTopAlbumsInteractor.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetTopAlbumsInteractor.kt index e8be4be..48546e6 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetTopAlbumsInteractor.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetTopAlbumsInteractor.kt @@ -16,21 +16,12 @@ package com.antonioleiva.bandhookkotlin.domain.interactor -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Event -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Interactor -import com.antonioleiva.bandhookkotlin.domain.interactor.event.TopAlbumsEvent import com.antonioleiva.bandhookkotlin.domain.repository.AlbumRepository -class GetTopAlbumsInteractor(val albumRepository: AlbumRepository) : Interactor { +class GetTopAlbumsInteractor(val albumRepository: AlbumRepository) { var artistId: String? = null var artistName: String? = null - override fun invoke(): Event { - if (artistId == null && artistName == null) { - throw IllegalStateException("Either mbid or name should be specified") - } - val albums = albumRepository.getTopAlbums(artistId, artistName) - return TopAlbumsEvent(albums) - } -} \ No newline at end of file + fun getTopAlbums(artistId: String?, artistName: String?) = albumRepository.getTopAlbums(artistId, artistName) +} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/Bus.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/Bus.kt deleted file mode 100644 index f3398df..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/Bus.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2015 Antonio Leiva - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain.interactor.base - -interface Bus { - fun post(event: Any): Unit - fun register(observer: Any): Unit - fun unregister(observer: Any): Unit -} \ No newline at end of file diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/CustomJobManager.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/CustomJobManager.kt deleted file mode 100644 index 4dccfd6..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/CustomJobManager.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2015 Antonio Leiva - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain.interactor.base - -import android.content.Context -import com.birbit.android.jobqueue.JobManager -import com.birbit.android.jobqueue.config.Configuration - -class CustomJobManager(context: Context) -: JobManager(CustomJobManager.getJobManagerConfiguration(context)) { - - companion object { - - private fun getJobManagerConfiguration(context: Context): Configuration { - - return Configuration.Builder(context) - .minConsumerCount(1) // always keep at least one consumer alive - .maxConsumerCount(3) // up to 3 consumers at NextOnEditorActionListener time - .loadFactor(3) // 3 jobs per consumer - .consumerKeepAlive(120) // wait 2 minutes - .build() - - } - } -} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/Event.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/Event.kt deleted file mode 100644 index 7fff52c..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/Event.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2015 Antonio Leiva - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain.interactor.base - -interface Event { - -} \ No newline at end of file diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/Interactor.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/Interactor.kt deleted file mode 100644 index 11406ac..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/Interactor.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2015 Antonio Leiva - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain.interactor.base - -interface Interactor { - - operator fun invoke(): Event -} \ No newline at end of file diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/InteractorExecutor.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/InteractorExecutor.kt deleted file mode 100644 index 531d19f..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/InteractorExecutor.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2015 Antonio Leiva - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain.interactor.base - -interface InteractorExecutor { - fun execute(interactor: Interactor, priority: InteractorPriority = InteractorPriority.LOW) -} \ No newline at end of file diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/InteractorExecutorImpl.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/InteractorExecutorImpl.kt deleted file mode 100644 index 2fb68e2..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/InteractorExecutorImpl.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2015 Antonio Leiva - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain.interactor.base - -import com.birbit.android.jobqueue.JobManager - -class InteractorExecutorImpl(val jobManager: JobManager, val bus: Bus) : InteractorExecutor { - - override fun execute(interactor: Interactor, priority: InteractorPriority) { - jobManager.addJobInBackground(InteractorWrapper(interactor, priority, bus)) - } -} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/InteractorPriority.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/InteractorPriority.kt deleted file mode 100644 index ae4e88c..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/InteractorPriority.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2015 Antonio Leiva - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain.interactor.base - -enum class InteractorPriority(val value: Int) { - LOW(0), - MID(500), - HIGH(1000) -} \ No newline at end of file diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/InteractorWrapper.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/InteractorWrapper.kt deleted file mode 100644 index 8076c33..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/base/InteractorWrapper.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2015 Antonio Leiva - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain.interactor.base - -import com.birbit.android.jobqueue.Job -import com.birbit.android.jobqueue.Params -import com.birbit.android.jobqueue.RetryConstraint - -class InteractorWrapper(val interactor: Interactor, priority: InteractorPriority, val bus: Bus) : - Job(Params(priority.value).requireNetwork()) { - - override fun onRun() { - val event = interactor.invoke() - bus.post(event) - } - - override fun onAdded() = Unit - override fun onCancel(p0: Int, p1: Throwable?) = Unit - override fun shouldReRunOnThrowable(p0: Throwable, p1: Int, p2: Int): RetryConstraint = - RetryConstraint.CANCEL -} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/event/AlbumEvent.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/event/AlbumEvent.kt deleted file mode 100644 index 36e339a..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/event/AlbumEvent.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2016 Alexey Verein - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain.interactor.event - -import com.antonioleiva.bandhookkotlin.domain.entity.Album -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Event - -data class AlbumEvent(val album: Album?) : Event \ No newline at end of file diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/event/ArtistDetailEvent.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/event/ArtistDetailEvent.kt deleted file mode 100644 index 8c87ddd..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/event/ArtistDetailEvent.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2015 Antonio Leiva - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain.interactor.event - -import com.antonioleiva.bandhookkotlin.domain.entity.Artist -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Event - -class ArtistDetailEvent(val artist: Artist) : Event \ No newline at end of file diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/event/ArtistsEvent.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/event/ArtistsEvent.kt deleted file mode 100644 index 3839be4..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/event/ArtistsEvent.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2015 Antonio Leiva - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain.interactor.event - -import com.antonioleiva.bandhookkotlin.domain.entity.Artist -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Event - -class ArtistsEvent(val artists: List) : Event \ No newline at end of file diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/event/TopAlbumsEvent.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/event/TopAlbumsEvent.kt deleted file mode 100644 index 6bd11e8..0000000 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/interactor/event/TopAlbumsEvent.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2016 Alexey Verein - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.antonioleiva.bandhookkotlin.domain.interactor.event - -import com.antonioleiva.bandhookkotlin.domain.entity.Album -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Event - -data class TopAlbumsEvent(val topAlbums: List) : Event \ No newline at end of file diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/repository/AlbumRepository.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/repository/AlbumRepository.kt index 3242189..4f1cae2 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/repository/AlbumRepository.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/repository/AlbumRepository.kt @@ -19,8 +19,9 @@ package com.antonioleiva.bandhookkotlin.domain.repository import com.antonioleiva.bandhookkotlin.Result import com.antonioleiva.bandhookkotlin.domain.entity.Album import com.antonioleiva.bandhookkotlin.domain.entity.BizException.AlbumNotFound +import com.antonioleiva.bandhookkotlin.domain.entity.BizException.TopAlbumsNotFound interface AlbumRepository { - fun get(id: String): Result - fun getTopAlbums(artistId: String?, artistName: String?): List + fun getAlbum(id: String): Result + fun getTopAlbums(artistId: String?, artistName: String?): Result> } diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/repository/ArtistRepository.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/repository/ArtistRepository.kt index d99a126..9e26554 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/repository/ArtistRepository.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/domain/repository/ArtistRepository.kt @@ -19,9 +19,10 @@ package com.antonioleiva.bandhookkotlin.domain.repository import com.antonioleiva.bandhookkotlin.NonEmptyList import com.antonioleiva.bandhookkotlin.Result import com.antonioleiva.bandhookkotlin.domain.entity.Artist -import com.antonioleiva.bandhookkotlin.domain.entity.BizException.* +import com.antonioleiva.bandhookkotlin.domain.entity.BizException.ArtistNotFound +import com.antonioleiva.bandhookkotlin.domain.entity.BizException.RecomendationsNotFound interface ArtistRepository { - fun get(id: String): Result + fun getArtist(id: String): Result fun getRecommendedArtists(): Result> } diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/predef.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/predef.kt index 4bde4ec..27ae5a2 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/predef.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/predef.kt @@ -43,16 +43,16 @@ class Result(private val value: Promise, Exception>) { * flatMap over the left exceptional case */ fun recoverWith(fa: (E) -> Result): Result = - swap().flatMap { fa(it).swap() }.swap() + swap().flatMap { fa(it).swap() }.swap() /** * Monadic bind allows sequential chains of promises */ fun flatMap(fa: (A) -> Result): Result = - Result(value.bind { - it.fold(fl = { l -> raiseError(l).value }, fr = { r -> fa(r).value }) - }) + Result(value.bind { + it.fold(fl = { l -> raiseError(l).value }, fr = { r -> fa(r).value }) + }) /** * Side effects @@ -192,6 +192,3 @@ class NonEmptyList(val head: A, vararg t: A) : Collection { inline fun unsafeFromList(l: List): NonEmptyList = of(l[0], l.tail()) } } - - - diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/repository/AlbumRepositoryImpl.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/repository/AlbumRepositoryImpl.kt index d8f43f9..33cf57b 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/repository/AlbumRepositoryImpl.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/repository/AlbumRepositoryImpl.kt @@ -19,27 +19,25 @@ package com.antonioleiva.bandhookkotlin.repository import com.antonioleiva.bandhookkotlin.Result import com.antonioleiva.bandhookkotlin.domain.entity.Album import com.antonioleiva.bandhookkotlin.domain.entity.BizException.AlbumNotFound +import com.antonioleiva.bandhookkotlin.domain.entity.BizException.TopAlbumsNotFound import com.antonioleiva.bandhookkotlin.domain.repository.AlbumRepository import com.antonioleiva.bandhookkotlin.repository.datasource.AlbumDataSource class AlbumRepositoryImpl(val dataSources: List) : AlbumRepository { - override fun get(id: String): Result = + override fun getAlbum(id: String): Result = Result.firstSuccessIn( fa = dataSources, - acc = Result.raiseError(AlbumNotFound(id)), - f = { it.get(id) } + f = { it.get(id) }, + acc = Result.raiseError(AlbumNotFound(id)) ) - override fun getTopAlbums(artistId: String?, artistName: String?): List { - for (dataSource in dataSources) { - val result = dataSource.requestTopAlbums(artistId, artistName) - if (result.isNotEmpty()) { - return result - } - } - - return emptyList() - } + override fun getTopAlbums(artistId: String?, artistName: String?): + Result> = + Result.firstSuccessIn( + fa = dataSources, + acc = Result.raiseError(TopAlbumsNotFound(artistId, artistName)), + f = { it.requestTopAlbums(artistId, artistName) } + ) } diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/repository/ArtistRepositoryImpl.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/repository/ArtistRepositoryImpl.kt index d9c5bf9..9fb4592 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/repository/ArtistRepositoryImpl.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/repository/ArtistRepositoryImpl.kt @@ -21,25 +21,25 @@ import com.antonioleiva.bandhookkotlin.Result import com.antonioleiva.bandhookkotlin.Result.Factory.firstSuccessIn import com.antonioleiva.bandhookkotlin.Result.Factory.raiseError import com.antonioleiva.bandhookkotlin.domain.entity.Artist -import com.antonioleiva.bandhookkotlin.domain.entity.BizException.* +import com.antonioleiva.bandhookkotlin.domain.entity.BizException.ArtistNotFound +import com.antonioleiva.bandhookkotlin.domain.entity.BizException.RecomendationsNotFound import com.antonioleiva.bandhookkotlin.domain.repository.ArtistRepository import com.antonioleiva.bandhookkotlin.repository.datasource.ArtistDataSource class ArtistRepositoryImpl(val dataSources: List) : ArtistRepository { - override fun get(id: String): Result = + override fun getArtist(id: String): Result = firstSuccessIn( fa = dataSources, - acc = raiseError(ArtistNotFound(id)), + acc = raiseError(ArtistNotFound(id)), f = { it.get(id) } ) override fun getRecommendedArtists(): Result> = firstSuccessIn( fa = dataSources, - acc = raiseError>(RecomendationsNotFound), + acc = raiseError(RecomendationsNotFound), f = { it.requestRecommendedArtists() } ) - } diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/repository/datasource/AlbumDataSource.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/repository/datasource/AlbumDataSource.kt index 34d8372..d0156ad 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/repository/datasource/AlbumDataSource.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/repository/datasource/AlbumDataSource.kt @@ -19,10 +19,12 @@ package com.antonioleiva.bandhookkotlin.repository.datasource import com.antonioleiva.bandhookkotlin.Result import com.antonioleiva.bandhookkotlin.domain.entity.Album import com.antonioleiva.bandhookkotlin.domain.entity.BizException.AlbumNotFound +import com.antonioleiva.bandhookkotlin.domain.entity.BizException.TopAlbumsNotFound interface AlbumDataSource { fun get(id: String): Result - fun requestTopAlbums(artistId: String?, artistName: String?): List + fun requestTopAlbums(artistId: String?, artistName: String?): + Result> } diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumPresenter.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumPresenter.kt index 16f8eea..7f883ae 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumPresenter.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumPresenter.kt @@ -17,13 +17,11 @@ package com.antonioleiva.bandhookkotlin.ui.presenter import com.antonioleiva.bandhookkotlin.domain.interactor.GetAlbumDetailInteractor -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Bus import com.antonioleiva.bandhookkotlin.ui.entity.mapper.AlbumDetailDataMapper import com.antonioleiva.bandhookkotlin.ui.view.AlbumView open class AlbumPresenter( override val view: AlbumView, - override val bus: Bus, val albumInteractor: GetAlbumDetailInteractor, val albumDetailMapper: AlbumDetailDataMapper) : Presenter { @@ -35,4 +33,4 @@ open class AlbumPresenter( ) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumsPresenter.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumsPresenter.kt index 0a254b1..07e7f19 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumsPresenter.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumsPresenter.kt @@ -18,6 +18,6 @@ package com.antonioleiva.bandhookkotlin.ui.presenter import com.antonioleiva.bandhookkotlin.ui.entity.ImageTitle -interface AlbumsPresenter { +interface AlbumsPresenter { fun onAlbumClicked(item: ImageTitle) -} \ No newline at end of file +} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/ArtistPresenter.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/ArtistPresenter.kt index 74c3396..94421d7 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/ArtistPresenter.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/ArtistPresenter.kt @@ -18,9 +18,6 @@ package com.antonioleiva.bandhookkotlin.ui.presenter import com.antonioleiva.bandhookkotlin.domain.interactor.GetArtistDetailInteractor import com.antonioleiva.bandhookkotlin.domain.interactor.GetTopAlbumsInteractor -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Bus -import com.antonioleiva.bandhookkotlin.domain.interactor.base.InteractorExecutor -import com.antonioleiva.bandhookkotlin.domain.interactor.event.TopAlbumsEvent import com.antonioleiva.bandhookkotlin.ui.entity.ImageTitle import com.antonioleiva.bandhookkotlin.ui.entity.mapper.ArtistDetailDataMapper import com.antonioleiva.bandhookkotlin.ui.entity.mapper.ImageTitleDataMapper @@ -28,10 +25,8 @@ import com.antonioleiva.bandhookkotlin.ui.view.ArtistView open class ArtistPresenter( override val view: ArtistView, - override val bus: Bus, val artistDetailInteractor: GetArtistDetailInteractor, val topAlbumsInteractor: GetTopAlbumsInteractor, - val interactorExecutor: InteractorExecutor, val artistDetailMapper: ArtistDetailDataMapper, val albumsMapper: ImageTitleDataMapper) : Presenter, AlbumsPresenter { @@ -42,16 +37,15 @@ open class ArtistPresenter( onUnhandledException = { view.showUnhandledException(it) } ) - val topAlbumsInteractor = topAlbumsInteractor - topAlbumsInteractor.artistId = artistId - interactorExecutor.execute(this.topAlbumsInteractor) - } - - fun onEvent(event: TopAlbumsEvent) { - view.showAlbums(albumsMapper.transformAlbums(event.topAlbums)) + topAlbumsInteractor.getTopAlbums(artistId, null).onComplete( + onSuccess = { view.showAlbums(albumsMapper.transformAlbums(it)) }, + onError = { view.showTopAlbumsNotFound(it) }, + onUnhandledException = { view.showUnhandledException(it) } + ) } override fun onAlbumClicked(item: ImageTitle) { view.navigateToAlbum(item.id) } + } diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/MainPresenter.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/MainPresenter.kt index b5c894b..6b5dd6a 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/MainPresenter.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/MainPresenter.kt @@ -17,24 +17,20 @@ package com.antonioleiva.bandhookkotlin.ui.presenter import com.antonioleiva.bandhookkotlin.domain.interactor.GetRecommendedArtistsInteractor -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Bus -import com.antonioleiva.bandhookkotlin.domain.interactor.base.InteractorExecutor import com.antonioleiva.bandhookkotlin.ui.entity.ImageTitle import com.antonioleiva.bandhookkotlin.ui.entity.mapper.ImageTitleDataMapper import com.antonioleiva.bandhookkotlin.ui.view.MainView class MainPresenter( override val view: MainView, - override val bus: Bus, val recommendedArtistsInteractor: GetRecommendedArtistsInteractor, - val interactorExecutor: InteractorExecutor, val mapper: ImageTitleDataMapper) : Presenter { override fun onResume() { super.onResume() recommendedArtistsInteractor.getRecommendedArtists().onComplete( onSuccess = { view.showArtists(mapper.transformArtists(it)) }, - onError = { e -> }, + onError = { e -> }, onUnhandledException = { e -> } ) } @@ -42,4 +38,4 @@ class MainPresenter( fun onArtistClicked(item: ImageTitle) { view.navigateToDetail(item.id) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/Presenter.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/Presenter.kt index ff708c7..a4717f7 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/Presenter.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/Presenter.kt @@ -16,18 +16,13 @@ package com.antonioleiva.bandhookkotlin.ui.presenter -import com.antonioleiva.bandhookkotlin.domain.interactor.base.Bus - interface Presenter { val view: T - val bus: Bus - fun onResume(){ - bus.register(this) + fun onResume() { } - fun onPause(){ - bus.unregister(this) + fun onPause() { } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/screens/detail/ArtistActivity.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/screens/detail/ArtistActivity.kt index 23d1aee..05f82cf 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/screens/detail/ArtistActivity.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/screens/detail/ArtistActivity.kt @@ -31,6 +31,7 @@ import com.antonioleiva.bandhookkotlin.R import com.antonioleiva.bandhookkotlin.di.ApplicationComponent import com.antonioleiva.bandhookkotlin.di.subcomponent.detail.ArtistActivityModule import com.antonioleiva.bandhookkotlin.domain.entity.BizException.ArtistNotFound +import com.antonioleiva.bandhookkotlin.domain.entity.BizException.TopAlbumsNotFound import com.antonioleiva.bandhookkotlin.ui.activity.BaseActivity import com.antonioleiva.bandhookkotlin.ui.adapter.ArtistDetailPagerAdapter import com.antonioleiva.bandhookkotlin.ui.entity.ArtistDetail @@ -134,6 +135,11 @@ class ArtistActivity : BaseActivity(), ArtistView, AlbumsFragmentContainer { supportFinishAfterTransition() } + override fun showTopAlbumsNotFound(e: TopAlbumsNotFound) = runOnUiThread { + supportStartPostponedEnterTransition() + supportFinishAfterTransition() + } + override fun showUnhandledException(e: Exception) { //TODO show unhandled exceptions } diff --git a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/view/ArtistView.kt b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/view/ArtistView.kt index f39acf6..43104bf 100644 --- a/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/view/ArtistView.kt +++ b/app/src/main/java/com/antonioleiva/bandhookkotlin/ui/view/ArtistView.kt @@ -17,12 +17,14 @@ package com.antonioleiva.bandhookkotlin.ui.view import com.antonioleiva.bandhookkotlin.domain.entity.BizException.ArtistNotFound +import com.antonioleiva.bandhookkotlin.domain.entity.BizException.TopAlbumsNotFound import com.antonioleiva.bandhookkotlin.ui.entity.ArtistDetail import com.antonioleiva.bandhookkotlin.ui.entity.ImageTitle interface ArtistView : PresentationView { fun showArtist(artistDetail: ArtistDetail) fun showArtistNotFound(e: ArtistNotFound) + fun showTopAlbumsNotFound(e: TopAlbumsNotFound) fun showAlbums(albums: List) diff --git a/app/src/test/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetAlbumDetailInteractorTest.kt b/app/src/test/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetAlbumDetailInteractorTest.kt index 1c77b9e..9d59061 100644 --- a/app/src/test/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetAlbumDetailInteractorTest.kt +++ b/app/src/test/java/com/antonioleiva/bandhookkotlin/domain/interactor/GetAlbumDetailInteractorTest.kt @@ -40,7 +40,7 @@ class GetAlbumDetailInteractorTest { @Before fun setUp() { - `when`(albumRepository.get(albumId)).thenReturn(Album("album id", "album name", + `when`(albumRepository.getAlbum(albumId)).thenReturn(Album("album id", "album name", Artist("artist id", "artist name", null, null, null), "album url", emptyList())) getAlbumDetailInteractor = GetAlbumDetailInteractor(albumRepository) diff --git a/app/src/test/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumPresenterTest.kt b/app/src/test/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumPresenterTest.kt index 2fca06c..e2910ce 100644 --- a/app/src/test/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumPresenterTest.kt +++ b/app/src/test/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumPresenterTest.kt @@ -20,7 +20,6 @@ import com.antonioleiva.bandhookkotlin.domain.entity.Album import com.antonioleiva.bandhookkotlin.domain.entity.Artist import com.antonioleiva.bandhookkotlin.domain.interactor.GetAlbumDetailInteractor import com.antonioleiva.bandhookkotlin.domain.interactor.base.Bus -import com.antonioleiva.bandhookkotlin.domain.interactor.base.InteractorExecutor import com.antonioleiva.bandhookkotlin.domain.interactor.event.AlbumEvent import com.antonioleiva.bandhookkotlin.domain.repository.AlbumRepository import com.antonioleiva.bandhookkotlin.ui.entity.mapper.AlbumDetailDataMapper diff --git a/app/src/test/java/com/antonioleiva/bandhookkotlin/ui/presenter/ArtistPresenterTest.kt b/app/src/test/java/com/antonioleiva/bandhookkotlin/ui/presenter/ArtistPresenterTest.kt index bdcf99f..8ae9441 100644 --- a/app/src/test/java/com/antonioleiva/bandhookkotlin/ui/presenter/ArtistPresenterTest.kt +++ b/app/src/test/java/com/antonioleiva/bandhookkotlin/ui/presenter/ArtistPresenterTest.kt @@ -21,7 +21,6 @@ import com.antonioleiva.bandhookkotlin.domain.entity.Artist import com.antonioleiva.bandhookkotlin.domain.interactor.GetArtistDetailInteractor import com.antonioleiva.bandhookkotlin.domain.interactor.GetTopAlbumsInteractor import com.antonioleiva.bandhookkotlin.domain.interactor.base.Bus -import com.antonioleiva.bandhookkotlin.domain.interactor.base.InteractorExecutor import com.antonioleiva.bandhookkotlin.domain.interactor.event.ArtistDetailEvent import com.antonioleiva.bandhookkotlin.domain.interactor.event.TopAlbumsEvent import com.antonioleiva.bandhookkotlin.domain.repository.AlbumRepository @@ -70,7 +69,7 @@ class ArtistPresenterTest { artistPresenter = ArtistPresenter(artistView, bus, artistDetailInteractor, topAlbumsInteractor, - interactorExecutor, artistDetailMapper, albumsMapper) + artistDetailMapper, albumsMapper) } @Test