forked from antoniolg/Bandhook-Kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexey Verein
committed
Jul 8, 2016
1 parent
d5a35f5
commit 20af3f5
Showing
20 changed files
with
287 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/antonioleiva/bandhookkotlin/data/mapper/TrackMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.antonioleiva.bandhookkotlin.data.mapper | ||
|
||
import com.antonioleiva.bandhookkotlin.data.lastfm.model.LastFmTrack | ||
import com.antonioleiva.bandhookkotlin.domain.entity.Track | ||
|
||
/** | ||
* @author alexey@plainvanillagames.com | ||
* | ||
* 05/07/16. | ||
*/ | ||
|
||
class TrackMapper() { | ||
|
||
fun transform(tracks: List<LastFmTrack>?) : List<Track> { | ||
return tracks?.map { transform(it) } ?: emptyList() | ||
} | ||
|
||
fun transform(track: LastFmTrack) : Track = Track(track.name, track.duration) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/antonioleiva/bandhookkotlin/ui/entity/AlbumDetail.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.antonioleiva.bandhookkotlin.ui.entity | ||
|
||
import com.antonioleiva.bandhookkotlin.domain.entity.Track | ||
|
||
/** | ||
* @author alexey@plainvanillagames.com | ||
* | ||
* 05/07/16. | ||
*/ | ||
data class AlbumDetail(val id: String, | ||
val name: String, | ||
val url: String?, | ||
val tracks: List<Track>) |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/antonioleiva/bandhookkotlin/ui/entity/mapper/AlbumDetailDataMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.antonioleiva.bandhookkotlin.ui.entity.mapper | ||
|
||
import com.antonioleiva.bandhookkotlin.domain.entity.Album | ||
import com.antonioleiva.bandhookkotlin.ui.entity.AlbumDetail | ||
|
||
/** | ||
* @author alexey@plainvanillagames.com | ||
* | ||
* 05/07/16. | ||
*/ | ||
class AlbumDetailDataMapper { | ||
|
||
fun transform(album: Album?): AlbumDetail? = if (album != null) AlbumDetail( | ||
album.id, | ||
album.name, | ||
album.url, | ||
album.tracks) else null | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/antonioleiva/bandhookkotlin/ui/fragment/AlbumsFragmentContainer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.antonioleiva.bandhookkotlin.ui.fragment | ||
|
||
import com.antonioleiva.bandhookkotlin.ui.presenter.AlbumsPresenter | ||
|
||
/** | ||
* @author tpom6oh@gmail.com | ||
* | ||
* 05/07/16. | ||
*/ | ||
interface AlbumsFragmentContainer { | ||
fun getAlbumsPresenter(): AlbumsPresenter | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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.domain.interactor.base.InteractorExecutor | ||
import com.antonioleiva.bandhookkotlin.domain.interactor.event.AlbumDetailEvent | ||
import com.antonioleiva.bandhookkotlin.ui.entity.mapper.AlbumDetailDataMapper | ||
import com.antonioleiva.bandhookkotlin.ui.view.AlbumView | ||
|
||
/** | ||
* @author tpom6oh@gmail.com | ||
* | ||
* 05/07/16. | ||
*/ | ||
class AlbumPresenter( | ||
override val view: AlbumView, | ||
override val bus: Bus, | ||
val albumInteractor: GetAlbumDetailInteractor, | ||
val interactorExecutor: InteractorExecutor, | ||
val albumDetailMapper: AlbumDetailDataMapper) : Presenter<AlbumView> { | ||
|
||
fun init(albumId: String) { | ||
val albumDetailInteractor = albumInteractor; | ||
albumInteractor.albumId = albumId | ||
interactorExecutor.execute(albumDetailInteractor) | ||
} | ||
|
||
fun onEvent(event: AlbumDetailEvent) { | ||
view.showAlbum(albumDetailMapper.transform(event.album)) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/antonioleiva/bandhookkotlin/ui/presenter/AlbumsPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.antonioleiva.bandhookkotlin.ui.presenter | ||
|
||
import com.antonioleiva.bandhookkotlin.ui.entity.ImageTitle | ||
|
||
/** | ||
* @author tpom6oh@gmail.com | ||
* | ||
* 05/07/16. | ||
*/ | ||
|
||
interface AlbumsPresenter { | ||
fun onAlbumClicked(item: ImageTitle) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/src/main/java/com/antonioleiva/bandhookkotlin/ui/screens/album/AlbumActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.antonioleiva.bandhookkotlin.ui.screens.album | ||
|
||
import android.os.Bundle | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import com.antonioleiva.bandhookkotlin.R | ||
import com.antonioleiva.bandhookkotlin.di.Inject | ||
import com.antonioleiva.bandhookkotlin.di.Injector | ||
import com.antonioleiva.bandhookkotlin.ui.activity.BaseActivity | ||
import com.antonioleiva.bandhookkotlin.ui.entity.AlbumDetail | ||
import com.antonioleiva.bandhookkotlin.ui.entity.mapper.AlbumDetailDataMapper | ||
import com.antonioleiva.bandhookkotlin.ui.presenter.AlbumPresenter | ||
import com.antonioleiva.bandhookkotlin.ui.util.getNavigationId | ||
import com.antonioleiva.bandhookkotlin.ui.util.supportsLollipop | ||
import com.antonioleiva.bandhookkotlin.ui.view.AlbumView | ||
import com.squareup.picasso.Callback | ||
import org.jetbrains.anko.find | ||
|
||
/** | ||
* @author alexey@plainvanillagames.com | ||
* | ||
* 05/07/16. | ||
*/ | ||
|
||
class AlbumActivity : BaseActivity(), AlbumView, Injector by Inject.instance { | ||
|
||
override val layoutResource = R.layout.activity_album | ||
|
||
val image by lazy { find<ImageView>(R.id.album_image) } | ||
val text by lazy { find<TextView>(R.id.albums) } | ||
|
||
var presenter = AlbumPresenter(this, bus, albumInteractorProvider, | ||
interactorExecutor, AlbumDetailDataMapper()) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
supportPostponeEnterTransition() | ||
supportsLollipop { image.transitionName = IMAGE_TRANSITION_NAME } | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
presenter.onResume() | ||
presenter.init(getNavigationId()) | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
presenter.onPause() | ||
} | ||
|
||
override fun showAlbum(albumDetail: AlbumDetail?) { | ||
if (albumDetail != null) { | ||
picasso.load(albumDetail.url).fit().centerCrop().into(image, object : Callback.EmptyCallback() { | ||
override fun onSuccess() { | ||
supportStartPostponedEnterTransition() | ||
|
||
val tracks = albumDetail.tracks.map { it.name }.joinToString() | ||
text.text = tracks | ||
} | ||
}) | ||
} else { | ||
supportStartPostponedEnterTransition(); | ||
supportFinishAfterTransition(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.