switch widget provider to use simpleloginmanager

This commit is contained in:
Andrew Dolgov 2013-10-17 16:41:45 +04:00
parent 68f8880a61
commit c79080545c

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import org.fox.ttrss.ApiRequest; import org.fox.ttrss.ApiRequest;
import org.fox.ttrss.R; import org.fox.ttrss.R;
import org.fox.ttrss.util.SimpleLoginManager;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -64,72 +65,69 @@ public class WidgetUpdateService extends Service {
} else { } else {
ApiRequest ar = new ApiRequest(getApplicationContext()) { SimpleLoginManager loginManager = new SimpleLoginManager() {
@SuppressWarnings({ "unchecked", "serial" })
@Override @Override
protected void onPostExecute(JsonElement result) { protected void onLoginSuccess(int requestId, String sessionId, int apiLevel) {
if (result != null) {
JsonObject content = result.getAsJsonObject(); ApiRequest aru = new ApiRequest(getApplicationContext()) {
@Override
if (content != null) { protected void onPostExecute(JsonElement result) {
final String sessionId = content.get("session_id").getAsString(); if (result != null) {
try {
ApiRequest aru = new ApiRequest(getApplicationContext()) { JsonObject content = result.getAsJsonObject();
@Override
protected void onPostExecute(JsonElement result) { if (content != null) {
if (result != null) { int unread = content.get("unread").getAsInt();
try {
JsonObject content = result.getAsJsonObject(); view.setViewVisibility(R.id.progress, View.GONE);
view.setTextViewText(R.id.counter, String.valueOf(unread));
if (content != null) { manager.updateAppWidget(thisWidget, view);
int unread = content.get("unread").getAsInt();
return;
view.setViewVisibility(R.id.progress, View.GONE); }
view.setTextViewText(R.id.counter, String.valueOf(unread)); } catch (Exception e) {
manager.updateAppWidget(thisWidget, view); e.printStackTrace();
}
return; }
}
} catch (Exception e) { view.setViewVisibility(R.id.progress, View.GONE);
e.printStackTrace(); view.setTextViewText(R.id.counter, "?");
} manager.updateAppWidget(thisWidget, view);
} }
};
view.setViewVisibility(R.id.progress, View.GONE);
view.setTextViewText(R.id.counter, "?");
manager.updateAppWidget(thisWidget, view);
}
};
HashMap<String, String> umap = new HashMap<String, String>() {
{
put("op", "getUnread");
put("sid", sessionId);
}
};
aru.execute(umap);
return;
}
}
// Toast: login failed
view.setViewVisibility(R.id.progress, View.GONE); final String fSessionId = sessionId;
HashMap<String, String> umap = new HashMap<String, String>() {
{
put("op", "getUnread");
put("sid", fSessionId);
}
};
aru.execute(umap);
}
@Override
protected void onLoginFailed(int requestId) {
view.setViewVisibility(R.id.progress, View.GONE);
view.setTextViewText(R.id.counter, "?"); view.setTextViewText(R.id.counter, "?");
manager.updateAppWidget(thisWidget, view); manager.updateAppWidget(thisWidget, view);
}; }
};
@Override
HashMap<String, String> map = new HashMap<String, String>() { protected void onLoggingIn(int requestId) {
{
put("op", "login");
put("user", m_prefs.getString("login", "").trim()); }
put("password", m_prefs.getString("password", "").trim()); };
}
}; String login = m_prefs.getString("login", "").trim();
String password = m_prefs.getString("password", "").trim();
ar.execute(map);
loginManager.logIn(getApplicationContext(), 1, login, password);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();