From ca39b4eb8a831406b36fef0f3489a5dad060ecd9 Mon Sep 17 00:00:00 2001 From: David Luhmer Date: Thu, 11 Apr 2019 16:50:39 -0300 Subject: [PATCH] possible workaround for app crash in widget --- ...actory.java => WidgetNewsViewsFactory.java} | 18 +++++++++--------- .../widget/WidgetService.java | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) rename News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/{WidgetTodoViewsFactory.java => WidgetNewsViewsFactory.java} (91%) diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetTodoViewsFactory.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetNewsViewsFactory.java similarity index 91% rename from News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetTodoViewsFactory.java rename to News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetNewsViewsFactory.java index 04e68924..dc60ebf8 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetTodoViewsFactory.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetNewsViewsFactory.java @@ -39,16 +39,16 @@ import de.luhmer.owncloudnewsreader.R; import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm; import de.luhmer.owncloudnewsreader.database.model.RssItem; -public class WidgetTodoViewsFactory implements RemoteViewsService.RemoteViewsFactory { - private static final String TAG = WidgetTodoViewsFactory.class.getCanonicalName(); +public class WidgetNewsViewsFactory implements RemoteViewsService.RemoteViewsFactory { + private static final String TAG = WidgetNewsViewsFactory.class.getCanonicalName(); private DatabaseConnectionOrm dbConn; private List rssItems; - private Context context = null; + private Context context; private int appWidgetId; - public WidgetTodoViewsFactory(Context context, Intent intent) { + public WidgetNewsViewsFactory(Context context, Intent intent) { this.context = context; appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); @@ -79,14 +79,14 @@ public class WidgetTodoViewsFactory implements RemoteViewsService.RemoteViewsFac // combination with the app widget item XML file to construct a RemoteViews object. @SuppressLint("SimpleDateFormat") public RemoteViews getViewAt(int position) { - if(Constants.debugModeWidget) + if(Constants.debugModeWidget) { Log.d(TAG, "getViewAt: " + position); + } - RssItem rssItem = rssItems.get(position); - - RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_item); + RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_item); try { + RssItem rssItem = rssItems.get(position); String header = rssItem.getFeed().getFeedTitle(); String colorString = rssItem.getFeed().getAvgColour(); @@ -140,7 +140,7 @@ public class WidgetTodoViewsFactory implements RemoteViewsService.RemoteViewsFac iCheck.putExtra(WidgetProvider.ACTION_CHECKED_CLICK, true); rv.setOnClickFillInIntent(R.id.cb_lv_item_read, iCheck); } catch(Exception ex) { - Log.e(TAG, "Error: " + ex.getLocalizedMessage()); + Log.e(TAG, "Error while getting view for widget at position: " + position, ex); } // Return the RemoteViews object. diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetService.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetService.java index 5269a1a4..84f3e63e 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetService.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetService.java @@ -28,6 +28,6 @@ public class WidgetService extends RemoteViewsService { @Override public RemoteViewsFactory onGetViewFactory(Intent intent) { - return new WidgetTodoViewsFactory(this.getApplicationContext(), intent); + return new WidgetNewsViewsFactory(this.getApplicationContext(), intent); } }