Skip to content

Commit f817e27

Browse files
authored
Fix proguard issues (#118)
1 parent 6d0aa64 commit f817e27

File tree

11 files changed

+18
-25
lines changed

11 files changed

+18
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
package com.zigis.paleontologas.core.architecture
22

33
import androidx.sqlite.db.SimpleSQLiteQuery
4-
import java.lang.reflect.ParameterizedType
54

65
abstract class BaseRepository<T>(
7-
private val dao: BaseDao<T>
6+
private val dao: BaseDao<T>,
7+
private val tableName: String
88
) {
99
abstract suspend fun initialize()
1010

1111
suspend fun findOne(id: Int): T {
1212
return dao.findOne(
1313
SimpleSQLiteQuery(
14-
"SELECT * FROM ${databaseName()} WHERE id=$id"
14+
"SELECT * FROM $tableName WHERE id=$id"
1515
)
1616
)
1717
}
1818

1919
suspend fun findAll(): List<T> {
2020
return dao.findAll(
2121
SimpleSQLiteQuery(
22-
"SELECT * FROM ${databaseName()}"
22+
"SELECT * FROM $tableName"
2323
)
2424
)
2525
}
@@ -31,15 +31,8 @@ abstract class BaseRepository<T>(
3131
protected suspend fun deleteAll(): Int {
3232
return dao.deleteAll(
3333
SimpleSQLiteQuery(
34-
"DELETE FROM ${databaseName()}"
34+
"DELETE FROM $tableName"
3535
)
3636
)
3737
}
38-
39-
@Suppress("UNCHECKED_CAST")
40-
private fun databaseName(): String {
41-
val parameterizedType = javaClass.genericSuperclass as ParameterizedType
42-
val classType = parameterizedType.actualTypeArguments[0] as Class<T>
43-
return classType.simpleName.lowercase()
44-
}
4538
}

features/library/src/main/java/com/zigis/paleontologas/features/library/data/LifeForm.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.zigis.paleontologas.features.library.data
33
import androidx.room.Entity
44
import androidx.room.PrimaryKey
55

6-
@Entity
6+
@Entity(tableName = "life_forms")
77
data class LifeForm(
88
@PrimaryKey(autoGenerate = true) val id: Int,
99
val periodId: Int,

features/library/src/main/java/com/zigis/paleontologas/features/library/data/LifeFormDatabase.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class LifeFormDatabase : RoomDatabase() {
2929
return Room.databaseBuilder(
3030
context.applicationContext,
3131
LifeFormDatabase::class.java,
32-
"lifeform"
32+
"life_forms"
3333
).fallbackToDestructiveMigration().build()
3434
}
3535
}

features/library/src/main/java/com/zigis/paleontologas/features/library/data/Period.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import androidx.room.Entity
44
import androidx.room.Ignore
55
import androidx.room.PrimaryKey
66

7-
@Entity
7+
@Entity(tableName = "periods")
88
data class Period(
99
@PrimaryKey(autoGenerate = true) val id: Int,
1010
val title: String,

features/library/src/main/java/com/zigis/paleontologas/features/library/data/PeriodDatabase.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class PeriodDatabase : RoomDatabase() {
2929
return Room.databaseBuilder(
3030
context.applicationContext,
3131
PeriodDatabase::class.java,
32-
"period"
32+
"periods"
3333
).fallbackToDestructiveMigration().build()
3434
}
3535
}

features/library/src/main/java/com/zigis/paleontologas/features/library/repositories/LifeFormRepository.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import com.zigis.paleontologas.features.library.data.LifeForm
1111
class LifeFormRepository(
1212
private val context: Context,
1313
private val lifeFormDao: LifeFormDao
14-
) : BaseRepository<LifeForm>(lifeFormDao) {
14+
) : BaseRepository<LifeForm>(lifeFormDao, tableName = "life_forms") {
1515

1616
@WorkerThread
1717
override suspend fun initialize() {
@@ -408,7 +408,7 @@ class LifeFormRepository(
408408
}
409409

410410
suspend fun findAll(periodId: Int): List<LifeForm> {
411-
val query = SimpleSQLiteQuery("SELECT * FROM lifeform WHERE periodId=${periodId}")
411+
val query = SimpleSQLiteQuery("SELECT * FROM life_forms WHERE periodId=${periodId}")
412412
return findAll(query)
413413
}
414414
}

features/library/src/main/java/com/zigis/paleontologas/features/library/repositories/PeriodRepository.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.zigis.paleontologas.features.library.data.Period
1010
class PeriodRepository(
1111
private val context: Context,
1212
private val periodDao: PeriodDao
13-
) : BaseRepository<Period>(periodDao) {
13+
) : BaseRepository<Period>(periodDao, tableName = "periods") {
1414

1515
@WorkerThread
1616
override suspend fun initialize() {

features/quiz/src/main/java/com/zigis/paleontologas/features/quiz/data/Question.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import androidx.room.Entity
44
import androidx.room.Ignore
55
import androidx.room.PrimaryKey
66

7-
@Entity
7+
@Entity(tableName = "quiz_questions")
88
data class Question(
99
@PrimaryKey(autoGenerate = true) val id: Int,
1010
val periodId: Int,

features/quiz/src/main/java/com/zigis/paleontologas/features/quiz/data/QuestionDatabase.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class QuestionDatabase : RoomDatabase() {
2929
return Room.databaseBuilder(
3030
context.applicationContext,
3131
QuestionDatabase::class.java,
32-
"question"
32+
"quiz_questions"
3333
).fallbackToDestructiveMigration().build()
3434
}
3535
}

features/quiz/src/main/java/com/zigis/paleontologas/features/quiz/repositories/QuestionRepository.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import com.zigis.paleontologas.features.quiz.data.QuestionDao
1111
class QuestionRepository(
1212
private val context: Context,
1313
private val questionDao: QuestionDao
14-
) : BaseRepository<Question>(questionDao) {
14+
) : BaseRepository<Question>(questionDao, "quiz_questions") {
1515

1616
@WorkerThread
1717
override suspend fun initialize() {
@@ -40,7 +40,7 @@ class QuestionRepository(
4040
}
4141

4242
suspend fun findAll(periodId: Int): List<Question> {
43-
val query = SimpleSQLiteQuery("SELECT * FROM question WHERE periodId=${periodId}")
43+
val query = SimpleSQLiteQuery("SELECT * FROM quiz_questions WHERE periodId=${periodId}")
4444
return findAll(query)
4545
}
4646

shared.build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ android {
3030
buildTypes {
3131
release {
3232
if (this.name == 'app') {
33-
shrinkResources true
33+
shrinkResources false
34+
minifyEnabled true
3435
}
35-
minifyEnabled true
3636
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
3737
}
3838
}

0 commit comments

Comments
 (0)