Skip to content
Permalink
Browse files

Autoformat code, optimize imports

  • Loading branch information
zsmb13 committed Jan 7, 2020
1 parent 03a41df commit 964d5f7ca48413ccf59d74262d9e7cc93882ab2b
Showing with 161 additions and 90 deletions.
  1. +3 −3 app/src/main/java/dev/marcosfarias/pokedex/App.kt
  2. +0 −4 app/src/main/java/dev/marcosfarias/pokedex/MainActivity.kt
  3. +1 −1 app/src/main/java/dev/marcosfarias/pokedex/model/Generation.kt
  4. +29 −29 app/src/main/java/dev/marcosfarias/pokedex/model/Pokemon.kt
  5. +1 −1 app/src/main/java/dev/marcosfarias/pokedex/repository/PokemonService.kt
  6. +21 −8 app/src/main/java/dev/marcosfarias/pokedex/ui/dashboard/DashboardFragment.kt
  7. +1 −6 app/src/main/java/dev/marcosfarias/pokedex/ui/dashboard/DashboardViewModel.kt
  8. +1 −1 app/src/main/java/dev/marcosfarias/pokedex/ui/dashboard/ViewPagerAdapter.kt
  9. +5 −2 app/src/main/java/dev/marcosfarias/pokedex/ui/dashboard/evolution/EvolutionFragment.kt
  10. +5 −1 app/src/main/java/dev/marcosfarias/pokedex/ui/dashboard/moves/MovesFragment.kt
  11. +5 −2 app/src/main/java/dev/marcosfarias/pokedex/ui/dashboard/stats/StatsFragment.kt
  12. +7 −3 app/src/main/java/dev/marcosfarias/pokedex/ui/generation/GenerationFragment.kt
  13. +40 −9 app/src/main/java/dev/marcosfarias/pokedex/ui/generation/GenerationViewModel.kt
  14. +6 −2 app/src/main/java/dev/marcosfarias/pokedex/ui/home/HomeFragment.kt
  15. +1 −1 app/src/main/java/dev/marcosfarias/pokedex/ui/home/HomeViewModel.kt
  16. +2 −1 app/src/main/java/dev/marcosfarias/pokedex/ui/home/MenuAdapter.kt
  17. +2 −1 app/src/main/java/dev/marcosfarias/pokedex/ui/home/NewsAdapter.kt
  18. +5 −3 app/src/main/java/dev/marcosfarias/pokedex/ui/newsdetail/NewsDetailFragment.kt
  19. +9 −4 app/src/main/java/dev/marcosfarias/pokedex/ui/pokedex/PokedexFragment.kt
  20. +8 −5 app/src/main/java/dev/marcosfarias/pokedex/ui/pokedex/PokedexViewModel.kt
  21. +4 −2 app/src/main/java/dev/marcosfarias/pokedex/ui/pokedex/PokemonAdapter.kt
  22. +5 −1 app/src/main/java/dev/marcosfarias/pokedex/ui/search/SearchFragment.kt
@@ -17,9 +17,9 @@ class App : Application() {

database = Room.databaseBuilder(
this,
AppDatabase::class.java,
getString(R.string.app_name)
)
AppDatabase::class.java,
getString(R.string.app_name)
)
.fallbackToDestructiveMigration()
.build()

@@ -1,10 +1,6 @@
package dev.marcosfarias.pokedex

import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.Window
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
@@ -1,6 +1,6 @@
package dev.marcosfarias.pokedex.model

class Generation (
class Generation(
val id: Int,
val title: String,
val image: Int
@@ -9,35 +9,35 @@ import dev.marcosfarias.pokedex.utils.ListStringConverter
@Entity
@TypeConverters(ListStringConverter::class)
class Pokemon {
@PrimaryKey @NonNull
var id: String? = null
var abilities: List<String>? = null
var attack: Int? = null
var base_exp: String? = null
var category: String? = null
var cycles: String? = null
var defense: Int? = null
var egg_groups: String? = null
var evolutions: List<String>? = null
var evolvedfrom: String? = null
var female_percentage: String? = null
var genderless: Int? = null
var height: String? = null
var hp: Int? = null
var imageurl: String? = null
var male_percentage: String? = null
var name: String? = null
var reason: String? = null
var special_attack: Int? = null
var special_defense: Int? = null
var speed: Int? = null
var total: Int? = null
var typeofpokemon: List<String>? = null
var weaknesses: List<String>? = null
var weight: String? = null
var xdescription: String? = null
var ydescription: String? = null

@PrimaryKey
@NonNull
var id: String? = null
var abilities: List<String>? = null
var attack: Int? = null
var base_exp: String? = null
var category: String? = null
var cycles: String? = null
var defense: Int? = null
var egg_groups: String? = null
var evolutions: List<String>? = null
var evolvedfrom: String? = null
var female_percentage: String? = null
var genderless: Int? = null
var height: String? = null
var hp: Int? = null
var imageurl: String? = null
var male_percentage: String? = null
var name: String? = null
var reason: String? = null
var special_attack: Int? = null
var special_defense: Int? = null
var speed: Int? = null
var total: Int? = null
var typeofpokemon: List<String>? = null
var weaknesses: List<String>? = null
var weight: String? = null
var xdescription: String? = null
var ydescription: String? = null


}
@@ -6,5 +6,5 @@ import retrofit2.http.GET

interface PokemonService {
@GET("pokemon.json")
fun get() : Call<List<Pokemon>>
fun get(): Call<List<Pokemon>>
}
@@ -22,7 +22,11 @@ class DashboardFragment : Fragment() {

private lateinit var dashboardViewModel: DashboardViewModel

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ) : View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel::class.java)

val root = inflater.inflate(R.layout.fragment_dashboard, container, false)
@@ -34,10 +38,14 @@ class DashboardFragment : Fragment() {
root.textViewID.text = pokemon?.id
root.textViewName.text = pokemon?.name

val color = PokemonColorUtil(root.context).getPokemonColor(pokemon?.typeofpokemon)
root.app_bar.background.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP )
root.toolbar_layout.contentScrim?.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP )
activity?.window?.statusBarColor = PokemonColorUtil(root.context).getPokemonColor(pokemon?.typeofpokemon)
val color =
PokemonColorUtil(root.context).getPokemonColor(pokemon?.typeofpokemon)
root.app_bar.background.colorFilter =
PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
root.toolbar_layout.contentScrim?.colorFilter =
PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
activity?.window?.statusBarColor =
PokemonColorUtil(root.context).getPokemonColor(pokemon?.typeofpokemon)

pokemon?.typeofpokemon?.elementAtOrNull(0).let {
root.textViewType3.text = it
@@ -70,8 +78,14 @@ class DashboardFragment : Fragment() {


val adapter = ViewPagerAdapter(fragmentManager!!)
adapter.addFragment(AboutFragment.newInstance(pokemon?.id), getString(R.string.dashboard_tab_1))
adapter.addFragment(StatsFragment.newInstance(pokemon?.id), getString(R.string.dashboard_tab_2))
adapter.addFragment(
AboutFragment.newInstance(pokemon?.id),
getString(R.string.dashboard_tab_1)
)
adapter.addFragment(
StatsFragment.newInstance(pokemon?.id),
getString(R.string.dashboard_tab_2)
)
adapter.addFragment(EvolutionFragment(), getString(R.string.dashboard_tab_3))
adapter.addFragment(MovesFragment(), getString(R.string.dashboard_tab_4))

@@ -91,5 +105,4 @@ class DashboardFragment : Fragment() {
}



}
@@ -1,19 +1,14 @@
package dev.marcosfarias.pokedex.ui.dashboard

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import dev.marcosfarias.pokedex.App
import dev.marcosfarias.pokedex.database.dao.PokemonDAO
import dev.marcosfarias.pokedex.model.Pokemon
import dev.marcosfarias.pokedex.repository.APIService
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class DashboardViewModel : ViewModel() {

private val pokemonDAO : PokemonDAO = App.database!!.pokemonDAO()
private val pokemonDAO: PokemonDAO = App.database!!.pokemonDAO()

fun getPokemonById(id: String?): LiveData<List<Pokemon?>?> {
return pokemonDAO.getById(id)
@@ -22,7 +22,7 @@ class ViewPagerAdapter(supportFragmentManager: FragmentManager) :
return mFragmentTitleList[position]
}

fun addFragment(fragment: Fragment, title : String) {
fun addFragment(fragment: Fragment, title: String) {
mFragmentList.add(fragment)
mFragmentTitleList.add(title)
}
@@ -13,7 +13,11 @@ class EvolutionFragment : Fragment() {

private lateinit var dashboardViewModel: DashboardViewModel

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ) : View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel::class.java)

val root = inflater.inflate(R.layout.fragment_evolution, container, false)
@@ -23,5 +27,4 @@ class EvolutionFragment : Fragment() {
}



}
@@ -9,7 +9,11 @@ import dev.marcosfarias.pokedex.R

class MovesFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ) : View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val root = inflater.inflate(R.layout.fragment_moves, container, false)
return root
}
@@ -24,7 +24,11 @@ class StatsFragment : Fragment() {

private lateinit var dashboardViewModel: DashboardViewModel

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ) : View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel::class.java)

val root = inflater.inflate(R.layout.fragment_stats, container, false)
@@ -59,5 +63,4 @@ class StatsFragment : Fragment() {
}



}
@@ -16,16 +16,20 @@ class GenerationFragment : BottomSheetDialogFragment() {

private lateinit var generationViewModel: GenerationViewModel

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ) : View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
generationViewModel = ViewModelProviders.of(this).get(GenerationViewModel::class.java)

val root = inflater.inflate(R.layout.fragment_generation, container, false)
val recyclerView = root.recyclerView
val layoutManager = GridLayoutManager(context, 2)
recyclerView.layoutManager = layoutManager

generationViewModel.getListGeneration().observe(this, Observer {
val pokemons : List<Generation> = it
generationViewModel.getListGeneration().observe(this, Observer {
val pokemons: List<Generation> = it
recyclerView.adapter = GenerationAdapter(pokemons, root.context)
})
return root
@@ -6,22 +6,53 @@ import androidx.lifecycle.ViewModel
import dev.marcosfarias.pokedex.App
import dev.marcosfarias.pokedex.R
import dev.marcosfarias.pokedex.model.Generation
import dev.marcosfarias.pokedex.model.Menu

class GenerationViewModel : ViewModel() {

private val listGeneration = MutableLiveData<List<Generation>>()

fun getListGeneration(): LiveData<List<Generation>> {
listGeneration.value = listOf(
Generation(1, App.context!!.resources.getString(R.string.generation_item_1), R.drawable.gen1),
Generation(1, App.context!!.resources.getString(R.string.generation_item_2), R.drawable.gen2),
Generation(1, App.context!!.resources.getString(R.string.generation_item_3), R.drawable.gen3),
Generation(1, App.context!!.resources.getString(R.string.generation_item_4), R.drawable.gen4),
Generation(1, App.context!!.resources.getString(R.string.generation_item_5), R.drawable.gen5),
Generation(1, App.context!!.resources.getString(R.string.generation_item_6), R.drawable.gen6),
Generation(1, App.context!!.resources.getString(R.string.generation_item_7), R.drawable.gen7),
Generation(1, App.context!!.resources.getString(R.string.generation_item_8), R.drawable.gen8)
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_1),
R.drawable.gen1
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_2),
R.drawable.gen2
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_3),
R.drawable.gen3
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_4),
R.drawable.gen4
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_5),
R.drawable.gen5
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_6),
R.drawable.gen6
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_7),
R.drawable.gen7
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_8),
R.drawable.gen8
)
)
return listGeneration
}
@@ -35,7 +35,12 @@ class HomeFragment : Fragment() {
recyclerViewMenu.layoutManager = GridLayoutManager(context, 2)

recyclerViewNews.layoutManager = GridLayoutManager(context, 1)
recyclerViewNews.addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
recyclerViewNews.addItemDecoration(
DividerItemDecoration(
context,
DividerItemDecoration.VERTICAL
)
)

homeViewModel.getListMenu().observe(this, Observer {
val items: List<Menu> = it
@@ -50,5 +55,4 @@ class HomeFragment : Fragment() {
}



}
@@ -20,7 +20,7 @@ class HomeViewModel : ViewModel() {
Menu(1, App.context!!.resources.getString(R.string.menu_item_3), R.color.lightBlue),
Menu(1, App.context!!.resources.getString(R.string.menu_item_4), R.color.lightYellow),
Menu(1, App.context!!.resources.getString(R.string.menu_item_5), R.color.lightPurple),
Menu(1, App.context!!.resources.getString(R.string.menu_item_6) ,R.color.lightBrown)
Menu(1, App.context!!.resources.getString(R.string.menu_item_6), R.color.lightBrown)
)
return listMenu
}
@@ -23,7 +23,8 @@ class MenuAdapter(
itemView.textViewName.text = item.name

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

itemView.setOnClickListener {
it.findNavController().navigate(R.id.action_navigation_home_to_navigation_pokedex)
@@ -18,7 +18,8 @@ class NewsAdapter(
fun bindView(item: News) {
// itemView.textViewName.text = item.title
itemView.setOnClickListener {
it.findNavController().navigate(R.id.action_navigation_home_to_navigation_news_detail)
it.findNavController()
.navigate(R.id.action_navigation_home_to_navigation_news_detail)
}
}

0 comments on commit 964d5f7

Please sign in to comment.
You can’t perform that action at this time.