A fork of Simple Time Tracker with WearOS support. (Now integrated upstream)
0

Configure Feed

Select the types of activity you want to include in your feed.

change settings inactivity duration

razeeman (Jan 16, 2021, 4:02 PM +0300) 6609ddfd 76373f2d

+34 -22
+29 -18
core/src/main/java/com/example/util/simpletimetracker/core/mapper/TimeMapper.kt
··· 161 161 return year1 == year2 && day1 == day2 162 162 } 163 163 164 + fun formatDuration(interval: Long): String { 165 + val hr: Long = TimeUnit.SECONDS.toHours( 166 + interval 167 + ) 168 + val min: Long = TimeUnit.SECONDS.toMinutes( 169 + interval - TimeUnit.HOURS.toSeconds(hr) 170 + ) 171 + val sec: Long = TimeUnit.SECONDS.toSeconds( 172 + interval - TimeUnit.HOURS.toSeconds(hr) - TimeUnit.MINUTES.toSeconds(min) 173 + ) 174 + 175 + val hrString = "${hr}h" 176 + val minString = min.toString().let { 177 + if (hr != 0L) it.padStart(2, '0') else it 178 + } + "m" 179 + val secString = sec.toString().let { 180 + if (hr != 0L || min != 0L) it.padStart(2, '0') else it 181 + } + "s" 182 + 183 + var res = "" 184 + if (hr != 0L) res += hrString 185 + if (hr != 0L && min != 0L) res += " " 186 + if (min != 0L) res += minString 187 + if ((hr != 0L || min != 0L) && sec != 0L) res += " " 188 + if (sec != 0L) res += secString 189 + 190 + return res 191 + } 192 + 164 193 private fun formatInterval(interval: Long, withSeconds: Boolean): String { 165 194 val hr: Long = TimeUnit.MILLISECONDS.toHours( 166 195 interval ··· 172 201 interval - TimeUnit.HOURS.toMillis(hr) - TimeUnit.MINUTES.toMillis(min) 173 202 ) 174 203 175 - return formatTimeString(hr, min, sec, withSeconds) 176 - } 177 - 178 - fun formatSecondsInterval(interval: Long): String { 179 - val hr: Long = TimeUnit.SECONDS.toHours( 180 - interval 181 - ) 182 - val min: Long = TimeUnit.SECONDS.toMinutes( 183 - interval - TimeUnit.HOURS.toSeconds(hr) 184 - ) 185 - val sec: Long = TimeUnit.SECONDS.toSeconds( 186 - interval - TimeUnit.HOURS.toSeconds(hr) - TimeUnit.MINUTES.toSeconds(min) 187 - ) 188 - 189 - return formatTimeString(hr, min, sec, withSeconds = true) 190 - } 191 - 192 - private fun formatTimeString(hr: Long, min: Long, sec: Long, withSeconds: Boolean): String { 193 204 var res = "" 194 205 if (hr != 0L) res += "${hr}h" 195 206 if (hr != 0L || min != 0L || !withSeconds) res += " ${min}m"
+1 -1
domain/src/main/java/com/example/util/simpletimetracker/domain/repo/PrefsRepo.kt
··· 16 16 17 17 var showNotifications: Boolean 18 18 19 - var inactivityReminderDuration: Long 19 + var inactivityReminderDuration: Long // in seconds 20 20 21 21 var darkMode: Boolean 22 22
+1 -1
feature_settings/src/main/java/com/example/util/simpletimetracker/feature_settings/mapper/SettingsMapper.kt
··· 33 33 34 34 fun toInactivityReminderText(duration: Long): String { 35 35 return if (duration > 0) { 36 - timeMapper.formatSecondsInterval(duration) // TODO no seconds if not needed? 36 + timeMapper.formatDuration(duration) 37 37 } else { 38 38 resourceRepo.getString(R.string.settings_inactivity_reminder_disabled) 39 39 }
+1
feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/inactivity/interactor/NotificationInactivityInteractorImpl.kt
··· 18 18 if (runningRecordInteractor.getAll().isEmpty()) { 19 19 prefsInteractor.getInactivityReminderDuration() 20 20 .takeIf { it > 0 } 21 + ?.let { it * 1000L } 21 22 ?.let(scheduler::schedule) 22 23 } 23 24 }
+2 -2
feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/inactivity/scheduler/NotificationInactivityScheduler.kt
··· 17 17 private val alarmManager 18 18 get() = context.getSystemService(Context.ALARM_SERVICE) as? AlarmManager 19 19 20 - fun schedule(duration: Long) { 21 - val timestamp = System.currentTimeMillis() + duration 20 + fun schedule(durationMillis: Long) { 21 + val timestamp = System.currentTimeMillis() + durationMillis 22 22 23 23 scheduleAtTime(timestamp) 24 24 }