Added method to getting app states

This commit is contained in:
Filip Izydorczyk
2020-12-12 15:33:00 +01:00
parent e02523b4f4
commit 84d7ed8e65
4 changed files with 178 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import com.plannaplan.models.TourData;
import com.plannaplan.types.AppState;
/**
* entity that keeps app configurations
@ -91,4 +92,27 @@ public class AppConfig {
return configDate;
}
/**
* current state getter
*
* @return AppState of app at the moment of calling method
*/
public AppState getCurrentState() {
final Date now = new Date(System.currentTimeMillis());
if (this.secondTourEnd.before(now)) {
return AppState.NO_TOUR;
}
if (this.secondTourStart.before(now)) {
return AppState.SECOND_TOUR;
}
if (this.firstTourEnd.before(now)) {
return AppState.NO_TOUR;
}
if (this.firstTourStart.before(now)) {
return AppState.FIRST_TOUR;
}
return AppState.NO_TOUR;
}
}

View File

@ -0,0 +1,5 @@
package com.plannaplan.types;
public enum AppState {
FIRST_TOUR, SECOND_TOUR, NO_TOUR
}