Created
June 24, 2020 21:06
-
-
Save florianwalther-private/e57158f03a80fd55e5981a143af3505c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codinginflow.just10minutes.data | |
import android.os.Parcelable | |
import androidx.room.Entity | |
import androidx.room.PrimaryKey | |
import kotlinx.android.parcel.Parcelize | |
@Entity(tableName = "task_table") | |
@Parcelize | |
data class Task( | |
var name: String, | |
var millisGoal: Long, | |
var weekDays: List<WeekDay>, | |
var millisDoneToday: Long = 0, | |
var running: Boolean = false, | |
@PrimaryKey(autoGenerate = true) | |
var id: Int = 0 | |
) : Parcelable { | |
val millisLeftToday get() = (millisGoal - millisDoneToday) | |
val secondsLeft get() = (millisLeftToday / 1000).toInt() | |
val secondsGoal get() = (millisGoal / 1000).toInt() | |
val minutesLeft get() = (millisLeftToday / 60_000).toInt() | |
val minutesGoal get() = (millisGoal / 60_000).toInt() | |
val timeLeftFormatted: String | |
get() { | |
val second: Long = millisLeftToday / 1000 % 60 | |
val minute: Long = millisLeftToday / (1000 * 60) % 60 | |
val hour: Long = millisLeftToday / (1000 * 60 * 60) % 24 | |
return when { | |
hour > 0 -> String.format("%02d:%02d:%02d", hour, minute, second) | |
second >= 0 -> String.format("%02d:%02d", minute, second) | |
else -> String.format("%02d:%02d", 0, 0) | |
} | |
} | |
/** | |
* Rounds up to the next full minute (unless <1) and returns it in an human-readable form | |
*/ | |
val minutesLeftFormatted: String | |
get() { | |
return when { | |
millisLeftToday < 60_000 -> "<1" | |
else -> ((millisLeftToday + 30_000) / 60_000).toString() | |
} | |
} | |
enum class WeekDay { | |
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment