├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── themes.xml
│ │ │ │ └── colors.xml
│ │ │ ├── font
│ │ │ │ ├── poppins_bold.ttf
│ │ │ │ ├── poppins_light.ttf
│ │ │ │ ├── poppins_medium.ttf
│ │ │ │ └── poppins_regular.ttf
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_plus.xml
│ │ │ │ ├── ic_minus.xml
│ │ │ │ ├── ic_menu.xml
│ │ │ │ ├── ic_launcher_foreground.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ └── xml
│ │ │ │ ├── backup_rules.xml
│ │ │ │ └── data_extraction_rules.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── cirilobido
│ │ │ │ └── focustimeryt
│ │ │ │ ├── FocusTimerApp.kt
│ │ │ │ ├── presentation
│ │ │ │ ├── theme
│ │ │ │ │ ├── Color.kt
│ │ │ │ │ ├── Dimens.kt
│ │ │ │ │ ├── Type.kt
│ │ │ │ │ └── Theme.kt
│ │ │ │ ├── components
│ │ │ │ │ ├── CircleDot.kt
│ │ │ │ │ ├── InformationItem.kt
│ │ │ │ │ ├── TimerTypeItem.kt
│ │ │ │ │ ├── AutoResizedText.kt
│ │ │ │ │ ├── BorderedIcon.kt
│ │ │ │ │ └── CustomButton.kt
│ │ │ │ ├── MainActivity.kt
│ │ │ │ └── home
│ │ │ │ │ ├── HomeScreenViewModel.kt
│ │ │ │ │ └── HomeScreen.kt
│ │ │ │ ├── domain
│ │ │ │ ├── model
│ │ │ │ │ ├── Resource.kt
│ │ │ │ │ ├── TimerSessionModel.kt
│ │ │ │ │ └── TimerTypeEnum.kt
│ │ │ │ ├── repository
│ │ │ │ │ └── LocalStorageRepository.kt
│ │ │ │ └── usecase
│ │ │ │ │ ├── GetTimerSessionByDateUseCase.kt
│ │ │ │ │ └── SaveTimerSessionUseCase.kt
│ │ │ │ ├── core
│ │ │ │ └── Constants.kt
│ │ │ │ ├── data
│ │ │ │ ├── local
│ │ │ │ │ ├── AppDatabase.kt
│ │ │ │ │ ├── entity
│ │ │ │ │ │ └── TimerSessionEntity.kt
│ │ │ │ │ └── dao
│ │ │ │ │ │ └── TimerSessionDao.kt
│ │ │ │ └── repository
│ │ │ │ │ └── LocalStorageRepositoryImpl.kt
│ │ │ │ └── di
│ │ │ │ ├── RepositoryModule.kt
│ │ │ │ └── DatabaseModule.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── cirilobido
│ │ │ └── focustimeryt
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── cirilobido
│ │ └── focustimeryt
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle.kts
├── .idea
├── .name
├── .gitignore
├── compiler.xml
├── kotlinc.xml
├── vcs.xml
├── misc.xml
├── gradle.xml
└── inspectionProfiles
│ └── Project_Default.xml
├── preview
├── banner.png
├── phone_dark.png
├── phone_light.png
├── preview_red.jpg
├── tablet_dark.png
├── dimens_banner.png
├── preview_blue.jpg
├── preview_green.jpg
└── tablet_light.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── settings.gradle.kts
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Focus Timer YT
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/preview/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/preview/banner.png
--------------------------------------------------------------------------------
/preview/phone_dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/preview/phone_dark.png
--------------------------------------------------------------------------------
/preview/phone_light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/preview/phone_light.png
--------------------------------------------------------------------------------
/preview/preview_red.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/preview/preview_red.jpg
--------------------------------------------------------------------------------
/preview/tablet_dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/preview/tablet_dark.png
--------------------------------------------------------------------------------
/preview/dimens_banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/preview/dimens_banner.png
--------------------------------------------------------------------------------
/preview/preview_blue.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/preview/preview_blue.jpg
--------------------------------------------------------------------------------
/preview/preview_green.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/preview/preview_green.jpg
--------------------------------------------------------------------------------
/preview/tablet_light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/preview/tablet_light.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Focus Timer YT
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/font/poppins_bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/font/poppins_bold.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/poppins_light.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/font/poppins_light.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/poppins_medium.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/font/poppins_medium.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/poppins_regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/font/poppins_regular.ttf
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cirilobido/Focus-Timer-YT/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/FocusTimerApp.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt
2 |
3 | import android.app.Application
4 | import dagger.hilt.android.HiltAndroidApp
5 |
6 | @HiltAndroidApp
7 | class FocusTimerApp: Application() {}
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Dec 05 00:55:56 AST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/theme/Color.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation.theme
2 |
3 | import androidx.compose.ui.graphics.Color
4 |
5 | val primaryBlack = Color(0XFF000000)
6 | val primaryWhite = Color(0xFFFFFFFF)
7 | val gray = Color(0XFF888888)
8 | val lightGray = Color(0XFFCCCCCC)
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/domain/model/Resource.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.domain.model
2 |
3 | sealed class Resource(val data: T? = null, val message: String? = null) {
4 | class Loading(data: T? = null): Resource(data)
5 | class Success(data: T?): Resource(data)
6 | class Error(message: String, data: T? = null): Resource(data, message)
7 | }
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/domain/repository/LocalStorageRepository.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.domain.repository
2 |
3 | import com.cirilobido.focustimeryt.domain.model.TimerSessionModel
4 |
5 | interface LocalStorageRepository {
6 | suspend fun saveTimerSession(timerSessionModel: TimerSessionModel): Boolean
7 | suspend fun getTimerSessionByDate(date: String): TimerSessionModel
8 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_plus.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 |
16 | rootProject.name = "Focus Timer YT"
17 | include(":app")
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_minus.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/cirilobido/focustimeryt/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu.xml:
--------------------------------------------------------------------------------
1 |
6 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/core/Constants.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.core
2 |
3 | class Constants {
4 | companion object {
5 | const val FOCUS_TIME: Long = 25
6 | const val SHORT_BREAK_TIME: Long = 5
7 | const val LONG_BREAK_TIME: Long = 15
8 |
9 | const val ONE_SEC_IN_MILLIS: Long = 1000
10 | const val ONE_MIN_IN_MILLIS: Long = 60000
11 | const val ONE_MIN_IN_SEC: Int = 60
12 | const val ONE_HOUR_IN_MIN: Int = 60
13 | }
14 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/data/local/AppDatabase.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.data.local
2 |
3 | import androidx.room.Database
4 | import androidx.room.RoomDatabase
5 | import com.cirilobido.focustimeryt.data.local.dao.TimerSessionDao
6 | import com.cirilobido.focustimeryt.data.local.entity.TimerSessionEntity
7 |
8 | @Database(entities = [TimerSessionEntity::class], version = 1)
9 | abstract class AppDatabase : RoomDatabase() {
10 | abstract fun timerSessionDao(): TimerSessionDao
11 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/domain/model/TimerSessionModel.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.domain.model
2 |
3 | import com.cirilobido.focustimeryt.data.local.entity.TimerSessionEntity
4 |
5 | data class TimerSessionModel(
6 | var date: String,
7 | var value: Long,
8 | var round: Int? = 0
9 | )
10 |
11 | fun TimerSessionModel.toTimerSessionEntity(): TimerSessionEntity {
12 | return TimerSessionEntity(
13 | date = this.date,
14 | value = this.value
15 | )
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/data/local/entity/TimerSessionEntity.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.data.local.entity
2 |
3 | import androidx.room.ColumnInfo
4 | import androidx.room.Entity
5 | import androidx.room.PrimaryKey
6 |
7 | @Entity(tableName = "timer_session")
8 | data class TimerSessionEntity(
9 | @PrimaryKey(autoGenerate = true)
10 | @ColumnInfo(name = "id") var id: Int = 0,
11 | @ColumnInfo(name = "date") var date: String,
12 | @ColumnInfo(name = "value") var value: Long? = 0
13 | )
14 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/data/local/dao/TimerSessionDao.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.data.local.dao
2 |
3 | import androidx.room.Dao
4 | import androidx.room.Insert
5 | import androidx.room.OnConflictStrategy
6 | import androidx.room.Query
7 | import com.cirilobido.focustimeryt.data.local.entity.TimerSessionEntity
8 |
9 | @Dao
10 | interface TimerSessionDao {
11 | @Query("SELECT * FROM timer_session WHERE date LIKE '%' || :date || '%'")
12 | suspend fun getTimerSessionByDate(date: String): MutableList
13 |
14 | @Insert(onConflict = OnConflictStrategy.REPLACE)
15 | suspend fun insertTimerSession(timerSessionEntity: TimerSessionEntity): Long
16 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/di/RepositoryModule.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.di
2 |
3 | import com.cirilobido.focustimeryt.data.repository.LocalStorageRepositoryImpl
4 | import com.cirilobido.focustimeryt.domain.repository.LocalStorageRepository
5 | import dagger.Binds
6 | import dagger.Module
7 | import dagger.hilt.InstallIn
8 | import dagger.hilt.components.SingletonComponent
9 | import javax.inject.Singleton
10 |
11 | @Module
12 | @InstallIn(SingletonComponent::class)
13 | abstract class RepositoryModule {
14 | @Singleton
15 | @Binds
16 | abstract fun bindLocalStorageRepository(
17 | localStorageRepositoryImpl: LocalStorageRepositoryImpl
18 | ): LocalStorageRepository
19 | }
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
19 |
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/cirilobido/focustimeryt/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.cirilobido.focustimeryt", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/domain/model/TimerTypeEnum.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.domain.model
2 |
3 | import com.cirilobido.focustimeryt.core.Constants.Companion.FOCUS_TIME
4 | import com.cirilobido.focustimeryt.core.Constants.Companion.LONG_BREAK_TIME
5 | import com.cirilobido.focustimeryt.core.Constants.Companion.ONE_MIN_IN_SEC
6 | import com.cirilobido.focustimeryt.core.Constants.Companion.ONE_SEC_IN_MILLIS
7 | import com.cirilobido.focustimeryt.core.Constants.Companion.SHORT_BREAK_TIME
8 |
9 | enum class TimerTypeEnum(val title: String, private val time: Long) {
10 | FOCUS("Focus Time", FOCUS_TIME),
11 | SHORT_BREAK("Short Break", SHORT_BREAK_TIME),
12 | LONG_BREAK("Long Break", LONG_BREAK_TIME);
13 |
14 | fun timeToMillis(): Long {
15 | return time * ONE_MIN_IN_SEC * ONE_SEC_IN_MILLIS
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/di/DatabaseModule.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.di
2 |
3 | import android.content.Context
4 | import androidx.room.Room
5 | import com.cirilobido.focustimeryt.data.local.AppDatabase
6 | import dagger.Module
7 | import dagger.Provides
8 | import dagger.hilt.InstallIn
9 | import dagger.hilt.android.qualifiers.ApplicationContext
10 | import dagger.hilt.components.SingletonComponent
11 | import javax.inject.Singleton
12 |
13 | @Module
14 | @InstallIn(SingletonComponent::class)
15 | class DatabaseModule {
16 |
17 | @Singleton
18 | @Provides
19 | fun provideRoomDatabase(@ApplicationContext appContext: Context): AppDatabase {
20 | return Room.databaseBuilder(
21 | appContext,
22 | AppDatabase::class.java, "focus_timer_database"
23 | ).build()
24 | }
25 |
26 | @Singleton
27 | @Provides
28 | fun provideTimerSessionDao(db: AppDatabase) = db.timerSessionDao()
29 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/domain/usecase/GetTimerSessionByDateUseCase.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.domain.usecase
2 |
3 | import com.cirilobido.focustimeryt.domain.model.Resource
4 | import com.cirilobido.focustimeryt.domain.model.TimerSessionModel
5 | import com.cirilobido.focustimeryt.domain.repository.LocalStorageRepository
6 | import kotlinx.coroutines.flow.Flow
7 | import kotlinx.coroutines.flow.flow
8 | import javax.inject.Inject
9 |
10 | class GetTimerSessionByDateUseCase @Inject constructor(
11 | private val repository: LocalStorageRepository
12 | ) {
13 | operator fun invoke(date: String): Flow> = flow {
14 | try {
15 | emit(Resource.Loading())
16 | emit(
17 | Resource.Success(
18 | data = repository.getTimerSessionByDate(date)
19 | )
20 | )
21 | } catch (e: Exception) {
22 | emit(
23 | Resource.Error(e.message ?: "Unknown Error")
24 | )
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/domain/usecase/SaveTimerSessionUseCase.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.domain.usecase
2 |
3 | import com.cirilobido.focustimeryt.domain.model.Resource
4 | import com.cirilobido.focustimeryt.domain.model.TimerSessionModel
5 | import com.cirilobido.focustimeryt.domain.repository.LocalStorageRepository
6 | import kotlinx.coroutines.flow.Flow
7 | import kotlinx.coroutines.flow.flow
8 | import javax.inject.Inject
9 |
10 | class SaveTimerSessionUseCase @Inject constructor(
11 | private val repository: LocalStorageRepository
12 | ) {
13 | operator fun invoke(timerSessionModel: TimerSessionModel): Flow> = flow {
14 | try {
15 | emit(Resource.Loading())
16 | emit(
17 | Resource.Success(
18 | data = repository.saveTimerSession(timerSessionModel)
19 | )
20 | )
21 | } catch (e: Exception) {
22 | emit(
23 | Resource.Error(e.message ?: "Unknown Error")
24 | )
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/theme/Dimens.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation.theme
2 |
3 | import androidx.compose.ui.unit.Dp
4 | import androidx.compose.ui.unit.dp
5 |
6 | data class Dimens(
7 | val borderNormal: Dp = 4.dp,
8 | val buttonHeightNormal: Dp = 56.dp,
9 | val iconSizeSmall: Dp = 24.dp,
10 | val iconSizeNormal: Dp = 36.dp,
11 | val paddingSmall: Dp = 4.dp,
12 | val paddingNormal: Dp = 8.dp,
13 | val paddingMedium: Dp = 16.dp,
14 | val roundedShapeNormal: Dp = 8.dp,
15 | val spacerSmall: Dp = 4.dp,
16 | val spacerNormal: Dp = 8.dp,
17 | val spacerMedium: Dp = 16.dp,
18 | val spacerLarge: Dp = 40.dp,
19 | )
20 |
21 | val DefaultDimens = Dimens()
22 |
23 | val TabletDimens = Dimens(
24 | buttonHeightNormal = 64.dp,
25 | iconSizeSmall = 36.dp,
26 | iconSizeNormal = 48.dp,
27 | paddingSmall = 8.dp,
28 | paddingNormal = 16.dp,
29 | paddingMedium = 24.dp,
30 | roundedShapeNormal = 16.dp,
31 | spacerSmall = 8.dp,
32 | spacerNormal = 16.dp,
33 | spacerMedium = 24.dp,
34 | spacerLarge = 56.dp,
35 | )
36 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
16 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/components/CircleDot.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation.components
2 |
3 | import androidx.compose.foundation.background
4 | import androidx.compose.foundation.layout.Box
5 | import androidx.compose.foundation.layout.size
6 | import androidx.compose.foundation.shape.CircleShape
7 | import androidx.compose.material3.MaterialTheme
8 | import androidx.compose.runtime.Composable
9 | import androidx.compose.ui.Modifier
10 | import androidx.compose.ui.draw.clip
11 | import androidx.compose.ui.graphics.Color
12 | import androidx.compose.ui.tooling.preview.Preview
13 | import com.cirilobido.focustimeryt.presentation.theme.FocusTimerYTTheme
14 |
15 | @Composable
16 | fun CircleDot(
17 | modifier: Modifier = Modifier,
18 | color: Color = MaterialTheme.colorScheme.primary
19 | ) {
20 | Box(
21 | modifier = modifier
22 | .size(FocusTimerYTTheme.dimens.iconSizeSmall)
23 | .clip(shape = CircleShape)
24 | .background(color)
25 | )
26 | }
27 |
28 | @Preview(
29 | name = "CircleDotPreview",
30 | showBackground = true,
31 | )
32 | @Composable
33 | fun CircleDotPreview() {
34 | FocusTimerYTTheme {
35 | CircleDot()
36 | }
37 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/components/InformationItem.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation.components
2 |
3 | import androidx.compose.foundation.layout.Column
4 | import androidx.compose.foundation.layout.fillMaxWidth
5 | import androidx.compose.material3.MaterialTheme
6 | import androidx.compose.material3.Text
7 | import androidx.compose.runtime.Composable
8 | import androidx.compose.ui.Modifier
9 | import androidx.compose.ui.tooling.preview.Preview
10 | import com.cirilobido.focustimeryt.presentation.theme.FocusTimerYTTheme
11 |
12 | @Composable
13 | fun InformationItem(
14 | modifier: Modifier = Modifier,
15 | text: String,
16 | label: String
17 | ) {
18 | Column(
19 | modifier = modifier
20 | ) {
21 | Text(
22 | text = text,
23 | modifier = Modifier.fillMaxWidth(),
24 | style = MaterialTheme.typography.bodyLarge,
25 | color = MaterialTheme.colorScheme.primary
26 | )
27 | Text(
28 | text = label,
29 | modifier = Modifier.fillMaxWidth(),
30 | style = MaterialTheme.typography.bodyLarge,
31 | color = MaterialTheme.colorScheme.secondary
32 | )
33 | }
34 | }
35 |
36 | @Preview(
37 | name = "InformationItemPreview",
38 | showBackground = true,
39 | )
40 | @Composable
41 | fun InformationItemPreview() {
42 | FocusTimerYTTheme {
43 | InformationItem(text = "35", label = "today round")
44 | }
45 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/data/repository/LocalStorageRepositoryImpl.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.data.repository
2 |
3 | import com.cirilobido.focustimeryt.data.local.dao.TimerSessionDao
4 | import com.cirilobido.focustimeryt.domain.model.TimerSessionModel
5 | import com.cirilobido.focustimeryt.domain.model.toTimerSessionEntity
6 | import com.cirilobido.focustimeryt.domain.repository.LocalStorageRepository
7 | import javax.inject.Inject
8 |
9 | class LocalStorageRepositoryImpl @Inject constructor(
10 | private val timerSessionDao: TimerSessionDao
11 | ) : LocalStorageRepository {
12 | override suspend fun saveTimerSession(timerSessionModel: TimerSessionModel): Boolean {
13 | try {
14 | val result =
15 | timerSessionDao.insertTimerSession(timerSessionModel.toTimerSessionEntity())
16 | return result.toInt() != -1
17 | } catch (e: Exception) {
18 | throw e
19 | }
20 | }
21 |
22 | override suspend fun getTimerSessionByDate(date: String): TimerSessionModel {
23 | try {
24 | var timerValue: Long = 0
25 | var rounds = 0
26 | timerSessionDao.getTimerSessionByDate(date).map { session ->
27 | timerValue += session.value ?: 0
28 | rounds += 1
29 | }
30 | return TimerSessionModel(
31 | date = date,
32 | value = timerValue,
33 | round = rounds
34 | )
35 | } catch (e: Exception) {
36 | throw e
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation
2 |
3 | import android.os.Bundle
4 | import androidx.activity.ComponentActivity
5 | import androidx.activity.compose.setContent
6 | import androidx.compose.foundation.layout.fillMaxSize
7 | import androidx.compose.material3.MaterialTheme
8 | import androidx.compose.material3.Surface
9 | import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
10 | import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
11 | import androidx.compose.ui.Modifier
12 | import com.cirilobido.focustimeryt.presentation.home.HomeScreen
13 | import com.cirilobido.focustimeryt.presentation.theme.FocusTimerYTTheme
14 | import dagger.hilt.android.AndroidEntryPoint
15 |
16 | @AndroidEntryPoint
17 | class MainActivity : ComponentActivity() {
18 | @OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
19 | override fun onCreate(savedInstanceState: Bundle?) {
20 | super.onCreate(savedInstanceState)
21 | setContent {
22 | val windowSize = calculateWindowSizeClass(this)
23 | FocusTimerYTTheme(
24 | windowSize = windowSize.widthSizeClass
25 | ) {
26 | // A surface container using the 'background' color from the theme
27 | Surface(
28 | modifier = Modifier.fillMaxSize(),
29 | color = MaterialTheme.colorScheme.surface
30 | ) {
31 | HomeScreen()
32 | }
33 | }
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | **Focus Timer** es una app Android creada para el [**Curso Android Desde Cero**](https://www.youtube.com/playlist?list=PLKzZ68VT1_2pH0O47HQsDmzLrIFh0YsF1).
4 |
5 | > **Herramientas:** **Jetpack Compose,** **Android Native**, **Kotlin**, **Clean Code**, **MVVM**, **ROOM**, **TESTING**, **Clean Architecture**, **Theme**
6 |
7 | > **Inspiración de Diseño:** **[Diseño](https://dribbble.com/shots/16055446-Focus-Timer)**
8 |
9 | > **Recursos:** **[Recursos del Projecto, Fuentes e Iconos](https://drive.google.com/drive/folders/1yNw0V8__bb86FDv-Mq5mfEPQpgWBmFg4)**
10 |
11 | ### Preview
12 | **Phone Portrait Preview:**
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | **Tablet Portrait Preview:**
25 |
26 |
27 |
28 |
29 |
30 | ### Cirilo Bido - Android Developer
31 | [](https://twitter.com/cirilobido)
32 | 
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/theme/Type.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation.theme
2 |
3 | import androidx.compose.material3.Typography
4 | import androidx.compose.ui.text.TextStyle
5 | import androidx.compose.ui.text.font.Font
6 | import androidx.compose.ui.text.font.FontFamily
7 | import androidx.compose.ui.text.font.FontWeight
8 | import androidx.compose.ui.text.style.TextAlign
9 | import androidx.compose.ui.unit.sp
10 | import com.cirilobido.focustimeryt.R
11 |
12 | val PoppinsFont = FontFamily(
13 | Font(R.font.poppins_bold, FontWeight.Bold),
14 | Font(R.font.poppins_medium, FontWeight.SemiBold),
15 | Font(R.font.poppins_regular, FontWeight.Normal),
16 | Font(R.font.poppins_light, FontWeight.Light),
17 | )
18 | // Set of Material typography styles to start with
19 | val Typography = Typography(
20 | displayLarge = TextStyle(
21 | fontFamily = PoppinsFont,
22 | fontWeight = FontWeight.Bold,
23 | fontSize = 88.sp,
24 | lineHeight = 0.sp,
25 | letterSpacing = 0.5.sp
26 | ),
27 | displayMedium = TextStyle(
28 | fontFamily = PoppinsFont,
29 | fontWeight = FontWeight.Bold,
30 | fontSize = 56.sp,
31 | lineHeight = 24.sp,
32 | letterSpacing = 0.5.sp
33 | ),
34 | bodyLarge = TextStyle(
35 | fontFamily = PoppinsFont,
36 | fontWeight = FontWeight.Bold,
37 | fontSize = 16.sp,
38 | lineHeight = 20.sp,
39 | letterSpacing = 0.5.sp,
40 | textAlign = TextAlign.Center
41 | ),
42 | bodyMedium = TextStyle(
43 | fontFamily = PoppinsFont,
44 | fontWeight = FontWeight.Bold,
45 | fontSize = 12.sp,
46 | lineHeight = 16.sp,
47 | letterSpacing = 0.5.sp,
48 | textAlign = TextAlign.Center
49 | ),
50 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/components/TimerTypeItem.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation.components
2 |
3 | import androidx.compose.foundation.clickable
4 | import androidx.compose.foundation.layout.Box
5 | import androidx.compose.foundation.layout.fillMaxSize
6 | import androidx.compose.foundation.layout.fillMaxWidth
7 | import androidx.compose.foundation.layout.padding
8 | import androidx.compose.material3.MaterialTheme
9 | import androidx.compose.material3.Text
10 | import androidx.compose.runtime.Composable
11 | import androidx.compose.ui.Alignment
12 | import androidx.compose.ui.Modifier
13 | import androidx.compose.ui.graphics.Color
14 | import androidx.compose.ui.tooling.preview.Preview
15 | import com.cirilobido.focustimeryt.presentation.theme.FocusTimerYTTheme
16 |
17 | @Composable
18 | fun TimerTypeItem(
19 | modifier: Modifier = Modifier,
20 | text: String,
21 | textColor: Color,
22 | onTap: () -> Unit = {}
23 | ) {
24 | Box(
25 | modifier = modifier
26 | .fillMaxSize()
27 | .padding(FocusTimerYTTheme.dimens.paddingSmall)
28 | .clickable { onTap() },
29 | contentAlignment = Alignment.Center
30 | ) {
31 | Text(
32 | text,
33 | modifier = Modifier
34 | .fillMaxWidth()
35 | .align(Alignment.Center),
36 | style = MaterialTheme.typography.bodyMedium,
37 | color = textColor
38 | )
39 | }
40 | }
41 |
42 | @Preview(
43 | name = "TimerTypeItemPreview",
44 | showBackground = true,
45 | )
46 | @Composable
47 | fun TimerTypeItemPreview() {
48 | FocusTimerYTTheme {
49 | TimerTypeItem(
50 | text = "Focus",
51 | textColor = MaterialTheme.colorScheme.primary
52 | )
53 | }
54 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/components/AutoResizedText.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation.components
2 |
3 | import androidx.compose.foundation.layout.fillMaxWidth
4 | import androidx.compose.material3.MaterialTheme
5 | import androidx.compose.material3.Text
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.runtime.getValue
8 | import androidx.compose.runtime.mutableStateOf
9 | import androidx.compose.runtime.remember
10 | import androidx.compose.runtime.setValue
11 | import androidx.compose.ui.Modifier
12 | import androidx.compose.ui.text.TextStyle
13 | import androidx.compose.ui.tooling.preview.Preview
14 | import com.cirilobido.focustimeryt.presentation.theme.FocusTimerYTTheme
15 |
16 | @Composable
17 | fun AutoResizedText(
18 | modifier: Modifier = Modifier,
19 | text: String,
20 | textStyle: TextStyle = MaterialTheme.typography.displayLarge,
21 | ) {
22 | var timeTextStyle by remember { mutableStateOf(textStyle) }
23 | val fontSizeFactor = 0.95
24 | Text(
25 | text,
26 | modifier = modifier.fillMaxWidth(),
27 | softWrap = false,
28 | style = timeTextStyle,
29 | onTextLayout = { result ->
30 | if (result.didOverflowWidth) {
31 | timeTextStyle = timeTextStyle.copy(
32 | fontSize = timeTextStyle.fontSize * fontSizeFactor
33 | )
34 | }
35 | }
36 | )
37 | }
38 |
39 | // 1-Preview Annotation
40 | @Preview(
41 | name = "AutoResizedTextPreview",
42 | showBackground = true,
43 | )
44 | // 2- Composable for the preview
45 | @Composable
46 | fun AutoResizedTextPreview() {
47 | // 3-Theme
48 | FocusTimerYTTheme {
49 | // 4-Composable to preview
50 | AutoResizedText(
51 | text = "Focus Timer"
52 | )
53 | }
54 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/components/BorderedIcon.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation.components
2 |
3 | import androidx.annotation.DrawableRes
4 | import androidx.compose.foundation.border
5 | import androidx.compose.foundation.clickable
6 | import androidx.compose.foundation.layout.padding
7 | import androidx.compose.foundation.layout.size
8 | import androidx.compose.foundation.shape.CircleShape
9 | import androidx.compose.material3.Icon
10 | import androidx.compose.material3.MaterialTheme
11 | import androidx.compose.runtime.Composable
12 | import androidx.compose.ui.Modifier
13 | import androidx.compose.ui.graphics.vector.ImageVector
14 | import androidx.compose.ui.res.vectorResource
15 | import androidx.compose.ui.tooling.preview.Preview
16 | import com.cirilobido.focustimeryt.R
17 | import com.cirilobido.focustimeryt.presentation.theme.FocusTimerYTTheme
18 |
19 | @Composable
20 | fun BorderedIcon(
21 | modifier: Modifier = Modifier,
22 | @DrawableRes icon: Int,
23 | onTap: () -> Unit = {}
24 | ) {
25 | Icon(
26 | modifier = modifier
27 | .size(FocusTimerYTTheme.dimens.iconSizeNormal)
28 | .border(
29 | width = FocusTimerYTTheme.dimens.borderNormal,
30 | color = MaterialTheme.colorScheme.primary,
31 | shape = CircleShape
32 | )
33 | .padding(FocusTimerYTTheme.dimens.paddingSmall)
34 | .clickable { onTap() },
35 | imageVector = ImageVector.vectorResource(id = icon),
36 | contentDescription = null,
37 | tint = MaterialTheme.colorScheme.primary
38 | )
39 | }
40 |
41 | @Preview(
42 | name = "BorderedIconPreview",
43 | showBackground = true,
44 | )
45 | @Composable
46 | fun BorderedIconPreview() {
47 | FocusTimerYTTheme {
48 | BorderedIcon(
49 | icon = R.drawable.ic_launcher_background
50 | )
51 | }
52 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/components/CustomButton.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation.components
2 |
3 | import androidx.compose.foundation.layout.fillMaxWidth
4 | import androidx.compose.foundation.layout.height
5 | import androidx.compose.foundation.shape.RoundedCornerShape
6 | import androidx.compose.material3.Button
7 | import androidx.compose.material3.ButtonDefaults
8 | import androidx.compose.material3.MaterialTheme
9 | import androidx.compose.material3.Text
10 | import androidx.compose.runtime.Composable
11 | import androidx.compose.ui.Alignment
12 | import androidx.compose.ui.Modifier
13 | import androidx.compose.ui.graphics.Color
14 | import androidx.compose.ui.tooling.preview.Preview
15 | import com.cirilobido.focustimeryt.presentation.theme.FocusTimerYTTheme
16 |
17 | @Composable
18 | fun CustomButton(
19 | modifier: Modifier = Modifier,
20 | text: String,
21 | textColor: Color,
22 | buttonColor: Color,
23 | onTap: () -> Unit = {}
24 | ) {
25 | Button(
26 | modifier = modifier
27 | .height(FocusTimerYTTheme.dimens.buttonHeightNormal),
28 | shape = RoundedCornerShape(FocusTimerYTTheme.dimens.roundedShapeNormal),
29 | colors = ButtonDefaults.buttonColors(
30 | containerColor = buttonColor
31 | ),
32 | onClick = { onTap() },
33 | ) {
34 | Text(
35 | text = text,
36 | modifier = Modifier
37 | .fillMaxWidth()
38 | .align(Alignment.CenterVertically),
39 | style = MaterialTheme.typography.bodyLarge,
40 | color = textColor
41 | )
42 | }
43 | }
44 |
45 | @Preview(
46 | name = "CustomButtonPreview",
47 | showBackground = true,
48 | )
49 | @Composable
50 | fun CustomButtonPreview() {
51 | FocusTimerYTTheme {
52 | CustomButton(
53 | text = "Start",
54 | textColor = MaterialTheme.colorScheme.surface,
55 | buttonColor = MaterialTheme.colorScheme.primary
56 | )
57 | }
58 | }
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.application")
3 | id("org.jetbrains.kotlin.android")
4 | id("kotlin-kapt")
5 | id("com.google.dagger.hilt.android")
6 | }
7 |
8 | android {
9 | namespace = "com.cirilobido.focustimeryt"
10 | compileSdk = 34
11 |
12 | defaultConfig {
13 | applicationId = "com.cirilobido.focustimeryt"
14 | minSdk = 24
15 | targetSdk = 33
16 | versionCode = 1
17 | versionName = "1.0"
18 |
19 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
20 | vectorDrawables {
21 | useSupportLibrary = true
22 | }
23 | }
24 |
25 | buildTypes {
26 | release {
27 | isMinifyEnabled = false
28 | proguardFiles(
29 | getDefaultProguardFile("proguard-android-optimize.txt"),
30 | "proguard-rules.pro"
31 | )
32 | }
33 | }
34 | compileOptions {
35 | sourceCompatibility = JavaVersion.VERSION_17
36 | targetCompatibility = JavaVersion.VERSION_17
37 | }
38 | kotlinOptions {
39 | jvmTarget = JavaVersion.VERSION_17.toString()
40 | }
41 | buildFeatures {
42 | compose = true
43 | }
44 | composeOptions {
45 | kotlinCompilerExtensionVersion = "1.4.3"
46 | }
47 | packaging {
48 | resources {
49 | excludes += "/META-INF/{AL2.0,LGPL2.1}"
50 | }
51 | }
52 | kapt {
53 | correctErrorTypes = true
54 | }
55 | }
56 |
57 | dependencies {
58 |
59 | implementation("androidx.core:core-ktx:1.9.0")
60 | implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
61 | // VIEWMODEL
62 | implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2")
63 | implementation("androidx.activity:activity-compose:1.8.1")
64 | implementation(platform("androidx.compose:compose-bom:2023.03.00"))
65 | implementation("androidx.compose.material3:material3-window-size-class")
66 | implementation("androidx.compose.ui:ui")
67 | implementation("androidx.compose.ui:ui-graphics")
68 | implementation("androidx.compose.ui:ui-tooling-preview")
69 | implementation("androidx.compose.material3:material3")
70 | // Hilt
71 | implementation("com.google.dagger:hilt-android:2.44")
72 | kapt("com.google.dagger:hilt-android-compiler:2.44")
73 | implementation("androidx.hilt:hilt-navigation-compose:1.2.0")
74 |
75 | // Room
76 | implementation("androidx.room:room-runtime:2.6.1")
77 | implementation("androidx.room:room-ktx:2.6.1")
78 | kapt("androidx.room:room-compiler:2.6.1")
79 |
80 | testImplementation("junit:junit:4.13.2")
81 | androidTestImplementation("androidx.test.ext:junit:1.1.5")
82 | androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
83 | androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
84 | androidTestImplementation("androidx.compose.ui:ui-test-junit4")
85 | debugImplementation("androidx.compose.ui:ui-tooling")
86 | debugImplementation("androidx.compose.ui:ui-test-manifest")
87 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation.theme
2 |
3 | import android.app.Activity
4 | import android.os.Build
5 | import androidx.compose.foundation.isSystemInDarkTheme
6 | import androidx.compose.material3.MaterialTheme
7 | import androidx.compose.material3.darkColorScheme
8 | import androidx.compose.material3.dynamicDarkColorScheme
9 | import androidx.compose.material3.dynamicLightColorScheme
10 | import androidx.compose.material3.lightColorScheme
11 | import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
12 | import androidx.compose.runtime.Composable
13 | import androidx.compose.runtime.CompositionLocalProvider
14 | import androidx.compose.runtime.ReadOnlyComposable
15 | import androidx.compose.runtime.SideEffect
16 | import androidx.compose.runtime.remember
17 | import androidx.compose.runtime.staticCompositionLocalOf
18 | import androidx.compose.ui.graphics.toArgb
19 | import androidx.compose.ui.platform.LocalContext
20 | import androidx.compose.ui.platform.LocalView
21 | import androidx.core.view.WindowCompat
22 |
23 | private val DarkColorScheme = darkColorScheme(
24 | primary = primaryWhite,
25 | secondary = gray,
26 | tertiary = lightGray,
27 | surface = primaryBlack,
28 | background = primaryBlack
29 | )
30 |
31 | private val LightColorScheme = lightColorScheme(
32 | primary = primaryBlack,
33 | secondary = gray,
34 | tertiary = lightGray,
35 | surface = primaryWhite,
36 | background = primaryWhite
37 | )
38 |
39 | private val LocalDimens = staticCompositionLocalOf { DefaultDimens }
40 |
41 | @Composable
42 | fun ProvideDimens(
43 | dimens: Dimens,
44 | content: @Composable () -> Unit
45 | ){
46 | val dimensionSet = remember { dimens }
47 | CompositionLocalProvider(LocalDimens provides dimensionSet, content = content)
48 | }
49 |
50 | @Composable
51 | fun FocusTimerYTTheme(
52 | darkTheme: Boolean = isSystemInDarkTheme(),
53 | // Dynamic color is available on Android 12+
54 | dynamicColor: Boolean = true,
55 | windowSize: WindowWidthSizeClass = WindowWidthSizeClass.Compact,
56 | content: @Composable () -> Unit
57 | ) {
58 | val colorScheme = when {
59 | dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
60 | val context = LocalContext.current
61 | if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
62 | }
63 |
64 | darkTheme -> DarkColorScheme
65 | else -> LightColorScheme
66 | }
67 | val view = LocalView.current
68 | if (!view.isInEditMode) {
69 | SideEffect {
70 | val window = (view.context as Activity).window
71 | window.statusBarColor = colorScheme.primary.toArgb()
72 | WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
73 | }
74 | }
75 |
76 | val dimensions = if (windowSize > WindowWidthSizeClass.Compact)
77 | TabletDimens
78 | else
79 | DefaultDimens
80 |
81 | ProvideDimens(dimens = dimensions) {
82 | MaterialTheme(
83 | colorScheme = colorScheme,
84 | typography = Typography,
85 | content = content
86 | )
87 | }
88 | }
89 |
90 | object FocusTimerYTTheme {
91 | val dimens: Dimens
92 | @Composable
93 | @ReadOnlyComposable
94 | get() = LocalDimens.current
95 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/home/HomeScreenViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation.home
2 |
3 | import android.annotation.SuppressLint
4 | import android.os.CountDownTimer
5 | import androidx.compose.runtime.mutableStateOf
6 | import androidx.lifecycle.ViewModel
7 | import androidx.lifecycle.viewModelScope
8 | import com.cirilobido.focustimeryt.core.Constants.Companion.ONE_HOUR_IN_MIN
9 | import com.cirilobido.focustimeryt.core.Constants.Companion.ONE_MIN_IN_MILLIS
10 | import com.cirilobido.focustimeryt.core.Constants.Companion.ONE_MIN_IN_SEC
11 | import com.cirilobido.focustimeryt.core.Constants.Companion.ONE_SEC_IN_MILLIS
12 | import com.cirilobido.focustimeryt.domain.model.Resource
13 | import com.cirilobido.focustimeryt.domain.model.TimerSessionModel
14 | import com.cirilobido.focustimeryt.domain.model.TimerTypeEnum
15 | import com.cirilobido.focustimeryt.domain.usecase.GetTimerSessionByDateUseCase
16 | import com.cirilobido.focustimeryt.domain.usecase.SaveTimerSessionUseCase
17 | import dagger.hilt.android.lifecycle.HiltViewModel
18 | import kotlinx.coroutines.flow.launchIn
19 | import kotlinx.coroutines.flow.onEach
20 | import kotlinx.coroutines.launch
21 | import java.text.SimpleDateFormat
22 | import java.util.Calendar
23 | import javax.inject.Inject
24 |
25 | @HiltViewModel
26 | class HomeScreenViewModel @Inject constructor(
27 | private val getTimerSessionByDateUseCase: GetTimerSessionByDateUseCase,
28 | private val saveTimerSessionUseCase: SaveTimerSessionUseCase
29 | ) : ViewModel() {
30 | private lateinit var timer: CountDownTimer
31 |
32 | private var isTimerActive: Boolean = false
33 |
34 | private val _timerValue = mutableStateOf(TimerTypeEnum.FOCUS.timeToMillis())
35 | val timerValueState = _timerValue
36 |
37 | private val _timerTypeState = mutableStateOf(TimerTypeEnum.FOCUS)
38 | val timerTypeState = _timerTypeState
39 |
40 | private val _roundsState = mutableStateOf(0)
41 | val roundsState = _roundsState
42 |
43 | private val _todayTimeState = mutableStateOf(0)
44 | val todayTimeState = _todayTimeState
45 |
46 | var _sessionTimerValue: Long = 0
47 |
48 | fun onStartTimer() {
49 | viewModelScope.launch {
50 | timer = object : CountDownTimer(
51 | _timerValue.value,
52 | ONE_SEC_IN_MILLIS
53 | ) {
54 | override fun onTick(millisUntilFinished: Long) {
55 | _timerValue.value = millisUntilFinished
56 | _todayTimeState.value += ONE_SEC_IN_MILLIS
57 | _sessionTimerValue += ONE_SEC_IN_MILLIS
58 | }
59 |
60 | override fun onFinish() {
61 | onCancelTimer()
62 | }
63 | }
64 | timer.start().also {
65 | if (!isTimerActive) _roundsState.value += 1
66 | _sessionTimerValue = 0
67 | isTimerActive = true
68 | }
69 | }
70 | }
71 |
72 | fun onCancelTimer(reset: Boolean = false) {
73 | try {
74 | saveTimerSession()
75 | timer.cancel()
76 | } catch (_: UninitializedPropertyAccessException) {
77 | // Handle better the timer error
78 | }
79 | if (!isTimerActive || reset) {
80 | _timerValue.value = _timerTypeState.value.timeToMillis()
81 | }
82 | isTimerActive = false
83 | }
84 |
85 | private fun onResetTime() {
86 | if (isTimerActive) {
87 | onCancelTimer()
88 | onStartTimer()
89 | }
90 | }
91 |
92 | fun onUpdateType(timerType: TimerTypeEnum) {
93 | _timerTypeState.value = timerType
94 | onCancelTimer(true)
95 | }
96 |
97 | fun onIncreaseTime() {
98 | _timerValue.value += ONE_MIN_IN_MILLIS
99 | onResetTime()
100 | }
101 |
102 | fun onDecreaseTime() {
103 | _timerValue.value -= ONE_MIN_IN_MILLIS
104 | onResetTime()
105 | if (_timerValue.value < 0) {
106 | onCancelTimer()
107 | }
108 | }
109 |
110 | fun getTimerSessionByDate() {
111 | getTimerSessionByDateUseCase(date = getCurrentDate()).onEach { result ->
112 | if (result is Resource.Success) {
113 | _roundsState.value = result.data?.round ?: 0
114 | _todayTimeState.value = result.data?.value ?: 0
115 | }
116 | }.launchIn(viewModelScope)
117 | }
118 |
119 | private fun saveTimerSession() {
120 | val session = TimerSessionModel(
121 | date = getCurrentDate(),
122 | value = _sessionTimerValue
123 | )
124 | saveTimerSessionUseCase(timerSessionModel = session).onEach { result ->
125 | when (result) {
126 | is Resource.Success -> {
127 | _sessionTimerValue = 0
128 | }
129 |
130 | is Resource.Loading -> {}
131 | is Resource.Error -> {}
132 | }
133 | }.launchIn(viewModelScope)
134 | }
135 |
136 | @SuppressLint("SimpleDateFormat")
137 | private fun getCurrentDate(): String {
138 | val currentDate = Calendar.getInstance().time
139 | val formatter = SimpleDateFormat("dd-MMMM-yyyy")
140 | return formatter.format(currentDate)
141 | }
142 |
143 | @SuppressLint("DefaultLocale")
144 | fun millisToMinutes(value: Long): String {
145 | val totalSeconds = value / ONE_SEC_IN_MILLIS
146 | val minutes = (totalSeconds / ONE_MIN_IN_SEC).toInt()
147 | val seconds = (totalSeconds % ONE_MIN_IN_SEC).toInt()
148 | return String.format("%02d:%02d", minutes, seconds)
149 | }
150 |
151 | @SuppressLint("DefaultLocale")
152 | fun millisToHours(value: Long): String {
153 | val totalSeconds = value / ONE_SEC_IN_MILLIS
154 | val seconds = (totalSeconds % ONE_MIN_IN_SEC)
155 | val totalMinutes = (totalSeconds / ONE_MIN_IN_SEC).toInt()
156 | val hours = (totalMinutes / ONE_HOUR_IN_MIN)
157 | val minutes = (totalMinutes % ONE_HOUR_IN_MIN)
158 | return if (totalMinutes <= ONE_HOUR_IN_MIN) {
159 | String.format("%02dm %02ds", minutes, seconds)
160 | } else {
161 | String.format("%02dh %02dm", hours, minutes)
162 | }
163 | }
164 |
165 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cirilobido/focustimeryt/presentation/home/HomeScreen.kt:
--------------------------------------------------------------------------------
1 | package com.cirilobido.focustimeryt.presentation.home
2 |
3 | import androidx.compose.foundation.layout.Arrangement
4 | import androidx.compose.foundation.layout.Box
5 | import androidx.compose.foundation.layout.Column
6 | import androidx.compose.foundation.layout.Row
7 | import androidx.compose.foundation.layout.Spacer
8 | import androidx.compose.foundation.layout.fillMaxSize
9 | import androidx.compose.foundation.layout.fillMaxWidth
10 | import androidx.compose.foundation.layout.height
11 | import androidx.compose.foundation.layout.padding
12 | import androidx.compose.foundation.layout.size
13 | import androidx.compose.foundation.layout.width
14 | import androidx.compose.foundation.lazy.grid.GridCells
15 | import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
16 | import androidx.compose.foundation.lazy.grid.items
17 | import androidx.compose.foundation.rememberScrollState
18 | import androidx.compose.foundation.verticalScroll
19 | import androidx.compose.material3.Icon
20 | import androidx.compose.material3.MaterialTheme
21 | import androidx.compose.runtime.Composable
22 | import androidx.compose.runtime.LaunchedEffect
23 | import androidx.compose.runtime.getValue
24 | import androidx.compose.runtime.mutableStateOf
25 | import androidx.compose.runtime.remember
26 | import androidx.compose.ui.Alignment
27 | import androidx.compose.ui.Modifier
28 | import androidx.compose.ui.platform.LocalLifecycleOwner
29 | import androidx.compose.ui.res.painterResource
30 | import androidx.compose.ui.text.style.TextAlign
31 | import androidx.compose.ui.tooling.preview.Preview
32 | import androidx.hilt.navigation.compose.hiltViewModel
33 | import androidx.lifecycle.Lifecycle
34 | import androidx.lifecycle.repeatOnLifecycle
35 | import com.cirilobido.focustimeryt.R
36 | import com.cirilobido.focustimeryt.domain.model.TimerTypeEnum
37 | import com.cirilobido.focustimeryt.presentation.components.AutoResizedText
38 | import com.cirilobido.focustimeryt.presentation.components.BorderedIcon
39 | import com.cirilobido.focustimeryt.presentation.components.CircleDot
40 | import com.cirilobido.focustimeryt.presentation.components.CustomButton
41 | import com.cirilobido.focustimeryt.presentation.components.InformationItem
42 | import com.cirilobido.focustimeryt.presentation.components.TimerTypeItem
43 | import com.cirilobido.focustimeryt.presentation.theme.FocusTimerYTTheme
44 |
45 | @Composable
46 | fun HomeScreen(viewModel: HomeScreenViewModel = hiltViewModel()) {
47 | val timeState by remember { mutableStateOf(viewModel.timerValueState) }
48 | val timerTypeState by remember { mutableStateOf(viewModel.timerTypeState) }
49 | val roundsState by remember { mutableStateOf(viewModel.roundsState) }
50 | val todayTimeState by remember { mutableStateOf(viewModel.todayTimeState) }
51 |
52 | val lifecycleOwner = LocalLifecycleOwner.current
53 | LaunchedEffect(viewModel) {
54 | lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
55 | viewModel.getTimerSessionByDate()
56 | }
57 | }
58 |
59 | Column(
60 | modifier = Modifier
61 | .fillMaxSize()
62 | .padding(FocusTimerYTTheme.dimens.paddingMedium)
63 | .verticalScroll(rememberScrollState()),
64 | horizontalAlignment = Alignment.CenterHorizontally
65 | ) {
66 | Box(
67 | modifier = Modifier.fillMaxWidth(),
68 | contentAlignment = Alignment.TopEnd
69 | ) {
70 | Icon(
71 | modifier = Modifier.size(FocusTimerYTTheme.dimens.iconSizeNormal),
72 | painter = painterResource(id = R.drawable.ic_menu),
73 | contentDescription = "Menu",
74 | tint = MaterialTheme.colorScheme.primary
75 | )
76 | }
77 | AutoResizedText(
78 | text = "Focus Timer",
79 | textStyle = MaterialTheme.typography.displayMedium.copy(
80 | color = MaterialTheme.colorScheme.primary,
81 | textAlign = TextAlign.Center
82 | )
83 | )
84 | Spacer(modifier = Modifier.height(FocusTimerYTTheme.dimens.spacerMedium))
85 | Row {
86 | CircleDot()
87 | Spacer(modifier = Modifier.width(FocusTimerYTTheme.dimens.spacerNormal))
88 | CircleDot()
89 | Spacer(modifier = Modifier.width(FocusTimerYTTheme.dimens.spacerNormal))
90 | CircleDot(color = MaterialTheme.colorScheme.tertiary)
91 | Spacer(modifier = Modifier.width(FocusTimerYTTheme.dimens.spacerNormal))
92 | CircleDot(color = MaterialTheme.colorScheme.tertiary)
93 | }
94 | Spacer(modifier = Modifier.height(FocusTimerYTTheme.dimens.spacerMedium))
95 | TimerSession(
96 | timer = viewModel.millisToMinutes(timeState.value),
97 | onIncreaseTap = {
98 | viewModel.onIncreaseTime()
99 | },
100 | onDecreaseTap = {
101 | viewModel.onDecreaseTime()
102 | }
103 | )
104 | Spacer(modifier = Modifier.height(FocusTimerYTTheme.dimens.spacerMedium))
105 | TimerTypeSession(
106 | type = timerTypeState.value,
107 | onTap = { type ->
108 | viewModel.onUpdateType(type)
109 | }
110 | )
111 | Spacer(modifier = Modifier.height(FocusTimerYTTheme.dimens.spacerMedium))
112 | Column(
113 | modifier = Modifier.fillMaxWidth(),
114 | horizontalAlignment = Alignment.CenterHorizontally,
115 | verticalArrangement = Arrangement.Center
116 | ) {
117 | CustomButton(
118 | text = "Start",
119 | textColor = MaterialTheme.colorScheme.surface,
120 | buttonColor = MaterialTheme.colorScheme.primary,
121 | onTap = {
122 | viewModel.onStartTimer()
123 | }
124 | )
125 | CustomButton(
126 | text = "Reset",
127 | textColor = MaterialTheme.colorScheme.primary,
128 | buttonColor = MaterialTheme.colorScheme.surface,
129 | onTap = {
130 | viewModel.onCancelTimer(true)
131 | }
132 | )
133 | }
134 | Spacer(modifier = Modifier.height(FocusTimerYTTheme.dimens.spacerMedium))
135 | InformationSession(
136 | modifier = Modifier.weight(1f),
137 | round = roundsState.value.toString(),
138 | time = viewModel.millisToHours(todayTimeState.value)
139 | )
140 | }
141 | }
142 |
143 | @Composable
144 | fun TimerSession(
145 | modifier: Modifier = Modifier,
146 | timer: String,
147 | onIncreaseTap: () -> Unit = {},
148 | onDecreaseTap: () -> Unit = {},
149 | ) {
150 | Row(
151 | modifier = modifier.fillMaxWidth(),
152 | verticalAlignment = Alignment.CenterVertically,
153 | horizontalArrangement = Arrangement.Center
154 | ) {
155 | Column(
156 | modifier = Modifier
157 | .fillMaxWidth()
158 | .weight(1f),
159 | horizontalAlignment = Alignment.CenterHorizontally
160 | ) {
161 | BorderedIcon(icon = R.drawable.ic_minus, onTap = onDecreaseTap)
162 | Spacer(modifier = Modifier.height(FocusTimerYTTheme.dimens.spacerMedium))
163 | }
164 | AutoResizedText(
165 | text = timer,
166 | modifier = Modifier
167 | .fillMaxWidth()
168 | .weight(6f)
169 | .align(Alignment.CenterVertically),
170 | textStyle = MaterialTheme.typography.displayLarge.copy(
171 | color = MaterialTheme.colorScheme.primary,
172 | textAlign = TextAlign.Center
173 | )
174 | )
175 | Column(
176 | modifier = Modifier
177 | .fillMaxWidth()
178 | .weight(1f),
179 | horizontalAlignment = Alignment.CenterHorizontally
180 | ) {
181 | BorderedIcon(icon = R.drawable.ic_plus, onTap = onIncreaseTap)
182 | Spacer(modifier = Modifier.height(FocusTimerYTTheme.dimens.spacerMedium))
183 | }
184 | }
185 | }
186 |
187 | @Composable
188 | fun TimerTypeSession(
189 | modifier: Modifier = Modifier,
190 | type: TimerTypeEnum,
191 | onTap: (TimerTypeEnum) -> Unit = {}
192 | ) {
193 | val gridCount = 3
194 | val itemsSpacing = Arrangement.spacedBy(FocusTimerYTTheme.dimens.paddingNormal)
195 | LazyVerticalGrid(
196 | modifier = modifier
197 | .fillMaxWidth()
198 | .height(FocusTimerYTTheme.dimens.spacerLarge),
199 | columns = GridCells.Fixed(gridCount),
200 | horizontalArrangement = itemsSpacing,
201 | verticalArrangement = itemsSpacing,
202 | ) {
203 | items(
204 | TimerTypeEnum.values(),
205 | key = { it.title }
206 | ) {
207 | TimerTypeItem(
208 | text = it.title,
209 | textColor = if (type == it)
210 | MaterialTheme.colorScheme.primary
211 | else
212 | MaterialTheme.colorScheme.secondary,
213 | onTap = { onTap(it) }
214 | )
215 | }
216 | }
217 | }
218 |
219 | @Composable
220 | fun InformationSession(
221 | modifier: Modifier = Modifier,
222 | round: String,
223 | time: String
224 | ) {
225 | Box(
226 | modifier = modifier.fillMaxSize(),
227 | contentAlignment = Alignment.BottomCenter
228 | ) {
229 | Row(
230 | modifier = Modifier.align(Alignment.BottomCenter)
231 | ) {
232 | InformationItem(
233 | modifier = modifier
234 | .fillMaxWidth()
235 | .weight(1f),
236 | text = round,
237 | label = "rounds"
238 | )
239 | Spacer(
240 | modifier = modifier
241 | .fillMaxWidth()
242 | .weight(1f)
243 | )
244 | InformationItem(
245 | modifier = modifier
246 | .fillMaxWidth()
247 | .weight(1f),
248 | text = time,
249 | label = "time"
250 | )
251 | }
252 | }
253 | }
254 |
255 |
256 | @Preview(
257 | name = "HomeScreenPreview",
258 | showBackground = true
259 | )
260 | @Composable
261 | fun HomeScreenPreview() {
262 | FocusTimerYTTheme {
263 | HomeScreen()
264 | }
265 | }
--------------------------------------------------------------------------------