Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ android {
applicationId = "com.shreyash.dotrack"
minSdk = 26
targetSdk = 36
versionCode = 55
versionName = "1.55"
versionCode = 56
versionName = "1.56"

testInstrumentationRunner = "com.shreyash.dotrack.HiltTestRunner"
}
Expand Down Expand Up @@ -87,6 +87,7 @@ dependencies {

// AndroidX Core
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.core.splashscreen)

// Compose
implementation(platform(libs.compose.bom))
Expand Down
20 changes: 14 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_app_icon"
android:supportsRtl="true"
android:theme="@style/Theme.DoTrack"
android:theme="@style/Theme.DoTrack.Splash"
tools:targetApi="31">
<!-- ✅ REMOVE default WorkManager initializer -->
<meta-data
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup"
tools:node="remove" />
<!-- Startup: WorkManager is provided via DoTrackApplication (#100); EmojiCompat not used -->
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<meta-data
android:name="androidx.work.WorkManagerInitializer"
tools:node="remove" />
<meta-data
android:name="androidx.emoji2.text.EmojiCompatInitializer"
tools:node="remove" />
</provider>
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
38 changes: 35 additions & 3 deletions app/src/main/java/com/shreyash/dotrack/DoTrackApplication.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.shreyash.dotrack

import android.app.Application
import android.content.Context
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import com.shreyash.dotrack.domain.model.AppLanguage
import com.shreyash.dotrack.domain.repository.UserPreferencesRepository
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.launch
import javax.inject.Inject

/**
Expand All @@ -22,12 +27,39 @@ class DoTrackApplication : Application(), Configuration.Provider {
@Inject
lateinit var userPreferencesRepository: UserPreferencesRepository

private val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)

companion object {
private const val SYNC_PREFS_NAME = "dotrack_sync_prefs"
private const val KEY_LANGUAGE = "language_sync"
}

/**
* Synchronous read of the persisted app language, used by MainActivity's
* attachBaseContext to wrap the configuration before the first frame.
* Uses SharedPreferences for fast sync read (no DataStore blocking).
* DataStore remains source of truth; this cache is kept in sync via
* UserPreferencesRepositoryImpl and onCreate migration.
*/
fun getLanguageCodeSync(): String = runBlocking {
userPreferencesRepository.getLanguage().first()
fun getLanguageCodeSync(): String {
return getSharedPreferences(SYNC_PREFS_NAME, Context.MODE_PRIVATE)
.getString(KEY_LANGUAGE, AppLanguage.SYSTEM.value) ?: AppLanguage.SYSTEM.value
}

override fun onCreate() {
super.onCreate()
// One-time migration / keep SharedPreferences cache in sync with DataStore
applicationScope.launch {
try {
val language = userPreferencesRepository.getLanguage().first()
val prefs = getSharedPreferences(SYNC_PREFS_NAME, Context.MODE_PRIVATE)
if (prefs.getString(KEY_LANGUAGE, null) != language) {
prefs.edit().putString(KEY_LANGUAGE, language).apply()
}
} catch (_: Exception) {
// ignore - next launch will retry
}
}
}

override val workManagerConfiguration: Configuration
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/shreyash/dotrack/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.shreyash.dotrack

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.LocalActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
Expand All @@ -29,7 +30,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
Expand Down Expand Up @@ -70,6 +70,7 @@ class MainActivity : ComponentActivity() {
}

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
Expand Down Expand Up @@ -112,7 +113,7 @@ fun DoTrackApp(

val languagePref by themeViewModel.language.collectAsState()
var isInitialLanguage by remember { mutableStateOf(true) }
val activity = LocalContext.current as? Activity
val activity = LocalActivity.current
LaunchedEffect(languagePref) {
if (isInitialLanguage) {
isInitialLanguage = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import com.shreyash.dotrack.domain.usecase.preferences.GetSortOptionUseCase
import com.shreyash.dotrack.domain.usecase.preferences.GetWallpaperColorUseCase
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
import java.time.LocalDateTime
Expand All @@ -44,10 +46,10 @@ class WallpaperGenerator @Inject constructor(
private val getSortDirectionUseCase: GetSortDirectionUseCase
) {

private val wallpaperManager = WallpaperManager.getInstance(context)
private val dateFormatter = DateTimeFormatter.ofPattern("MMM dd, yyyy HH:mm")
private val wallpaperManager by lazy { WallpaperManager.getInstance(context) }

companion object {
private val dateFormatter = DateTimeFormatter.ofPattern("MMM dd, yyyy HH:mm")
private val footerFormatter = DateTimeFormatter.ofPattern("MMM dd, yyyy HH:mm")
}

Expand All @@ -58,14 +60,30 @@ class WallpaperGenerator @Inject constructor(
suspend fun generateAndSetWallpaper(tasks: List<Task>): Result<Unit> {
return withContext(Dispatchers.IO) {
try {
// Get the user's preferred colors
val startColorHex = getWallpaperColorUseCase().first()
val secondaryStartColorHex = getSecondaryWallpaperColorUseCase().first()
val highPriorityColorHex = getHighPriorityColorUseCase().first()
val mediumPriorityColorHex = getMediumPriorityColorUseCase().first()
val lowPriorityColorHex = getLowPriorityColorUseCase().first()
val sortOption = getSortOptionUseCase().first()
val sortDirection = getSortDirectionUseCase().first()
// Get the user's preferred colors & sort prefs concurrently (#102)
val startColorHex: String
val secondaryStartColorHex: String
val highPriorityColorHex: String
val mediumPriorityColorHex: String
val lowPriorityColorHex: String
val sortOption: SortOption
val sortDirection: SortDirection
coroutineScope {
val deferredStart = async { getWallpaperColorUseCase().first() }
val deferredSecondary = async { getSecondaryWallpaperColorUseCase().first() }
val deferredHigh = async { getHighPriorityColorUseCase().first() }
val deferredMedium = async { getMediumPriorityColorUseCase().first() }
val deferredLow = async { getLowPriorityColorUseCase().first() }
val deferredSortOption = async { getSortOptionUseCase().first() }
val deferredSortDirection = async { getSortDirectionUseCase().first() }
startColorHex = deferredStart.await()
secondaryStartColorHex = deferredSecondary.await()
highPriorityColorHex = deferredHigh.await()
mediumPriorityColorHex = deferredMedium.await()
lowPriorityColorHex = deferredLow.await()
sortOption = deferredSortOption.await()
sortDirection = deferredSortDirection.await()
}

val bitmap = generateTaskListBitmap(
tasks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.shreyash.dotrack.R
import com.shreyash.dotrack.core.ui.theme.CardColorHighPriority
import com.shreyash.dotrack.core.ui.theme.CardColorLowPriority
import com.shreyash.dotrack.core.ui.theme.CardColorMediumPriority
import com.shreyash.dotrack.core.ui.theme.DoTrackTheme
import com.shreyash.dotrack.core.ui.theme.LocalPriorityCardColors
import com.shreyash.dotrack.domain.model.Priority
import com.shreyash.dotrack.domain.model.Task
import java.time.LocalDateTime
Expand Down Expand Up @@ -77,10 +75,11 @@ fun TaskItem(
onDeleteTask: (String) -> Unit = {},
modifier: Modifier = Modifier
) {
val priorityCardColors = LocalPriorityCardColors.current
val color = when (task.priority) {
Priority.HIGH -> CardColorHighPriority
Priority.MEDIUM -> CardColorMediumPriority
Priority.LOW -> CardColorLowPriority
Priority.HIGH -> priorityCardColors.high
Priority.MEDIUM -> priorityCardColors.medium
Priority.LOW -> priorityCardColors.low
}
Card(
modifier = modifier
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/com/shreyash/dotrack/ui/tasks/TasksViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,16 @@ class TasksViewModel @Inject constructor(
val filterPriority: Priority? get() = _filterPriority.value
val filterCompleted: Boolean? get() = _filterCompleted.value

// Shared upstream to avoid duplicate Room observers (#102)
private val tasksResultFlow: StateFlow<Result<List<Task>>> = getTasksUseCase()
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = Result.Loading
)

val sortedTasks: StateFlow<Result<List<Task>>> = combine(
getTasksUseCase(),
tasksResultFlow,
_sortOption,
_sortDirection,
_filterPriority,
Expand All @@ -122,7 +130,7 @@ class TasksViewModel @Inject constructor(
initialValue = Result.Loading
)

val taskCounts: StateFlow<TaskCounts> = getTasksUseCase()
val taskCounts: StateFlow<TaskCounts> = tasksResultFlow
.map { result ->
val tasks = result.getOrNull().orEmpty()
TaskCounts(
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="splash_background">#7C3AED</color>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@
</style>

<style name="Theme.DoTrack" parent="Base.Theme.DoTrack" />

<!-- SplashScreen theme (#101) - displayed until first frame -->
<style name="Theme.DoTrack.Splash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/splash_background</item>
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_app_icon</item>
<item name="postSplashScreenTheme">@style/Theme.DoTrack</item>
</style>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/xml/task_widget_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
android:minHeight="110dp"
android:previewImage="@drawable/widget_preview"
android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="300000"
android:updatePeriodMillis="0"
android:widgetCategory="home_screen" />
40 changes: 18 additions & 22 deletions core/src/main/java/com/shreyash/dotrack/core/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -76,30 +76,26 @@ fun DoTrackTheme(
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
val context = LocalContext.current
val colorScheme = remember(context, darkTheme, dynamicColor) {
when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> DarkColorScheme
else -> LightColorScheme
}

darkTheme -> DarkColorScheme
else -> LightColorScheme
}

// Set the priority card colors based on the current theme
val priorityCardColors = PriorityCardColors(
high = if (darkTheme) CardColorHighPriorityDark else CardColorHighPriorityLight,
medium = if (darkTheme) CardColorMediumPriorityDark else CardColorMediumPriorityLight,
low = if (darkTheme) CardColorLowPriorityDark else CardColorLowPriorityLight
)

// Update the global color variables for backward compatibility
SideEffect {
CardColorHighPriority = priorityCardColors.high
CardColorMediumPriority = priorityCardColors.medium
CardColorLowPriority = priorityCardColors.low

// Set the priority card colors based on the current theme - cached per theme
val priorityCardColors = remember(darkTheme) {
PriorityCardColors(
high = if (darkTheme) CardColorHighPriorityDark else CardColorHighPriorityLight,
medium = if (darkTheme) CardColorMediumPriorityDark else CardColorMediumPriorityLight,
low = if (darkTheme) CardColorLowPriorityDark else CardColorLowPriorityLight
)
}

CompositionLocalProvider(LocalPriorityCardColors provides priorityCardColors) {
MaterialTheme(
colorScheme = colorScheme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ object DatabaseModule {
TaskDatabase::class.java,
"dotrack_database"
)
.fallbackToDestructiveMigration() // This will recreate the database if a migration isn't found
.build()
.addMigrations(
TaskDatabase.MIGRATION_1_2,
TaskDatabase.MIGRATION_2_3,
TaskDatabase.MIGRATION_3_4
)
.build()
}

@Provides
Expand Down
Loading
Loading