Skip to content

Commit 733a954

Browse files
author
DBChoco
committed
finished weather (settings and units)
1 parent 436b1b5 commit 733a954

File tree

14 files changed

+110
-29
lines changed

14 files changed

+110
-29
lines changed

src/main/java/io/github/dbchoco/Salawat/Main.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
public class Main extends Application {
2020

2121
private static PrayerTimesCalculator prayerTimesCalculator;
22+
private static ApiTimer apiTimer;
2223
@Override
2324
public void start(Stage stage) throws IOException, ClassNotFoundException {
2425
//Fix arabic text bug
@@ -88,7 +89,11 @@ private void addStageSizeListener(Stage stage){
8889
}
8990

9091
private void checkForUpdates() {
91-
ApiTimer apiTimer = new ApiTimer();
92+
apiTimer = new ApiTimer();
93+
}
94+
95+
public static ApiTimer getApiTimer() {
96+
return apiTimer;
9297
}
9398

9499
public static void loadPrayerTimes() throws ClassNotFoundException {

src/main/java/io/github/dbchoco/Salawat/app/ApiTimer.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,24 @@ public void run() {
4848
Platform.runLater(new Runnable(){
4949
@Override
5050
public void run() {
51-
Controllers.getMainHeaderController().setWeather(apiRequester.requestWeather());
51+
if (UserSettings.showWeather){
52+
Controllers.getMainHeaderController().setWeather(apiRequester.requestWeather());
53+
}
5254
}
5355
});
5456
}
5557
}, 3000, 900000); //15 minutes
5658
}
5759

60+
public void reloadWeather(){
61+
if (UserSettings.showWeather){
62+
Controllers.getMainHeaderController().setWeather(apiRequester.requestWeather());
63+
}
64+
else {
65+
Controllers.getMainHeaderController().weatherBox.setVisible(false);
66+
}
67+
}
68+
5869
private Boolean compareVersion(){
5970
if (currentVersion.equals(githubVersion)) return false;
6071
String[] currentVersionSplit = currentVersion.split("\\.");

src/main/java/io/github/dbchoco/Salawat/app/MainTimer.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,20 @@ private void checkAdhan(){
6868
int minutes = Main.getPrayerTimesCalculator().timeAfterCurrentPrayer().getMinutes();
6969
int seconds = Main.getPrayerTimesCalculator().timeAfterCurrentPrayer().getSeconds();
7070
if (hours == 00 && minutes <= 10){
71+
if (AudioPlayer.getIsPlaying()){
72+
Controllers.getTimeController().displayTimeLeft("adhan");
73+
}
7174
if (minutes == 0 && seconds <= 10){
72-
if (AudioPlayer.getIsPlaying()){
73-
Controllers.getTimeController().displayTimeLeft("adhan");
74-
}
7575
if (!launchedAlerts){
7676
if (UserSettings.enableAdhan){
7777
if (!AudioPlayer.getIsPlaying()){
78-
if (UserSettings.customFajrAdhan && (Main.getPrayerTimesCalculator().getCurrentPrayer().getName()).equals("fajr")) AudioPlayer.play(UserSettings.customFajrAdhanPath, true);
79-
else AudioPlayer.play(true);
78+
Runnable runnable = () -> {
79+
if (UserSettings.customFajrAdhan &&
80+
(Main.getPrayerTimesCalculator().getCurrentPrayer().getName()).equals("fajr"))
81+
AudioPlayer.play(UserSettings.customFajrAdhanPath, true);
82+
else AudioPlayer.play(true);
83+
};
84+
runnable.run();
8085
}
8186
}
8287
if (UserSettings.notifications){

src/main/java/io/github/dbchoco/Salawat/controllers/main/HeaderController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.dbchoco.Salawat.controllers.main;
22

33
import io.github.dbchoco.Salawat.Main;
4+
import io.github.dbchoco.Salawat.app.UserSettings;
45
import io.github.dbchoco.Salawat.controllers.BaseController;
56
import io.github.dbchoco.Salawat.helpers.Controllers;
67
import io.github.dbchoco.Salawat.helpers.FontBinder;
@@ -37,7 +38,7 @@ public void initialize(){
3738
public void setWeather(String[] weather){
3839
if (weather[0] != null){
3940
weatherIcon.setText(getWeatherIcon(Integer.parseInt(weather[0]), weather[1]));
40-
weatherLabel.setText(Math.round(Double.parseDouble(weather[2])) + C");
41+
weatherLabel.setText(Math.round(Double.parseDouble(weather[2])) + " + UserSettings.weatherUnit);
4142
if (!weatherShown){
4243
weatherBox.setVisible(true);
4344
weatherShown = true;

src/main/java/io/github/dbchoco/Salawat/controllers/settings/tabs/AppearanceController.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
import io.github.dbchoco.Salawat.app.I18N;
55
import io.github.dbchoco.Salawat.app.UserSettings;
66
import io.github.dbchoco.Salawat.controllers.BaseController;
7-
import io.github.dbchoco.Salawat.helpers.Controllers;
8-
import io.github.dbchoco.Salawat.helpers.StageController;
9-
import io.github.dbchoco.Salawat.helpers.StringShortener;
7+
import io.github.dbchoco.Salawat.helpers.*;
108
import io.github.palexdev.materialfx.controls.MFXButton;
119
import io.github.palexdev.materialfx.controls.MFXCheckbox;
10+
import io.github.palexdev.materialfx.controls.MFXComboBox;
1211
import javafx.application.Platform;
1312
import javafx.beans.value.ChangeListener;
1413
import javafx.beans.value.ObservableValue;
@@ -27,8 +26,16 @@ public class AppearanceController extends BaseController implements SettingsPage
2726
public MFXCheckbox darkmodeCheck;
2827
public Label themeLabel;
2928
public Label backgroundImageLabel;
29+
public Label weatherLabel;
30+
public MFXCheckbox weatherCheck;
31+
public MFXComboBox unitCombo;
32+
private ListItemArray weatherUnits = new ListItemArray();
3033

3134
public void initialize() throws ClassNotFoundException {
35+
weatherUnits.add(new ListItem(I18N.get("celsius"), "C"));
36+
weatherUnits.add(new ListItem(I18N.get("fahrenheit"), "F"));
37+
weatherUnits.add(new ListItem(I18N.get("kelvin"), "K"));
38+
ListGenerator.generateList(unitCombo, weatherUnits);
3239
translate();
3340
setupFilePickers();
3441
setupThemeListener();
@@ -51,6 +58,9 @@ public void saveSettings() {
5158
else if (!UserSettings.darkMode && UserSettings.bgImagePath.equals(Main.class.getResource("images/bgImage_dark.jpg").toExternalForm())){
5259
UserSettings.bgImagePath = Main.class.getResource("images/bgImage.jpg").toExternalForm();
5360
}
61+
62+
UserSettings.showWeather = weatherCheck.isSelected();
63+
UserSettings.weatherUnit = weatherUnits.getItembyName(unitCombo.getText()).getValue();
5464
}
5565

5666
@Override
@@ -60,6 +70,10 @@ public void loadSettings() {
6070
darkmodeCheck.setSelected(UserSettings.darkMode);
6171
bgImageCheck.setSelected(UserSettings.bgImage);
6272
bgImageButton.setText(StringShortener.shortenString(UserSettings.bgImagePath, 25));
73+
74+
weatherCheck.setSelected(UserSettings.showWeather);
75+
System.out.println(unitCombo.getSelectionModel().getSelectedItem());
76+
unitCombo.getSelectionModel().selectItem(weatherUnits.getItembyValue(UserSettings.weatherUnit));
6377
}
6478

6579
private void setupFilePickers() {
@@ -99,6 +113,10 @@ protected void translate() {
99113
I18N.bindString(darkmodeCheck, "darkMode");
100114
I18N.bindString(bgImageCheck, "bgImageCheck");
101115
bgImageButton.setText(I18N.get("selectFile"));
116+
117+
I18N.bindString(weatherLabel, "weather");
118+
I18N.bindString(weatherCheck, "showWeather");
119+
I18N.bindString(unitCombo, "unit");
102120
}
103121

104122
@Override

src/main/java/io/github/dbchoco/Salawat/helpers/ApiRequester.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ public String requestVersion(){
4848

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

5761
if (response != null){

src/main/java/io/github/dbchoco/Salawat/helpers/Reloader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.dbchoco.Salawat.helpers;
22

33
import io.github.dbchoco.Salawat.Main;
4+
import io.github.dbchoco.Salawat.app.UserSettings;
45

56
import java.time.LocalDate;
67

@@ -16,5 +17,7 @@ public static void reload() throws ClassNotFoundException {
1617
//TODO add if value of dateformat changed
1718
Controllers.getPrayerGridController().setupDatePicker();
1819
Controllers.getTimeController().loadFormat();
20+
21+
Main.getApiTimer().reloadWeather();
1922
}
2023
}

src/main/resources/io/github/dbchoco/Salawat/css/main.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
}
4242

4343
.mfx-checkbox, .mfx-radio-button{
44-
-mfx-main: -common-gradient;
44+
-mfx-main: -color-main;
4545
}
4646

4747
.mfx-checkbox .mfx-ripple-generator {
48-
-mfx-ripple-color: -common-gradient;
48+
-mfx-ripple-color: -color-main;
4949
-fx-opacity: 0.5;
5050
}
5151

src/main/resources/io/github/dbchoco/Salawat/fxml/settings/tabs/appearance.fxml

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<?import io.github.palexdev.materialfx.controls.MFXButton?>
44
<?import io.github.palexdev.materialfx.controls.MFXCheckbox?>
5+
<?import io.github.palexdev.materialfx.controls.MFXComboBox?>
56
<?import javafx.geometry.Insets?>
67
<?import javafx.scene.control.Label?>
78
<?import javafx.scene.layout.AnchorPane?>
@@ -12,19 +13,17 @@
1213
<?import javafx.scene.layout.VBox?>
1314
<?import javafx.scene.text.Font?>
1415

15-
<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">
16+
<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">
1617
<children>
17-
<GridPane prefHeight="400" prefWidth="400">
18+
<GridPane prefHeight="231.0" prefWidth="400">
1819
<columnConstraints>
1920
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
2021
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
2122
</columnConstraints>
2223
<rowConstraints>
23-
<RowConstraints maxHeight="57.0" minHeight="10.0" prefHeight="48.0" vgrow="SOMETIMES" />
24-
<RowConstraints maxHeight="139.0" minHeight="10.0" prefHeight="98.0" vgrow="SOMETIMES" />
25-
<RowConstraints maxHeight="111.0" minHeight="10.0" prefHeight="56.0" vgrow="SOMETIMES" />
26-
<RowConstraints maxHeight="97.0" minHeight="10.0" prefHeight="51.0" vgrow="SOMETIMES" />
27-
<RowConstraints maxHeight="85.0" minHeight="10.0" prefHeight="85.0" vgrow="SOMETIMES" />
24+
<RowConstraints maxHeight="57.0" minHeight="10.0" prefHeight="56.0" vgrow="SOMETIMES" />
25+
<RowConstraints maxHeight="139.0" minHeight="10.0" prefHeight="101.0" vgrow="SOMETIMES" />
26+
<RowConstraints maxHeight="162.0" minHeight="10.0" prefHeight="82.0" vgrow="SOMETIMES" />
2827
</rowConstraints>
2928
<children>
3029

@@ -59,7 +58,7 @@
5958

6059
<FlowPane alignment="TOP_RIGHT" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
6160
<children>
62-
<VBox prefHeight="108.0" prefWidth="186.0">
61+
<VBox prefHeight="74.0" prefWidth="186.0">
6362
<FlowPane alignment="TOP_RIGHT">
6463
<children>
6564
<MFXCheckbox fx:id="bgImageCheck" text="Enable background image">
@@ -82,6 +81,33 @@
8281
</VBox>
8382
</children>
8483
</FlowPane>
84+
<FlowPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="2">
85+
<children>
86+
<Label fx:id="weatherLabel" text="Weather">
87+
<font>
88+
<Font size="20.0" />
89+
</font>
90+
</Label>
91+
</children>
92+
</FlowPane>
93+
<VBox prefHeight="108.0" prefWidth="186.0" GridPane.columnIndex="1" GridPane.rowIndex="2">
94+
<children>
95+
<FlowPane alignment="TOP_RIGHT">
96+
<children>
97+
<MFXCheckbox fx:id="weatherCheck" text="Show weather">
98+
<FlowPane.margin>
99+
<Insets bottom="10.0" />
100+
</FlowPane.margin>
101+
</MFXCheckbox>
102+
</children>
103+
</FlowPane>
104+
<FlowPane alignment="TOP_RIGHT" prefHeight="18.0" prefWidth="171.0">
105+
<children>
106+
<MFXComboBox fx:id="unitCombo" floatingText="Unit" />
107+
</children>
108+
</FlowPane>
109+
</children>
110+
</VBox>
85111

86112
</children>
87113
</GridPane>

src/main/resources/language_ar.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,11 @@ resetSettings = \u0625\u0639\u0627\u062F\u0629 \u0636\u0628\u0637 \u0627\u0644\u
116116
open = \u0641\u062A\u062D
117117
hide = \u0625\u062E\u0641\u0627\u0621
118118
quit = \u062A\u0631\u0643
119+
120+
//Weather
121+
weather = \u0637\u0642\u0633
122+
showWeather = \u0639\u0631\u0636 \u0627\u0644\u0637\u0642\u0633
123+
unit = \u0648\u062D\u062F\u0629
124+
celsius = \u062F\u0631\u062C\u0629 \u0645\u0626\u0648\u064A\u0629
125+
kelvin = \u0643\u0644\u0641\u0646
126+
fahrenheit = \u0641\u0647\u0631\u0646\u0647\u0627\u064A\u062A

0 commit comments

Comments
 (0)