Skip to content

Commit b4a8684

Browse files
committed
Add Pomodoro Timer
1 parent f2a9734 commit b4a8684

File tree

174 files changed

+4233
-1580
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+4233
-1580
lines changed

app/schemas/com.ismartcoding.plain.db.AppDatabase/5.json

Lines changed: 623 additions & 0 deletions
Large diffs are not rendered by default.

app/src/main/java/com/ismartcoding/plain/Constants.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
package com.ismartcoding.plain
22

3-
import java.util.regex.Pattern
4-
53
object Constants {
64
const val SSL_NAME = "Plain"
75
const val DATABASE_NAME = "plain.db"
8-
const val GRAY_OUT_ALPHA = 0.4F
96
const val NOTIFICATION_CHANNEL_ID = "default"
10-
const val DEFAULT_FOLDER_NAME = "SDCARD"
11-
const val CLICK_DRAG_TOLERANCE = 10f // Often, there will be a slight, unintentional, drag when the user taps the FAB, so we need to account for this.
127
const val MAX_READABLE_TEXT_FILE_SIZE = 10 * 1024 * 1024 // 10 MB
138
const val SUPPORT_EMAIL = "[email protected]"
149
const val AUTHORITY = "${BuildConfig.APPLICATION_ID}.provider"
15-
val EMAIL_PATTERN: Pattern = Pattern.compile("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}")
1610
const val LATEST_RELEASE_URL = "https://api.github.com/repos/ismartcoding/plain-app/releases/latest"
1711
const val ONE_DAY = 24 * 60 * 60L
1812
const val ONE_DAY_MS = ONE_DAY * 1000L

app/src/main/java/com/ismartcoding/plain/MainApp.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.ismartcoding.plain.enums.AppFeatureType
1212
import com.ismartcoding.plain.enums.DarkTheme
1313
import com.ismartcoding.plain.events.AcquireWakeLockEvent
1414
import com.ismartcoding.plain.events.AppEvents
15-
import com.ismartcoding.plain.features.bluetooth.BluetoothEvents
1615
import com.ismartcoding.plain.helpers.AppHelper
1716
import com.ismartcoding.plain.preference.AudioPlayModePreference
1817
import com.ismartcoding.plain.preference.CheckUpdateTimePreference
@@ -41,7 +40,6 @@ class MainApp : Application() {
4140

4241
LogCat.addLogAdapter(DiskLogAdapter(DiskLogFormatStrategy.getInstance(this)))
4342

44-
BluetoothEvents.register()
4543
AppEvents.register()
4644

4745
// https://stackoverflow.com/questions/77683434/the-getnextentry-method-of-zipinputstream-throws-a-zipexception-invalid-zip-ent

app/src/main/java/com/ismartcoding/plain/TempData.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.ismartcoding.plain
22

33
import com.ismartcoding.plain.data.DNotification
44
import com.ismartcoding.plain.enums.MediaPlayMode
5+
import com.ismartcoding.plain.ui.page.pomodoro.PomodoroState
56

67
object TempData {
78
var webEnabled = false
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.ismartcoding.plain.data
2+
3+
import com.ismartcoding.plain.ui.page.pomodoro.PomodoroState
4+
import kotlinx.serialization.Serializable
5+
6+
@Serializable
7+
data class DPomodoroSettings(
8+
val workDuration: Int = 25,
9+
val shortBreakDuration: Int = 5,
10+
val longBreakDuration: Int = 15,
11+
val pomodorosBeforeLongBreak: Int = 4,
12+
val showNotification: Boolean = true,
13+
val playSoundOnComplete: Boolean = true,
14+
) {
15+
fun getTotalSeconds(state: PomodoroState): Int {
16+
return when (state) {
17+
PomodoroState.WORK -> workDuration * 60
18+
PomodoroState.SHORT_BREAK -> shortBreakDuration * 60
19+
PomodoroState.LONG_BREAK -> longBreakDuration * 60
20+
}
21+
}
22+
23+
fun getTimeLeft(state: PomodoroState): Int {
24+
return when (state) {
25+
PomodoroState.WORK -> workDuration * 60
26+
PomodoroState.SHORT_BREAK -> shortBreakDuration * 60
27+
PomodoroState.LONG_BREAK -> longBreakDuration * 60
28+
}
29+
}
30+
}

app/src/main/java/com/ismartcoding/plain/db/AppDatabase.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class AiChatsDeletionSpec : AutoMigrationSpec
2222
entities = [
2323
DChat::class, DSession::class, DTag::class, DTagRelation::class,
2424
DNote::class, DFeed::class, DFeedEntry::class, DBook::class, DBookChapter::class,
25+
DPomodoroItem::class,
2526
],
26-
version = 4,
27+
version = 5,
2728
autoMigrations = [
2829
AutoMigration(from = 1, to = 2, spec = AppDatabase.AutoMigration1To2::class),
2930
AutoMigration(
@@ -34,6 +35,9 @@ class AiChatsDeletionSpec : AutoMigrationSpec
3435
from = 3,
3536
to = 4,
3637
spec = AiChatsDeletionSpec::class
38+
), AutoMigration(
39+
from = 4,
40+
to = 5
3741
)
3842
],
3943
exportSchema = true,
@@ -56,6 +60,8 @@ abstract class AppDatabase : RoomDatabase() {
5660

5761
abstract fun bookDao(): BookDao
5862

63+
abstract fun pomodoroItemDao(): PomodoroItemDao
64+
5965
class AutoMigration1To2 : AutoMigrationSpec {
6066

6167
}

app/src/main/java/com/ismartcoding/plain/db/DChat.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class DLinkPreview(
8080
val imageHeight: Int = 0,
8181
val siteName: String? = null,
8282
val domain: String? = null,
83-
@Transient val hasError: Boolean = false,
83+
@kotlinx.serialization.Transient val hasError: Boolean = false,
8484
val createdAt: Instant = Clock.System.now()
8585
)
8686

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.ismartcoding.plain.db
2+
3+
import androidx.room.*
4+
import com.ismartcoding.lib.helpers.StringHelper
5+
import com.ismartcoding.plain.data.IData
6+
7+
@Entity(tableName = "pomodoro_items")
8+
data class DPomodoroItem(
9+
@PrimaryKey override var id: String = StringHelper.shortUUID(),
10+
) : IData, DEntityBase() {
11+
var date: String = "" // YYYY-MM-DD format
12+
13+
@ColumnInfo(name = "completed_count")
14+
var completedCount: Int = 0
15+
16+
@ColumnInfo(name = "total_work_seconds")
17+
var totalWorkSeconds: Int = 0
18+
19+
@ColumnInfo(name = "total_break_seconds")
20+
var totalBreakSeconds: Int = 0
21+
}
22+
23+
@Dao
24+
interface PomodoroItemDao {
25+
@Query("SELECT * FROM pomodoro_items ORDER BY date DESC")
26+
fun getAll(): List<DPomodoroItem>
27+
28+
@Query("SELECT * FROM pomodoro_items WHERE date = :date")
29+
fun getByDate(date: String): DPomodoroItem?
30+
31+
@Query("SELECT * FROM pomodoro_items WHERE date >= :startDate ORDER BY date DESC LIMIT :limit")
32+
fun getRecentRecords(startDate: String, limit: Int): List<DPomodoroItem>
33+
34+
@Query("SELECT SUM(completed_count) FROM pomodoro_items")
35+
fun getTotalPomodoros(): Int?
36+
37+
@Insert(onConflict = OnConflictStrategy.REPLACE)
38+
fun insert(vararg item: DPomodoroItem)
39+
40+
@Update
41+
fun update(vararg item: DPomodoroItem)
42+
43+
@Query("DELETE FROM pomodoro_items WHERE id = :id")
44+
fun deleteById(id: String)
45+
}

app/src/main/java/com/ismartcoding/plain/enums/AppFeatureType.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum class AppFeatureType {
1818
CONTACTS,
1919
SMS,
2020
SOUND_METER,
21+
POMODORO_TIMER,
2122
NOTIFICATIONS,
2223
CHECK_UPDATES,
2324
MEDIA_TRASH;

0 commit comments

Comments
 (0)