Skip to content

Commit f12fcc3

Browse files
committed
Merge branch 'develop'
2 parents 61b6dde + a857bbb commit f12fcc3

File tree

25 files changed

+951
-1062
lines changed

25 files changed

+951
-1062
lines changed

.idea/codeStyles/Project.xml

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
23

34
android {
4-
compileSdkVersion 28
5+
compileSdkVersion 29
6+
57
defaultConfig {
6-
applicationId "de.interaapps.localweather"
78
minSdkVersion 15
8-
targetSdkVersion 28
9+
targetSdkVersion 29
910
versionCode 1
1011
versionName "1.0"
1112
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -20,11 +21,17 @@ android {
2021

2122
dependencies {
2223
implementation fileTree(dir: 'libs', include: ['*.jar'])
23-
implementation 'androidx.appcompat:appcompat:1.0.2'
24+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
25+
implementation 'androidx.appcompat:appcompat:1.1.0'
26+
implementation "androidx.core:core-ktx:1.3.0"
2427
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
25-
testImplementation 'junit:junit:4.12'
28+
29+
testImplementation 'junit:junit:4.13'
2630
androidTestImplementation 'androidx.test:runner:1.2.0'
2731
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
32+
2833
implementation project(path: ':localWeather')
29-
implementation 'org.jetbrains:annotations-java5:15.0'
34+
}
35+
repositories {
36+
mavenCentral()
3037
}

app/src/androidTest/java/de/interaapps/localweather/ExampleInstrumentedTest.java renamed to app/src/androidTest/java/de/interaapps/localweather/example/ExampleInstrumentedTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package de.interaapps.localweather;
1+
package de.interaapps.localweather.example;
22

33
import android.content.Context;
44

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="de.interaapps.localweather">
3+
package="de.interaapps.localweather.example">
44

55
<application
66
android:allowBackup="true"

app/src/main/java/de/interaapps/localweather/MainActivity.java renamed to app/src/main/java/de/interaapps/localweather/example/MainActivity.java

Lines changed: 49 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
package de.interaapps.localweather;
1+
package de.interaapps.localweather.example;
22

3-
import androidx.annotation.NonNull;
43
import androidx.appcompat.app.AppCompatActivity;
54
import androidx.appcompat.widget.AppCompatImageView;
65
import androidx.appcompat.widget.AppCompatTextView;
76
import androidx.core.os.ConfigurationCompat;
87

98
import android.content.Intent;
9+
import android.location.Location;
1010
import android.os.Bundle;
1111
import android.util.Log;
1212

13-
import org.jetbrains.annotations.Nullable;
14-
1513
import java.text.SimpleDateFormat;
1614
import java.util.Calendar;
17-
import java.util.Timer;
18-
import java.util.TimerTask;
1915

16+
import de.interaapps.localweather.utils.Lang;
2017
import de.interaapps.localweather.utils.LocationFailedEnum;
21-
import de.interaapps.localweather.utils.OpenWeatherIcons;
18+
import de.interaapps.localweather.example.utils.OpenWeatherIcons;
2219
import de.interaapps.localweather.utils.Units;
20+
import de.interaapps.localweather.LocalWeather;
21+
import de.interaapps.localweather.Weather;
2322

2423
public class MainActivity extends AppCompatActivity {
2524

2625
private LocalWeather localWeather;
27-
private Weather weather;
28-
private boolean weatherReady = false;
2926
private AppCompatImageView weatherImage;
3027
private AppCompatTextView dayInfo;
3128
private AppCompatTextView weatherTemp;
@@ -73,90 +70,81 @@ private void initialize() {
7370
weatherWindDeg = findViewById(R.id.weather_wind_deg);
7471
weatherSunrise = findViewById(R.id.weather_sunrise);
7572
weatherSunset = findViewById(R.id.weather_sunset);
76-
localWeather = new LocalWeather(this,
77-
"OpenWeatherApiKey",
78-
true,
79-
true,
80-
new LocalWeather.Callbacks() {
81-
@Override
82-
public void onLocationFailure(LocationFailedEnum locationFailedEnum) {
83-
Log.e("LOCATION-ERROR", locationFailedEnum.toString());
84-
}
85-
86-
@Override
87-
public void onWeatherFailure(Throwable throwable) {
88-
Log.e("WEATHER-ERROR", throwable.getMessage());
89-
}
90-
91-
@Override
92-
public void onLocationSuccess() {
93-
localWeather.fetchWeather();
94-
}
95-
96-
@Override
97-
public void onWeatherSuccess() {
98-
weather = localWeather.getWeather();
99-
weatherReady = true;
100-
updateWeatherDetails();
101-
}
102-
});
73+
localWeather = new LocalWeather(this, "OpenWeatherApiKey");
10374
}
10475

10576
private void initializeLogic() {
106-
Timer timer = new Timer ();
107-
TimerTask tenMinTask = new TimerTask () {
77+
localWeather.setUseCurrentLocation(true);
78+
localWeather.setUpdateCurrentLocation(true);
79+
localWeather.lang = Lang.ENGLISH;
80+
localWeather.unit = Units.METRIC;
81+
82+
localWeather.setWeatherCallback(new LocalWeather.WeatherCallback() {
83+
@Override
84+
public void onSuccess(Weather weather) {
85+
updateWeatherDetails(weather);
86+
}
87+
88+
@Override
89+
public void onFailure(Throwable exception) {
90+
Log.e("Weather fetching Error", exception.getMessage());
91+
}
92+
});
93+
94+
localWeather.fetchCurrentLocation(new LocalWeather.CurrentLocationCallback() {
95+
@Override
96+
public void onSuccess(Location location) {
97+
Log.e("Location Success", location.toString());
98+
localWeather.fetchCurrentWeatherByLocation(location);
99+
}
100+
108101
@Override
109-
public void run () {
110-
weatherReady = false;
111-
localWeather.fetchLocation();
102+
public void onFailure(LocationFailedEnum locationFailedEnum) {
103+
Log.e("Location fetching Error", locationFailedEnum.toString());
112104
}
113-
};
114-
timer.schedule(tenMinTask, 0, 1000*60*10); //1000*60 = 1min *10 = 10min
105+
});
115106
}
116107

117-
private void updateWeatherDetails() {
118-
//extra check but should always be true
119-
if (weatherReady) {
108+
private void updateWeatherDetails(Weather weather) {
120109
new OpenWeatherIcons(getApplicationContext(), weather.getIcons()[0], weatherImage);
121-
String unit = (localWeather.getUnit() == Units.METRIC) ? "°C" : "°F" ;
122-
String speed = (localWeather.getUnit() == Units.METRIC) ? "km/h" : "mi/h" ;
123-
weatherTemp.setText(((int) weather.getTemp()) + unit);
110+
String unit = (localWeather.unit == Units.METRIC) ? "°C" : "°F" ;
111+
String speed = (localWeather.unit == Units.METRIC) ? "km/h" : "mi/h" ;
112+
weatherTemp.setText(((int) weather.getTemperature()) + unit);
124113
weatherInfo.setText("Description: " + weather.getDescriptions()[0]);
125114
weatherClouds.setText("Clouds: " + ((int) weather.getClouds()));
126-
weatherMaxTemp.setText("Max. Temp.: " + ((int) weather.getMaxTemp()) + unit);
127-
weatherMinTemp.setText("Min. Temp.: " + ((int) weather.getMinTemp()) + unit);
128-
weatherTempKf.setText("Temp Kf.: " + ((int) weather.getTempKf()));
115+
weatherMaxTemp.setText("Max. Temp.: " + ((int) weather.getMaxTemperature()) + unit);
116+
weatherMinTemp.setText("Min. Temp.: " + ((int) weather.getMinTemperature()) + unit);
117+
weatherTempKf.setText("Temp Kf.: " + ((int) weather.getTemperatureKf()));
129118
locationCountry.setText("Country: " + weather.getCountry());
130119

131120
//real location based: localWeather.getLatitude();
132-
locationLat.setText("Latitude: " + weather.getLat());
121+
locationLat.setText("Latitude: " + weather.getLatitude());
133122
//real location based: localWeather.getLongitude();
134-
locationLon.setText("Longitude: " + weather.getLon());
123+
locationLon.setText("Longitude: " + weather.getLongitude());
135124

136-
locationGroundLevel.setText("Ground Level: " + weather.getGrndLevel());
125+
locationGroundLevel.setText("Ground Level: " + weather.getGroundLevel());
137126
locationSeaLevel.setText("Sea Level: " + weather.getSeaLevel());
138127

139128
weatherBase.setText("Base: " + weather.getBase());
140129
weatherWindSpeed.setText("Wind Speed: " + weather.getWindSpeed() + speed);
141-
weatherWindDeg.setText("Wind Angle: " + ((int) weather.getWindDeg()) + "°");
130+
weatherWindDeg.setText("Wind Angle: " + ((int) weather.getWindAngle()) + "°");
142131
weatherSunrise.setText("Sunrise: " + weather.getSunrise());
143132
weatherSunset.setText("Sunset: " + weather.getSunset());
144-
}
145133

146134
Calendar calendar = Calendar.getInstance();
147135
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM", ConfigurationCompat.getLocales(getResources().getConfiguration()).get(0));
148136
dayInfo.setText(dateFormat.format(calendar.getTime()));
149137
}
150138

151139
@Override
152-
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
140+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
153141
super.onActivityResult(requestCode, resultCode, data);
154-
localWeather.getLocationAccess().onActivityResult(requestCode, resultCode, data);
142+
localWeather.onActivityResult(requestCode, resultCode, data);
155143
}
156144

157145
@Override
158-
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
146+
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
159147
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
160-
localWeather.getLocationAccess().onRequestPermissionsResult(requestCode, permissions, grantResults);
148+
localWeather.onRequestPermissionResult(requestCode, permissions, grantResults);
161149
}
162150
}

0 commit comments

Comments
 (0)