diff --git a/.idea/ktlint.xml b/.idea/ktlint.xml
new file mode 100644
index 0000000..e44b786
--- /dev/null
+++ b/.idea/ktlint.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Screen Shot 2022-07-12 at 21.21.52.png b/Screen Shot 2022-07-12 at 21.21.52.png
deleted file mode 100644
index 898b0e9..0000000
Binary files a/Screen Shot 2022-07-12 at 21.21.52.png and /dev/null differ
diff --git a/Screen Shot 2022-07-19 at 09.01.07.png b/Screen Shot 2022-07-19 at 09.01.07.png
deleted file mode 100644
index c5af1e1..0000000
Binary files a/Screen Shot 2022-07-19 at 09.01.07.png and /dev/null differ
diff --git a/app/build.gradle b/app/build.gradle
index 4ba442e..3a2a721 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -17,7 +17,7 @@ android {
versionCode 1
versionName "1.0"
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ testInstrumentationRunner "com.example.pokedex.HiltTestRunner"
}
buildTypes {
@@ -25,6 +25,9 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
+ debug {
+ testCoverageEnabled true
+ }
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
@@ -36,6 +39,9 @@ android {
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
+ hilt {
+ enableTransformForLocalTests = true
+ }
buildFeatures {
viewBinding true
compose true
@@ -54,6 +60,21 @@ dependencies {
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
+ androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.4.0'
+ androidTestImplementation 'androidx.navigation:navigation-testing:2.5.2'
+
+ debugImplementation 'androidx.fragment:fragment-testing:1.5.3'
+
+ testImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
+ androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
+ testAnnotationProcessor "com.google.dagger:hilt-android-compiler:$hilt_version"
+ androidTestAnnotationProcessor "com.google.dagger:hilt-android-compiler:$hilt_version"
+
+ kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.37'
+
+ androidTestImplementation 'org.mockito:mockito-android:3.2.4'
+
+ debugImplementation "androidx.fragment:fragment-testing:1.3.0-alpha08"
//compose
implementation "androidx.compose.ui:ui:$compose_version"
@@ -78,9 +99,10 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
// Dagger - Hilt
- implementation "com.google.dagger:hilt-android:$hilt_version"
+ implementation "com.google.dagger:hilt-android:2.37"
+ kapt "com.google.dagger:hilt-android-compiler:2.37"
+
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
- kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
kapt "androidx.hilt:hilt-compiler:1.0.0"
def fragment_version = "1.4.1"
diff --git a/app/src/androidTest/kotlin/com/example/pokedex/HiltExt.kt b/app/src/androidTest/kotlin/com/example/pokedex/HiltExt.kt
new file mode 100644
index 0000000..c8ee90b
--- /dev/null
+++ b/app/src/androidTest/kotlin/com/example/pokedex/HiltExt.kt
@@ -0,0 +1,49 @@
+package com.example.pokedex
+
+import android.content.ComponentName
+import android.content.Intent
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.FragmentFactory
+import androidx.fragment.app.testing.FragmentScenario
+import androidx.test.core.app.ActivityScenario
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.espresso.core.internal.deps.dagger.internal.Preconditions
+import com.example.pokedex.testing.HiltTestActivity
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+
+@ExperimentalCoroutinesApi
+inline fun launchFragmentInHiltContainer(
+ fragmentArgs: Bundle? = null,
+ themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme,
+ fragmentFactory: FragmentFactory? = null,
+ crossinline action: T.() -> Unit = {}
+) {
+ val mainActivityIntent = Intent.makeMainActivity(
+ ComponentName(
+ ApplicationProvider.getApplicationContext(),
+ HiltTestActivity::class.java
+ )
+ ).putExtra(
+ "androidx.fragment.app.testing.FragmentScenario.EmptyFragmentActivity.THEME_EXTRAS_BUNDLE_KEY",
+ themeResId
+ )
+
+ ActivityScenario.launch(mainActivityIntent).onActivity { activity ->
+ fragmentFactory?.let {
+ activity.supportFragmentManager.fragmentFactory = it
+ }
+ val fragment = activity.supportFragmentManager.fragmentFactory.instantiate(
+ Preconditions.checkNotNull(T::class.java.classLoader),
+ T::class.java.name
+ )
+ fragment.arguments = fragmentArgs
+
+ activity.supportFragmentManager.beginTransaction()
+ .add(android.R.id.content, fragment, "")
+ .commitNow()
+
+ (fragment as T).action()
+ }
+
+}
diff --git a/app/src/androidTest/kotlin/com/example/pokedex/HiltTestRunner.kt b/app/src/androidTest/kotlin/com/example/pokedex/HiltTestRunner.kt
new file mode 100644
index 0000000..40d9feb
--- /dev/null
+++ b/app/src/androidTest/kotlin/com/example/pokedex/HiltTestRunner.kt
@@ -0,0 +1,15 @@
+package com.example.pokedex
+
+import android.app.Application
+import android.content.Context
+import androidx.test.runner.AndroidJUnitRunner
+import dagger.hilt.android.testing.HiltTestApplication
+
+@Suppress("unused")
+class HiltTestRunner : AndroidJUnitRunner() {
+ override fun newApplication(
+ cl: ClassLoader?,
+ className: String?,
+ context: Context?
+ ): Application = super.newApplication(cl, HiltTestApplication::class.java.name, context)
+}
diff --git a/app/src/androidTest/kotlin/com/example/pokedex/MockPokemon.kt b/app/src/androidTest/kotlin/com/example/pokedex/MockPokemon.kt
new file mode 100644
index 0000000..ca3ae4d
--- /dev/null
+++ b/app/src/androidTest/kotlin/com/example/pokedex/MockPokemon.kt
@@ -0,0 +1,20 @@
+package com.example.pokedex
+
+import androidx.navigation.NavController
+import com.example.pokedex.data.Pokemon
+import com.example.pokedex.data.PokemonType
+import org.mockito.Mockito
+
+object MockPokemon {
+
+ val navController = Mockito.mock(NavController::class.java)
+
+ val list: List = listOf(PokemonType("grass"), PokemonType("poison"))
+
+ val mockPokemon: Pokemon = Pokemon(
+ number = "3",
+ name = "venusaur",
+ types = list,
+ imageUrl = "3"
+ )
+}
diff --git a/app/src/androidTest/kotlin/com/example/pokedex/ui/details/PokedexDetailsFragmentTest.kt b/app/src/androidTest/kotlin/com/example/pokedex/ui/details/PokedexDetailsFragmentTest.kt
new file mode 100644
index 0000000..4f49ee6
--- /dev/null
+++ b/app/src/androidTest/kotlin/com/example/pokedex/ui/details/PokedexDetailsFragmentTest.kt
@@ -0,0 +1,59 @@
+package com.example.pokedex.ui.details
+
+import androidx.core.os.bundleOf
+import androidx.navigation.Navigation
+import androidx.test.espresso.Espresso
+import androidx.test.espresso.assertion.ViewAssertions
+import androidx.test.espresso.matcher.ViewMatchers
+import androidx.test.espresso.matcher.ViewMatchers.withId
+import com.example.pokedex.MockPokemon
+import com.example.pokedex.MockPokemon.navController
+import com.example.pokedex.R
+import com.example.pokedex.launchFragmentInHiltContainer
+import dagger.hilt.android.testing.HiltAndroidRule
+import dagger.hilt.android.testing.HiltAndroidTest
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+
+@ExperimentalCoroutinesApi
+@HiltAndroidTest
+class PokedexDetailsFragmentTest {
+
+ @get:Rule
+ var hiltRule = HiltAndroidRule(this)
+
+ @Before
+ fun setup() {
+ hiltRule.inject()
+
+ launchFragmentInHiltContainer(fragmentArgs = bundleOf("pokemon" to MockPokemon.mockPokemon)) {
+ Navigation.setViewNavController(requireView(), navController)
+ }
+ }
+
+ @Test
+ fun checkIfAfterPassArgumentThePokemonNameIsCorrect() {
+ Espresso.onView(withId(R.id.pokemon_name))
+ .check(ViewAssertions.matches(ViewMatchers.withText("Venusaur")))
+ }
+
+ @Test
+ fun checkIfAfterPassArgumentThePokemonNumberIsCorrect() {
+ Espresso.onView(withId(R.id.pokemon_number))
+ .check(ViewAssertions.matches(ViewMatchers.withText("003")))
+ }
+
+ @Test
+ fun checkIfAfterPassArgumentThePokemonTypeIsCorrect() {
+ Espresso.onView(withId(R.id.pokemon_primary_type))
+ .check(ViewAssertions.matches(ViewMatchers.withText("grass")))
+ }
+
+ @Test
+ fun checkIfAfterPassArgumentThePokemonSecondTypeIsCorrect() {
+ Espresso.onView(withId(R.id.pokemon_second_type))
+ .check(ViewAssertions.matches(ViewMatchers.withText("poison")))
+ }
+}
diff --git a/app/src/androidTest/kotlin/com/example/pokedex/ui/home/PokedexHomeFragmentTest.kt b/app/src/androidTest/kotlin/com/example/pokedex/ui/home/PokedexHomeFragmentTest.kt
new file mode 100644
index 0000000..e65d26c
--- /dev/null
+++ b/app/src/androidTest/kotlin/com/example/pokedex/ui/home/PokedexHomeFragmentTest.kt
@@ -0,0 +1,49 @@
+package com.example.pokedex.ui.home
+
+import androidx.navigation.Navigation
+import androidx.recyclerview.widget.RecyclerView
+import androidx.test.espresso.Espresso.onView
+import androidx.test.espresso.action.ViewActions.click
+import androidx.test.espresso.contrib.RecyclerViewActions
+import androidx.test.espresso.matcher.ViewMatchers.*
+import com.example.pokedex.MockPokemon.mockPokemon
+import com.example.pokedex.MockPokemon.navController
+import com.example.pokedex.R
+import com.example.pokedex.launchFragmentInHiltContainer
+import dagger.hilt.android.testing.HiltAndroidRule
+import dagger.hilt.android.testing.HiltAndroidTest
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.mockito.Mockito.verify
+
+@ExperimentalCoroutinesApi
+@HiltAndroidTest
+class PokedexHomeFragmentTest {
+
+ @get:Rule
+ var hiltRule = HiltAndroidRule(this)
+
+ @Before
+ fun setup() {
+ hiltRule.inject()
+
+ launchFragmentInHiltContainer {
+ Navigation.setViewNavController(requireView(), navController)
+ }
+ }
+
+ @Test
+ fun navigate_to_detailsPokedex() {
+ onView(withId(R.id.pokemon_recycler))
+ .perform(
+ RecyclerViewActions
+ .actionOnItemAtPosition(2, click())
+ )
+
+ verify(navController).navigate(
+ PokedexHomeFragmentDirections.actionFirstDestinationToPokedexDetailsFragment(mockPokemon)
+ )
+ }
+}
diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml
new file mode 100644
index 0000000..ccdc677
--- /dev/null
+++ b/app/src/debug/AndroidManifest.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/debug/java/com/example/pokedex/testing/HiltTestActivity.kt b/app/src/debug/java/com/example/pokedex/testing/HiltTestActivity.kt
new file mode 100644
index 0000000..22b87d0
--- /dev/null
+++ b/app/src/debug/java/com/example/pokedex/testing/HiltTestActivity.kt
@@ -0,0 +1,7 @@
+package com.example.pokedex.testing
+
+import androidx.appcompat.app.AppCompatActivity
+import dagger.hilt.android.AndroidEntryPoint
+
+@AndroidEntryPoint
+class HiltTestActivity : AppCompatActivity()
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 9d80f72..3c4d2a3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -13,7 +13,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.Pokedex">
@@ -23,7 +23,7 @@
diff --git a/app/src/main/kotlin/com/example/pokedex/PokedexApplication.kt b/app/src/main/kotlin/com/example/pokedex/PokedexApplication.kt
index 9502e3e..254df96 100644
--- a/app/src/main/kotlin/com/example/pokedex/PokedexApplication.kt
+++ b/app/src/main/kotlin/com/example/pokedex/PokedexApplication.kt
@@ -4,4 +4,4 @@ import android.app.Application
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
-class PokedexApplication : Application()
\ No newline at end of file
+class PokedexApplication : Application()
diff --git a/app/src/main/kotlin/com/example/pokedex/api/PokemonService.kt b/app/src/main/kotlin/com/example/pokedex/api/PokemonService.kt
index 08ac4da..8f2551f 100644
--- a/app/src/main/kotlin/com/example/pokedex/api/PokemonService.kt
+++ b/app/src/main/kotlin/com/example/pokedex/api/PokemonService.kt
@@ -17,4 +17,4 @@ interface PokemonService {
suspend fun getPokemon(
@Path("number") number: Int
): Response
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/example/pokedex/data/Pokemon.kt b/app/src/main/kotlin/com/example/pokedex/data/Pokemon.kt
index 59cfb18..3082032 100644
--- a/app/src/main/kotlin/com/example/pokedex/data/Pokemon.kt
+++ b/app/src/main/kotlin/com/example/pokedex/data/Pokemon.kt
@@ -1,45 +1,15 @@
package com.example.pokedex.data
import android.os.Parcelable
-import androidx.room.Entity
import androidx.room.PrimaryKey
-import androidx.room.TypeConverters
-import com.example.pokedex.data.local.PokedexConverters
import kotlinx.android.parcel.Parcelize
import kotlinx.android.parcel.RawValue
@Parcelize
-@Entity(tableName = "pokemon")
-@TypeConverters(PokedexConverters::class)
data class Pokemon(
@PrimaryKey
val number: String,
val name: String,
val types: @RawValue List,
val imageUrl: String
-) : Parcelable {
-
-// val formattedNumber = when {
-// number.length < 2 -> "00$number"
-// number.length < 3 -> "0$number"
-// else -> number
-// }
-//
-// val formattedName = name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
-//
-// val imageUrl = "https://assets.pokemon.com/assets/cms2/img/pokedex/full/$formattedNumber.png"
-}
-
-/*
-@Entity(tableName = "pokemon")
-data class Pokemon(
- @PrimaryKey(autoGenerate = true)
- @SerializedName("number")
- val number: String,
- @SerializedName("name")
- val name: String,
- @SerializedName("types")
- val types: @RawValue List
-) : Serializable {
-
- */
+) : Parcelable
diff --git a/app/src/main/kotlin/com/example/pokedex/data/PokemonRepository.kt b/app/src/main/kotlin/com/example/pokedex/data/PokemonRepository.kt
index 17929aa..e202755 100644
--- a/app/src/main/kotlin/com/example/pokedex/data/PokemonRepository.kt
+++ b/app/src/main/kotlin/com/example/pokedex/data/PokemonRepository.kt
@@ -1,18 +1,12 @@
package com.example.pokedex.data
import com.example.pokedex.api.PokemonService
-import com.example.pokedex.data.local.PokedexDao
import javax.inject.Inject
class PokemonRepository @Inject constructor(
- private val service: PokemonService,
- private val dao: PokedexDao
+ private val service: PokemonService
) {
- suspend fun listPokemons(limit: Int = 100) = service.listPokemons(limit)
+ suspend fun listPokemons(limit: Int = 500) = service.listPokemons(limit)
suspend fun getPokemons(number: Int) = service.getPokemon(number)
-
- suspend fun insert(pokemonModel: Pokemon) = dao.insert(pokemonModel)
- fun getAll() = dao.getAll()
- suspend fun delete(pokemonModel: Pokemon) = dao.delete(pokemonModel)
}
diff --git a/app/src/main/kotlin/com/example/pokedex/data/PokemonType.kt b/app/src/main/kotlin/com/example/pokedex/data/PokemonType.kt
index 86f8084..420857d 100644
--- a/app/src/main/kotlin/com/example/pokedex/data/PokemonType.kt
+++ b/app/src/main/kotlin/com/example/pokedex/data/PokemonType.kt
@@ -1,5 +1,5 @@
package com.example.pokedex.data
data class PokemonType(
- val name: String,
-)
\ No newline at end of file
+ val name: String
+)
diff --git a/app/src/main/kotlin/com/example/pokedex/data/local/PokedexConverters.kt b/app/src/main/kotlin/com/example/pokedex/data/local/PokedexConverters.kt
deleted file mode 100644
index 57e0ea8..0000000
--- a/app/src/main/kotlin/com/example/pokedex/data/local/PokedexConverters.kt
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.example.pokedex.data.local
-
-import androidx.room.TypeConverter
-import com.example.pokedex.data.PokemonType
-import com.example.pokedex.data.model.PokemonImage
-import com.google.gson.Gson
-import com.google.gson.reflect.TypeToken
-/*
- @TypeConverter
- fun fromThumbnail(thumbnailModel: ThumbnailModel): String = Gson().toJson(thumbnailModel)
-
- @TypeConverter
- fun toThumbnail(thumbnailModel: String): ThumbnailModel =
- Gson().fromJson(thumbnailModel, ThumbnailModel::class.java)
- */
-class PokedexConverters {
-// @TypeConverter
-// fun fromType(type: List): String = Gson().toJson(type)
-//
-// @TypeConverter
-// fun toType(type: String) = Gson().fromJson(type, PokemonType::class.java)
-
-// private val gson = Gson()
-// private val type: Type = object : TypeToken>() {}.type
-//
-// @TypeConverter
-// fun fromString(json: String?): List {
-// return gson.fromJson(json, type)
-// }
-//
-// @TypeConverter
-// fun fromList(list: List?): String {
-// return gson.toJson(list, type)
-// }
-
- @TypeConverter
- fun fromString(value: List): String {
- val gson = Gson()
- val type = object : TypeToken>() {}.type
- return gson.toJson(value, type)
- }
-
- @TypeConverter
- fun toString(value: String): List {
- val gson = Gson()
- val type = object : TypeToken>() {}.type
- return gson.fromJson(value, type)
- }
-
- @TypeConverter
- fun fromImage(image: PokemonImage): String = Gson().toJson(image)
-
- @TypeConverter
- fun fromImage(image: String): PokemonImage = Gson().fromJson(image, PokemonImage::class.java)
-
- /*
-
- @TypeConverter
- fun fromThumbnail(thumbnailModel: ThumbnailModel): String = Gson().toJson(thumbnailModel)
-
- @TypeConverter
- fun toThumbnail(thumbnailModel: String): ThumbnailModel =
- Gson().fromJson(thumbnailModel, ThumbnailModel::class.java)
- */
-
-// @TypeConverter
-// fun fromInfoType(type: List?): String {
-// val listType =
-// Types.newParameterizedType(List::class.java, PokemonType::class.java)
-// val adapter: JsonAdapter> = moshi.adapter(listType)
-// return adapter.toJson(type)
-// }
-}
diff --git a/app/src/main/kotlin/com/example/pokedex/data/local/PokedexDao.kt b/app/src/main/kotlin/com/example/pokedex/data/local/PokedexDao.kt
deleted file mode 100644
index 65b19fb..0000000
--- a/app/src/main/kotlin/com/example/pokedex/data/local/PokedexDao.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.example.pokedex.data.local
-
-import androidx.lifecycle.LiveData
-import androidx.room.*
-import com.example.pokedex.data.Pokemon
-
-@Dao
-interface PokedexDao {
-
- @Insert(onConflict = OnConflictStrategy.REPLACE)
- suspend fun insert(pokemon: Pokemon): Long
-
- @Query("SELECT * FROM pokemon ORDER BY number")
- fun getAll(): LiveData>
-
- @Delete
- suspend fun delete(characterModel: Pokemon)
-}
diff --git a/app/src/main/kotlin/com/example/pokedex/data/local/PokedexDataBase.kt b/app/src/main/kotlin/com/example/pokedex/data/local/PokedexDataBase.kt
deleted file mode 100644
index cda6511..0000000
--- a/app/src/main/kotlin/com/example/pokedex/data/local/PokedexDataBase.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.example.pokedex.data.local
-
-import androidx.room.Database
-import androidx.room.RoomDatabase
-import androidx.room.TypeConverters
-import com.example.pokedex.data.Pokemon
-
-@Database(entities = [Pokemon::class], version = 1, exportSchema = false)
-@TypeConverters(PokedexConverters::class)
-abstract class PokedexDataBase : RoomDatabase() {
- abstract fun pokedexDao(): PokedexDao
-}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/example/pokedex/data/model/PokemonImage.kt b/app/src/main/kotlin/com/example/pokedex/data/model/PokemonImage.kt
deleted file mode 100644
index 14b2240..0000000
--- a/app/src/main/kotlin/com/example/pokedex/data/model/PokemonImage.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.example.pokedex.data.model
-
-data class PokemonImage(
- val path: String
-)
diff --git a/app/src/main/kotlin/com/example/pokedex/di/Module.kt b/app/src/main/kotlin/com/example/pokedex/di/Module.kt
index bf5b1ad..8fab52c 100644
--- a/app/src/main/kotlin/com/example/pokedex/di/Module.kt
+++ b/app/src/main/kotlin/com/example/pokedex/di/Module.kt
@@ -1,15 +1,10 @@
package com.example.pokedex.di
-import android.content.Context
-import androidx.room.Room
import com.example.pokedex.api.PokemonService
-import com.example.pokedex.data.local.PokedexDataBase
import com.example.pokedex.utils.Constants.BASE_URL
-import com.example.pokedex.utils.Constants.DATABASE_NAME
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
-import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
@@ -19,36 +14,6 @@ import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
object Module {
- @Singleton
- @Provides
- fun providePokedexDatabase(
- @ApplicationContext context: Context
- ) = Room.databaseBuilder(
- context,
- PokedexDataBase::class.java,
- DATABASE_NAME
- ).build()
-
- @Singleton
- @Provides
- fun provideMarvelDAO(database: PokedexDataBase) = database.pokedexDao()
- /*
- @Singleton
- @Provides
- fun provideMarvelDatabase(
- @ApplicationContext context: Context
- ) = Room.databaseBuilder(
- context,
- MarvelDataBase::class.java,
- DATABASE_NAME
- ).build()
-
- @Singleton
- @Provides
- fun provideMarvelDAO(database: MarvelDataBase) = database.marvelDao()
-
- */
-
@Singleton
@Provides
fun provideRetrofit(): Retrofit {
diff --git a/app/src/main/kotlin/com/example/pokedex/ui/PokedexDetailsFragment.kt b/app/src/main/kotlin/com/example/pokedex/ui/details/PokedexDetailsFragment.kt
similarity index 98%
rename from app/src/main/kotlin/com/example/pokedex/ui/PokedexDetailsFragment.kt
rename to app/src/main/kotlin/com/example/pokedex/ui/details/PokedexDetailsFragment.kt
index 8ec75af..857ca4a 100644
--- a/app/src/main/kotlin/com/example/pokedex/ui/PokedexDetailsFragment.kt
+++ b/app/src/main/kotlin/com/example/pokedex/ui/details/PokedexDetailsFragment.kt
@@ -1,4 +1,4 @@
-package com.example.pokedex.ui
+package com.example.pokedex.ui.details
import android.content.res.ColorStateList
import android.graphics.drawable.GradientDrawable
diff --git a/app/src/main/kotlin/com/example/pokedex/ui/PokedexHomeFragment.kt b/app/src/main/kotlin/com/example/pokedex/ui/home/PokedexHomeFragment.kt
similarity index 93%
rename from app/src/main/kotlin/com/example/pokedex/ui/PokedexHomeFragment.kt
rename to app/src/main/kotlin/com/example/pokedex/ui/home/PokedexHomeFragment.kt
index ec83f31..9b3075c 100644
--- a/app/src/main/kotlin/com/example/pokedex/ui/PokedexHomeFragment.kt
+++ b/app/src/main/kotlin/com/example/pokedex/ui/home/PokedexHomeFragment.kt
@@ -1,4 +1,4 @@
-package com.example.pokedex.ui
+package com.example.pokedex.ui.home
import android.os.Bundle
import android.view.View
@@ -14,14 +14,13 @@ import com.example.dsmpokedex.PokeballLoading
import com.example.pokedex.R
import com.example.pokedex.databinding.FragmentPokedexHomeBinding
import com.example.pokedex.utils.Resource
-import com.example.pokedex.viewmodel.PokemonViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
@AndroidEntryPoint
class PokedexHomeFragment : Fragment(R.layout.fragment_pokedex_home) {
- private lateinit var viewModel: PokemonViewModel
+ private lateinit var viewModel: PokedexHomeViewModel
private var _binding: FragmentPokedexHomeBinding? = null
private val binding get() = _binding!!
@@ -30,7 +29,7 @@ class PokedexHomeFragment : Fragment(R.layout.fragment_pokedex_home) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- viewModel = ViewModelProvider(this).get(PokemonViewModel::class.java)
+ viewModel = ViewModelProvider(this).get(PokedexHomeViewModel::class.java)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
diff --git a/app/src/main/kotlin/com/example/pokedex/viewmodel/PokemonViewModel.kt b/app/src/main/kotlin/com/example/pokedex/ui/home/PokedexHomeViewModel.kt
similarity index 96%
rename from app/src/main/kotlin/com/example/pokedex/viewmodel/PokemonViewModel.kt
rename to app/src/main/kotlin/com/example/pokedex/ui/home/PokedexHomeViewModel.kt
index 918885c..5dafe19 100644
--- a/app/src/main/kotlin/com/example/pokedex/viewmodel/PokemonViewModel.kt
+++ b/app/src/main/kotlin/com/example/pokedex/ui/home/PokedexHomeViewModel.kt
@@ -1,4 +1,4 @@
-package com.example.pokedex.viewmodel
+package com.example.pokedex.ui.home
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
@@ -15,7 +15,7 @@ import java.io.IOException
import javax.inject.Inject
@HiltViewModel
-class PokemonViewModel @Inject constructor(
+class PokedexHomeViewModel @Inject constructor(
private val repository: PokemonRepository
) : ViewModel() {
@@ -67,4 +67,4 @@ class PokemonViewModel @Inject constructor(
}
return Resource.Error(response.message())
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/example/pokedex/ui/PokemonAdapter.kt b/app/src/main/kotlin/com/example/pokedex/ui/home/PokemonAdapter.kt
similarity index 98%
rename from app/src/main/kotlin/com/example/pokedex/ui/PokemonAdapter.kt
rename to app/src/main/kotlin/com/example/pokedex/ui/home/PokemonAdapter.kt
index 1f9092b..68b4a49 100644
--- a/app/src/main/kotlin/com/example/pokedex/ui/PokemonAdapter.kt
+++ b/app/src/main/kotlin/com/example/pokedex/ui/home/PokemonAdapter.kt
@@ -1,4 +1,4 @@
-package com.example.pokedex.ui
+package com.example.pokedex.ui.home
import android.view.LayoutInflater
import android.view.ViewGroup
diff --git a/app/src/main/kotlin/com/example/pokedex/ui/MainActivity.kt b/app/src/main/kotlin/com/example/pokedex/ui/main/MainActivity.kt
similarity index 91%
rename from app/src/main/kotlin/com/example/pokedex/ui/MainActivity.kt
rename to app/src/main/kotlin/com/example/pokedex/ui/main/MainActivity.kt
index 7b562c3..d4b246c 100644
--- a/app/src/main/kotlin/com/example/pokedex/ui/MainActivity.kt
+++ b/app/src/main/kotlin/com/example/pokedex/ui/main/MainActivity.kt
@@ -1,4 +1,4 @@
-package com.example.pokedex.ui
+package com.example.pokedex.ui.main
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
diff --git a/app/src/main/kotlin/com/example/pokedex/ui/SplashActivity.kt b/app/src/main/kotlin/com/example/pokedex/ui/splash/SplashActivity.kt
similarity index 85%
rename from app/src/main/kotlin/com/example/pokedex/ui/SplashActivity.kt
rename to app/src/main/kotlin/com/example/pokedex/ui/splash/SplashActivity.kt
index 75f9aa0..c98f5a3 100644
--- a/app/src/main/kotlin/com/example/pokedex/ui/SplashActivity.kt
+++ b/app/src/main/kotlin/com/example/pokedex/ui/splash/SplashActivity.kt
@@ -1,9 +1,10 @@
-package com.example.pokedex.ui
+package com.example.pokedex.ui.splash
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
+import com.example.pokedex.ui.main.MainActivity
class SplashActivity : AppCompatActivity() {
diff --git a/app/src/main/kotlin/com/example/pokedex/utils/Constants.kt b/app/src/main/kotlin/com/example/pokedex/utils/Constants.kt
index 8fc5b8f..9b95164 100644
--- a/app/src/main/kotlin/com/example/pokedex/utils/Constants.kt
+++ b/app/src/main/kotlin/com/example/pokedex/utils/Constants.kt
@@ -2,7 +2,5 @@ package com.example.pokedex.utils
object Constants {
- const val DATABASE_NAME = "pokedex.db"
const val BASE_URL = "https://pokeapi.co/api/v2/"
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/example/pokedex/utils/Extensions.kt b/app/src/main/kotlin/com/example/pokedex/utils/Extensions.kt
index e1de5d3..5f43dde 100644
--- a/app/src/main/kotlin/com/example/pokedex/utils/Extensions.kt
+++ b/app/src/main/kotlin/com/example/pokedex/utils/Extensions.kt
@@ -14,4 +14,4 @@ fun String.formatteName() = this.replaceFirstChar {
) else it.toString()
}
-fun String.formattedImageLink() = "https://assets.pokemon.com/assets/cms2/img/pokedex/full/${this.formatteNumber()}.png"
\ No newline at end of file
+fun String.formattedImageLink() = "https://assets.pokemon.com/assets/cms2/img/pokedex/full/${this.formatteNumber()}.png"
diff --git a/app/src/main/kotlin/com/example/pokedex/utils/Resource.kt b/app/src/main/kotlin/com/example/pokedex/utils/Resource.kt
index 033d65d..e660dab 100644
--- a/app/src/main/kotlin/com/example/pokedex/utils/Resource.kt
+++ b/app/src/main/kotlin/com/example/pokedex/utils/Resource.kt
@@ -9,4 +9,3 @@ sealed class Resource (
class Loading : Resource()
class Empty : Resource()
}
-
diff --git a/app/src/main/res/drawable-v24/ic_logo.png b/app/src/main/res/drawable/ic_logo.png
similarity index 100%
rename from app/src/main/res/drawable-v24/ic_logo.png
rename to app/src/main/res/drawable/ic_logo.png
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 46b00c3..5c28cfb 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context=".ui.MainActivity">
+ tools:context=".ui.main.MainActivity">
+ tools:context=".ui.home.PokedexHomeFragment">