From add0edd175b4b1454814108373252f1ddafe6a84 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Wed, 17 Dec 2014 10:12:45 -0600 Subject: [PATCH] Stop scrollable widget update service --- .../com/todoroo/astrid/utility/Constants.java | 6 ------ .../astrid/widget/WidgetUpdateService.java | 14 ++++++------- .../widget/ScrollableWidgetUpdateService.java | 7 +++++++ .../java/org/tasks/widget/WidgetHelper.java | 20 ++++++------------- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/todoroo/astrid/utility/Constants.java b/src/main/java/com/todoroo/astrid/utility/Constants.java index e1fea5f8d..c5361f7d5 100644 --- a/src/main/java/com/todoroo/astrid/utility/Constants.java +++ b/src/main/java/com/todoroo/astrid/utility/Constants.java @@ -21,12 +21,6 @@ public final class Constants { */ public static final MarketStrategy MARKET_STRATEGY = new MarketStrategy.AndroidMarketStrategy(); - /** - * Interval to update the widget (in order to detect hidden tasks - * becoming visible) - */ - public static final long WIDGET_UPDATE_INTERVAL = 30 * 60 * 1000L; - // --- task list activity source strings public static final int SOURCE_OTHER = -1; diff --git a/src/main/java/com/todoroo/astrid/widget/WidgetUpdateService.java b/src/main/java/com/todoroo/astrid/widget/WidgetUpdateService.java index c26bc531c..2c88abcce 100644 --- a/src/main/java/com/todoroo/astrid/widget/WidgetUpdateService.java +++ b/src/main/java/com/todoroo/astrid/widget/WidgetUpdateService.java @@ -59,7 +59,12 @@ public class WidgetUpdateService extends InjectingService { }).start(); } - public void startServiceInBackgroundThread(Intent intent) { + @Override + public IBinder onBind(Intent intent) { + return null; + } + + private void startServiceInBackgroundThread(Intent intent) { ComponentName thisWidget = new ComponentName(this, TasksWidget.class); AppWidgetManager manager = AppWidgetManager.getInstance(this); @@ -88,12 +93,7 @@ public class WidgetUpdateService extends InjectingService { stopSelf(); } - @Override - public IBinder onBind(Intent intent) { - return null; - } - - public RemoteViews buildUpdate(Context context, int widgetId) { + private RemoteViews buildUpdate(Context context, int widgetId) { RemoteViews views = getThemedRemoteViews(context); int numberOfTasks = NUM_VISIBLE_TASKS; diff --git a/src/main/java/org/tasks/widget/ScrollableWidgetUpdateService.java b/src/main/java/org/tasks/widget/ScrollableWidgetUpdateService.java index 9d3f2ea0e..030d58001 100644 --- a/src/main/java/org/tasks/widget/ScrollableWidgetUpdateService.java +++ b/src/main/java/org/tasks/widget/ScrollableWidgetUpdateService.java @@ -26,6 +26,13 @@ public class ScrollableWidgetUpdateService extends InjectingRemoteViewsService { @Inject TagDataDao tagDataDao; @Inject Preferences preferences; + @Override + public void onStart(Intent intent, int startId) { + super.onStart(intent, startId); + + stopSelf(); + } + @Override public RemoteViewsFactory onGetViewFactory(Intent intent) { if (intent == null) { diff --git a/src/main/java/org/tasks/widget/WidgetHelper.java b/src/main/java/org/tasks/widget/WidgetHelper.java index 337a4758e..5aab13cde 100644 --- a/src/main/java/org/tasks/widget/WidgetHelper.java +++ b/src/main/java/org/tasks/widget/WidgetHelper.java @@ -34,30 +34,19 @@ import org.tasks.R; import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.Preferences; +import java.util.concurrent.TimeUnit; + import javax.inject.Inject; import javax.inject.Singleton; import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; -import static com.todoroo.andlib.utility.AndroidUtilities.preIceCreamSandwich; @Singleton public class WidgetHelper { public static int flags = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_MULTIPLE_TASK; - public static void startWidgetService(Context context) { - Class widgetServiceClass = preIceCreamSandwich() - ? WidgetUpdateService.class - : ScrollableWidgetUpdateService.class; - AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - Intent intent = new Intent(context, widgetServiceClass); - PendingIntent pendingIntent = PendingIntent.getService(context, - 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); - am.setInexactRepeating(AlarmManager.RTC, 0, - Constants.WIDGET_UPDATE_INTERVAL, pendingIntent); - } - public static void triggerUpdate(Context context) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager == null) { @@ -81,7 +70,10 @@ public class WidgetHelper { @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public RemoteViews createScrollableWidget(Context context, int id) { - startWidgetService(context); + AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + Intent intent = new Intent(context, ScrollableWidgetUpdateService.class); + PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); + am.setInexactRepeating(AlarmManager.RTC, 0, TimeUnit.MINUTES.toMillis(30), pendingIntent); Filter filter = getFilter(context, id); Intent rvIntent = new Intent(context, ScrollableWidgetUpdateService.class);