3838
3939@ Service
4040public class Controller {
41- private final long QUICK_SAVE_INTERVAL = 60 ;
4241
4342 private static final Logger LOG = LoggerFactory .getLogger (Controller .class );
4443
44+ private final long AUTO_SAVE_INTERVAL_SECONDS = 60 ;
45+ private Interval autoSaveInterval ;
46+
4547 private final Model model ;
4648
4749 private final DateProvider dateProvider ;
4850
4951 public Controller (final Model model , final DateProvider dateProvider ) {
5052 this .model = model ;
5153 this .dateProvider = dateProvider ;
54+ }
5255
53- // initiate quicksaving
54- new Interval (QUICK_SAVE_INTERVAL ).registerCallBack (() -> saveCurrentWork (dateProvider .dateTimeNow ()));
56+ public void enableAutoSave () {
57+ LOG .info ("Enabling auto save with interval '{}' seconds." , AUTO_SAVE_INTERVAL_SECONDS );
58+ autoSaveInterval = new Interval (AUTO_SAVE_INTERVAL_SECONDS );
59+ autoSaveInterval .registerCallBack (() -> {
60+ LOG .debug ("Auto saving current work." );
61+ saveCurrentWork (dateProvider .dateTimeNow ());
62+ });
5563 }
5664
5765 public void changeProject (final Project newProject ) {
@@ -178,7 +186,7 @@ public void deleteProject(final Project p) {
178186 changeProject (model .getIdleProject ());
179187 }
180188
181- LOG .info ("Disabeling project '{}'." , p );
189+ LOG .info ("Disabling project '{}'." , p );
182190
183191 final int indexToRemove = p .getIndex ();
184192 p .setEnabled (false ); // we don't delete it because of the referenced work
@@ -317,7 +325,7 @@ public void setComment(final String notes) {
317325 }
318326
319327 /**
320- * Calculate todays seconds counted as work
328+ * Calculate today's seconds counted as work
321329 */
322330 public long calcTodaysWorkSeconds () {
323331 final List <Work > workItems = new ArrayList <>();
@@ -338,16 +346,12 @@ public long calcTodaysWorkSeconds() {
338346 }
339347
340348 /**
341- * Calculate todays present seconds (work+nonWork)
349+ * Calculate today's present seconds (work+nonWork)
342350 */
343351 public long calcTodaysSeconds () {
344352 return calcSeconds (model .getPastWorkItems ());
345353 }
346354
347- public ObservableList <Project > getAvailableProjects () {
348- return model .getAvailableProjects ();
349- }
350-
351355 public long calcSeconds (final List <Work > workItems ) {
352356 long seconds = 0 ;
353357
0 commit comments