-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add artist gallery feature module #8
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,33 @@ package com.ataulm.artcollector | |
import android.content.Intent | ||
import android.net.Uri | ||
|
||
enum class Navigation(private val semiQualifiedActivityName: String) { | ||
private const val SCHEME = "https" | ||
private const val AUTHORITY = "art-collector.ataulm.com" | ||
private const val ARTIST_GALLERY = "${BuildConfig.APPLICATION_ID}.artist.ui.ArtistActivity" | ||
private const val PAINTING = "${BuildConfig.APPLICATION_ID}.painting.ui.PaintingActivity" | ||
|
||
GALLERY("gallery.ui.GalleryActivity"), | ||
PAINTING("painting.ui.PaintingActivity"); | ||
fun artistGalleryIntent(artistId: String): Intent { | ||
val uri = Uri.Builder() | ||
.scheme(SCHEME) | ||
.authority(AUTHORITY) | ||
.path(artistId) | ||
.build() | ||
|
||
fun viewIntent(artistId: String, paintingId: String): Intent { | ||
val uri = Uri.Builder() | ||
.scheme("https://") | ||
.authority("art-collector.ataulm.com") | ||
.path("$artistId/$paintingId") | ||
.build() | ||
return intent(uri, ARTIST_GALLERY) | ||
} | ||
|
||
fun paintingIntent(artistId: String, paintingId: String): Intent { | ||
val uri = Uri.Builder() | ||
.scheme(SCHEME) | ||
.authority(AUTHORITY) | ||
.path("$artistId/$paintingId") | ||
.build() | ||
|
||
return intent(uri, PAINTING) | ||
} | ||
|
||
return Intent(Intent.ACTION_VIEW) | ||
.setClassName(BuildConfig.APPLICATION_ID, "${BuildConfig.APPLICATION_ID}.$semiQualifiedActivityName") | ||
.setData(uri) | ||
} | ||
private fun intent(uri: Uri, componentName: String): Intent { | ||
return Intent(Intent.ACTION_VIEW) | ||
.setClassName(BuildConfig.APPLICATION_ID, componentName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should just be able to ditch this line when we add the correct intent filters in the manifest 🤔 |
||
.setData(uri) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apply plugin: 'com.android.dynamic-feature' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'kotlin-kapt' | ||
|
||
android { | ||
compileSdkVersion versions.androidSdk.compile | ||
} | ||
|
||
dependencies { | ||
implementation project(':app') | ||
|
||
kapt libraries.daggerCompiler | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:dist="http://schemas.android.com/apk/distribution" | ||
package="com.ataulm.artcollector.artist"> | ||
|
||
<dist:module | ||
dist:onDemand="false" | ||
dist:title="@string/title_artist"> | ||
<dist:fusing dist:include="true" /> | ||
</dist:module> | ||
|
||
<application> | ||
<activity android:name=".ui.ArtistActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.VIEW" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.ataulm.artcollector.artist | ||
|
||
import com.ataulm.artcollector.ApplicationComponent | ||
import com.ataulm.artcollector.ArtCollectorApplication | ||
import com.ataulm.artcollector.artist.domain.ArtistId | ||
import com.ataulm.artcollector.artist.ui.ArtistActivity | ||
import dagger.BindsInstance | ||
import dagger.Component | ||
|
||
@Component(modules = [ArtistModule::class], dependencies = [ApplicationComponent::class]) | ||
internal interface ArtistComponent { | ||
|
||
fun inject(activity: ArtistActivity) | ||
|
||
@Component.Builder | ||
interface Builder { | ||
|
||
@BindsInstance | ||
fun activity(activity: ArtistActivity): Builder | ||
|
||
fun withParent(component: ApplicationComponent): Builder | ||
|
||
@BindsInstance | ||
fun with(artistId: ArtistId): Builder | ||
|
||
fun build(): ArtistComponent | ||
} | ||
} | ||
|
||
internal fun ArtistActivity.injectDependencies(artistId: ArtistId) = DaggerArtistComponent.builder() | ||
.withParent(ArtCollectorApplication.component(this)) | ||
.activity(this) | ||
.with(artistId) | ||
.build() | ||
.inject(this) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.ataulm.artcollector.artist | ||
|
||
import android.arch.lifecycle.ViewModelProviders | ||
import com.ataulm.artcollector.artist.data.AndroidArtistRepository | ||
import com.ataulm.artcollector.artist.domain.ArtistRepository | ||
import com.ataulm.artcollector.artist.ui.ArtistActivity | ||
import com.ataulm.artcollector.artist.ui.ArtistViewModel | ||
import com.ataulm.artcollector.artist.ui.ArtistViewModelFactory | ||
import dagger.Module | ||
import dagger.Provides | ||
|
||
@Module | ||
internal object ArtistModule { | ||
|
||
@JvmStatic | ||
@Provides | ||
fun artistRepository(artistRepository: AndroidArtistRepository): ArtistRepository { | ||
return artistRepository | ||
} | ||
|
||
@JvmStatic | ||
@Provides | ||
fun viewModel(activity: ArtistActivity, viewModelFactory: ArtistViewModelFactory) = | ||
ViewModelProviders.of(activity, viewModelFactory).get(ArtistViewModel::class.java) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.ataulm.artcollector.artist.data | ||
|
||
import com.ataulm.artcollector.ApiRecord | ||
import com.ataulm.artcollector.HarvardArtMuseumApi | ||
import com.ataulm.artcollector.artist.domain.Artist | ||
import com.ataulm.artcollector.artist.domain.ArtistId | ||
import com.ataulm.artcollector.artist.domain.ArtistRepository | ||
import com.ataulm.artcollector.artist.domain.Gallery | ||
import com.ataulm.artcollector.artist.domain.Painting | ||
import javax.inject.Inject | ||
|
||
internal class AndroidArtistRepository @Inject constructor( | ||
private val harvardArtMuseumApi: HarvardArtMuseumApi, | ||
private val artistId: ArtistId | ||
) : ArtistRepository { | ||
|
||
override suspend fun artistGallery(): Gallery { | ||
val paintings = harvardArtMuseumApi.artistGallery(artistId.value).await().records | ||
.map { it.toPainting() } | ||
return Gallery(paintings) | ||
} | ||
|
||
private fun ApiRecord.toPainting(): Painting { | ||
val apiPerson = people.first() | ||
return Painting( | ||
id.toString(), | ||
title, | ||
description, | ||
primaryImageUrl, | ||
Artist(apiPerson.personId.toString(), apiPerson.name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we probably don't need the Artist in this module - it'll be the same for each one I think |
||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.ataulm.artcollector.artist.domain | ||
|
||
internal interface ArtistRepository { | ||
|
||
suspend fun artistGallery(): Gallery | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.ataulm.artcollector.artist.domain | ||
|
||
import javax.inject.Inject | ||
|
||
internal class GetArtistGalleryUseCase @Inject constructor( | ||
private val repository: ArtistRepository | ||
) { | ||
|
||
suspend operator fun invoke() = repository.artistGallery() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.ataulm.artcollector.artist.domain | ||
|
||
internal class Gallery(collection: Collection<Painting>) : ArrayList<Painting>(collection) | ||
|
||
internal data class Painting( | ||
val id: String, | ||
val title: String, | ||
val description: String?, | ||
val imageUrl: String?, // nullable because https://github.com/harvardartmuseums/api-docs/issues/6 | ||
val artist: Artist | ||
) | ||
|
||
internal data class Artist(val id: String, val name: String) | ||
|
||
internal data class ArtistId(val value: String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for single page, this is null