Skip to content

Commit

Permalink
Fixed refresh stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb-yun committed Feb 13, 2018
1 parent c062d2e commit 83b48fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class WidgetUtils {
//private static final String SYNC_CLICKED = "automaticWidgetSyncButtonClick";
private static final String SYNC_CLICKED = "com.cogentworks.overwidget.action.UPDATE";
private static final String SYNC_CLICKED = OverWidgetProvider.SYNC_CLICKED;
public static final String TAG = "WidgetUtils";

public static final String PREFS_NAME = "layout.OverWidgetProvider";
Expand Down Expand Up @@ -155,6 +155,7 @@ public static Profile getProfile(Context context, int appWidgetId) throws IOExce
result.SetRank("- - -", "nullrank");
}
responseBody.close();
Log.d(TAG, "responseBody.close");
} else {
// Other response code
Log.e(TAG, urlConnection.getResponseMessage());
Expand Down
18 changes: 10 additions & 8 deletions app/src/main/java/layout/OverWidgetProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.widget.Toast;

Expand All @@ -23,10 +24,10 @@
*/

public class OverWidgetProvider extends AppWidgetProvider {
private static final String SYNC_CLICKED = "automaticWidgetSyncButtonClick";

private static final String TAG = "OverWidgetProvider";
public static final String REFRESH_INTENT = "com.cogentworks.overwidget.action.UPDATE";
public static final String SYNC_CLICKED = "com.cogentworks.overwidget.action.SYNC_CLICKED";
//public static final String SYNC_CLICKED = REFRESH_INTENT;
//private static final String URI_SCHEME = "OVRWG";

@Override
Expand All @@ -38,7 +39,7 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
intent.setAction(OverWidgetProvider.REFRESH_INTENT);
intent.putExtra("appWidgetId", appWidgetId);
PendingIntent pi = PendingIntent.getBroadcast(context, appWidgetId, intent, 0);
alarmManager.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis(), 1000*60*60, pi);
alarmManager.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), 1000*60*60, pi);
}
}

Expand All @@ -50,7 +51,6 @@ private void onUpdate(Context context) {
onUpdate(context, appWidgetManager, appWidgetIds);
}


@Override
public void onDeleted(Context context, int[] appWidgetIds) {
// When the user deletes the widget, delete the preference associated with it.
Expand All @@ -75,29 +75,31 @@ public void onDisabled(Context context) {
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "OnReceive: " + intent.getAction());

if (SYNC_CLICKED.equals(intent.getAction())) {
/*if (SYNC_CLICKED.equals(intent.getAction())) {
Log.d(TAG, "Refreshing");
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
Bundle extras = intent.getExtras();
if (extras != null) {
int appWidgetId = (int) extras.get("WIDGET_ID");
Log.d(TAG, Integer.toString(appWidgetId));
int appWidgetId = (int) extras.get("appWidgetId");
Log.d(TAG, "appWidgetId: " + Integer.toString(appWidgetId));
//WidgetUtils.loadUserPref(context, appWidgetManager, appWidgetId, true);
Intent updateIntent = new Intent(context.getApplicationContext(), UpdateService.class);
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
context.startService(intent);
Toast.makeText(context, "Refreshing...", Toast.LENGTH_SHORT).show();
}
} else if (REFRESH_INTENT.equals(intent.getAction())) {
} else*/ if (REFRESH_INTENT.equals(intent.getAction()) || SYNC_CLICKED.equals(intent.getAction())) {
int appWidgetId = intent.getIntExtra("appWidgetId", 0);
Intent serviceIntent = new Intent(intent);
serviceIntent.setAction("com.cogentworks.overwidget.UPDATE_SERVICE");
serviceIntent.putExtra("appWidgetId", appWidgetId);
UpdateService.enqueueWork(context, serviceIntent);
context.startService(serviceIntent);
if (SYNC_CLICKED.equals(intent.getAction()))
Toast.makeText(context, "Refreshing...", Toast.LENGTH_SHORT).show();
} else super.onReceive(context, intent);
}

Expand Down

0 comments on commit 83b48fc

Please sign in to comment.