Skip to content

Commit

Permalink
Merge pull request #10 from naufalprakoso/master
Browse files Browse the repository at this point in the history
Pokemon Info Evolution & Gradle Kotlin DSL
  • Loading branch information
mrcsxsiq authored May 23, 2020
2 parents 14f8ed1 + 436b485 commit 27a96cc
Show file tree
Hide file tree
Showing 21 changed files with 259 additions and 144 deletions.
3 changes: 0 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/google-java-format.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Also available in Play Store
- [x] [ViewModel](https://developer.android.com/topic/libraries/architecture/viewmodel)
- [x] [Room](https://developer.android.com/topic/libraries/architecture/room)
- [ ] [Coroutines](https://developer.android.com/topic/libraries/architecture/coroutines)
- [x] [Gradle Kotlin DSL](https://docs.gradle.org/current/userguide/kotlin_dsl.html)
- [x] [Databinding](https://developer.android.com/topic/libraries/data-binding)
- [x] [Retrofit](https://square.github.io/retrofit/)
- [x] [Koin](https://insert-koin.io/)
Expand All @@ -85,7 +86,7 @@ Also available in Play Store
- [x] Pokemon Info
- [x] Pokemon Info - About
- [x] Pokemon Info - Base Stats
- [ ] Pokemon Info - Evolution
- [x] Pokemon Info - Evolution
- [x] News Detail

## Thanks
Expand All @@ -104,8 +105,8 @@ Also available in Play Store

## Contributors

| [<img src="https://avatars3.githubusercontent.com/u/12054216?s=115&v=4" width="48"><br><sub>@zsmb13</sub>](https://github.com/zsmb13) | [<img src="https://avatars0.githubusercontent.com/u/8435541?s=115&v=4" width="48"><br><sub>@aesean</sub>](https://github.com/aesean) | [<img src="https://avatars1.githubusercontent.com/u/988405?s=115&v=4" width="48"><br><sub>@STFBEE</sub>](https://github.com/STFBEE) | [<img src="https://avatars1.githubusercontent.com/u/25616312?s=115&v=4" width="48"><br><sub>@CorneilleEdi</sub>](https://github.com/CorneilleEdi) | [<img src="https://user-images.githubusercontent.com/95717/60592969-5da81680-9d67-11e9-92a3-8664ee0e2eda.png" width="48"><br><sub>You</sub>](https://github.com/mrcsxsiq/Kotlin-Pokedex/pulls) |
| :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars3.githubusercontent.com/u/12054216?s=115&v=4" width="48"><br><sub>@zsmb13</sub>](https://github.com/zsmb13) | [<img src="https://avatars0.githubusercontent.com/u/8435541?s=115&v=4" width="48"><br><sub>@aesean</sub>](https://github.com/aesean) | [<img src="https://avatars1.githubusercontent.com/u/988405?s=115&v=4" width="48"><br><sub>@STFBEE</sub>](https://github.com/STFBEE) | [<img src="https://avatars1.githubusercontent.com/u/25616312?s=115&v=4" width="48"><br><sub>@CorneilleEdi</sub>](https://github.com/CorneilleEdi) | [<img src="https://avatars2.githubusercontent.com/u/15768474?s=115&v=4" width="48"><br><sub>@naufalprakoso</sub>](https://github.com/naufalprakoso) | [<img src="https://user-images.githubusercontent.com/95717/60592969-5da81680-9d67-11e9-92a3-8664ee0e2eda.png" width="48"><br><sub>You</sub>](https://github.com/mrcsxsiq/Kotlin-Pokedex/pulls) |
| :---: | :---: | :---: | :---: | :---: | :---: |

## Author

Expand Down
79 changes: 0 additions & 79 deletions app/build.gradle

This file was deleted.

75 changes: 75 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-android-extensions")
id("kotlin-kapt")
id("androidx.navigation.safeargs.kotlin")
}
apply(from = "../ktlint.gradle.kts")

android {
compileSdkVersion(29)
buildToolsVersion("29.0.3")
defaultConfig {
applicationId = "dev.marcosfarias.pokedex"
minSdkVersion(23)
targetSdkVersion(29)
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72")

// Architecture
implementation("androidx.core:core-ktx:1.2.0")
implementation("androidx.appcompat:appcompat:1.1.0")
implementation("androidx.navigation:navigation-ui:2.2.2")
implementation("androidx.navigation:navigation-ui-ktx:2.2.2")
implementation("androidx.navigation:navigation-fragment:2.2.2")
implementation("androidx.navigation:navigation-fragment-ktx:2.2.2")
implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")
implementation("androidx.constraintlayout:constraintlayout:1.1.3")
implementation("androidx.coordinatorlayout:coordinatorlayout:1.1.0")

// Material
implementation("com.google.android.material:material:1.1.0")

// Third Party
implementation("com.leinardi.android:speed-dial:3.1.1")

// Retrofit
implementation("com.squareup.retrofit2:retrofit:2.6.0")
implementation("com.squareup.retrofit2:converter-gson:2.6.0")

// Persistence
implementation("android.arch.persistence.room:runtime:1.1.1")
kapt("android.arch.persistence.room:compiler:1.1.1")

// Glide
kapt("android.arch.lifecycle:compiler:1.1.1")
kapt("com.github.bumptech.glide:compiler:4.10.0")
implementation("com.github.bumptech.glide:glide:4.10.0")

// Koin
implementation("org.koin:koin-android:2.0.1")
implementation("org.koin:koin-androidx-scope:2.0.1")
implementation("org.koin:koin-androidx-viewmodel:2.0.1")

// Test
testImplementation("junit:junit:4.12")
androidTestImplementation("androidx.test.ext:junit:1.1.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.2.0")
}
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ interface PokemonDAO {
@Query("SELECT * FROM pokemon WHERE id = :id")
fun getById(id: String?): LiveData<Pokemon>

@Query("SELECT * FROM pokemon WHERE id IN(:evolutionIds)")
fun getEvolutionsByIds(evolutionIds: List<String>): LiveData<List<Pokemon>>

@Query("SELECT * FROM pokemon")
fun all(): LiveData<List<Pokemon>>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ class DashboardViewModel(private val pokemonDAO: PokemonDAO) : ViewModel() {
fun getPokemonById(id: String?): LiveData<Pokemon> {
return pokemonDAO.getById(id)
}

fun getPokemonEvolutionsByIds(ids: List<String>): LiveData<List<Pokemon>> {
return pokemonDAO.getEvolutionsByIds(ids)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ViewPagerAdapter(
),
Page(
context.getString(R.string.dashboard_tab_3),
{ EvolutionFragment() }
{ EvolutionFragment.newInstance(pokemonId) }
),
Page(
context.getString(R.string.dashboard_tab_4),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package dev.marcosfarias.pokedex.ui.dashboard.evolution

import android.content.Context
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import dev.marcosfarias.pokedex.R
import dev.marcosfarias.pokedex.model.Pokemon
import dev.marcosfarias.pokedex.utils.PokemonColorUtil
import kotlinx.android.synthetic.main.item_pokemon.view.*

class EvolutionAdapter(
private val context: Context
) : RecyclerView.Adapter<EvolutionAdapter.ViewHolder>() {

private val list = arrayListOf<Pokemon>()

fun setList(list: List<Pokemon>) {
this.list.clear()
this.list.addAll(list)
}

class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindView(item: Pokemon) {
itemView.textViewName.text = item.name
itemView.textViewID.text = item.id

val color = PokemonColorUtil(itemView.context).getPokemonColor(item.typeofpokemon)
itemView.relativeLayoutBackground.background.colorFilter =
PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)

item.typeofpokemon?.getOrNull(0).let { firstType ->
itemView.textViewType3.text = firstType
itemView.textViewType3.isVisible = firstType != null
}

item.typeofpokemon?.getOrNull(1).let { secondType ->
itemView.textViewType2.text = secondType
itemView.textViewType2.isVisible = secondType != null
}

item.typeofpokemon?.getOrNull(2).let { thirdType ->
itemView.textViewType1.text = thirdType
itemView.textViewType1.isVisible = thirdType != null
}

Glide.with(itemView.context)
.load(item.imageurl)
.placeholder(android.R.color.transparent)
.into(itemView.imageView)
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.item_pokemon, parent, false)
return ViewHolder(view)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = list[position]
holder.bindView(item)
}

override fun getItemCount(): Int {
return list.size
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import dev.marcosfarias.pokedex.R
import dev.marcosfarias.pokedex.model.Pokemon
import dev.marcosfarias.pokedex.ui.dashboard.DashboardViewModel
import kotlinx.android.synthetic.main.fragment_evolution.*
import org.koin.androidx.viewmodel.ext.android.viewModel

class EvolutionFragment : Fragment() {

companion object {
@JvmStatic
fun newInstance(id: String?) = EvolutionFragment().apply {
arguments = Bundle().apply {
putString("id", id)
}
}
}

private val dashboardViewModel: DashboardViewModel by viewModel()

override fun onCreateView(
Expand All @@ -20,4 +33,29 @@ class EvolutionFragment : Fragment() {
): View? {
return inflater.inflate(R.layout.fragment_evolution, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val id = checkNotNull(arguments?.getString("id"))
val recyclerView = recyclerViewEvolvingPokemon
val layoutManager = LinearLayoutManager(context)
recyclerView.layoutManager = layoutManager
val adapter = EvolutionAdapter(view.context)
recyclerView.adapter = adapter

dashboardViewModel.getPokemonById(id).observe(viewLifecycleOwner, Observer { pokemonValue ->
pokemonValue?.let { pokemon ->
val evolutions = pokemon.evolutions ?: emptyList()
dashboardViewModel.getPokemonEvolutionsByIds(evolutions).observe(viewLifecycleOwner, Observer {
val pokemons: List<Pokemon> = it
adapter.setList(pokemons)
adapter.notifyDataSetChanged()

if (pokemons.isEmpty())
textNonEvolving.visibility = View.VISIBLE
})
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.google.gson.reflect.TypeToken
import java.lang.reflect.Type

class ListStringConverter {
val gson = Gson()
val type: Type = object : TypeToken<List<String?>?>() {}.type
private val gson = Gson()
private val type: Type = object : TypeToken<List<String>>() {}.type

@TypeConverter
fun fromString(json: String?): List<String> {
Expand Down
Loading

0 comments on commit 27a96cc

Please sign in to comment.