Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accurately Pull From Pokemon Base Stats #5

Merged
merged 5 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,45 @@
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".PokedexApp"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.PokedexCompose"
tools:ignore="AllowBackup">

<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- <provider-->
<!-- android:name="androidx.startup.InitializationProvider"-->
<!-- android:authorities="com.skydoves.pokedex.androidx-startup"-->
<!-- android:exported="false"-->
<!-- tools:node="merge">-->

<!-- <meta-data-->
<!-- android:name="com.skydoves.pokedex.initializer.TimberInitializer"-->
<!-- android:value="androidx.startup" />-->
<!-- </provider>-->

<profileable
android:shell="true"
tools:targetApi="q" />

</application>
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".PokedexApp"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.PokedexCompose"
tools:ignore="AllowBackup">

<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- <provider-->
<!-- android:name="androidx.startup.InitializationProvider"-->
<!-- android:authorities="com.skydoves.pokedex.androidx-startup"-->
<!-- android:exported="false"-->
<!-- tools:node="merge">-->

<!-- <meta-data-->
<!-- android:name="com.skydoves.pokedex.initializer.TimberInitializer"-->
<!-- android:value="androidx.startup" />-->
<!-- </provider>-->

<profileable
android:shell="true"
tools:targetApi="q" />

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "2ce2c0e046fdc408aab83eb7e475bf26",
"entities": [
{
"tableName": "PokemonEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`page` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, PRIMARY KEY(`name`))",
"fields": [
{
"fieldPath": "page",
"columnName": "page",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "url",
"columnName": "url",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"name"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "PokemonInfoEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `height` INTEGER NOT NULL, `weight` INTEGER NOT NULL, `experience` INTEGER NOT NULL, `types` TEXT NOT NULL, `exp` INTEGER NOT NULL, `stats` TEXT NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "height",
"columnName": "height",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "weight",
"columnName": "weight",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "experience",
"columnName": "experience",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "types",
"columnName": "types",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "exp",
"columnName": "exp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "stats",
"columnName": "stats",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '2ce2c0e046fdc408aab83eb7e475bf26')"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"formatVersion": 1,
"database": {
"version": 4,
"identityHash": "2ce2c0e046fdc408aab83eb7e475bf26",
"entities": [
{
"tableName": "PokemonEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`page` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, PRIMARY KEY(`name`))",
"fields": [
{
"fieldPath": "page",
"columnName": "page",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "url",
"columnName": "url",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"name"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "PokemonInfoEntity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `height` INTEGER NOT NULL, `weight` INTEGER NOT NULL, `experience` INTEGER NOT NULL, `types` TEXT NOT NULL, `exp` INTEGER NOT NULL, `stats` TEXT NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "height",
"columnName": "height",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "weight",
"columnName": "weight",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "experience",
"columnName": "experience",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "types",
"columnName": "types",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "exp",
"columnName": "exp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "stats",
"columnName": "stats",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '2ce2c0e046fdc408aab83eb7e475bf26')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import com.skydoves.pokedex.compose.core.database.entitiy.PokemonInfoEntity

@Database(
entities = [PokemonEntity::class, PokemonInfoEntity::class],
version = 2,
version = 4,
exportSchema = true,
)
@TypeConverters(value = [TypeResponseConverter::class])
@TypeConverters(value = [TypeResponseConverter::class, StatsResponseConverter::class])
abstract class PokedexDatabase : RoomDatabase() {

abstract fun pokemonDao(): PokemonDao
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Designed and developed by 2024 skydoves (Jaewoong Eum)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.skydoves.pokedex.compose.core.database

import androidx.room.ProvidedTypeConverter
import androidx.room.TypeConverter
import com.skydoves.pokedex.compose.core.model.PokemonInfo
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import javax.inject.Inject

@ProvidedTypeConverter
class StatsResponseConverter @Inject constructor(
private val moshi: Moshi,
) {

@TypeConverter
fun fromString(value: String): List<PokemonInfo.StatsResponse>? {
val listType =
Types.newParameterizedType(List::class.java, PokemonInfo.StatsResponse::class.java)
val adapter: JsonAdapter<List<PokemonInfo.StatsResponse>> = moshi.adapter(listType)
return adapter.fromJson(value)
}

@TypeConverter
fun fromInfoType(type: List<PokemonInfo.StatsResponse>?): String {
val listType =
Types.newParameterizedType(List::class.java, PokemonInfo.StatsResponse::class.java)
val adapter: JsonAdapter<List<PokemonInfo.StatsResponse>> = moshi.adapter(listType)
return adapter.toJson(type)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.room.Room
import com.skydoves.pokedex.compose.core.database.PokedexDatabase
import com.skydoves.pokedex.compose.core.database.PokemonDao
import com.skydoves.pokedex.compose.core.database.PokemonInfoDao
import com.skydoves.pokedex.compose.core.database.StatsResponseConverter
import com.skydoves.pokedex.compose.core.database.TypeResponseConverter
import com.squareup.moshi.Moshi
import dagger.Module
Expand All @@ -45,11 +46,13 @@ internal object DatabaseModule {
fun provideAppDatabase(
application: Application,
typeResponseConverter: TypeResponseConverter,
statsResponseConverter: StatsResponseConverter,
): PokedexDatabase {
return Room
.databaseBuilder(application, PokedexDatabase::class.java, "Pokedex.db")
.fallbackToDestructiveMigration()
.addTypeConverter(typeResponseConverter)
.addTypeConverter(statsResponseConverter)
.build()
}

Expand Down
Loading
Loading