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,15 +65,10 @@ public class WidgetUpdateService extends Service {
} else { } else {
ApiRequest ar = new ApiRequest(getApplicationContext()) { SimpleLoginManager loginManager = new SimpleLoginManager() {
@SuppressWarnings({ "unchecked", "serial" })
@Override
protected void onPostExecute(JsonElement result) {
if (result != null) {
JsonObject content = result.getAsJsonObject();
if (content != null) { @Override
final String sessionId = content.get("session_id").getAsString(); protected void onLoginSuccess(int requestId, String sessionId, int apiLevel) {
ApiRequest aru = new ApiRequest(getApplicationContext()) { ApiRequest aru = new ApiRequest(getApplicationContext()) {
@Override @Override
@ -101,35 +97,37 @@ public class WidgetUpdateService extends Service {
} }
}; };
final String fSessionId = sessionId;
HashMap<String, String> umap = new HashMap<String, String>() { HashMap<String, String> umap = new HashMap<String, String>() {
{ {
put("op", "getUnread"); put("op", "getUnread");
put("sid", sessionId); put("sid", fSessionId);
} }
}; };
aru.execute(umap); aru.execute(umap);
return;
}
} }
// Toast: login failed @Override
protected void onLoginFailed(int requestId) {
view.setViewVisibility(R.id.progress, View.GONE); 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
protected void onLoggingIn(int requestId) {
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); String login = m_prefs.getString("login", "").trim();
String password = m_prefs.getString("password", "").trim();
loginManager.logIn(getApplicationContext(), 1, login, password);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();