()
26 | }
27 |
28 | fun getPokemonInfo(pokemonName: String) {
29 | viewModelScope.launch {
30 | when (val result = repository.getPokemonInfo(pokemonName.lowercase())) {
31 | is Resource.Success -> {
32 | if (result.data != null) pokemonInfo.value = result.data
33 |
34 | loadError.value = ""
35 | isLoading = false
36 | }
37 | is Resource.Error -> {
38 | loadError.value = result.message.toString()
39 | isLoading = false
40 | }
41 | }
42 | }
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_pokeball_144.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/pokemon_list_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
22 |
23 |
35 |
36 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/pokemon_list_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
22 |
23 |
35 |
36 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
13 |
16 |
19 |
22 |
25 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/pokemon_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
30 |
31 |
43 |
44 |
58 |
59 |
60 |
61 |
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/tech/pokedex/functions/Functions.kt:
--------------------------------------------------------------------------------
1 | package ru.tech.pokedex.functions
2 |
3 | import ru.tech.pokedex.utils.Values.TypeBug
4 | import ru.tech.pokedex.utils.Values.TypeDark
5 | import ru.tech.pokedex.utils.Values.TypeDragon
6 | import ru.tech.pokedex.utils.Values.TypeElectric
7 | import ru.tech.pokedex.utils.Values.TypeFairy
8 | import ru.tech.pokedex.utils.Values.TypeFighting
9 | import ru.tech.pokedex.utils.Values.TypeFire
10 | import ru.tech.pokedex.utils.Values.TypeFlying
11 | import ru.tech.pokedex.utils.Values.TypeGhost
12 | import ru.tech.pokedex.utils.Values.TypeGrass
13 | import ru.tech.pokedex.utils.Values.TypeGround
14 | import ru.tech.pokedex.utils.Values.TypeIce
15 | import ru.tech.pokedex.utils.Values.TypeNormal
16 | import ru.tech.pokedex.utils.Values.TypePoison
17 | import ru.tech.pokedex.utils.Values.TypePsychic
18 | import ru.tech.pokedex.utils.Values.TypeRock
19 | import ru.tech.pokedex.utils.Values.TypeSteel
20 | import ru.tech.pokedex.utils.Values.TypeWater
21 |
22 | object Functions {
23 |
24 | fun String.containsAt(subString: String): Int {
25 | val d = 256
26 | val q = 101
27 | var h = 1
28 | var i: Int
29 | var j: Int
30 | var p = 0
31 | var t = 0
32 | val m = subString.length
33 | val n = this.length
34 | if (m <= n) {
35 | i = 0
36 | while (i < m - 1) {
37 | h = h * d % q
38 | ++i
39 | }
40 | i = 0
41 | while (i < m) {
42 | p = (d * p + subString[i].code) % q
43 | t = (d * t + this[i].code) % q
44 | ++i
45 | }
46 | i = 0
47 | while (i <= n - m) {
48 | if (p == t) {
49 | j = 0
50 | while (j < m) {
51 | if (this[i + j] != subString[j]) break
52 | ++j
53 | }
54 | if (j == m) return i
55 | }
56 | if (i < n - m) {
57 | t = (d * (t - this[i].code * h) + this[i + m].code) % q
58 | if (t < 0) t += q
59 | }
60 | ++i
61 | }
62 | } else return q
63 | return q
64 | }
65 |
66 | fun String.getColor(): Int {
67 | return when (this.lowercase()) {
68 | "fire" -> TypeFire
69 | "water" -> TypeWater
70 | "electric" -> TypeElectric
71 | "grass" -> TypeGrass
72 | "ice" -> TypeIce
73 | "fighting" -> TypeFighting
74 | "poison" -> TypePoison
75 | "ground" -> TypeGround
76 | "flying" -> TypeFlying
77 | "psychic" -> TypePsychic
78 | "bug" -> TypeBug
79 | "rock" -> TypeRock
80 | "ghost" -> TypeGhost
81 | "dragon" -> TypeDragon
82 | "dark" -> TypeDark
83 | "steel" -> TypeSteel
84 | "fairy" -> TypeFairy
85 | else -> TypeNormal
86 | }
87 | }
88 |
89 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Pokedex
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Simple Pokedex app that allows you to easily search and look around for your favourite pokemons and theirs statistics
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | ## Download
20 | Go to the [Releases](https://github.com/t8rin/Pokedex/releases) to download the latest APK.
21 |
22 |
23 | ## Tech stack & Open-source libraries
24 | - Minimum SDK level 21
25 |
26 | - [Kotlin](https://kotlinlang.org/) based
27 |
28 | - [Coroutines](https://github.com/Kotlin/kotlinx.coroutines) to work with internet and move tasks to a secondary thread
29 |
30 | - [Hilt](https://dagger.dev/hilt/) for dependency injection.
31 |
32 | - JetPack
33 | - Lifecycle - Observe Android lifecycles and handle UI states upon the lifecycle changes.
34 | - ViewModel - Manages UI-related data holder and lifecycle aware. Allows data to survive configuration changes such as screen rotations.
35 | - ViewBinding - Binds UI components in your layouts to data sources in your app using a declarative format rather than programmatically.
36 | - Palette - to generate color palette based on bitmap
37 | - RecyclerView - for displaying large sets of data in UI while minimizing memory usage.
38 |
39 | - Architecture
40 | - MVVM Architecture (View - DataBinding - ViewModel - Model)
41 | - Repository Pattern
42 |
43 | - [Retrofit2 & OkHttp3](https://github.com/square/retrofit) - Construct the REST APIs.
44 |
45 | - [Coil](https://github.com/coil-kt/coil) - loading images.
46 |
47 | - [Material-Components](https://github.com/material-components/material-components-android) - Material design components like ripple animation, cardView.
48 |
49 | - [ProgressView](https://github.com/skydoves/progressview) - A polished and flexible ProgressView, fully customizable with animations.
50 |
51 | # License
52 | ```xml
53 | Designed and developed by 2021 T8RIN
54 |
55 | Licensed under the Apache License, Version 2.0 (the "License");
56 | you may not use this file except in compliance with the License.
57 | You may obtain a copy of the License at
58 |
59 | http://www.apache.org/licenses/LICENSE-2.0
60 |
61 | Unless required by applicable law or agreed to in writing, software
62 | distributed under the License is distributed on an "AS IS" BASIS,
63 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
64 | See the License for the specific language governing permissions and
65 | limitations under the License.
66 | ```
67 |
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.application")
3 | id("kotlin-android")
4 | id("kotlin-kapt")
5 | id("dagger.hilt.android.plugin")
6 | }
7 |
8 | android {
9 | compileSdk = 31
10 |
11 | defaultConfig {
12 | applicationId = "ru.tech.pokedex"
13 | minSdk = 21
14 | targetSdk = 31
15 | versionCode = 1
16 | versionName = "1.0"
17 |
18 | vectorDrawables {
19 | useSupportLibrary = true
20 | }
21 | }
22 |
23 | buildTypes {
24 | release {
25 | isMinifyEnabled = false
26 | proguardFiles(
27 | getDefaultProguardFile("proguard-android-optimize.txt"),
28 | "proguard-rules.pro"
29 | )
30 | }
31 | }
32 | compileOptions {
33 | isCoreLibraryDesugaringEnabled = true
34 | sourceCompatibility = JavaVersion.VERSION_1_8
35 | targetCompatibility = JavaVersion.VERSION_1_8
36 | }
37 | kotlinOptions {
38 | jvmTarget = "1.8"
39 | }
40 |
41 | buildFeatures {
42 | viewBinding = true
43 | }
44 |
45 | packagingOptions {
46 | resources {
47 | excludes += "/META-INF/{AL2.0,LGPL2.1}"
48 | }
49 | }
50 | }
51 |
52 | dependencies {
53 |
54 | implementation("androidx.core:core-ktx:1.7.0")
55 | implementation("androidx.appcompat:appcompat:1.4.1")
56 | implementation("com.google.android.material:material:1.6.0-alpha02")
57 | implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.1")
58 |
59 | // Retrofit
60 | implementation("com.squareup.retrofit2:retrofit:2.9.0")
61 | implementation("com.squareup.retrofit2:converter-gson:2.9.0")
62 | implementation("com.squareup.okhttp3:okhttp:4.9.2")
63 | implementation("com.squareup.okhttp3:logging-interceptor:4.9.2")
64 |
65 | // Coroutines
66 | implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
67 | implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0")
68 |
69 | // Coroutine Lifecycle Scopes
70 | implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1")
71 | implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.1")
72 |
73 | // Coil
74 | implementation("io.coil-kt:coil:1.1.1")
75 | implementation("com.google.accompanist:accompanist-coil:0.7.0")
76 |
77 | //Dagger - Hilt
78 | implementation("com.google.dagger:hilt-android:2.38.1")
79 | implementation("androidx.constraintlayout:constraintlayout:2.1.3")
80 | implementation("androidx.recyclerview:recyclerview:1.2.1")
81 | implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")
82 | implementation("androidx.navigation:navigation-fragment-ktx:2.4.1")
83 | implementation("androidx.navigation:navigation-ui-ktx:2.4.1")
84 | kapt("com.google.dagger:hilt-android-compiler:2.38.1")
85 | implementation("androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03")
86 | kapt("androidx.hilt:hilt-compiler:1.0.0")
87 |
88 | implementation("androidx.palette:palette-ktx:1.0.0")
89 | implementation("com.github.skydoves:progressview:1.1.3")
90 |
91 | coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
92 |
93 | }
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/tech/pokedex/adapter/PokemonListAdapter.kt:
--------------------------------------------------------------------------------
1 | package ru.tech.pokedex.adapter
2 |
3 | import android.content.Context
4 | import android.view.LayoutInflater
5 | import android.view.View.GONE
6 | import android.view.View.VISIBLE
7 | import android.view.ViewGroup
8 | import android.widget.ImageView
9 | import android.widget.TextView
10 | import androidx.core.content.ContextCompat
11 | import androidx.recyclerview.widget.RecyclerView
12 | import coil.clear
13 | import coil.load
14 | import coil.request.CachePolicy
15 | import com.google.android.material.card.MaterialCardView
16 | import com.google.android.material.progressindicator.CircularProgressIndicator
17 | import ru.tech.pokedex.R
18 | import ru.tech.pokedex.data.model.PokedexListEntry
19 | import ru.tech.pokedex.databinding.PokemonItemBinding
20 | import ru.tech.pokedex.fragment.pokelist.PokemonListFragment
21 | import ru.tech.pokedex.fragment.pokelist.PokemonListViewModel
22 |
23 | class PokemonListAdapter(
24 | private val context: Context,
25 | private val viewModel: PokemonListViewModel,
26 | private val fragment: PokemonListFragment,
27 | var pokemonList: ArrayList = ArrayList()
28 | ) : RecyclerView.Adapter() {
29 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
30 | return ViewHolder(
31 | PokemonItemBinding.inflate(
32 | LayoutInflater.from(parent.context),
33 | parent,
34 | false
35 | )
36 | )
37 | }
38 |
39 | override fun onBindViewHolder(holder: ViewHolder, position: Int) {
40 | val entry = pokemonList[position]
41 | holder.number.text = entry.number.toString()
42 | holder.pokemonName.text = entry.pokemonName
43 | holder.pokemonImage.load(entry.imageUrl) {
44 | memoryCachePolicy(CachePolicy.ENABLED)
45 | listener { _, _ ->
46 | holder.loading.visibility = GONE
47 | viewModel.getDominantColor(holder.pokemonImage.drawable) { dominantColor ->
48 | holder.card.setCardBackgroundColor(dominantColor)
49 | holder.itemView.setOnClickListener {
50 | fragment.openDetails(entry.pokemonName, dominantColor)
51 | }
52 | }
53 | }
54 | }
55 |
56 | }
57 |
58 | override fun getItemCount(): Int {
59 | return pokemonList.size
60 | }
61 |
62 | inner class ViewHolder(binding: PokemonItemBinding) :
63 | RecyclerView.ViewHolder(binding.root) {
64 | val card: MaterialCardView = binding.card
65 | val pokemonName: TextView = binding.pokemonName
66 | val pokemonImage: ImageView = binding.pokemonImage
67 | val number: TextView = binding.number
68 | val loading: CircularProgressIndicator = binding.loading
69 | }
70 |
71 | fun addData(listItems: ArrayList) {
72 | val size = pokemonList.size
73 | for (i in size..listItems.lastIndex) {
74 | pokemonList.add(listItems[i])
75 | }
76 | val sizeNew = pokemonList.size
77 | notifyItemRangeChanged(size, sizeNew)
78 | }
79 |
80 | override fun onViewRecycled(holder: ViewHolder) {
81 | super.onViewRecycled(holder)
82 | holder.pokemonImage.clear()
83 | holder.card.setCardBackgroundColor(
84 | ContextCompat.getColor(
85 | context,
86 | R.color.manualBackground
87 | )
88 | )
89 | holder.loading.visibility = VISIBLE
90 | }
91 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Pokedex
3 |
4 |
5 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam in scelerisque sem. Mauris
6 | volutpat, dolor id interdum ullamcorper, risus dolor egestas lectus, sit amet mattis purus
7 | dui nec risus. Maecenas non sodales nisi, vel dictum dolor. Class aptent taciti sociosqu ad
8 | litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse blandit eleifend
9 | diam, vel rutrum tellus vulputate quis. Aliquam eget libero aliquet, imperdiet nisl a,
10 | ornare ex. Sed rhoncus est ut libero porta lobortis. Fusce in dictum tellus.\n\n
11 | Suspendisse interdum ornare ante. Aliquam nec cursus lorem. Morbi id magna felis. Vivamus
12 | egestas, est a condimentum egestas, turpis nisl iaculis ipsum, in dictum tellus dolor sed
13 | neque. Morbi tellus erat, dapibus ut sem a, iaculis tincidunt dui. Interdum et malesuada
14 | fames ac ante ipsum primis in faucibus. Curabitur et eros porttitor, ultricies urna vitae,
15 | molestie nibh. Phasellus at commodo eros, non aliquet metus. Sed maximus nisl nec dolor
16 | bibendum, vel congue leo egestas.\n\n
17 | Sed interdum tortor nibh, in sagittis risus mollis quis. Curabitur mi odio, condimentum sit
18 | amet auctor at, mollis non turpis. Nullam pretium libero vestibulum, finibus orci vel,
19 | molestie quam. Fusce blandit tincidunt nulla, quis sollicitudin libero facilisis et. Integer
20 | interdum nunc ligula, et fermentum metus hendrerit id. Vestibulum lectus felis, dictum at
21 | lacinia sit amet, tristique id quam. Cras eu consequat dui. Suspendisse sodales nunc ligula,
22 | in lobortis sem porta sed. Integer id ultrices magna, in luctus elit. Sed a pellentesque
23 | est.\n\n
24 | Aenean nunc velit, lacinia sed dolor sed, ultrices viverra nulla. Etiam a venenatis nibh.
25 | Morbi laoreet, tortor sed facilisis varius, nibh orci rhoncus nulla, id elementum leo dui
26 | non lorem. Nam mollis ipsum quis auctor varius. Quisque elementum eu libero sed commodo. In
27 | eros nisl, imperdiet vel imperdiet et, scelerisque a mauris. Pellentesque varius ex nunc,
28 | quis imperdiet eros placerat ac. Duis finibus orci et est auctor tincidunt. Sed non viverra
29 | ipsum. Nunc quis augue egestas, cursus lorem at, molestie sem. Morbi a consectetur ipsum, a
30 | placerat diam. Etiam vulputate dignissim convallis. Integer faucibus mauris sit amet finibus
31 | convallis.\n\n
32 | Phasellus in aliquet mi. Pellentesque habitant morbi tristique senectus et netus et
33 | malesuada fames ac turpis egestas. In volutpat arcu ut felis sagittis, in finibus massa
34 | gravida. Pellentesque id tellus orci. Integer dictum, lorem sed efficitur ullamcorper,
35 | libero justo consectetur ipsum, in mollis nisl ex sed nisl. Donec maximus ullamcorper
36 | sodales. Praesent bibendum rhoncus tellus nec feugiat. In a ornare nulla. Donec rhoncus
37 | libero vel nunc consequat, quis tincidunt nisl eleifend. Cras bibendum enim a justo luctus
38 | vestibulum. Fusce dictum libero quis erat maximus, vitae volutpat diam dignissim.
39 |
40 | none
41 | Search here
42 | HP
43 | Base stats
44 | ATK
45 | DEF
46 | SPD
47 | SpATK
48 | SpDEF
49 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/tech/pokedex/fragment/pokelist/PokemonListFragment.kt:
--------------------------------------------------------------------------------
1 | package ru.tech.pokedex.fragment.pokelist
2 |
3 | import android.annotation.SuppressLint
4 | import android.os.Bundle
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.View.GONE
8 | import android.view.ViewGroup
9 | import android.widget.Toast
10 | import androidx.core.os.bundleOf
11 | import androidx.core.widget.addTextChangedListener
12 | import androidx.fragment.app.Fragment
13 | import androidx.fragment.app.viewModels
14 | import androidx.lifecycle.viewModelScope
15 | import androidx.recyclerview.widget.DefaultItemAnimator
16 | import androidx.recyclerview.widget.GridLayoutManager
17 | import androidx.recyclerview.widget.RecyclerView
18 | import dagger.hilt.android.AndroidEntryPoint
19 | import kotlinx.coroutines.Job
20 | import kotlinx.coroutines.delay
21 | import kotlinx.coroutines.launch
22 | import ru.tech.pokedex.R
23 | import ru.tech.pokedex.activity.MainActivity
24 | import ru.tech.pokedex.adapter.PokemonListAdapter
25 | import ru.tech.pokedex.databinding.PokemonListFragmentBinding
26 | import ru.tech.pokedex.fragment.details.PokemonDetailsFragment
27 |
28 | @AndroidEntryPoint
29 | class PokemonListFragment : Fragment() {
30 |
31 | private var _binding: PokemonListFragmentBinding? = null
32 | private val binding get() = _binding!!
33 |
34 | private val viewModel by viewModels()
35 |
36 | override fun onCreateView(
37 | inflater: LayoutInflater,
38 | container: ViewGroup?,
39 | savedInstanceState: Bundle?
40 | ): View {
41 | _binding = PokemonListFragmentBinding.inflate(inflater, container, false)
42 | return binding.root
43 | }
44 |
45 | override fun onDestroyView() {
46 | super.onDestroyView()
47 | _binding = null
48 | }
49 |
50 | @SuppressLint("NotifyDataSetChanged")
51 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
52 | super.onViewCreated(view, savedInstanceState)
53 |
54 | val adapter = PokemonListAdapter(requireContext(), viewModel, this)
55 | binding.pokemonRecycler.itemAnimator = DefaultItemAnimator()
56 | binding.pokemonRecycler.adapter = adapter
57 | val layoutManager = binding.pokemonRecycler.layoutManager as GridLayoutManager
58 |
59 | viewModel.pokemonList.observe(viewLifecycleOwner) {
60 | adapter.addData(it)
61 | binding.loading.visibility = GONE
62 | }
63 |
64 | viewModel.searchList.observe(viewLifecycleOwner) {
65 | if (!viewModel.isFinding) {
66 | viewModel.pokemonList.value?.let { `val` -> adapter.pokemonList = `val` }
67 | } else {
68 | adapter.pokemonList = it
69 | }
70 | adapter.notifyDataSetChanged()
71 | }
72 |
73 | viewModel.loadError.observe(viewLifecycleOwner) {
74 | if (it != "") Toast.makeText(requireContext(), it, Toast.LENGTH_LONG).show()
75 | }
76 |
77 | binding.pokemonRecycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
78 | override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
79 | super.onScrolled(recyclerView, dx, dy)
80 | if (!viewModel.isLoading && !viewModel.endReached) {
81 | val curPos = layoutManager.findLastCompletelyVisibleItemPosition()
82 | if (curPos == (viewModel.pokemonList.value?.size ?: 0) - 1) {
83 | viewModel.loadPokemonList()
84 | }
85 | }
86 | }
87 | })
88 |
89 | adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
90 | override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
91 | layoutManager.scrollToPositionWithOffset(positionStart, 0)
92 | }
93 | })
94 |
95 | binding.searchField.addTextChangedListener(onTextChanged = { s, _, _, _ ->
96 | val search = s.toString().trim().replace("null", "")
97 | viewModel.isFinding = search.isNotEmpty()
98 | searchDebounced(search)
99 | })
100 |
101 | }
102 |
103 | private var searchJob: Job? = null
104 |
105 | private fun searchDebounced(searchText: String) {
106 | searchJob?.cancel()
107 | searchJob = viewModel.viewModelScope.launch {
108 | delay(300)
109 | viewModel.searchForPokemon(searchText)
110 | }
111 | }
112 |
113 | fun openDetails(pokemonName: String, dominantColor: Int) {
114 | val fragment = PokemonDetailsFragment()
115 | fragment.arguments = bundleOf(Pair("name", pokemonName), Pair("color", dominantColor))
116 |
117 | val tag = "pokemon_info"
118 | (requireActivity() as MainActivity).supportFragmentManager.beginTransaction()
119 | .replace(
120 | R.id.container,
121 | fragment,
122 | tag
123 | )
124 | .addToBackStack(tag)
125 | .commit()
126 | }
127 |
128 | }
--------------------------------------------------------------------------------
/app/src/main/java/ru/tech/pokedex/fragment/details/PokemonDetailsFragment.kt:
--------------------------------------------------------------------------------
1 | package ru.tech.pokedex.fragment.details
2 |
3 | import android.annotation.SuppressLint
4 | import android.os.Bundle
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.View.GONE
8 | import android.view.ViewGroup
9 | import android.widget.Toast
10 | import androidx.fragment.app.Fragment
11 | import androidx.fragment.app.viewModels
12 | import coil.load
13 | import coil.size.Scale
14 | import coil.transform.CircleCropTransformation
15 | import dagger.hilt.android.AndroidEntryPoint
16 | import ru.tech.pokedex.databinding.PokemonDetailsFragmentBinding
17 | import ru.tech.pokedex.extensions.Extensions.capitalized
18 | import ru.tech.pokedex.functions.Functions.getColor
19 |
20 | @AndroidEntryPoint
21 | class PokemonDetailsFragment : Fragment() {
22 |
23 | private var _binding: PokemonDetailsFragmentBinding? = null
24 | private val binding get() = _binding!!
25 |
26 | private val viewModel by viewModels()
27 |
28 | override fun onCreateView(
29 | inflater: LayoutInflater,
30 | container: ViewGroup?,
31 | savedInstanceState: Bundle?
32 | ): View {
33 | _binding = PokemonDetailsFragmentBinding.inflate(inflater, container, false)
34 | return binding.root
35 | }
36 |
37 | override fun onDestroyView() {
38 | super.onDestroyView()
39 | _binding = null
40 | }
41 |
42 | @SuppressLint("SetTextI18n")
43 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
44 | super.onViewCreated(view, savedInstanceState)
45 |
46 | val color = requireArguments().getInt("color")
47 | val pokemonNameStr = requireArguments().getString("name", "")
48 |
49 | viewModel.pokemonInfo.observe(viewLifecycleOwner) { pokemon ->
50 |
51 | binding.apply {
52 | try {
53 | val type0 = pokemon.types[0].type.name.capitalized()
54 | elementText.text = type0
55 | element.setImageResource(type0.getColor())
56 |
57 | val type1 = pokemon.types[1].type.name.capitalized()
58 | typeText.text = type1
59 | type.setImageResource(type1.getColor())
60 |
61 | } catch (e: Exception) {
62 | typeText.visibility = GONE
63 | type.visibility = GONE
64 | }
65 |
66 | val max = pokemon.stats.maxOf { it.base_stat }.toFloat()
67 |
68 | hpProgress.max = max
69 | attackProgress.max = max
70 | defProgress.max = max
71 | spAtkProgress.max = max
72 | spDefProgress.max = max
73 | speedProgress.max = max
74 |
75 | hpProgress.setOnProgressChangeListener {
76 | hpProgress.labelText = "${it.toInt()}"
77 | }
78 | attackProgress.setOnProgressChangeListener {
79 | attackProgress.labelText = "${it.toInt()}"
80 | }
81 | defProgress.setOnProgressChangeListener {
82 | defProgress.labelText = "${it.toInt()}"
83 | }
84 | spAtkProgress.setOnProgressChangeListener {
85 | spAtkProgress.labelText = "${it.toInt()}"
86 | }
87 | spDefProgress.setOnProgressChangeListener {
88 | spDefProgress.labelText = "${it.toInt()}"
89 | }
90 | speedProgress.setOnProgressChangeListener {
91 | speedProgress.labelText = "${it.toInt()}"
92 | }
93 |
94 | hpProgress.progress = pokemon.stats[0].base_stat.toFloat()
95 | attackProgress.progress = pokemon.stats[1].base_stat.toFloat()
96 | defProgress.progress = pokemon.stats[2].base_stat.toFloat()
97 | spAtkProgress.progress = pokemon.stats[3].base_stat.toFloat()
98 | spDefProgress.progress = pokemon.stats[4].base_stat.toFloat()
99 | speedProgress.progress = pokemon.stats[5].base_stat.toFloat()
100 |
101 | pokemonName.text = "#${pokemon.id} $pokemonNameStr"
102 | weight.text = "${pokemon.weight / 10f} kg"
103 | height.text = "${pokemon.height / 10f} m"
104 | pokemonImage.load(pokemon.sprites.front_default) {
105 | crossfade(300)
106 | transformations(CircleCropTransformation())
107 | scale(Scale.FILL)
108 | }
109 | }
110 | }
111 |
112 | viewModel.getPokemonInfo(pokemonNameStr)
113 |
114 | binding.rootView.setBackgroundColor(color)
115 |
116 | binding.goBack.setOnClickListener {
117 | requireActivity().supportFragmentManager.popBackStackImmediate()
118 | }
119 |
120 | viewModel.loadError.observe(viewLifecycleOwner) {
121 | if (it != "") Toast.makeText(requireContext(), it, Toast.LENGTH_LONG).show()
122 | }
123 |
124 | }
125 |
126 |
127 | }
--------------------------------------------------------------------------------
/app/src/main/java/ru/tech/pokedex/fragment/pokelist/PokemonListViewModel.kt:
--------------------------------------------------------------------------------
1 | package ru.tech.pokedex.fragment.pokelist
2 |
3 | import android.graphics.Bitmap
4 | import android.graphics.Color
5 | import android.graphics.drawable.BitmapDrawable
6 | import android.graphics.drawable.Drawable
7 | import androidx.lifecycle.MutableLiveData
8 | import androidx.lifecycle.ViewModel
9 | import androidx.lifecycle.viewModelScope
10 | import androidx.palette.graphics.Palette
11 | import dagger.hilt.android.lifecycle.HiltViewModel
12 | import kotlinx.coroutines.launch
13 | import ru.tech.pokedex.data.model.PokedexListEntry
14 | import ru.tech.pokedex.extensions.Extensions.capitalized
15 | import ru.tech.pokedex.functions.Functions.containsAt
16 | import ru.tech.pokedex.repository.PokemonRepository
17 | import ru.tech.pokedex.utils.Resource
18 | import ru.tech.pokedex.utils.Values.PAGE_SIZE
19 | import ru.tech.pokedex.utils.Values.SPRITE_URL
20 | import javax.inject.Inject
21 |
22 | @HiltViewModel
23 | class PokemonListViewModel @Inject constructor(
24 | private val repository: PokemonRepository
25 | ) : ViewModel() {
26 |
27 | private var currentPage = 0
28 |
29 | var isFinding = false
30 |
31 | val pokemonList: MutableLiveData> by lazy {
32 | MutableLiveData>()
33 | }
34 |
35 | val searchList: MutableLiveData> by lazy {
36 | MutableLiveData>()
37 | }
38 |
39 | private var allPokemons: ArrayList = ArrayList()
40 |
41 | val loadError: MutableLiveData by lazy {
42 | MutableLiveData("")
43 | }
44 |
45 | var isLoading = false
46 | var endReached = false
47 |
48 | init {
49 | loadPokemonList()
50 | initAllPokemons()
51 | }
52 |
53 | private fun initAllPokemons() {
54 | viewModelScope.launch {
55 | when (val result = repository.getPokemonList(1118, 0)) {
56 | is Resource.Success -> {
57 | if (result.data != null) {
58 | val pokedexEntries = result.data.results.mapIndexed { _, entry ->
59 | val number = if (entry.url.endsWith("/")) {
60 | entry.url.dropLast(1).takeLastWhile { it.isDigit() }
61 | } else {
62 | entry.url.takeLastWhile { it.isDigit() }
63 | }
64 | val url = SPRITE_URL.replace("*", number)
65 | PokedexListEntry(entry.name.capitalized(), url, number.toInt())
66 | }
67 | allPokemons = ArrayList(pokedexEntries)
68 | }
69 | }
70 | is Resource.Error -> {
71 | loadError.value = result.message.toString()
72 | }
73 | }
74 | }
75 | }
76 |
77 | fun loadPokemonList() {
78 | viewModelScope.launch {
79 | isLoading = true
80 | when (val result = repository.getPokemonList(PAGE_SIZE, currentPage * PAGE_SIZE)) {
81 | is Resource.Success -> {
82 | if (result.data != null) {
83 | endReached = currentPage * PAGE_SIZE >= result.data.count
84 | val pokedexEntries = result.data.results.mapIndexed { _, entry ->
85 | val number = if (entry.url.endsWith("/")) {
86 | entry.url.dropLast(1).takeLastWhile { it.isDigit() }
87 | } else {
88 | entry.url.takeLastWhile { it.isDigit() }
89 | }
90 | val url = SPRITE_URL.replace("*", number)
91 | PokedexListEntry(entry.name.capitalized(), url, number.toInt())
92 | }
93 | currentPage++
94 | if (pokemonList.value == null) {
95 | pokemonList.value = ArrayList(pokedexEntries)
96 | } else {
97 | val `val` = pokemonList.value
98 | if (`val` != null) pokemonList.value = ArrayList(`val` + pokedexEntries)
99 | }
100 | }
101 | loadError.value = ""
102 | isLoading = false
103 | }
104 | is Resource.Error -> {
105 | loadError.value = result.message.toString()
106 | isLoading = false
107 | }
108 | }
109 | }
110 | }
111 |
112 | fun searchForPokemon(query: String) {
113 | viewModelScope.launch {
114 | isLoading = true
115 | val tempArr: ArrayList = ArrayList()
116 | val pairList: ArrayList> = ArrayList()
117 |
118 | allPokemons.forEach {
119 | val index = it.pokemonName.lowercase().containsAt(query.lowercase())
120 | if (index != 101) {
121 | pairList.add(Pair(it, index))
122 | }
123 | }
124 |
125 | pairList.sortBy { it.second }
126 | pairList.forEach { tempArr.add(it.first) }
127 |
128 | searchList.value = tempArr
129 | isLoading = false
130 | }
131 | }
132 |
133 | fun getDominantColor(drawable: Drawable, onFinish: (Int) -> Unit) {
134 | val bitmap = (drawable as BitmapDrawable).bitmap.copy(Bitmap.Config.ARGB_8888, true)
135 |
136 | Palette.from(bitmap).generate { palette ->
137 | palette?.getDominantColor(Color.WHITE)?.let { onFinish(it) }
138 | }
139 | }
140 |
141 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/pokemon_details_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
23 |
24 |
30 |
31 |
37 |
38 |
44 |
45 |
56 |
57 |
70 |
71 |
82 |
83 |
90 |
91 |
101 |
102 |
113 |
114 |
115 |
116 |
124 |
125 |
136 |
137 |
149 |
150 |
151 |
152 |
164 |
165 |
177 |
178 |
192 |
193 |
207 |
208 |
218 |
219 |
232 |
233 |
243 |
244 |
247 |
248 |
254 |
255 |
263 |
264 |
280 |
281 |
282 |
283 |
290 |
291 |
299 |
300 |
316 |
317 |
318 |
319 |
326 |
327 |
335 |
336 |
352 |
353 |
354 |
355 |
362 |
363 |
371 |
372 |
388 |
389 |
390 |
391 |
398 |
399 |
407 |
408 |
424 |
425 |
426 |
427 |
434 |
435 |
443 |
444 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
480 |
481 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/pokemon_details_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
23 |
24 |
30 |
31 |
37 |
38 |
44 |
45 |
56 |
57 |
70 |
71 |
84 |
85 |
94 |
95 |
105 |
106 |
117 |
118 |
119 |
120 |
130 |
131 |
142 |
143 |
155 |
156 |
157 |
158 |
170 |
171 |
183 |
184 |
199 |
200 |
215 |
216 |
226 |
227 |
240 |
241 |
251 |
252 |
255 |
256 |
262 |
263 |
271 |
272 |
288 |
289 |
290 |
291 |
298 |
299 |
307 |
308 |
324 |
325 |
326 |
327 |
334 |
335 |
343 |
344 |
360 |
361 |
362 |
363 |
370 |
371 |
379 |
380 |
396 |
397 |
398 |
399 |
406 |
407 |
415 |
416 |
432 |
433 |
434 |
435 |
442 |
443 |
451 |
452 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
486 |
487 |
502 |
503 |
--------------------------------------------------------------------------------