Skip to content
Open
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
2,978 changes: 2,978 additions & 0 deletions core/schemas/in.testpress.database.TestpressDatabase/25.json

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions core/src/main/java/in/testpress/database/Room.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ import `in`.testpress.database.roommigration.RoomMigration20To21.MIGRATION_20_21
import `in`.testpress.database.roommigration.RoomMigration21To22.MIGRATION_21_22
import `in`.testpress.database.roommigration.RoomMigration22To23.MIGRATION_22_23
import `in`.testpress.database.roommigration.RoomMigration23To24.MIGRATION_23_24
import `in`.testpress.database.roommigration.RoomMigration24To25.MIGRATION_24_25

@Database(version = 24,
@Database(version = 25,
entities = [
ContentEntity::class,
OfflineVideo::class,
Expand Down Expand Up @@ -59,7 +60,8 @@ import `in`.testpress.database.roommigration.RoomMigration23To24.MIGRATION_23_24
OfflineExam::class,
OfflineCourseAttempt::class,
OfflineAttempt::class,
OfflineAttemptSection::class
OfflineAttemptSection::class,
OfflineAttemptItem::class
], exportSchema = true)
@TypeConverters(Converters::class)
abstract class TestpressDatabase : RoomDatabase() {
Expand All @@ -84,6 +86,7 @@ abstract class TestpressDatabase : RoomDatabase() {
abstract fun offlineCourseAttemptDao():OfflineCourseAttemptDao
abstract fun offlineAttemptDao():OfflineAttemptDao
abstract fun offlineAttemptSectionDao():OfflineAttemptSectionDao
abstract fun offlineAttemptItemDoa(): OfflineAttemptItemDao

companion object {
private lateinit var INSTANCE: TestpressDatabase
Expand All @@ -92,7 +95,8 @@ abstract class TestpressDatabase : RoomDatabase() {
MIGRATION_3_4, MIGRATION_4_5, MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9,
MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13, MIGRATION_13_14,
MIGRATION_14_15, MIGRATION_15_16, MIGRATION_16_17, MIGRATION_17_18, MIGRATION_18_19,
MIGRATION_19_20, MIGRATION_20_21, MIGRATION_21_22, MIGRATION_22_23, MIGRATION_23_24
MIGRATION_19_20, MIGRATION_20_21, MIGRATION_21_22, MIGRATION_22_23, MIGRATION_23_24,
MIGRATION_24_25
)

operator fun invoke(context: Context): TestpressDatabase {
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/in/testpress/database/dao/DirectionDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package `in`.testpress.database.dao
import `in`.testpress.database.BaseDao
import `in`.testpress.database.entities.Direction
import androidx.room.Dao
import androidx.room.Query

@Dao
interface DirectionDao: BaseDao<Direction>
interface DirectionDao : BaseDao<Direction> {

@Query("SELECT * FROM Direction WHERE id = :directionId")
suspend fun getDirectionById(directionId: Long): Direction?
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ interface ExamQuestionDao: BaseDao<ExamQuestion> {

@Query("DELETE FROM ExamQuestion WHERE examId = :examId")
suspend fun deleteByExamId(examId: Long)

@Query("SELECT DISTINCT sectionId FROM ExamQuestion WHERE examId = :examId")
suspend fun getUniqueSectionIdsByExamId(examId: Long): List<Long>

@Query("SELECT * FROM ExamQuestion WHERE examId = :examId ORDER BY `order`")
suspend fun getExamQuestionsByExamId(examId: Long): List<ExamQuestion>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package `in`.testpress.database.dao

import `in`.testpress.database.BaseDao
import `in`.testpress.database.entities.OfflineAttemptItem
import `in`.testpress.models.greendao.Attempt
import androidx.room.Dao
import androidx.room.Query
import androidx.room.Update

@Dao
interface OfflineAttemptItemDao : BaseDao<OfflineAttemptItem> {

@Query("SELECT * FROM OfflineAttemptItem WHERE attemptId = :attemptId")
suspend fun getOfflineAttemptItemByAttemptId(attemptId: Long): List<OfflineAttemptItem>

@Update
suspend fun update(offlineAttemptItem: OfflineAttemptItem)

@Query("SELECT * FROM OfflineAttemptItem WHERE id = :id")
suspend fun getAttemptItemById(id: Long): OfflineAttemptItem?
}
7 changes: 6 additions & 1 deletion core/src/main/java/in/testpress/database/dao/QuestionDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package `in`.testpress.database.dao
import `in`.testpress.database.BaseDao
import `in`.testpress.database.entities.Question
import androidx.room.Dao
import androidx.room.Query

@Dao
interface QuestionDao: BaseDao<Question>
interface QuestionDao : BaseDao<Question> {

@Query("SELECT * FROM Question WHERE id = :id")
suspend fun getQuestionById(id: Long): Question?
}
7 changes: 6 additions & 1 deletion core/src/main/java/in/testpress/database/dao/SubjectDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package `in`.testpress.database.dao
import `in`.testpress.database.BaseDao
import `in`.testpress.database.entities.Subject
import androidx.room.Dao
import androidx.room.Query

@Dao
interface SubjectDao: BaseDao<Subject>
interface SubjectDao : BaseDao<Subject> {

@Query("SELECT * FROM Subject WHERE id = :subjectId")
suspend fun getSubjectById(subjectId: Long): Subject?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package `in`.testpress.database.entities

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity
data class OfflineAttemptItem(
@PrimaryKey(autoGenerate = true)
var id: Long = 0,
var question: Question,
var selectedAnswers: List<Int> = arrayListOf(),
var review: Boolean? = null,
var savedAnswers: List<Int> = arrayListOf(),
var order: Int,
var shortText: String? = null,
var currentShortText: String? = null,
var attemptSection: OfflineAttemptSection? = null,
var essayText: String? = null,
var localEssayText: String? = null,
var files: ArrayList<OfflineUserUploadedFile> = arrayListOf(),
var unSyncedFiles: List<String> = arrayListOf(),
var attemptId: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package `in`.testpress.database.entities

data class OfflineUserUploadedFile(
val id: Long? = null,
val url: String? = null,
val path: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package `in`.testpress.database.mapping

import `in`.testpress.database.entities.OfflineAttemptSection
import `in`.testpress.models.greendao.AttemptSection

fun OfflineAttemptSection?.asGreenDoaModel(): AttemptSection? {
if (this == null) return null
val attemptSection = AttemptSection()
attemptSection.id = this.id
attemptSection.state = this.state
attemptSection.questionsUrl = null
attemptSection.startUrl = null
attemptSection.endUrl = null
attemptSection.remainingTime = this.remainingTime
attemptSection.name = this.name
attemptSection.duration = this.duration
attemptSection.order = this.order
attemptSection.instructions = this.instructions
attemptSection.attemptId = this.attemptId
return attemptSection
}

fun List<OfflineAttemptSection?>.asGreenDoaModels(): List<AttemptSection?> {
return this.map {
it?.asGreenDoaModel()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package `in`.testpress.database.roommigration

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

object RoomMigration24To25 {
val MIGRATION_24_25: Migration = object : Migration(24, 25) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS `OfflineAttemptItem` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `question` TEXT NOT NULL, `selectedAnswers` TEXT NOT NULL, `review` INTEGER, `savedAnswers` TEXT NOT NULL, `order` INTEGER NOT NULL, `shortText` TEXT, `currentShortText` TEXT, `attemptSection` TEXT, `essayText` TEXT, `localEssayText` TEXT, `files` TEXT NOT NULL, `unSyncedFiles` TEXT NOT NULL, `attemptId` INTEGER NOT NULL)")
}
}
}
50 changes: 48 additions & 2 deletions core/src/main/java/in/testpress/util/Converters.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package `in`.testpress.util

import `in`.testpress.database.entities.Answer
import `in`.testpress.database.entities.OfflineAttemptSection
import `in`.testpress.database.entities.OfflineUserUploadedFile
import `in`.testpress.database.entities.Question
import androidx.room.TypeConverter
import com.google.gson.Gson
Expand Down Expand Up @@ -40,8 +42,10 @@ object Converters {

@TypeConverter
@JvmStatic
fun toIntList(value: String?): List<Int>? {
return value?.split(",")?.map { it.toInt() }
fun toIntList(value: String?): List<Int> {
if (value == null) return listOf()
if (value.isEmpty()) return listOf()
return value.split(",").map { it.toInt() }
}

@TypeConverter
Expand Down Expand Up @@ -71,4 +75,46 @@ object Converters {
val listType = object : TypeToken<ArrayList<Answer>>() {}.type
return Gson().fromJson(value, listType)
}

@TypeConverter
@JvmStatic
fun fromOfflineUserUploadedFileList(value: ArrayList<OfflineUserUploadedFile>?): String? {
val gson = Gson()
return gson.toJson(value)
}

@TypeConverter
@JvmStatic
fun toOfflineUserUploadedFileList(value: String?): ArrayList<OfflineUserUploadedFile>? {
val listType = object : TypeToken<ArrayList<OfflineUserUploadedFile>>() {}.type
return Gson().fromJson(value, listType)
}

@TypeConverter
@JvmStatic
fun fromQuestion(value: Question?): String? {
val gson = Gson()
return gson.toJson(value)
}

@TypeConverter
@JvmStatic
fun toQuestion(value: String?): Question? {
val questionType = object : TypeToken<Question>() {}.type
return Gson().fromJson(value, questionType)
}

@TypeConverter
@JvmStatic
fun fromOfflineAttemptSection(value: OfflineAttemptSection?): String? {
val gson = Gson()
return gson.toJson(value)
}

@TypeConverter
@JvmStatic
fun toOfflineAttemptSection(value: String?): OfflineAttemptSection? {
val offlineAttemptSectionType = object : TypeToken<OfflineUserUploadedFile>() {}.type
return Gson().fromJson(value, offlineAttemptSectionType)
}
}
36 changes: 0 additions & 36 deletions exam/src/main/java/in/testpress/exam/pager/TestQuestionsPager.java

This file was deleted.

Loading