Skip to content

Commit

Permalink
Added hero information screen with navigation component in module - f…
Browse files Browse the repository at this point in the history
…eature:avengers
  • Loading branch information
dksung committed Feb 5, 2023
1 parent cb4a38d commit 4c164d9
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 123 deletions.
Expand Up @@ -5,11 +5,4 @@ import dagger.hilt.android.HiltAndroidApp
import io.reactivex.rxjava3.plugins.RxJavaPlugins

@HiltAndroidApp
class MultiModuleHilt : Application() {

override fun onCreate() {
super.onCreate()

RxJavaPlugins.setErrorHandler { }
}
}
class MultiModuleHilt : Application()
11 changes: 0 additions & 11 deletions app/src/main/res/navigation/page_avengers.xml

This file was deleted.

3 changes: 2 additions & 1 deletion build.gradle.kts
@@ -1,6 +1,7 @@
buildscript {
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.21")
classpath(libs.kotlin.gradlePlugin)
classpath(libs.androidx.navigationPlugin)
}
}
// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed
Expand Down
42 changes: 37 additions & 5 deletions core/model/build.gradle.kts
@@ -1,9 +1,41 @@
// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("java-library")
id("kotlin")
alias(libs.plugins.android.library)
kotlin("android")
kotlin("kapt")
id("kotlin-parcelize")
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
android {

namespace = "com.turtle.multimodulehilt.core.model"
compileSdk = libs.versions.compileSdkVersion.get().toInt()

defaultConfig {

minSdk = libs.versions.minSdkVersion.get().toInt()
targetSdk = libs.versions.targetSdkVersion.get().toInt()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

compileOptions {
sourceCompatibility(JavaVersion.VERSION_1_8)
targetCompatibility(JavaVersion.VERSION_1_8)
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
130 changes: 72 additions & 58 deletions core/model/src/main/java/com/turtle/multimodulehilt/core/model/Hero.kt
@@ -1,96 +1,110 @@
package com.turtle.multimodulehilt.core.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

data class HeroJsonBody(
val code: Int,
val status: String,
val copyright: String,
val attributionText: String,
val attributionHTML: String,
val etag: String,
val data: HeroJsonDataBody
val code: Int = 0,
val status: String = "",
val copyright: String = "",
val attributionText: String = "",
val attributionHTML: String = "",
val etag: String = "",
val data: HeroJsonDataBody = HeroJsonDataBody()
)

data class HeroJsonDataBody(
val offset: Int,
val limit: Int,
val total: Int,
val count: Int,
val results: List<Hero>
val offset: Int = 0,
val limit: Int = 0,
val total: Int = 0,
val count: Int = 0,
val results: List<Hero> = emptyList()
)

@Parcelize
data class Hero(
val id: Int = 0,
val name: String = "0",
val description: String = "0",
val modified: String,
val thumbnail: HeroThumbnail,
val modified: String = "",
val thumbnail: HeroThumbnail = HeroThumbnail(),
val resourceURI: String = "0",
val comics: HeroComics,
val series: HeroSeries,
val stories: HeroStories,
val events: HeroEvents,
val urls: List<HeroUrl>,
)
val comics: HeroComics = HeroComics(),
val series: HeroSeries = HeroSeries(),
val stories: HeroStories = HeroStories(),
val events: HeroEvents = HeroEvents(),
val urls: List<HeroUrl> = emptyList(),
) : Parcelable

@Parcelize
data class HeroThumbnail(
val path: String = "", // 썸네일 다운로드 위치
val extension: String = "" // 확장자
)
) : Parcelable

@Parcelize
data class HeroComics(
val available: Int,
val collectionURI: String,
val items: List<HeroComicsItem>,
val returned: Int
)
val available: Int = 0,
val collectionURI: String = "",
val items: List<HeroComicsItem> = emptyList(),
val returned: Int = 0
) : Parcelable

@Parcelize
data class HeroComicsItem(
val resourceURI: String,
val name: String
)
val resourceURI: String = "",
val name: String = ""
) : Parcelable

@Parcelize
data class HeroSeries(
val available: Int,
val collectionURI: String,
val items: List<HeroSeriesItem>,
val returned: Int
)
val available: Int = 0,
val collectionURI: String = "",
val items: List<HeroSeriesItem> = emptyList(),
val returned: Int = 0
) : Parcelable

@Parcelize
data class HeroSeriesItem(
val resourceURI: String,
val name: String
)
val resourceURI: String = "",
val name: String = ""
) : Parcelable

@Parcelize
data class HeroStories(
val available: Int,
val collectionURI: String,
val items: List<HeroStoriesItem>,
val returned: Int
)
val available: Int = 0,
val collectionURI: String = "",
val items: List<HeroStoriesItem> = emptyList(),
val returned: Int = 0
) : Parcelable

@Parcelize
data class HeroStoriesItem(
val resourceURI: String,
val name: String,
val type: String
)
val resourceURI: String = "",
val name: String = "",
val type: String = ""
) : Parcelable

@Parcelize
data class HeroEvents(
val available: Int,
val collectionURI: String,
val items: List<HeroEventsItem>,
val returned: Int
)
val available: Int = 0,
val collectionURI: String = "",
val items: List<HeroEventsItem> = emptyList(),
val returned: Int = 0
) : Parcelable

@Parcelize
data class HeroEventsItem(
val resourceURI: String,
val name: String,
val type: String
)
val resourceURI: String = "",
val name: String = "",
val type: String = ""
) : Parcelable

@Parcelize
data class HeroUrl(
val type: String,
val url: String
)
val type: String = "",
val url: String = ""
) : Parcelable

data class LoadPage(
val nowPage: Int,
Expand Down
2 changes: 2 additions & 0 deletions feature/avengers/build.gradle.kts
Expand Up @@ -5,6 +5,8 @@ plugins {
alias(libs.plugins.hilt)
kotlin("android")
kotlin("kapt")
id("kotlin-parcelize")
id("androidx.navigation.safeargs.kotlin")
}

android {
Expand Down
@@ -1,22 +1,20 @@
package com.turtle.multimodulehilt.feature.avengers

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import com.turtle.multimodulehilt.core.model.Hero
import com.turtle.multimodulehilt.feature.avengers.databinding.ListItemHeroBinding
import dagger.hilt.android.qualifiers.ActivityContext
import dagger.hilt.android.scopes.ActivityScoped
import javax.inject.Inject

class AvengersAdapter @Inject constructor(
@ActivityContext private val context: Context
): ListAdapter<Hero, AvengersViewHolder>(AvengersDiffCallback()) {
class AvengersAdapter constructor(
private val onHeroClick: (Hero) -> Unit
) :
ListAdapter<Hero, AvengersViewHolder>(AvengersDiffCallback()) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AvengersViewHolder {
return AvengersViewHolder(
context,
ListItemHeroBinding.inflate(
LayoutInflater.from(parent.context),
parent,
Expand All @@ -26,7 +24,19 @@ class AvengersAdapter @Inject constructor(
}

override fun onBindViewHolder(holder: AvengersViewHolder, position: Int) {
holder.bind(getItem(position))
holder.bind(onHeroClick, getItem(position))
}

}

class AvengersDiffCallback : DiffUtil.ItemCallback<Hero>() {

override fun areItemsTheSame(oldItem: Hero, newItem: Hero): Boolean {
return oldItem.id == newItem.id
}

override fun areContentsTheSame(oldItem: Hero, newItem: Hero): Boolean {
return oldItem.id == newItem.id
}

}
@@ -0,0 +1,28 @@
package com.turtle.multimodulehilt.feature.avengers

import androidx.navigation.fragment.navArgs
import com.bumptech.glide.Glide
import com.turtle.multimodulehilt.core.common.base.BaseFragment
import com.turtle.multimodulehilt.core.model.Hero
import com.turtle.multimodulehilt.feature.avengers.databinding.FragmentAvengersDetailBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class AvengersDetailFragment :
BaseFragment<FragmentAvengersDetailBinding>(R.layout.fragment_avengers_detail) {

private val args: AvengersDetailFragmentArgs by navArgs()
private val hero: Hero by lazy {
args.hero
}

// TODO: 공유 요소를 사용하여 이미지뷰를 출력
override fun init() {
Glide.with(binding.imageviewAvengersDetailFragmentCenter)
.load("${hero.thumbnail.path}.${hero.thumbnail.extension}")
.error(R.drawable.whoishe)
.placeholder(R.drawable.whoishe)
.into(binding.imageviewAvengersDetailFragmentCenter)
}

}

This file was deleted.

0 comments on commit 4c164d9

Please sign in to comment.