From aa64bbcb1358f5032a609564546db5897f3f3373 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 21 May 2013 16:31:05 +0400 Subject: catch exceptions in widget update service --- src/org/fox/ttrss/widget/WidgetUpdateService.java | 162 ++++++++++++---------- 1 file changed, 85 insertions(+), 77 deletions(-) (limited to 'src') diff --git a/src/org/fox/ttrss/widget/WidgetUpdateService.java b/src/org/fox/ttrss/widget/WidgetUpdateService.java index 68a61e4d..4d19526d 100644 --- a/src/org/fox/ttrss/widget/WidgetUpdateService.java +++ b/src/org/fox/ttrss/widget/WidgetUpdateService.java @@ -45,87 +45,95 @@ public class WidgetUpdateService extends Service { @Override public void onStart(Intent intent, int startId) { final RemoteViews view = new RemoteViews(getPackageName(), R.layout.widget_small); - - view.setTextViewText(R.id.counter, String.valueOf("")); - view.setViewVisibility(R.id.progress, View.VISIBLE); final ComponentName thisWidget = new ComponentName(this, SmallWidgetProvider.class); final AppWidgetManager manager = AppWidgetManager.getInstance(this); - - manager.updateAppWidget(thisWidget, view); - - final SharedPreferences m_prefs = PreferenceManager - .getDefaultSharedPreferences(getApplicationContext()); - - if (m_prefs.getString("ttrss_url", "").trim().length() == 0) { - - // Toast: need configure - - } else { - - ApiRequest ar = new ApiRequest(getApplicationContext()) { - @SuppressWarnings({ "unchecked", "serial" }) - @Override - protected void onPostExecute(JsonElement result) { - if (result != null) { - JsonObject content = result.getAsJsonObject(); - - if (content != null) { - final String sessionId = content.get("session_id").getAsString(); - - ApiRequest aru = new ApiRequest(getApplicationContext()) { - @Override - protected void onPostExecute(JsonElement result) { - if (result != null) { - JsonObject content = result.getAsJsonObject(); - - if (content != null) { - int unread = content.get("unread").getAsInt(); - - view.setViewVisibility(R.id.progress, View.GONE); - view.setTextViewText(R.id.counter, String.valueOf(unread)); - manager.updateAppWidget(thisWidget, view); - - return; - } - } - - view.setViewVisibility(R.id.progress, View.GONE); - view.setTextViewText(R.id.counter, getString(R.string.app_name)); - manager.updateAppWidget(thisWidget, view); - } - }; - HashMap umap = new HashMap() { - { - put("op", "getUnread"); - put("sid", sessionId); - } - }; + try { + view.setTextViewText(R.id.counter, String.valueOf("")); + view.setViewVisibility(R.id.progress, View.VISIBLE); - aru.execute(umap); - return; - } - } - - // Toast: login failed - - view.setViewVisibility(R.id.progress, View.GONE); - view.setTextViewText(R.id.counter, getString(R.string.app_name)); - manager.updateAppWidget(thisWidget, view); - }; - }; - - HashMap map = new HashMap() { - { - put("op", "login"); - put("user", m_prefs.getString("login", "").trim()); - put("password", m_prefs.getString("password", "").trim()); - } - }; - - ar.execute(map); - } - + manager.updateAppWidget(thisWidget, view); + + final SharedPreferences m_prefs = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()); + + if (m_prefs.getString("ttrss_url", "").trim().length() == 0) { + + // Toast: need configure + + } else { + + ApiRequest ar = new ApiRequest(getApplicationContext()) { + @SuppressWarnings({ "unchecked", "serial" }) + @Override + protected void onPostExecute(JsonElement result) { + if (result != null) { + JsonObject content = result.getAsJsonObject(); + + if (content != null) { + final String sessionId = content.get("session_id").getAsString(); + + ApiRequest aru = new ApiRequest(getApplicationContext()) { + @Override + protected void onPostExecute(JsonElement result) { + if (result != null) { + JsonObject content = result.getAsJsonObject(); + + if (content != null) { + int unread = content.get("unread").getAsInt(); + + view.setViewVisibility(R.id.progress, View.GONE); + view.setTextViewText(R.id.counter, String.valueOf(unread)); + manager.updateAppWidget(thisWidget, view); + + return; + } + } + + view.setViewVisibility(R.id.progress, View.GONE); + view.setTextViewText(R.id.counter, getString(R.string.app_name)); + manager.updateAppWidget(thisWidget, view); + } + }; + + HashMap umap = new HashMap() { + { + put("op", "getUnread"); + put("sid", sessionId); + } + }; + + aru.execute(umap); + return; + } + } + + // Toast: login failed + + view.setViewVisibility(R.id.progress, View.GONE); + view.setTextViewText(R.id.counter, getString(R.string.app_name)); + manager.updateAppWidget(thisWidget, view); + }; + }; + + HashMap map = new HashMap() { + { + put("op", "login"); + put("user", m_prefs.getString("login", "").trim()); + put("password", m_prefs.getString("password", "").trim()); + } + }; + + ar.execute(map); + } + } catch (Exception e) { + e.printStackTrace(); + + view.setViewVisibility(R.id.progress, View.GONE); + view.setTextViewText(R.id.counter, getString(R.string.app_name)); + manager.updateAppWidget(thisWidget, view); + + } } } -- cgit v1.2.3