File tree 11 files changed +18
-25
lines changed
core/src/main/java/com/zigis/paleontologas/core/architecture
library/src/main/java/com/zigis/paleontologas/features/library
quiz/src/main/java/com/zigis/paleontologas/features/quiz
11 files changed +18
-25
lines changed Original file line number Diff line number Diff line change 1
1
package com.zigis.paleontologas.core.architecture
2
2
3
3
import androidx.sqlite.db.SimpleSQLiteQuery
4
- import java.lang.reflect.ParameterizedType
5
4
6
5
abstract class BaseRepository <T >(
7
- private val dao : BaseDao <T >
6
+ private val dao : BaseDao <T >,
7
+ private val tableName : String
8
8
) {
9
9
abstract suspend fun initialize ()
10
10
11
11
suspend fun findOne (id : Int ): T {
12
12
return dao.findOne(
13
13
SimpleSQLiteQuery (
14
- " SELECT * FROM ${databaseName()} WHERE id=$id "
14
+ " SELECT * FROM $tableName WHERE id=$id "
15
15
)
16
16
)
17
17
}
18
18
19
19
suspend fun findAll (): List <T > {
20
20
return dao.findAll(
21
21
SimpleSQLiteQuery (
22
- " SELECT * FROM ${databaseName()} "
22
+ " SELECT * FROM $tableName "
23
23
)
24
24
)
25
25
}
@@ -31,15 +31,8 @@ abstract class BaseRepository<T>(
31
31
protected suspend fun deleteAll (): Int {
32
32
return dao.deleteAll(
33
33
SimpleSQLiteQuery (
34
- " DELETE FROM ${databaseName()} "
34
+ " DELETE FROM $tableName "
35
35
)
36
36
)
37
37
}
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
- }
45
38
}
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ package com.zigis.paleontologas.features.library.data
3
3
import androidx.room.Entity
4
4
import androidx.room.PrimaryKey
5
5
6
- @Entity
6
+ @Entity(tableName = " life_forms " )
7
7
data class LifeForm (
8
8
@PrimaryKey(autoGenerate = true ) val id : Int ,
9
9
val periodId : Int ,
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ abstract class LifeFormDatabase : RoomDatabase() {
29
29
return Room .databaseBuilder(
30
30
context.applicationContext,
31
31
LifeFormDatabase ::class .java,
32
- " lifeform "
32
+ " life_forms "
33
33
).fallbackToDestructiveMigration().build()
34
34
}
35
35
}
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import androidx.room.Entity
4
4
import androidx.room.Ignore
5
5
import androidx.room.PrimaryKey
6
6
7
- @Entity
7
+ @Entity(tableName = " periods " )
8
8
data class Period (
9
9
@PrimaryKey(autoGenerate = true ) val id : Int ,
10
10
val title : String ,
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ abstract class PeriodDatabase : RoomDatabase() {
29
29
return Room .databaseBuilder(
30
30
context.applicationContext,
31
31
PeriodDatabase ::class .java,
32
- " period "
32
+ " periods "
33
33
).fallbackToDestructiveMigration().build()
34
34
}
35
35
}
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import com.zigis.paleontologas.features.library.data.LifeForm
11
11
class LifeFormRepository (
12
12
private val context : Context ,
13
13
private val lifeFormDao : LifeFormDao
14
- ) : BaseRepository<LifeForm>(lifeFormDao) {
14
+ ) : BaseRepository<LifeForm>(lifeFormDao, tableName = " life_forms " ) {
15
15
16
16
@WorkerThread
17
17
override suspend fun initialize () {
@@ -408,7 +408,7 @@ class LifeFormRepository(
408
408
}
409
409
410
410
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} " )
412
412
return findAll(query)
413
413
}
414
414
}
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import com.zigis.paleontologas.features.library.data.Period
10
10
class PeriodRepository (
11
11
private val context : Context ,
12
12
private val periodDao : PeriodDao
13
- ) : BaseRepository<Period>(periodDao) {
13
+ ) : BaseRepository<Period>(periodDao, tableName = " periods " ) {
14
14
15
15
@WorkerThread
16
16
override suspend fun initialize () {
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import androidx.room.Entity
4
4
import androidx.room.Ignore
5
5
import androidx.room.PrimaryKey
6
6
7
- @Entity
7
+ @Entity(tableName = " quiz_questions " )
8
8
data class Question (
9
9
@PrimaryKey(autoGenerate = true ) val id : Int ,
10
10
val periodId : Int ,
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ abstract class QuestionDatabase : RoomDatabase() {
29
29
return Room .databaseBuilder(
30
30
context.applicationContext,
31
31
QuestionDatabase ::class .java,
32
- " question "
32
+ " quiz_questions "
33
33
).fallbackToDestructiveMigration().build()
34
34
}
35
35
}
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import com.zigis.paleontologas.features.quiz.data.QuestionDao
11
11
class QuestionRepository (
12
12
private val context : Context ,
13
13
private val questionDao : QuestionDao
14
- ) : BaseRepository<Question>(questionDao) {
14
+ ) : BaseRepository<Question>(questionDao, " quiz_questions " ) {
15
15
16
16
@WorkerThread
17
17
override suspend fun initialize () {
@@ -40,7 +40,7 @@ class QuestionRepository(
40
40
}
41
41
42
42
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} " )
44
44
return findAll(query)
45
45
}
46
46
Original file line number Diff line number Diff line change @@ -30,9 +30,9 @@ android {
30
30
buildTypes {
31
31
release {
32
32
if (this . name == ' app' ) {
33
- shrinkResources true
33
+ shrinkResources false
34
+ minifyEnabled true
34
35
}
35
- minifyEnabled true
36
36
proguardFiles getDefaultProguardFile(' proguard-android-optimize.txt' ), ' proguard-rules.pro'
37
37
}
38
38
}
You can’t perform that action at this time.
0 commit comments