Updated welcome screen to show if race is finished or starting

#story[572]
This commit is contained in:
Zhi You Tan
2017-04-28 21:28:34 +12:00
parent ffdfc24e65
commit b939086e10
2 changed files with 30 additions and 2 deletions
@@ -53,6 +53,9 @@ public class Controller implements Initializable {
} }
/**
* Running a timer to update the livestream status on welcome screen. Update interval is 500 miliseconds.
*/
public void startStream() { public void startStream() {
if (StreamParser.isStreamStatus()) { if (StreamParser.isStreamStatus()) {
streamButton.setVisible(false); streamButton.setVisible(false);
@@ -64,7 +67,18 @@ public class Controller implements Initializable {
@Override @Override
public void run() { public void run() {
Platform.runLater(() -> { Platform.runLater(() -> {
if (StreamParser.getTimeSinceStart() != 0) { if (StreamParser.isRaceFinished()) {
timeTillLive.setTextFill(Color.RED);
timeTillLive.setText("Race finished! Waiting for new race...");
switchToRaceViewButton.setDisable(true);
} else if (StreamParser.getTimeSinceStart() > 0 && StreamParser.getTimeSinceStart() % 10 == 0) {
timeTillLive.setTextFill(Color.RED);
switchToRaceViewButton.setDisable(false);
Long timerMinute = StreamParser.getTimeSinceStart() / 60;
Long timerSecond = StreamParser.getTimeSinceStart() % 60;
String timerString = "-" + timerMinute + "." + timerSecond + " minutes";
timeTillLive.setText(timerString);
} else if (StreamParser.getTimeSinceStart() % 10 == 0) {
timeTillLive.setTextFill(Color.BLACK); timeTillLive.setTextFill(Color.BLACK);
switchToRaceViewButton.setDisable(false); switchToRaceViewButton.setDisable(false);
Long timerMinute = -1 * StreamParser.getTimeSinceStart() / 60; Long timerMinute = -1 * StreamParser.getTimeSinceStart() / 60;
@@ -32,8 +32,9 @@ public class StreamParser extends Thread{
private String threadName; private String threadName;
private Thread t; private Thread t;
private static boolean raceStarted = false; private static boolean raceStarted = false;
private static boolean raceFinished = false;
private static boolean streamStatus = false; private static boolean streamStatus = false;
private static long timeSinceStart = 0; private static long timeSinceStart = -1;
public StreamParser(String threadName){ public StreamParser(String threadName){
this.threadName = threadName; this.threadName = threadName;
@@ -145,12 +146,16 @@ public class StreamParser extends Thread{
format.setTimeZone(TimeZone.getTimeZone("UTC")); format.setTimeZone(TimeZone.getTimeZone("UTC"));
long timeTillStart = ((new Date (expectedStartTime)).getTime() - (new Date (currentTime)).getTime())/1000; long timeTillStart = ((new Date (expectedStartTime)).getTime() - (new Date (currentTime)).getTime())/1000;
if (timeTillStart > 0 && timeTillStart % 10 == 0) { if (timeTillStart > 0 && timeTillStart % 10 == 0) {
timeSinceStart = timeTillStart;
System.out.println("Time till start: " + timeTillStart + " Seconds"); System.out.println("Time till start: " + timeTillStart + " Seconds");
} else { } else {
if (raceStatus == 4 || raceStatus == 8){ if (raceStatus == 4 || raceStatus == 8){
raceFinished = true;
raceStarted = false;
System.out.println("RACE HAS FINISHED"); System.out.println("RACE HAS FINISHED");
} else if (!raceStarted){ } else if (!raceStarted){
raceStarted = true; raceStarted = true;
raceFinished = false;
System.out.println("RACE HAS STARTED"); System.out.println("RACE HAS STARTED");
} }
if (timeTillStart % 10 == 0){ if (timeTillStart % 10 == 0){
@@ -430,5 +435,14 @@ public class StreamParser extends Thread{
public static long getTimeSinceStart() { public static long getTimeSinceStart() {
return timeSinceStart; return timeSinceStart;
} }
/**
* return false if race not finished, true otherwise
*
* @return race finished status
*/
public static boolean isRaceFinished() {
return raceFinished;
}
} }