Skip to content

Commit

Permalink
Album activity
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Verein committed Jul 8, 2016
1 parent d5a35f5 commit 20af3f5
Show file tree
Hide file tree
Showing 20 changed files with 287 additions and 17 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<activity
android:name=".ui.screens.detail.ArtistActivity"
android:parentActivityName=".ui.screens.main.MainActivity"/>

<activity
android:name=".ui.screens.album.AlbumActivity"
android:parentActivityName=".ui.screens.detail.ArtistActivity"/>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ class LastFmAlbum(
val url: String,
val artist: LastFmArtist,
@SerializedName("image") val images: List<LastFmImage>,
val tracks: LastFmTracklist
val tracks: LastFmTracklist?
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.antonioleiva.bandhookkotlin.data.lastfm.model
class LastFmTrack (
val name: String,
val duration: Int = 0,
val mbid: String,
val url: String,
val mbid: String?,
val url: String?,
val artist: LastFmArtist
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import com.antonioleiva.bandhookkotlin.domain.entity.Artist
* 03/07/16.
*/

class AlbumMapper(val artistMapper: ArtistMapper = ArtistMapper(), val imageMapper: ImageMapper = ImageMapper()) {
class AlbumMapper(val artistMapper: ArtistMapper = ArtistMapper(), val imageMapper: ImageMapper = ImageMapper(),
val trackMapper: TrackMapper = TrackMapper()) {

fun transform(albums: List<LastFmAlbum>): List<Album> {
return albums.filter { albumHasQualityInfo(it) }.mapNotNull { transform(it) }
Expand All @@ -31,7 +32,8 @@ class AlbumMapper(val artistMapper: ArtistMapper = ArtistMapper(), val imageMapp
album.mbid,
album.name,
imageMapper.getMainImageUrl(album.images),
Artist("", album.artist))
Artist("", album.artist),
trackMapper.transform(album.tracks.tracks))
} else {
return null
}
Expand All @@ -43,7 +45,8 @@ class AlbumMapper(val artistMapper: ArtistMapper = ArtistMapper(), val imageMapp
album.mbid,
album.name,
imageMapper.getMainImageUrl(album.images),
artistMapper.transform(album.artist))
artistMapper.transform(album.artist),
trackMapper.transform(album.tracks?.tracks))
} else {
return null
}
Expand Down
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package com.antonioleiva.bandhookkotlin.domain.entity

data class Album(val id: String, val name: String, val url: String?, val artist: Artist)
data class Album(val id: String, val name: String, val url: String?, val artist: Artist, val tracks: List<Track>)
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package com.antonioleiva.bandhookkotlin.domain.entity

public data class Track(val id: String, val name: String, val album: Album)
data class Track(val name: String, val duration: Int)
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>)
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
}
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
}
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))
}
}
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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.ui.entity.ImageTitle
import com.antonioleiva.bandhookkotlin.ui.entity.mapper.ArtistDetailDataMapper
import com.antonioleiva.bandhookkotlin.ui.entity.mapper.ImageTitleDataMapper
import com.antonioleiva.bandhookkotlin.ui.view.ArtistView
Expand All @@ -33,7 +34,7 @@ open class ArtistPresenter(
val topAlbumsInteractor: GetTopAlbumsInteractor,
val interactorExecutor: InteractorExecutor,
val artistDetailMapper: ArtistDetailDataMapper,
val albumsMapper: ImageTitleDataMapper) : Presenter<ArtistView> {
val albumsMapper: ImageTitleDataMapper) : Presenter<ArtistView>, AlbumsPresenter {

open fun init(artistId: String) {
val artistDetailInteractor = artistDetailInteractor;
Expand All @@ -52,4 +53,8 @@ open class ArtistPresenter(
fun onEvent(event: TopAlbumsEvent) {
view.showAlbums(albumsMapper.transformAlbums(event.topAlbums))
}

override fun onAlbumClicked(item: ImageTitle) {
view.navigateToAlbum(item.id)
}
}
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();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.antonioleiva.bandhookkotlin.ui.screens.detail


import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.RecyclerView
Expand All @@ -9,6 +10,7 @@ import android.view.View
import android.view.ViewGroup
import com.antonioleiva.bandhookkotlin.R
import com.antonioleiva.bandhookkotlin.ui.adapter.ImageTitleAdapter
import com.antonioleiva.bandhookkotlin.ui.fragment.AlbumsFragmentContainer

/**
* @author tpom6oh@gmail.com
Expand All @@ -20,6 +22,11 @@ class AlbumsFragment: Fragment() {

lateinit var adapter: ImageTitleAdapter
private set
lateinit var recycler: RecyclerView
private set

var albumsFragmentContainer: AlbumsFragmentContainer? = null
private set

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

Expand All @@ -33,8 +40,26 @@ class AlbumsFragment: Fragment() {
}

private fun setUpRecyclerView(view: View) {
val recyclerView = view.findViewById(R.id.albums_view) as RecyclerView
recycler = view.findViewById(R.id.albums_view) as RecyclerView
adapter = ImageTitleAdapter();
recyclerView.adapter = adapter;
recycler.adapter = adapter;

adapter.onItemClickListener = {
albumsFragmentContainer?.getAlbumsPresenter()?.onAlbumClicked(it)
}
}

override fun onAttach(context: Context?) {
super.onAttach(context)

if (context is AlbumsFragmentContainer) {
albumsFragmentContainer = context
}
}

override fun onDetach() {
super.onDetach()

albumsFragmentContainer = null
}
}
Loading

0 comments on commit 20af3f5

Please sign in to comment.