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) {
|
public void onStart(Intent intent, int startId) {
|
||||||
final RemoteViews view = new RemoteViews(getPackageName(), R.layout.widget_small);
|
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 ComponentName thisWidget = new ComponentName(this, SmallWidgetProvider.class);
|
||||||
final AppWidgetManager manager = AppWidgetManager.getInstance(this);
|
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
|
manager.updateAppWidget(thisWidget, view);
|
||||||
.getDefaultSharedPreferences(getApplicationContext());
|
|
||||||
|
|
||||||
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()) {
|
} else {
|
||||||
@SuppressWarnings({ "unchecked", "serial" })
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(JsonElement result) {
|
|
||||||
if (result != null) {
|
|
||||||
JsonObject content = result.getAsJsonObject();
|
|
||||||
|
|
||||||
if (content != null) {
|
ApiRequest ar = new ApiRequest(getApplicationContext()) {
|
||||||
final String sessionId = content.get("session_id").getAsString();
|
@SuppressWarnings({ "unchecked", "serial" })
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(JsonElement result) {
|
||||||
|
if (result != null) {
|
||||||
|
JsonObject content = result.getAsJsonObject();
|
||||||
|
|
||||||
ApiRequest aru = new ApiRequest(getApplicationContext()) {
|
if (content != null) {
|
||||||
@Override
|
final String sessionId = content.get("session_id").getAsString();
|
||||||
protected void onPostExecute(JsonElement result) {
|
|
||||||
if (result != null) {
|
|
||||||
JsonObject content = result.getAsJsonObject();
|
|
||||||
|
|
||||||
if (content != null) {
|
ApiRequest aru = new ApiRequest(getApplicationContext()) {
|
||||||
int unread = content.get("unread").getAsInt();
|
@Override
|
||||||
|
protected void onPostExecute(JsonElement result) {
|
||||||
|
if (result != null) {
|
||||||
|
JsonObject content = result.getAsJsonObject();
|
||||||
|
|
||||||
view.setViewVisibility(R.id.progress, View.GONE);
|
if (content != null) {
|
||||||
view.setTextViewText(R.id.counter, String.valueOf(unread));
|
int unread = content.get("unread").getAsInt();
|
||||||
manager.updateAppWidget(thisWidget, view);
|
|
||||||
|
|
||||||
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);
|
return;
|
||||||
view.setTextViewText(R.id.counter, getString(R.string.app_name));
|
}
|
||||||
manager.updateAppWidget(thisWidget, view);
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
HashMap<String, String> umap = new HashMap<String, String>() {
|
view.setViewVisibility(R.id.progress, View.GONE);
|
||||||
{
|
view.setTextViewText(R.id.counter, getString(R.string.app_name));
|
||||||
put("op", "getUnread");
|
manager.updateAppWidget(thisWidget, view);
|
||||||
put("sid", sessionId);
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
aru.execute(umap);
|
HashMap<String, String> umap = new HashMap<String, String>() {
|
||||||
return;
|
{
|
||||||
}
|
put("op", "getUnread");
|
||||||
}
|
put("sid", sessionId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Toast: login failed
|
aru.execute(umap);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
view.setViewVisibility(R.id.progress, View.GONE);
|
// Toast: login failed
|
||||||
view.setTextViewText(R.id.counter, getString(R.string.app_name));
|
|
||||||
manager.updateAppWidget(thisWidget, view);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
HashMap<String, String> map = new HashMap<String, String>() {
|
view.setViewVisibility(R.id.progress, View.GONE);
|
||||||
{
|
view.setTextViewText(R.id.counter, getString(R.string.app_name));
|
||||||
put("op", "login");
|
manager.updateAppWidget(thisWidget, view);
|
||||||
put("user", m_prefs.getString("login", "").trim());
|
};
|
||||||
put("password", m_prefs.getString("password", "").trim());
|
};
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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