switch commonshareactivity to simpleloginmanager
This commit is contained in:
parent
c79080545c
commit
f4a992ed4e
@ -74,7 +74,7 @@ public class ApiRequest extends AsyncTask<HashMap<String,String>, Integer, JsonE
|
||||
super.execute(map);
|
||||
}
|
||||
|
||||
protected int getErrorMessage() {
|
||||
public int getErrorMessage() {
|
||||
switch (m_lastError) {
|
||||
case NO_ERROR:
|
||||
return R.string.error_unknown;
|
||||
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import org.fox.ttrss.ApiRequest;
|
||||
import org.fox.ttrss.PreferencesActivity;
|
||||
import org.fox.ttrss.R;
|
||||
import org.fox.ttrss.util.SimpleLoginManager;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@ -54,7 +55,6 @@ public abstract class CommonShareActivity extends CommonActivity {
|
||||
|
||||
protected abstract void onLoggingIn(int requestId);
|
||||
|
||||
@SuppressWarnings({ "serial" })
|
||||
public void login(int requestId) {
|
||||
|
||||
if (m_prefs.getString("ttrss_url", "").trim().length() == 0) {
|
||||
@ -81,82 +81,33 @@ public abstract class CommonShareActivity extends CommonActivity {
|
||||
|
||||
} else {
|
||||
|
||||
LoginRequest ar = new LoginRequest(getApplicationContext(), requestId);
|
||||
SimpleLoginManager loginManager = new SimpleLoginManager() {
|
||||
|
||||
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());
|
||||
}
|
||||
};
|
||||
@Override
|
||||
protected void onLoginSuccess(int requestId, String sessionId, int apiLevel) {
|
||||
m_sessionId = sessionId;
|
||||
m_apiLevel = apiLevel;
|
||||
|
||||
onLoggingIn(requestId);
|
||||
|
||||
ar.execute(map);
|
||||
}
|
||||
CommonShareActivity.this.onLoggedIn(requestId);
|
||||
}
|
||||
|
||||
protected class LoginRequest extends ApiRequest {
|
||||
private int m_requestId;
|
||||
|
||||
public LoginRequest(Context context, int requestId) {
|
||||
super(context);
|
||||
m_requestId = requestId;
|
||||
}
|
||||
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
if (result != null) {
|
||||
try {
|
||||
JsonObject content = result.getAsJsonObject();
|
||||
if (content != null) {
|
||||
m_sessionId = content.get("session_id").getAsString();
|
||||
|
||||
Log.d(TAG, "Authenticated!");
|
||||
|
||||
ApiRequest req = new ApiRequest(m_context) {
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
m_apiLevel = 0;
|
||||
|
||||
if (result != null) {
|
||||
try {
|
||||
m_apiLevel = result.getAsJsonObject()
|
||||
.get("level").getAsInt();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Log.d(TAG, "Received API level: " + m_apiLevel);
|
||||
|
||||
onLoggedIn(m_requestId);
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
HashMap<String, String> map = new HashMap<String, String>() {
|
||||
{
|
||||
put("sid", m_sessionId);
|
||||
put("op", "getApiLevel");
|
||||
}
|
||||
};
|
||||
|
||||
req.execute(map);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
m_sessionId = null;
|
||||
|
||||
toast(getErrorMessage());
|
||||
@Override
|
||||
protected void onLoginFailed(int requestId, ApiRequest ar) {
|
||||
toast(ar.getErrorMessage());
|
||||
setProgressBarIndeterminateVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoggingIn(int requestId) {
|
||||
CommonShareActivity.this.onLoggingIn(requestId);
|
||||
}
|
||||
};
|
||||
|
||||
String login = m_prefs.getString("login", "").trim();
|
||||
String password = m_prefs.getString("password", "").trim();
|
||||
|
||||
loginManager.logIn(this, requestId, login, password);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.fox.ttrss.tasker;
|
||||
|
||||
import org.fox.ttrss.ApiRequest;
|
||||
import org.fox.ttrss.CommonActivity;
|
||||
import org.fox.ttrss.OnlineActivity;
|
||||
import org.fox.ttrss.offline.OfflineDownloadService;
|
||||
@ -41,8 +42,8 @@ public class TaskerReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoginFailed(int requestId) {
|
||||
Toast toast = Toast.makeText(fContext, "Could not download articles: login failed", Toast.LENGTH_SHORT);
|
||||
protected void onLoginFailed(int requestId, ApiRequest ar) {
|
||||
Toast toast = Toast.makeText(fContext, fContext.getString(ar.getErrorMessage()), Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public abstract class SimpleLoginManager {
|
||||
if (content != null) {
|
||||
m_sessionId = content.get("session_id").getAsString();
|
||||
|
||||
Log.d(TAG, "Authenticated!");
|
||||
Log.d(TAG, "[SLM] Authenticated!");
|
||||
|
||||
ApiRequest req = new ApiRequest(m_context) {
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
@ -49,7 +49,7 @@ public abstract class SimpleLoginManager {
|
||||
}
|
||||
}
|
||||
|
||||
Log.d(TAG, "Received API level: " + m_apiLevel);
|
||||
Log.d(TAG, "[SLM] Received API level: " + m_apiLevel);
|
||||
|
||||
onLoginSuccess(m_requestId, m_sessionId, m_apiLevel);
|
||||
}
|
||||
@ -75,7 +75,7 @@ public abstract class SimpleLoginManager {
|
||||
|
||||
m_sessionId = null;
|
||||
|
||||
onLoginFailed(m_requestId);
|
||||
onLoginFailed(m_requestId, this);
|
||||
}
|
||||
|
||||
}
|
||||
@ -100,6 +100,6 @@ public abstract class SimpleLoginManager {
|
||||
|
||||
protected abstract void onLoginSuccess(int requestId, String sessionId, int apiLevel);
|
||||
|
||||
protected abstract void onLoginFailed(int requestId);
|
||||
protected abstract void onLoginFailed(int requestId, ApiRequest ar);
|
||||
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public class WidgetUpdateService extends Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoginFailed(int requestId) {
|
||||
protected void onLoginFailed(int requestId, ApiRequest ar) {
|
||||
|
||||
view.setViewVisibility(R.id.progress, View.GONE);
|
||||
view.setTextViewText(R.id.counter, "?");
|
||||
|
Loading…
Reference in New Issue
Block a user