Compare commits
	
		
			2 Commits
		
	
	
		
			c8aa18338a
			...
			130f93a9f3
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 130f93a9f3 | |||
| 67a2eff6a2 | 
| @@ -9,6 +9,7 @@ import java.nio.charset.StandardCharsets; | ||||
| import java.nio.file.Files; | ||||
| import java.nio.file.Path; | ||||
| import java.nio.file.Paths; | ||||
| import java.time.format.DateTimeFormatter; | ||||
| import java.util.ArrayList; | ||||
| import java.util.logging.Level; | ||||
| import java.util.logging.Logger; | ||||
| @@ -46,6 +47,8 @@ public class MainController implements Initializable { | ||||
|     private MainSettings settings; | ||||
|     private StationSettings selectedStation; | ||||
|  | ||||
|     private StringProperty nextSendTime = new SimpleStringProperty(); | ||||
|  | ||||
|     private StringProperty selectedStationName = new SimpleStringProperty(); | ||||
|  | ||||
|     private SimpleBooleanProperty unsavedChanges = new SimpleBooleanProperty(); | ||||
| @@ -53,7 +56,7 @@ public class MainController implements Initializable { | ||||
|     public StringProperty windowTitle = new SimpleStringProperty("Numbers Station"); | ||||
|  | ||||
|     @FXML | ||||
|     private Label lastRetrievedLabel; | ||||
|     private Label nextSendTimeLabel; | ||||
|  | ||||
|     @FXML | ||||
|     private TextArea messageTextArea; | ||||
| @@ -171,6 +174,9 @@ public class MainController implements Initializable { | ||||
|     @Override | ||||
|     public void initialize(URL location, ResourceBundle resources) { | ||||
|         stationNameField.textProperty().bindBidirectional(selectedStationName); | ||||
|         nextSendTimeLabel.textProperty().bind(nextSendTime); | ||||
|  | ||||
|         nextSendTime.set("sup brah"); | ||||
|  | ||||
|         Result<MainSettings, Exception> result = MainSettings.load(); | ||||
|         if (!result.hasSuccess()) { | ||||
| @@ -283,6 +289,21 @@ public class MainController implements Initializable { | ||||
|  | ||||
|         logger.info("Updating station settings: " + newStationSettings.getName()); | ||||
|  | ||||
|         DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); | ||||
|  | ||||
|         try { | ||||
|         nextSendTime.set(newStationSettings.nextSendTime().format(dateFormatter)); | ||||
|         } catch (StationSettings.StationSettingsException e) { | ||||
|             String errMessage = "Failed to calculate next message time"; | ||||
|             logger.log(Level.SEVERE, errMessage, e); | ||||
|             Alert alert = new Alert(Alert.AlertType.ERROR); | ||||
|             alert.setTitle("Exception"); | ||||
|             alert.setHeaderText(null); | ||||
|             alert.setContentText(errMessage + ": " + e.getMessage()); | ||||
|             alert.showAndWait(); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         selectedStation = newStationSettings; | ||||
|         selectedStationName.set(newStationSettings.getName()); | ||||
|         settings.setSelectedStationName(selectedStationName.get()); | ||||
|   | ||||
| @@ -11,7 +11,9 @@ import java.nio.file.Paths; | ||||
| import java.nio.file.SimpleFileVisitor; | ||||
| import java.security.SecureRandom; | ||||
| import java.time.LocalDate; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.LocalTime; | ||||
| import java.time.Period; | ||||
| import java.util.ArrayList; | ||||
| import java.util.logging.Logger; | ||||
| import java.util.logging.Level; | ||||
| @@ -191,6 +193,49 @@ public class StationSettings { | ||||
|         return messageFormattedBuilder.toString(); | ||||
|     } | ||||
|  | ||||
|     public LocalDateTime nextSendTime() throws StationSettingsException { | ||||
|         Period sinceScheduleStart = Period.between(scheduleStartDate , LocalDate.now()); | ||||
|         // If this period's time has not yet passed, then show that time. | ||||
|         // Otherwise, show the next period's time. | ||||
|         switch (messagePeriod) { | ||||
|             case DAILY: | ||||
|                 if (LocalTime.now().isBefore(scheduleStartTime)) { | ||||
|                     return LocalDate.now().atTime(scheduleStartTime); | ||||
|                 } else { | ||||
|                     return LocalDate.now().plusDays(1).atTime(scheduleStartTime); | ||||
|                 } | ||||
|             case WEEKLY: | ||||
|                 int weekdayDifference = scheduleStartDate.getDayOfWeek().getValue() - LocalDate.now().getDayOfWeek().getValue(); | ||||
|                 System.out.println("weekdayDifference: " + weekdayDifference); | ||||
|                 if (weekdayDifference > 0) { | ||||
|                     LocalDate.now().plusDays(weekdayDifference).atTime(scheduleStartTime); | ||||
|                  } else if (weekdayDifference == 0){ | ||||
|                     if (LocalTime.now().isBefore(scheduleStartTime)) { | ||||
|                         return LocalDate.now().atTime(scheduleStartTime); | ||||
|                     } else { | ||||
|                         return LocalDate.now().plusWeeks(1).atTime(scheduleStartTime); | ||||
|                     } | ||||
|                 } else { | ||||
|                     return LocalDate.now().plusDays(7 + weekdayDifference).atTime(scheduleStartTime); | ||||
|                 } | ||||
|             case MONTHLY: | ||||
|                 int monthdayDifference = scheduleStartDate.getDayOfMonth() - LocalDate.now().getDayOfMonth(); | ||||
|                 if (monthdayDifference > 0) { | ||||
|                     LocalDate.now().plusDays(monthdayDifference).atTime(scheduleStartTime); | ||||
|                 } else if (monthdayDifference == 0) { | ||||
|                     if (LocalTime.now().isBefore(scheduleStartTime)) { | ||||
|                         return LocalDate.now().atTime(scheduleStartTime); | ||||
|                     } else { | ||||
|                         return LocalDate.now().plusMonths(1).atTime(scheduleStartTime); | ||||
|                     } | ||||
|                 } else { | ||||
|                     return LocalDate.now().plusMonths(1).plusDays(monthdayDifference).atTime(scheduleStartTime); | ||||
|                 } | ||||
|             default: | ||||
|                 throw new StationSettingsException("Invalid period value: " + messagePeriod); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public String getAddress() { | ||||
|         return address; | ||||
|     } | ||||
| @@ -304,4 +349,11 @@ public class StationSettings { | ||||
|             super(message); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public static class StationSettingsException extends Exception { | ||||
|         public StationSettingsException(String message) { | ||||
|             super(message); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -77,12 +77,12 @@ | ||||
|                         <Font size="14.0" /> | ||||
|                      </font> | ||||
|                   </Label> | ||||
|                   <Label fx:id="lastRetrievedLabel" layoutX="201.0" layoutY="15.0" text="2024-12-25T12:59:47" AnchorPane.leftAnchor="201.0" AnchorPane.topAnchor="15.0"> | ||||
|                   <Label fx:id="nextSendTimeLabel" layoutX="202.0" layoutY="14.0" text="2024-12-25T12:59:47" AnchorPane.leftAnchor="202.0" AnchorPane.topAnchor="14.0"> | ||||
|                      <font> | ||||
|                         <Font size="14.0" /> | ||||
|                      </font> | ||||
|                   </Label> | ||||
|                   <Button layoutX="534.0" layoutY="13.0" mnemonicParsing="false" onAction="#handleStationSettingsButtonPress" text="Station Settings" AnchorPane.rightAnchor="6.5" AnchorPane.topAnchor="13.0" /> | ||||
|                   <Button layoutX="516.0" layoutY="13.0" mnemonicParsing="false" onAction="#handleStationSettingsButtonPress" text="Station Settings" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="13.0" /> | ||||
|                </children> | ||||
|             </AnchorPane> | ||||
|             <Separator prefWidth="200.0" GridPane.rowIndex="2" /> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user