### Record Model Definition and Usage Source: https://context7.com/razeeman/android-simpletimetracker/llms.txt Defines the 'Record' data model for time tracking entries, including ID, type, start/end times, comments, and tags. Includes an example of creating a completed time record. ```kotlin data class Record( val id: Long = 0, val typeId: Long, val timeStarted: Long, val timeEnded: Long, val comment: String, val tags: List, ) // Example usage - Creating a completed time record val workRecord = Record( id = 0, // Auto-generated typeId = 1L, // Reference to activity type timeStarted = 1704528000000L, // Unix timestamp timeEnded = 1704531600000L, // Unix timestamp comment = "Working on project documentation", tags = listOf( RecordBase.Tag(id = 1L, value = "urgent"), RecordBase.Tag(id = 2L, value = "remote") ) ) ``` -------------------------------- ### Manage Active Timers with RunningRecordInteractor (Kotlin) Source: https://context7.com/razeeman/android-simpletimetracker/llms.txt The RunningRecordInteractor class manages active timers (running records). It uses RunningRecordRepo and RunningRecordToRecordTagRepo to handle the lifecycle of timers. It provides methods to get all running records, a specific running record, check for its existence, add a new timer, and remove an existing timer. Examples include starting and stopping timers. ```kotlin class RunningRecordInteractor @Inject constructor( private val runningRecordRepo: RunningRecordRepo, private val runningRecordToRecordTagRepo: RunningRecordToRecordTagRepo, ) { suspend fun getAll(): List suspend fun get(id: Long): RunningRecord? suspend fun has(id: Long): Boolean suspend fun add(runningRecord: RunningRecord) suspend fun remove(id: Long) } // Example usage - Starting a new activity timer suspend fun startActivityTimer( runningRecordInteractor: RunningRecordInteractor, activityTypeId: Long ) { val runningRecord = RunningRecord( id = activityTypeId, timeStarted = System.currentTimeMillis(), comment = "Currently working", tags = listOf( RecordBase.Tag(id = 1L, value = "in-progress") ) ) try { runningRecordInteractor.add(runningRecord) println("Timer started for activity ${activityTypeId}") } catch (e: Exception) { println("Error starting timer: ${e.message}") } } // Example usage - Stopping an activity timer suspend fun stopActivityTimer( runningRecordInteractor: RunningRecordInteractor, recordInteractor: RecordInteractor, activityTypeId: Long ) { val runningRecord = runningRecordInteractor.get(activityTypeId) if (runningRecord != null) { // Convert running record to completed record recordInteractor.addFromRunning( runningRecord = runningRecord, timeEnded = System.currentTimeMillis() ) // Remove the running record runningRecordInteractor.remove(activityTypeId) println("Timer stopped and record saved") } else { println("No running timer found for activity ${activityTypeId}") } } ``` -------------------------------- ### Manage Application Settings with PrefsInteractor (Kotlin) Source: https://context7.com/razeeman/android-simpletimetracker/llms.txt The PrefsInteractor class manages application settings like filtered list items and card display order. It relies on PrefsRepo for data persistence and IsSystemInDarkModeInteractor for system theme information. Functions include getting and setting filtered lists (List) and card order (CardOrder). ```kotlin class PrefsInteractor @Inject constructor( private val prefsRepo: PrefsRepo, private val isSystemInDarkModeInteractor: IsSystemInDarkModeInteractor, ) { suspend fun getFilteredTypesOnList(): List suspend fun setFilteredTypesOnList(typeIdsFiltered: List) suspend fun getCardOrder(): CardOrder suspend fun setCardOrder(cardOrder: CardOrder) } // Example usage - Managing activity filters suspend fun configureActivityFilters( prefsInteractor: PrefsInteractor, visibleActivityIds: List ) { // Get currently filtered (hidden) activities val currentFilters = prefsInteractor.getFilteredTypesOnList() println("Currently hidden activities: $currentFilters") // Update filter to show only specific activities prefsInteractor.setFilteredTypesOnList(visibleActivityIds) println("Updated activity filter") } // Example usage - Setting card display order suspend fun configureActivityOrder( prefsInteractor: PrefsInteractor, orderType: CardOrder ) { prefsInteractor.setCardOrder(orderType) println("Activities will be displayed in ${orderType.name} order") } ``` -------------------------------- ### RecordDao Interface for Database Operations Source: https://context7.com/razeeman/android-simpletimetracker/llms.txt Defines the Room DAO interface for 'Record' entities, providing suspend functions for CRUD operations and querying records by type or time range. Includes examples for querying records from the last week and for specific activity types. ```kotlin @Dao interface RecordDao { @Query("SELECT * FROM records") suspend fun getAll(): List @Query("SELECT * FROM records WHERE type_id IN (:typesIds)") suspend fun getByType(typesIds: List): List @Query("SELECT * FROM records WHERE time_started < :end AND time_ended > :start") suspend fun getFromRange(start: Long, end: Long): List @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insert(record: RecordDBO): Long @Query("DELETE FROM records WHERE id = :id") suspend fun delete(id: Long) } // Example usage - Querying records from last week suspend fun getLastWeekRecords(recordDao: RecordDao): List { val now = System.currentTimeMillis() val weekAgo = now - (7 * 24 * 60 * 60 * 1000L) return recordDao.getFromRange( start = weekAgo, end = now ) } // Example usage - Getting all records for specific activities suspend fun getWorkAndStudyRecords(recordDao: RecordDao): List { val workTypeId = 1L val studyTypeId = 2L return recordDao.getByType( typesIds = listOf(workTypeId, studyTypeId) ) } ``` -------------------------------- ### RecordType Model Definition and Usage Source: https://context7.com/razeeman/android-simpletimetracker/llms.txt Defines the 'RecordType' data model for different types of activities users can track, including name, icon, color, default duration, and notes. Provides an example of creating a 'Work' activity type. ```kotlin data class RecordType( val id: Long = 0, val name: String, val icon: String, val color: AppColor, val defaultDuration: Long, val note: String, val hidden: Boolean = false, ) // Example usage - Creating an activity type val workActivity = RecordType( id = 0, name = "Work", icon = "💼", color = AppColor(index = 5, colorInt = 0xFF2196F3.toInt()), defaultDuration = 3600000L, // 1 hour in milliseconds note = "Office work and meetings", hidden = false ) ``` -------------------------------- ### Backup Data Export and Import using Kotlin Source: https://context7.com/razeeman/android-simpletimetracker/llms.txt Demonstrates how to save and restore full or partial backups of the application data using the BackupInteractor. This functionality allows users to back up their time tracking data and restore it later. It involves specifying backup options like file names and data types to be included. Dependencies include BackupRepo and BackupPartialRepo. ```kotlin class BackupInteractor @Inject constructor( private val backupRepo: BackupRepo, private val backupPartialRepo: BackupPartialRepo, private val externalViewsInteractor: UpdateExternalViewsInteractor, ) { suspend fun saveBackupFile(uriString: String, params: BackupOptionsData.Save): ResultCode suspend fun restoreBackupFile(uriString: String, params: BackupOptionsData.Restore): ResultCode suspend fun partialRestoreBackupFile(params: BackupOptionsData.Custom): ResultCode suspend fun readBackupFileContent(uriString: String): Pair } // Example usage - Creating a full database backup suspend fun createFullBackup( backupInteractor: BackupInteractor, backupUri: String ): Boolean { val saveOptions = BackupOptionsData.Save( customFileName = "timetracker_backup_${System.currentTimeMillis()}.stt", saveRecordTypes = true, saveCategories = true, saveRecords = true, saveTags = true, saveComplexRules = true, saveSettings = true ) return when (backupInteractor.saveBackupFile(backupUri, saveOptions)) { ResultCode.SUCCESS -> { println("Backup created successfully") true } ResultCode.ERROR -> { println("Backup failed") false } } } // Example usage - Restoring from backup file suspend fun restoreFromBackup( backupInteractor: BackupInteractor, backupUri: String ): Boolean { val restoreOptions = BackupOptionsData.Restore( restoreRecordTypes = true, restoreCategories = true, restoreRecords = true, restoreTags = true, restoreComplexRules = true, restoreSettings = false // Keep existing settings ) return when (backupInteractor.restoreBackupFile(backupUri, restoreOptions)) { ResultCode.SUCCESS -> { println("Backup restored successfully") true } ResultCode.ERROR -> { println("Restore failed") false } } } ``` -------------------------------- ### Trigger Wear OS Data Sync using Kotlin Source: https://context7.com/razeeman/android-simpletimetracker/llms.txt Initiates a data synchronization process with a Wear OS device. This function retrieves currently running activities and then calls `wearInteractor.update()` to push the latest state to the watch. Error handling is included to catch and report any exceptions during the update process. ```kotlin interface WearInteractor { suspend fun update() } // Example usage - Triggering watch data sync suspend fun updateWearOSData( wearInteractor: WearInteractor, runningRecordInteractor: RunningRecordInteractor ) { try { // Get current running activities val runningRecords = runningRecordInteractor.getAll() // Update wear device with latest state wearInteractor.update() println("Watch updated with ${runningRecords.size} running activities") } catch (e: Exception) { println("Failed to update watch: ${e.message}") } } ``` -------------------------------- ### Sync Activities to Wear OS Device using Kotlin Source: https://context7.com/razeeman/android-simpletimetracker/llms.txt Synchronizes activity data from the phone to a Wear OS device. It filters out hidden activities and maps them to the `WearActivity` data class before sending them to the watch via `WearInteractor`. This enables users to view and potentially interact with their time tracking activities on their smartwatches. ```kotlin data class WearActivity( val id: Long, val name: String, val icon: String, val color: Long, ) // Example usage - Syncing activities to Wear OS device suspend fun syncActivitiesToWatch( recordTypeInteractor: RecordTypeInteractor, wearInteractor: WearInteractor ) { val activities = recordTypeInteractor.getAll() val wearActivities = activities .filter { !it.hidden } .map { activity -> WearActivity( id = activity.id, name = activity.name, icon = activity.icon, color = activity.color.colorInt.toLong() ) } // Send to wear device wearInteractor.update() println("Synced ${wearActivities.size} activities to watch") } ``` -------------------------------- ### Manage Time Records with RecordInteractor (Kotlin) Source: https://context7.com/razeeman/android-simpletimetracker/llms.txt The RecordInteractor class handles CRUD operations for completed time records. It interacts with repositories to fetch, add, update, and remove records. Dependencies include RecordRepo and RecordToRecordTagRepo. It supports operations like retrieving all records, records by type, records within a date range, and adding/updating/removing individual records. ```kotlin class RecordInteractor @Inject constructor( private val recordRepo: RecordRepo, private val recordToRecordTagRepo: RecordToRecordTagRepo, ) { suspend fun getAll(): List suspend fun getByType(typeIds: List): List suspend fun getFromRange(range: Range): List suspend fun add(record: Record) suspend fun update(recordId: Long, typeId: Long, comment: String, tags: List) suspend fun remove(id: Long) } // Example usage - Adding a new completed record suspend fun trackCompletedActivity( recordInteractor: RecordInteractor, activityTypeId: Long ) { val record = Record( typeId = activityTypeId, timeStarted = System.currentTimeMillis() - 3600000L, // Started 1 hour ago timeEnded = System.currentTimeMillis(), comment = "Completed task successfully", tags = listOf( RecordBase.Tag(id = 1L, value = "productive"), RecordBase.Tag(id = 2L, value = "completed") ) ) try { recordInteractor.add(record) println("Record added successfully") } catch (e: Exception) { println("Error adding record: ${e.message}") } } // Example usage - Getting records for date range suspend fun getMonthlyReport( recordInteractor: RecordInteractor ): List { val now = System.currentTimeMillis() val monthStart = now - (30 * 24 * 60 * 60 * 1000L) val range = Range( timeStarted = monthStart, timeEnded = now ) return recordInteractor.getFromRange(range) } ``` -------------------------------- ### Manage Activity Types with RecordTypeInteractor (Kotlin) Source: https://context7.com/razeeman/android-simpletimetracker/llms.txt The RecordTypeInteractor provides methods to manage different types of activities or records within the application. It supports CRUD operations and archiving/restoring. Dependencies include repositories for record types and records, and a preferences interactor. ```kotlin class RecordTypeInteractor @Inject constructor( private val recordTypeRepo: RecordTypeRepo, private val recordRepo: RecordRepo, private val prefsInteractor: PrefsInteractor, // ... other dependencies ) { suspend fun getAll(cardOrder: CardOrder? = null): List suspend fun get(id: Long): RecordType? suspend fun add(recordType: RecordType): Long suspend fun archive(id: Long) suspend fun restore(id: Long) suspend fun remove(id: Long) } ``` ```kotlin // Example usage - Creating a new activity type suspend fun createNewActivity( recordTypeInteractor: RecordTypeInteractor ): Long { val newActivity = RecordType( name = "Exercise", icon = "🏃", color = AppColor(index = 3, colorInt = 0xFF4CAF50.toInt()), defaultDuration = 1800000L, // 30 minutes note = "Physical activities and workouts", hidden = false ) return try { val activityId = recordTypeInteractor.add(newActivity) println("Activity created with ID: $activityId") activityId } catch (e: Exception) { println("Error creating activity: ${e.message}") -1L } } ``` ```kotlin // Example usage - Archiving unused activity types suspend fun cleanupUnusedActivities( recordTypeInteractor: RecordTypeInteractor, unusedActivityIds: List ) { unusedActivityIds.forEach { activityId -> try { recordTypeInteractor.archive(activityId) println("Archived activity $activityId") } catch (e: Exception) { println("Error archiving activity $activityId: ${e.message}") } } } ``` -------------------------------- ### Update Home Screen Widgets using Kotlin Source: https://context7.com/razeeman/android-simpletimetracker/llms.txt Manages the updating of home screen widgets for the time tracking application. It provides functions to initialize cached widget views, update individual widgets based on ID or activity types, and refresh specific widget types like statistics or quick settings. This ensures that widgets display the most current information. ```kotlin interface WidgetInteractor { fun initializeCachedViews() fun updateSingleWidget(widgetId: Int) fun updateSingleWidgets(typeIds: List) fun updateStatisticsWidget(widgetId: Int) fun updateQuickSettingsWidget(widgetId: Int) fun updateWidgets(type: WidgetType) } // Example usage - Updating all widgets after data change fun refreshAllWidgets( widgetInteractor: WidgetInteractor ) { widgetInteractor.initializeCachedViews() widgetInteractor.updateWidgets(WidgetType.SINGLE) widgetInteractor.updateWidgets(WidgetType.STATISTICS) widgetInteractor.updateWidgets(WidgetType.QUICK_SETTINGS) println("All widgets updated") } // Example usage - Updating specific activity widgets fun updateActivityWidgets( widgetInteractor: WidgetInteractor, changedActivityIds: List ) { widgetInteractor.updateSingleWidgets(changedActivityIds) println("Updated widgets for ${changedActivityIds.size} activities") } ``` -------------------------------- ### Generate Time Statistics with StatisticsInteractor (Kotlin) Source: https://context7.com/razeeman/android-simpletimetracker/llms.txt The StatisticsInteractor is responsible for calculating and retrieving time-based statistics for different activities. It relies on record interactors to fetch data and can include or exclude untracked time. The output is a list of Statistics objects. ```kotlin class StatisticsInteractor @Inject constructor( private val recordInteractor: RecordInteractor, private val runningRecordInteractor: RunningRecordInteractor, private val getUntrackedRecordsInteractor: GetUntrackedRecordsInteractor, ) { suspend fun getFromRange(range: Range, addUntracked: Boolean): List suspend fun getRecords(range: Range): List fun getStatistics(range: Range, records: Map>): List } ``` ```kotlin // Example usage - Generating weekly statistics suspend fun generateWeeklyStatistics( statisticsInteractor: StatisticsInteractor ): List { val now = System.currentTimeMillis() val weekAgo = now - (7 * 24 * 60 * 60 * 1000L) val range = Range( timeStarted = weekAgo, timeEnded = now ) return try { val stats = statisticsInteractor.getFromRange( range = range, addUntracked = true // Include untracked time gaps ) stats.forEach { statistic -> println("Activity ${statistic.id}: " + "${statistic.data.duration}ms total, " + "${statistic.data.count} sessions") } stats } catch (e: Exception) { println("Error generating statistics: ${e.message}") emptyList() } } ``` ```kotlin // Example usage - Calculating activity percentages suspend fun calculateActivityBreakdown( statisticsInteractor: StatisticsInteractor, range: Range ): Map { val stats = statisticsInteractor.getFromRange(range, addUntracked = false) val totalDuration = stats.sumOf { it.data.duration } return stats.associate { val percentage = if (totalDuration > 0) { (statistic.data.duration.toDouble() / totalDuration) * 100 } else { 0.0 } statistic.id to percentage } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.