Skip to content

Commit

Permalink
add goal type for limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Dec 15, 2024
1 parent 149f321 commit db65d82
Show file tree
Hide file tree
Showing 39 changed files with 239 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,18 +505,23 @@ class BackupRepoImpl @Inject constructor(
is RecordTypeGoal.Type.Duration -> 0L
is RecordTypeGoal.Type.Count -> 1L
}.toString()
val subtypeString = when (recordTypeGoal.subType) {
is RecordTypeGoal.Subtype.Goal -> 0L
is RecordTypeGoal.Subtype.Limit -> 1L
}.toString()
val daysOfWeekString = daysOfWeekDataLocalMapper
.mapDaysOfWeek(recordTypeGoal.daysOfWeek)

return String.format(
"$ROW_RECORD_TYPE_GOAL\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
"$ROW_RECORD_TYPE_GOAL\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
recordTypeGoal.id.toString(),
(recordTypeGoal.idData as? RecordTypeGoal.IdData.Type)?.value.orZero(),
rangeString,
typeString,
recordTypeGoal.type.value.toString(),
(recordTypeGoal.idData as? RecordTypeGoal.IdData.Category)?.value.orZero(),
daysOfWeekString,
subtypeString,
)
}

Expand Down Expand Up @@ -550,7 +555,8 @@ class BackupRepoImpl @Inject constructor(
val weeklyGoalTime = parts.getOrNull(9)?.toLongOrNull().orZero()
val monthlyGoalTime = parts.getOrNull(10)?.toLongOrNull().orZero()
// Didn't exist when goal time was in type db, no need to migrate.
val daysOfWeek = DayOfWeek.values().toList()
val daysOfWeek = DayOfWeek.entries
val subType = RecordTypeGoal.Subtype.Goal

val goalTimes = mutableListOf<RecordTypeGoal>().apply {
if (goalTime != 0L) {
Expand All @@ -559,6 +565,7 @@ class BackupRepoImpl @Inject constructor(
idData = RecordTypeGoal.IdData.Type(typeId),
range = RecordTypeGoal.Range.Session,
type = RecordTypeGoal.Type.Duration(goalTime),
subType = subType,
daysOfWeek = daysOfWeek,
).let(::add)
}
Expand All @@ -567,6 +574,7 @@ class BackupRepoImpl @Inject constructor(
idData = RecordTypeGoal.IdData.Type(typeId),
range = RecordTypeGoal.Range.Daily,
type = RecordTypeGoal.Type.Duration(dailyGoalTime),
subType = subType,
daysOfWeek = daysOfWeek,
).let(::add)
}
Expand All @@ -575,6 +583,7 @@ class BackupRepoImpl @Inject constructor(
idData = RecordTypeGoal.IdData.Type(typeId),
range = RecordTypeGoal.Range.Weekly,
type = RecordTypeGoal.Type.Duration(weeklyGoalTime),
subType = subType,
daysOfWeek = daysOfWeek,
).let(::add)
}
Expand All @@ -583,6 +592,7 @@ class BackupRepoImpl @Inject constructor(
idData = RecordTypeGoal.IdData.Type(typeId),
range = RecordTypeGoal.Range.Monthly,
type = RecordTypeGoal.Type.Duration(monthlyGoalTime),
subType = subType,
daysOfWeek = daysOfWeek,
).let(::add)
}
Expand Down Expand Up @@ -755,6 +765,13 @@ class BackupRepoImpl @Inject constructor(
else -> RecordTypeGoal.Type.Duration(value)
}
},
subType = run {
when (parts.getOrNull(8)?.toLongOrNull()) {
0L -> RecordTypeGoal.Subtype.Goal
1L -> RecordTypeGoal.Subtype.Limit
else -> RecordTypeGoal.Subtype.Goal
}
},
daysOfWeek = daysOfWeekDataLocalMapper.mapDaysOfWeek(daysOfWeekString),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import com.example.util.simpletimetracker.data_local.recordType.RecordTypeGoalDa
ComplexRuleDBO::class,
FavouriteColorDBO::class,
],
version = 23,
version = 24,
exportSchema = true,
)
abstract class AppDatabase : RoomDatabase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.util.simpletimetracker.data_local.database
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")
class AppDatabaseMigrations {

companion object {
Expand Down Expand Up @@ -30,6 +31,7 @@ class AppDatabaseMigrations {
migration_20_21,
migration_21_22,
migration_22_23,
migration_23_24,
)

private val migration_1_2 = object : Migration(1, 2) {
Expand Down Expand Up @@ -297,5 +299,13 @@ class AppDatabaseMigrations {
)
}
}

private val migration_23_24 = object : Migration(23, 24) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
"ALTER TABLE recordTypeGoals ADD COLUMN goalType INTEGER NOT NULL DEFAULT 0",
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ data class RecordTypeGoalDBO(
@ColumnInfo(name = "type")
val type: Long,

// 0 - goal
// 1 - limit
@ColumnInfo(name = "goalType")
val subType: Long,

// seconds if goal time
// count if goal count
@ColumnInfo(name = "value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class RecordTypeGoalDataLocalMapper @Inject constructor(
1L -> RecordTypeGoal.Type.Count(dbo.value)
else -> RecordTypeGoal.Type.Duration(dbo.value)
},
subType = when (dbo.subType) {
0L -> RecordTypeGoal.Subtype.Goal
1L -> RecordTypeGoal.Subtype.Limit
else -> RecordTypeGoal.Subtype.Goal
},
daysOfWeek = daysOfWeekDataLocalMapper.mapDaysOfWeek(dbo.daysOfWeek),
)
}
Expand All @@ -47,6 +52,10 @@ class RecordTypeGoalDataLocalMapper @Inject constructor(
is RecordTypeGoal.Type.Duration -> 0L
is RecordTypeGoal.Type.Count -> 1L
},
subType = when (domain.subType) {
is RecordTypeGoal.Subtype.Goal -> 0L
is RecordTypeGoal.Subtype.Limit -> 1L
},
value = domain.type.value,
categoryId = (domain.idData as? RecordTypeGoal.IdData.Category)?.value.orZero(),
daysOfWeek = daysOfWeekDataLocalMapper.mapDaysOfWeek(domain.daysOfWeek),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ data class RecordTypeGoal(
val idData: IdData,
val range: Range,
val type: Type,
val subType: Subtype,
val daysOfWeek: List<DayOfWeek>,
) {

Expand All @@ -15,12 +16,11 @@ data class RecordTypeGoal(
data class Category(override val value: Long) : IdData
}

// TODO switch to GoalTimeType
sealed interface Range {
object Session : Range
object Daily : Range
object Weekly : Range
object Monthly : Range
data object Session : Range
data object Daily : Range
data object Weekly : Range
data object Monthly : Range
}

sealed interface Type {
Expand All @@ -29,4 +29,9 @@ data class RecordTypeGoal(
data class Duration(override val value: Long) : Type
data class Count(override val value: Long) : Type
}

sealed interface Subtype {
data object Goal: Subtype
data object Limit: Subtype
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.util.simpletimetracker.feature_change_goals.api

import com.example.util.simpletimetracker.core.view.buttonsRowView.ButtonsRowViewData
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType
import com.example.util.simpletimetracker.feature_views.spinner.CustomSpinner

Expand All @@ -17,11 +18,12 @@ data class ChangeRecordTypeGoalsViewData(
val typeItems: List<CustomSpinner.CustomSpinnerItem>,
val typeSelectedPosition: Int,
val type: Type,
val subtypeItems: List<ButtonsRowViewData>,
val value: String,
)

sealed interface Type {
object Duration : Type
object Count : Type
data object Duration : Type
data object Count : Type
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.util.simpletimetracker.feature_change_goals.api

import androidx.lifecycle.LiveData
import com.example.util.simpletimetracker.core.view.buttonsRowView.ButtonsRowViewData
import com.example.util.simpletimetracker.domain.model.RecordTypeGoal
import com.example.util.simpletimetracker.feature_base_adapter.dayOfWeek.DayOfWeekViewData

Expand All @@ -14,6 +15,7 @@ interface GoalsViewModelDelegate {
fun onGoalDurationSet(tag: String?, duration: Long, anchor: Any)
fun onGoalDurationDisabled(tag: String?)
fun onGoalTypeSelected(range: RecordTypeGoal.Range, position: Int)
fun onGoalSubTypeSelected(range: RecordTypeGoal.Range, viewData: ButtonsRowViewData)
fun onGoalCountChange(range: RecordTypeGoal.Range, count: String)
fun onGoalTimeClick(range: RecordTypeGoal.Range)
fun onDayOfWeekClick(data: DayOfWeekViewData)
Expand Down
Loading

0 comments on commit db65d82

Please sign in to comment.