possible workaround for app crash in widget

This commit is contained in:
David Luhmer 2019-04-11 16:50:39 -03:00
parent 71fa993608
commit ca39b4eb8a
2 changed files with 10 additions and 10 deletions

View file

@ -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<RssItem> 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.

View file

@ -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);
}
}