catch exceptions in widget update service
This commit is contained in:
parent
390eee760c
commit
aa64bbcb13
@ -46,86 +46,94 @@ public class WidgetUpdateService extends Service {
|
||||
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);
|
||||
try {
|
||||
view.setTextViewText(R.id.counter, String.valueOf(""));
|
||||
view.setViewVisibility(R.id.progress, View.VISIBLE);
|
||||
|
||||
final SharedPreferences m_prefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(getApplicationContext());
|
||||
manager.updateAppWidget(thisWidget, view);
|
||||
|
||||
if (m_prefs.getString("ttrss_url", "").trim().length() == 0) {
|
||||
final SharedPreferences m_prefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(getApplicationContext());
|
||||
|
||||
// Toast: need configure
|
||||
if (m_prefs.getString("ttrss_url", "").trim().length() == 0) {
|
||||
|
||||
} else {
|
||||
// Toast: need configure
|
||||
|
||||
ApiRequest ar = new ApiRequest(getApplicationContext()) {
|
||||
@SuppressWarnings({ "unchecked", "serial" })
|
||||
@Override
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
if (result != null) {
|
||||
JsonObject content = result.getAsJsonObject();
|
||||
} else {
|
||||
|
||||
if (content != null) {
|
||||
final String sessionId = content.get("session_id").getAsString();
|
||||
ApiRequest ar = new ApiRequest(getApplicationContext()) {
|
||||
@SuppressWarnings({ "unchecked", "serial" })
|
||||
@Override
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
if (result != null) {
|
||||
JsonObject content = result.getAsJsonObject();
|
||||
|
||||
ApiRequest aru = new ApiRequest(getApplicationContext()) {
|
||||
@Override
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
if (result != null) {
|
||||
JsonObject content = result.getAsJsonObject();
|
||||
if (content != null) {
|
||||
final String sessionId = content.get("session_id").getAsString();
|
||||
|
||||
if (content != null) {
|
||||
int unread = content.get("unread").getAsInt();
|
||||
ApiRequest aru = new ApiRequest(getApplicationContext()) {
|
||||
@Override
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
if (result != null) {
|
||||
JsonObject content = result.getAsJsonObject();
|
||||
|
||||
view.setViewVisibility(R.id.progress, View.GONE);
|
||||
view.setTextViewText(R.id.counter, String.valueOf(unread));
|
||||
manager.updateAppWidget(thisWidget, view);
|
||||
if (content != null) {
|
||||
int unread = content.get("unread").getAsInt();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
view.setViewVisibility(R.id.progress, View.GONE);
|
||||
view.setTextViewText(R.id.counter, String.valueOf(unread));
|
||||
manager.updateAppWidget(thisWidget, view);
|
||||
|
||||
view.setViewVisibility(R.id.progress, View.GONE);
|
||||
view.setTextViewText(R.id.counter, getString(R.string.app_name));
|
||||
manager.updateAppWidget(thisWidget, view);
|
||||
}
|
||||
};
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<String, String> umap = new HashMap<String, String>() {
|
||||
{
|
||||
put("op", "getUnread");
|
||||
put("sid", sessionId);
|
||||
}
|
||||
};
|
||||
view.setViewVisibility(R.id.progress, View.GONE);
|
||||
view.setTextViewText(R.id.counter, getString(R.string.app_name));
|
||||
manager.updateAppWidget(thisWidget, view);
|
||||
}
|
||||
};
|
||||
|
||||
aru.execute(umap);
|
||||
return;
|
||||
}
|
||||
}
|
||||
HashMap<String, String> umap = new HashMap<String, String>() {
|
||||
{
|
||||
put("op", "getUnread");
|
||||
put("sid", sessionId);
|
||||
}
|
||||
};
|
||||
|
||||
// Toast: login failed
|
||||
aru.execute(umap);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
view.setViewVisibility(R.id.progress, View.GONE);
|
||||
view.setTextViewText(R.id.counter, getString(R.string.app_name));
|
||||
manager.updateAppWidget(thisWidget, view);
|
||||
};
|
||||
};
|
||||
// Toast: login failed
|
||||
|
||||
HashMap<String, String> map = new HashMap<String, String>() {
|
||||
{
|
||||
put("op", "login");
|
||||
put("user", m_prefs.getString("login", "").trim());
|
||||
put("password", m_prefs.getString("password", "").trim());
|
||||
}
|
||||
};
|
||||
view.setViewVisibility(R.id.progress, View.GONE);
|
||||
view.setTextViewText(R.id.counter, getString(R.string.app_name));
|
||||
manager.updateAppWidget(thisWidget, view);
|
||||
};
|
||||
};
|
||||
|
||||
ar.execute(map);
|
||||
}
|
||||
HashMap<String, String> map = new HashMap<String, String>() {
|
||||
{
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user