-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added #882 - Weather feature overlay
Signed-off-by: Amr Hossam <[email protected]>
- Loading branch information
1 parent
e36d188
commit 3df18c7
Showing
32 changed files
with
752 additions
and
4 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...usaway-android/src/androidTest/java/org/onebusaway/android/io/test/RegionWeatherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.onebusaway.android.io.test; | ||
|
||
import static androidx.test.InstrumentationRegistry.getTargetContext; | ||
import static junit.framework.Assert.assertNotNull; | ||
|
||
import android.content.ContentResolver; | ||
import android.net.Uri; | ||
|
||
import org.junit.Test; | ||
import org.onebusaway.android.R; | ||
import org.onebusaway.android.io.elements.ObaRegion; | ||
import org.onebusaway.android.io.request.ObaRegionsRequest; | ||
import org.onebusaway.android.io.request.ObaRegionsResponse; | ||
import org.onebusaway.android.io.request.weather.ObaWeatherRequest; | ||
import org.onebusaway.android.io.request.weather.models.ObaWeatherResponse; | ||
|
||
|
||
public class RegionWeatherTest { | ||
@Test | ||
public void testRequest() { | ||
|
||
final Uri.Builder builder = new Uri.Builder(); | ||
builder.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE); | ||
builder.authority(getTargetContext().getPackageName()); | ||
builder.path(String.valueOf(R.raw.regions_v3)); | ||
|
||
ObaRegionsRequest regionsRequest = ObaRegionsRequest.newRequest(getTargetContext(), builder.build()); | ||
ObaRegionsResponse regionsResponse = regionsRequest.call(); | ||
|
||
final ObaRegion[] list = regionsResponse.getRegions(); | ||
|
||
for (ObaRegion region : list) { | ||
ObaWeatherRequest weatherRequest= ObaWeatherRequest.newRequest(region.getId()); | ||
ObaWeatherResponse weatherResponse = weatherRequest.call(); | ||
assertNotNull(weatherResponse); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ay-android/src/main/java/org/onebusaway/android/io/request/weather/ObaWeatherRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.onebusaway.android.io.request.weather; | ||
|
||
import android.net.Uri; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import org.onebusaway.android.R; | ||
import org.onebusaway.android.app.Application; | ||
import org.onebusaway.android.io.request.RequestBase; | ||
import org.onebusaway.android.io.request.weather.models.ObaWeatherResponse; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
|
||
public final class ObaWeatherRequest extends RequestBase implements Callable<ObaWeatherResponse> { | ||
|
||
private ObaWeatherRequest(Uri uri) { | ||
super(uri); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private static Uri URI = null; | ||
|
||
public Builder(long regionId) { | ||
String weatherAPIURL = Application.get().getResources().getString(R.string.weather_api_url); | ||
|
||
// Replacing param regionID with our current region id. | ||
weatherAPIURL = weatherAPIURL.replace("regionID",String.valueOf(regionId)); | ||
URI = Uri.parse(weatherAPIURL); | ||
} | ||
|
||
public ObaWeatherRequest build() { | ||
return new ObaWeatherRequest(URI); | ||
} | ||
} | ||
|
||
public static ObaWeatherRequest newRequest(long regionId) { | ||
return new Builder(regionId).build(); | ||
} | ||
|
||
@Override | ||
public ObaWeatherResponse call() { | ||
return call(ObaWeatherResponse.class); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String toString() { | ||
return "ObaWeatherRequest [mUri=" + mUri + "]"; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...droid/src/main/java/org/onebusaway/android/io/request/weather/WeatherRequestListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.onebusaway.android.io.request.weather; | ||
|
||
import org.onebusaway.android.io.request.weather.models.ObaWeatherResponse; | ||
|
||
public interface WeatherRequestListener { | ||
void onWeatherResponseReceived(ObaWeatherResponse response); | ||
void onWeatherRequestFailed(); | ||
} |
34 changes: 34 additions & 0 deletions
34
...y-android/src/main/java/org/onebusaway/android/io/request/weather/WeatherRequestTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.onebusaway.android.io.request.weather; | ||
|
||
import android.os.AsyncTask; | ||
import android.util.Log; | ||
|
||
import org.onebusaway.android.io.request.weather.models.ObaWeatherResponse; | ||
|
||
public class WeatherRequestTask extends AsyncTask<ObaWeatherRequest, Void, ObaWeatherResponse> { | ||
private static final String TAG = "Weather Request"; | ||
private WeatherRequestListener mListener; | ||
|
||
public WeatherRequestTask(WeatherRequestListener listener) { | ||
mListener = listener; | ||
} | ||
|
||
@Override | ||
protected ObaWeatherResponse doInBackground(ObaWeatherRequest... requests) { | ||
try { | ||
return requests[0].call(); | ||
} catch (Exception e) { | ||
Log.e(TAG, "Error executing weather request", e); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(ObaWeatherResponse response) { | ||
if (response != null) { | ||
mListener.onWeatherResponseReceived(response); | ||
} else { | ||
mListener.onWeatherRequestFailed(); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...droid/src/main/java/org/onebusaway/android/io/request/weather/models/CurrentForecast.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.onebusaway.android.io.request.weather.models; | ||
|
||
public class CurrentForecast { | ||
public String icon; | ||
public double precip_per_hour; | ||
public double precip_probability; | ||
public String summary; | ||
public double temperature; | ||
public double temperature_feels_like; | ||
public int time; | ||
public double wind_speed; | ||
|
||
public String getIcon() { | ||
return icon; | ||
} | ||
|
||
public double getPrecip_per_hour() { | ||
return precip_per_hour; | ||
} | ||
|
||
public double getPrecip_probability() { | ||
return precip_probability; | ||
} | ||
|
||
public String getSummary() { | ||
return summary; | ||
} | ||
|
||
public double getTemperature() { | ||
return temperature; | ||
} | ||
|
||
public double getTemperature_feels_like() { | ||
return temperature_feels_like; | ||
} | ||
|
||
public int getTime() { | ||
return time; | ||
} | ||
|
||
public double getWind_speed() { | ||
return wind_speed; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...ndroid/src/main/java/org/onebusaway/android/io/request/weather/models/HourlyForecast.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.onebusaway.android.io.request.weather.models; | ||
|
||
public class HourlyForecast { | ||
|
||
private String icon; | ||
private double precip_per_hour; | ||
private double precip_probability; | ||
private String summary; | ||
private double temperature; | ||
private double temperature_feels_like; | ||
private int time; | ||
private double wind_speed; | ||
|
||
public String getIcon() { | ||
return icon; | ||
} | ||
|
||
public double getPrecip_per_hour() { | ||
return precip_per_hour; | ||
} | ||
|
||
public double getPrecip_probability() { | ||
return precip_probability; | ||
} | ||
|
||
public String getSummary() { | ||
return summary; | ||
} | ||
|
||
public double getTemperature() { | ||
return temperature; | ||
} | ||
|
||
public double getTemperature_feels_like() { | ||
return temperature_feels_like; | ||
} | ||
|
||
public int getTime() { | ||
return time; | ||
} | ||
|
||
public double getWind_speed() { | ||
return wind_speed; | ||
} | ||
|
||
|
||
} |
72 changes: 72 additions & 0 deletions
72
...id/src/main/java/org/onebusaway/android/io/request/weather/models/ObaWeatherResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.onebusaway.android.io.request.weather.models; | ||
|
||
import java.util.List; | ||
|
||
public class ObaWeatherResponse { | ||
|
||
private CurrentForecast current_forecast; | ||
private List<HourlyForecast> hourly_forecast; | ||
private double latitude; | ||
private double longitude; | ||
private int region_identifier; | ||
private String region_name; | ||
private String retrieved_at; | ||
private String today_summary; | ||
private String units; | ||
|
||
public CurrentForecast getCurrent_forecast() { | ||
return current_forecast; | ||
} | ||
|
||
public List<HourlyForecast> getHourly_forecast() { | ||
return hourly_forecast; | ||
} | ||
|
||
|
||
public double getLatitude() { | ||
return latitude; | ||
} | ||
|
||
public double getLongitude() { | ||
return longitude; | ||
} | ||
|
||
public int getRegion_identifier() { | ||
return region_identifier; | ||
} | ||
|
||
|
||
public String getRegion_name() { | ||
return region_name; | ||
} | ||
|
||
|
||
public String getRetrieved_at() { | ||
return retrieved_at; | ||
} | ||
|
||
|
||
public String getToday_summary() { | ||
return today_summary; | ||
} | ||
|
||
|
||
public String getUnits() { | ||
return units; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ObaWeatherResponse{" + | ||
"current_forecast=" + current_forecast + | ||
", hourly_forecast=" + hourly_forecast + | ||
", latitude=" + latitude + | ||
", longitude=" + longitude + | ||
", region_identifier=" + region_identifier + | ||
", region_name='" + region_name + '\'' + | ||
", retrieved_at='" + retrieved_at + '\'' + | ||
", today_summary='" + today_summary + '\'' + | ||
", units='" + units + '\'' + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.