Skip to content

Commit

Permalink
finished weather (settings and units)
Browse files Browse the repository at this point in the history
  • Loading branch information
DBChoco committed May 29, 2022
1 parent 436b1b5 commit 733a954
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 29 deletions.
7 changes: 6 additions & 1 deletion src/main/java/io/github/dbchoco/Salawat/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class Main extends Application {

private static PrayerTimesCalculator prayerTimesCalculator;
private static ApiTimer apiTimer;
@Override
public void start(Stage stage) throws IOException, ClassNotFoundException {
//Fix arabic text bug
Expand Down Expand Up @@ -88,7 +89,11 @@ private void addStageSizeListener(Stage stage){
}

private void checkForUpdates() {
ApiTimer apiTimer = new ApiTimer();
apiTimer = new ApiTimer();
}

public static ApiTimer getApiTimer() {
return apiTimer;
}

public static void loadPrayerTimes() throws ClassNotFoundException {
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/io/github/dbchoco/Salawat/app/ApiTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,24 @@ public void run() {
Platform.runLater(new Runnable(){
@Override
public void run() {
Controllers.getMainHeaderController().setWeather(apiRequester.requestWeather());
if (UserSettings.showWeather){
Controllers.getMainHeaderController().setWeather(apiRequester.requestWeather());
}
}
});
}
}, 3000, 900000); //15 minutes
}

public void reloadWeather(){
if (UserSettings.showWeather){
Controllers.getMainHeaderController().setWeather(apiRequester.requestWeather());
}
else {
Controllers.getMainHeaderController().weatherBox.setVisible(false);
}
}

private Boolean compareVersion(){
if (currentVersion.equals(githubVersion)) return false;
String[] currentVersionSplit = currentVersion.split("\\.");
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/io/github/dbchoco/Salawat/app/MainTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,20 @@ private void checkAdhan(){
int minutes = Main.getPrayerTimesCalculator().timeAfterCurrentPrayer().getMinutes();
int seconds = Main.getPrayerTimesCalculator().timeAfterCurrentPrayer().getSeconds();
if (hours == 00 && minutes <= 10){
if (AudioPlayer.getIsPlaying()){
Controllers.getTimeController().displayTimeLeft("adhan");
}
if (minutes == 0 && seconds <= 10){
if (AudioPlayer.getIsPlaying()){
Controllers.getTimeController().displayTimeLeft("adhan");
}
if (!launchedAlerts){
if (UserSettings.enableAdhan){
if (!AudioPlayer.getIsPlaying()){
if (UserSettings.customFajrAdhan && (Main.getPrayerTimesCalculator().getCurrentPrayer().getName()).equals("fajr")) AudioPlayer.play(UserSettings.customFajrAdhanPath, true);
else AudioPlayer.play(true);
Runnable runnable = () -> {
if (UserSettings.customFajrAdhan &&
(Main.getPrayerTimesCalculator().getCurrentPrayer().getName()).equals("fajr"))
AudioPlayer.play(UserSettings.customFajrAdhanPath, true);
else AudioPlayer.play(true);
};
runnable.run();
}
}
if (UserSettings.notifications){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.dbchoco.Salawat.controllers.main;

import io.github.dbchoco.Salawat.Main;
import io.github.dbchoco.Salawat.app.UserSettings;
import io.github.dbchoco.Salawat.controllers.BaseController;
import io.github.dbchoco.Salawat.helpers.Controllers;
import io.github.dbchoco.Salawat.helpers.FontBinder;
Expand Down Expand Up @@ -37,7 +38,7 @@ public void initialize(){
public void setWeather(String[] weather){
if (weather[0] != null){
weatherIcon.setText(getWeatherIcon(Integer.parseInt(weather[0]), weather[1]));
weatherLabel.setText(Math.round(Double.parseDouble(weather[2])) + C");
weatherLabel.setText(Math.round(Double.parseDouble(weather[2])) + " + UserSettings.weatherUnit);
if (!weatherShown){
weatherBox.setVisible(true);
weatherShown = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import io.github.dbchoco.Salawat.app.I18N;
import io.github.dbchoco.Salawat.app.UserSettings;
import io.github.dbchoco.Salawat.controllers.BaseController;
import io.github.dbchoco.Salawat.helpers.Controllers;
import io.github.dbchoco.Salawat.helpers.StageController;
import io.github.dbchoco.Salawat.helpers.StringShortener;
import io.github.dbchoco.Salawat.helpers.*;
import io.github.palexdev.materialfx.controls.MFXButton;
import io.github.palexdev.materialfx.controls.MFXCheckbox;
import io.github.palexdev.materialfx.controls.MFXComboBox;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
Expand All @@ -27,8 +26,16 @@ public class AppearanceController extends BaseController implements SettingsPage
public MFXCheckbox darkmodeCheck;
public Label themeLabel;
public Label backgroundImageLabel;
public Label weatherLabel;
public MFXCheckbox weatherCheck;
public MFXComboBox unitCombo;
private ListItemArray weatherUnits = new ListItemArray();

public void initialize() throws ClassNotFoundException {
weatherUnits.add(new ListItem(I18N.get("celsius"), "C"));
weatherUnits.add(new ListItem(I18N.get("fahrenheit"), "F"));
weatherUnits.add(new ListItem(I18N.get("kelvin"), "K"));
ListGenerator.generateList(unitCombo, weatherUnits);
translate();
setupFilePickers();
setupThemeListener();
Expand All @@ -51,6 +58,9 @@ public void saveSettings() {
else if (!UserSettings.darkMode && UserSettings.bgImagePath.equals(Main.class.getResource("images/bgImage_dark.jpg").toExternalForm())){
UserSettings.bgImagePath = Main.class.getResource("images/bgImage.jpg").toExternalForm();
}

UserSettings.showWeather = weatherCheck.isSelected();
UserSettings.weatherUnit = weatherUnits.getItembyName(unitCombo.getText()).getValue();
}

@Override
Expand All @@ -60,6 +70,10 @@ public void loadSettings() {
darkmodeCheck.setSelected(UserSettings.darkMode);
bgImageCheck.setSelected(UserSettings.bgImage);
bgImageButton.setText(StringShortener.shortenString(UserSettings.bgImagePath, 25));

weatherCheck.setSelected(UserSettings.showWeather);
System.out.println(unitCombo.getSelectionModel().getSelectedItem());
unitCombo.getSelectionModel().selectItem(weatherUnits.getItembyValue(UserSettings.weatherUnit));
}

private void setupFilePickers() {
Expand Down Expand Up @@ -99,6 +113,10 @@ protected void translate() {
I18N.bindString(darkmodeCheck, "darkMode");
I18N.bindString(bgImageCheck, "bgImageCheck");
bgImageButton.setText(I18N.get("selectFile"));

I18N.bindString(weatherLabel, "weather");
I18N.bindString(weatherCheck, "showWeather");
I18N.bindString(unitCombo, "unit");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ public String requestVersion(){

public String[] requestWeather(){
String[] weather = {null, null, null};
String unit;
if (UserSettings.weatherUnit.equals("C")) unit = "metric";
else if (UserSettings.weatherUnit.equals("F")) unit = "imperial";
else unit = "standard";
ResourceBundle bundle = ResourceBundle.getBundle("data");
JSONObject response = request("https://api.openweathermap.org/data/2.5/weather?lat=" + UserSettings.latitude +
"&lon=" + UserSettings.longitude +
"&units=" + "metric" +
"&units=" + unit +
"&appid=" + bundle.getString("weatherApiKey"));

if (response != null){
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/github/dbchoco/Salawat/helpers/Reloader.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.dbchoco.Salawat.helpers;

import io.github.dbchoco.Salawat.Main;
import io.github.dbchoco.Salawat.app.UserSettings;

import java.time.LocalDate;

Expand All @@ -16,5 +17,7 @@ public static void reload() throws ClassNotFoundException {
//TODO add if value of dateformat changed
Controllers.getPrayerGridController().setupDatePicker();
Controllers.getTimeController().loadFormat();

Main.getApiTimer().reloadWeather();
}
}
4 changes: 2 additions & 2 deletions src/main/resources/io/github/dbchoco/Salawat/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
}

.mfx-checkbox, .mfx-radio-button{
-mfx-main: -common-gradient;
-mfx-main: -color-main;
}

.mfx-checkbox .mfx-ripple-generator {
-mfx-ripple-color: -common-gradient;
-mfx-ripple-color: -color-main;
-fx-opacity: 0.5;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<?import io.github.palexdev.materialfx.controls.MFXButton?>
<?import io.github.palexdev.materialfx.controls.MFXCheckbox?>
<?import io.github.palexdev.materialfx.controls.MFXComboBox?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
Expand All @@ -12,19 +13,17 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<AnchorPane prefHeight="400" prefWidth="400" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="io.github.dbchoco.Salawat.controllers.settings.tabs.AppearanceController">
<AnchorPane prefHeight="239.0" prefWidth="400" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="io.github.dbchoco.Salawat.controllers.settings.tabs.AppearanceController">
<children>
<GridPane prefHeight="400" prefWidth="400">
<GridPane prefHeight="231.0" prefWidth="400">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="57.0" minHeight="10.0" prefHeight="48.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="139.0" minHeight="10.0" prefHeight="98.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="111.0" minHeight="10.0" prefHeight="56.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="97.0" minHeight="10.0" prefHeight="51.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="85.0" minHeight="10.0" prefHeight="85.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="57.0" minHeight="10.0" prefHeight="56.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="139.0" minHeight="10.0" prefHeight="101.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="162.0" minHeight="10.0" prefHeight="82.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>

Expand Down Expand Up @@ -59,7 +58,7 @@

<FlowPane alignment="TOP_RIGHT" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
<children>
<VBox prefHeight="108.0" prefWidth="186.0">
<VBox prefHeight="74.0" prefWidth="186.0">
<FlowPane alignment="TOP_RIGHT">
<children>
<MFXCheckbox fx:id="bgImageCheck" text="Enable background image">
Expand All @@ -82,6 +81,33 @@
</VBox>
</children>
</FlowPane>
<FlowPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="2">
<children>
<Label fx:id="weatherLabel" text="Weather">
<font>
<Font size="20.0" />
</font>
</Label>
</children>
</FlowPane>
<VBox prefHeight="108.0" prefWidth="186.0" GridPane.columnIndex="1" GridPane.rowIndex="2">
<children>
<FlowPane alignment="TOP_RIGHT">
<children>
<MFXCheckbox fx:id="weatherCheck" text="Show weather">
<FlowPane.margin>
<Insets bottom="10.0" />
</FlowPane.margin>
</MFXCheckbox>
</children>
</FlowPane>
<FlowPane alignment="TOP_RIGHT" prefHeight="18.0" prefWidth="171.0">
<children>
<MFXComboBox fx:id="unitCombo" floatingText="Unit" />
</children>
</FlowPane>
</children>
</VBox>

</children>
</GridPane>
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/language_ar.properties
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,11 @@ resetSettings = \u0625\u0639\u0627\u062F\u0629 \u0636\u0628\u0637 \u0627\u0644\u
open = \u0641\u062A\u062D
hide = \u0625\u062E\u0641\u0627\u0621
quit = \u062A\u0631\u0643

//Weather
weather = \u0637\u0642\u0633
showWeather = \u0639\u0631\u0636 \u0627\u0644\u0637\u0642\u0633
unit = \u0648\u062D\u062F\u0629
celsius = \u062F\u0631\u062C\u0629 \u0645\u0626\u0648\u064A\u0629
kelvin = \u0643\u0644\u0641\u0646
fahrenheit = \u0641\u0647\u0631\u0646\u0647\u0627\u064A\u062A
2 changes: 1 addition & 1 deletion src/main/resources/language_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ TOTN = Third of the night
//Weather
weather = Weather
showWeather = Show weather
units = Units
unit = Unit
celsius = Celsius
kelvin = Kelvin
fahrenheit = Fahrenheit
8 changes: 4 additions & 4 deletions src/main/resources/language_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ download = Download
later = Later

//SunnahTimes
showSunnah = Show Sunnah times
showSunnah = Mostrar tiempo de Sunnah

//Weather
weather = Weather
showWeather = Show weather
units = Units
weather = Clima
showWeather = Mostrar clima
unit = Unidad
celsius = Celsius
kelvin = Kelvin
fahrenheit = Fahrenheit
2 changes: 1 addition & 1 deletion src/main/resources/language_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ TOTN = Tiers de la nuit
//Weather
weather = M\u00E9t\u00E9o
showWeather = Montrer la m\u00E9teo
units = Unit\u00E9s
unit = Unit\u00E9
celsius = Celsius
kelvin = Kelvin
fahrenheit = Fahrenheit
2 changes: 1 addition & 1 deletion src/main/resources/language_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ TOTN = Gecenin \u00DC\u00E7te Biri
//Weather
weather = Hava Durumu
showWeather = Hava Durumunu G\u00F6ster
units = Birimler
unit = Birimler
celsius = Santigrat
kelvin = Kelvin
fahrenheit = Fahrenayt

0 comments on commit 733a954

Please sign in to comment.