Skip to content

Commit

Permalink
Widgets now display the correct weather.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamuno committed Mar 13, 2018
1 parent c0ea983 commit 07909d6
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 17 deletions.
16 changes: 8 additions & 8 deletions app/build.gradle
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
compileSdkVersion 26
buildToolsVersion '26.0.2'

defaultConfig {
applicationId "org.secuso.privacyfriendlyweather"
minSdkVersion 17
targetSdkVersion 25
targetSdkVersion 26
versionCode 4
versionName "1.2.0"

Expand All @@ -25,13 +25,13 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:design:25.4.0'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.j256.ormlite:ormlite-core:5.0'
compile 'com.j256.ormlite:ormlite-android:5.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:recyclerview-v7:25.4.0'
compile 'com.android.support:cardview-v7:25.4.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
}
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -102,7 +102,6 @@
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/weather_widget_5day_info" />
Expand Down
@@ -1,6 +1,9 @@
package org.secuso.privacyfriendlyweather.services;

import android.app.IntentService;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
Expand All @@ -14,6 +17,8 @@
import org.secuso.privacyfriendlyweather.database.Forecast;
import org.secuso.privacyfriendlyweather.database.PFASQLiteHelper;
import org.secuso.privacyfriendlyweather.preferences.PrefManager;
import org.secuso.privacyfriendlyweather.ui.updater.IUpdateableCityUI;
import org.secuso.privacyfriendlyweather.ui.updater.ViewUpdater;
import org.secuso.privacyfriendlyweather.weather_api.IHttpRequestForCityList;
import org.secuso.privacyfriendlyweather.weather_api.IHttpRequestForForecast;
import org.secuso.privacyfriendlyweather.weather_api.open_weather_map.OwmHttpRequestForForecast;
Expand Down Expand Up @@ -55,7 +60,7 @@ public void onCreate() {
dbHelper = PFASQLiteHelper.getInstance(getApplicationContext());
prefManager = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
}

/**
* @see IntentService#onHandleIntent(Intent)
*/
Expand Down
Expand Up @@ -2,6 +2,7 @@

import org.secuso.privacyfriendlyweather.database.CurrentWeatherData;
import org.secuso.privacyfriendlyweather.database.Forecast;
import org.secuso.privacyfriendlyweather.widget.WeatherWidget;

import java.util.ArrayList;
import java.util.List;
Expand Down
Expand Up @@ -3,6 +3,7 @@
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
Expand Down Expand Up @@ -129,5 +130,22 @@ public void onEnabled(Context context) {
public void onDisabled(Context context) {
// Enter relevant functionality for when the last widget is disabled
}

public static void forceWidgetUpdate(Context context){
forceWidgetUpdate(null, context);
}

public static void forceWidgetUpdate(Integer widgetId, Context context){
Intent intent = new Intent(context, WeatherWidget.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
int[] ids;
if(widgetId == null) {
ids = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, WeatherWidget.class));
}else{
ids = new int[]{widgetId};
}
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
context.sendBroadcast(intent);
}
}

Expand Up @@ -3,6 +3,7 @@
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -24,6 +25,11 @@

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;

/**
Expand Down Expand Up @@ -55,8 +61,20 @@ protected Void doInBackground(Integer... params) {

City city = database.getCityById(cityId);
List<Forecast> forecastList = database.getForecastsByCityId(cityId);
List<Forecast> weekForecastList = new ArrayList<>();
Date now = new Date();

updateView(context, appWidgetManager, views, appWidgetId, forecastList, city);
for(Forecast fc : forecastList) {
if(fc.getForecastTime().after(now)) {
Calendar c = new GregorianCalendar();
c.setTime(fc.getForecastTime());
if (c.get(Calendar.HOUR_OF_DAY) == 12) {
weekForecastList.add(fc);
}
}
}

updateView(context, appWidgetManager, views, appWidgetId, weekForecastList, city);

database.close();

Expand All @@ -71,7 +89,8 @@ private static void updateView(Context context, AppWidgetManager appWidgetManage
DecimalFormat decimalFormat = new DecimalFormat("#.0");
SimpleDateFormat dayFormat = new SimpleDateFormat("EEE");

forecastList = DayForecastFilter.filter(forecastList, 5);
//forecastList = DayForecastFilter.filter(forecastList, 5);
if(forecastList.size() < 5) return;

String day1 = dayFormat.format(forecastList.get(0).getForecastTime());
String day2 = dayFormat.format(forecastList.get(1).getForecastTime());
Expand Down Expand Up @@ -173,5 +192,22 @@ public void onEnabled(Context context) {
public void onDisabled(Context context) {
// Enter relevant functionality for when the last widget is disabled
}

public static void forceWidgetUpdate(Context context){
forceWidgetUpdate(null, context);
}

public static void forceWidgetUpdate(Integer widgetId, Context context){
Intent intent = new Intent(context, WeatherWidgetFiveDayForecast.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
int[] ids;
if(widgetId == null) {
ids = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, WeatherWidgetFiveDayForecast.class));
}else{
ids = new int[]{widgetId};
}
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
context.sendBroadcast(intent);
}
}

Expand Up @@ -3,6 +3,7 @@
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -23,6 +24,10 @@

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

/**
Expand Down Expand Up @@ -55,8 +60,20 @@ protected Void doInBackground(Integer... params) {

City city = database.getCityById(cityId);
List<Forecast> forecastList = database.getForecastsByCityId(cityId);
List<Forecast> weekForecastList = new ArrayList<>();
Date now = new Date();

updateView(context, appWidgetManager, views, appWidgetId, forecastList, city);
for(Forecast fc : forecastList) {
if(fc.getForecastTime().after(now)) {
Calendar c = new GregorianCalendar();
c.setTime(fc.getForecastTime());
if (c.get(Calendar.HOUR_OF_DAY) == 12) {
weekForecastList.add(fc);
}
}
}

updateView(context, appWidgetManager, views, appWidgetId, weekForecastList, city);

database.close();

Expand All @@ -71,7 +88,8 @@ private static void updateView(Context context, AppWidgetManager appWidgetManage
DecimalFormat decimalFormat = new DecimalFormat("#.0");
SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE");

forecastList = DayForecastFilter.filter(forecastList, 3);
//forecastList = DayForecastFilter.filter(forecastList, 3);
if(forecastList.size() < 3) return;

String day1 = dayFormat.format(forecastList.get(0).getForecastTime());
String day2 = dayFormat.format(forecastList.get(1).getForecastTime());
Expand Down Expand Up @@ -152,5 +170,22 @@ public void onEnabled(Context context) {
public void onDisabled(Context context) {
// Enter relevant functionality for when the last widget is disabled
}

public static void forceWidgetUpdate(Context context){
forceWidgetUpdate(null, context);
}

public static void forceWidgetUpdate(Integer widgetId, Context context){
Intent intent = new Intent(context, WeatherWidgetThreeDayForecast.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
int[] ids;
if(widgetId == null) {
ids = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, WeatherWidgetThreeDayForecast.class));
}else{
ids = new int[]{widgetId};
}
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
context.sendBroadcast(intent);
}
}

2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -9,7 +9,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Sat Apr 29 01:00:33 CEST 2017
#Tue Mar 13 11:04:32 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

0 comments on commit 07909d6

Please sign in to comment.