mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-19 04:05:36 +00:00
logout in overflow
This commit is contained in:
@@ -65,4 +65,8 @@
|
||||
<string name="http_request_aborted" translatable="false">(Request %d) HTTP request aborted.</string>
|
||||
<string name="http_request_failed" translatable="false">(Request %d) HTTP request failed.</string>
|
||||
|
||||
<!-- Message Sending -->
|
||||
<string name="sending_waiting">Currently %1$d events waiting to be sent.\nLast successful sent was at %2$s</string>
|
||||
<string name="sending_no_waiting">Currently no event waiting to be sent.</string>
|
||||
|
||||
</resources>
|
||||
+11
-2
@@ -14,14 +14,20 @@ public class HttpJsonPostRequest extends HttpRequest {
|
||||
public final static String ContentType = "application/json;charset=UTF-8";
|
||||
|
||||
private String requestBody;
|
||||
private String accessToken;
|
||||
|
||||
public HttpJsonPostRequest(URL requestUrl, Context context) {
|
||||
this(requestUrl, null, context);
|
||||
this(requestUrl, null, context, null);
|
||||
}
|
||||
|
||||
|
||||
public HttpJsonPostRequest(URL requestUrl, String body, Context context) {
|
||||
this(requestUrl, body, context, null);
|
||||
}
|
||||
|
||||
public HttpJsonPostRequest(URL requestUrl, String body, Context context, String accessToken) {
|
||||
super(requestUrl, context);
|
||||
this.requestBody = body;
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,6 +38,9 @@ public class HttpJsonPostRequest extends HttpRequest {
|
||||
|
||||
connection.setRequestProperty("Content-Type", ContentType);
|
||||
connection.setRequestProperty("Accept", ContentType);
|
||||
if (accessToken != null) {
|
||||
connection.setRequestProperty("Authorization", "Bearer " + accessToken);
|
||||
}
|
||||
OutputStream outputStream = new BufferedOutputStream(connection.getOutputStream());
|
||||
try {
|
||||
sendBody(outputStream);
|
||||
|
||||
+19
-19
@@ -14,23 +14,24 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.sap.sailing.android.shared.data.http.UnauthorizedException;
|
||||
import com.sap.sailing.android.shared.logging.ExLog;
|
||||
import com.sap.sailing.android.shared.util.FileHandlerUtils;
|
||||
|
||||
public class MessagePersistenceManager {
|
||||
|
||||
|
||||
private final static String TAG = MessagePersistenceManager.class.getName();
|
||||
|
||||
private final static String delayedMessagesFileName = "delayedMessages.txt";
|
||||
|
||||
protected Context context;
|
||||
protected List<String> persistedMessages;
|
||||
|
||||
|
||||
private final MessageRestorer messageRestorer;
|
||||
|
||||
public MessagePersistenceManager(Context context, MessageRestorer messageRestorer) {
|
||||
this.context = context;
|
||||
persistedMessages = new ArrayList<String>();
|
||||
persistedMessages = new ArrayList<>();
|
||||
this.messageRestorer = messageRestorer;
|
||||
initializeFileAndPersistedMessages();
|
||||
}
|
||||
@@ -60,14 +61,13 @@ public class MessagePersistenceManager {
|
||||
|
||||
/**
|
||||
* @param payload will be URL-encoded to ensure that the resulting string does not contain newlines
|
||||
* @throws UnsupportedEncodingException
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
private String getSerializedIntentForPersistence(String url, String callbackPayload,
|
||||
String payload, String callbackClass) throws UnsupportedEncodingException {
|
||||
String messageLine = String.format("%s;%s;%s;%s", callbackPayload, URLEncoder.encode(payload,
|
||||
MessageSendingService.charsetName),
|
||||
private String getSerializedIntentForPersistence(String url, String callbackPayload,
|
||||
String payload, String callbackClass) throws UnsupportedEncodingException {
|
||||
return String.format("%s;%s;%s;%s", callbackPayload, URLEncoder.encode(payload,
|
||||
MessageSendingService.charsetName),
|
||||
url, callbackClass);
|
||||
return messageLine;
|
||||
}
|
||||
|
||||
public void removeIntent(Intent intent) throws UnsupportedEncodingException {
|
||||
@@ -86,7 +86,7 @@ public class MessagePersistenceManager {
|
||||
removePersistedMessage(messageLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes all pending messages and clears the persistence file.
|
||||
*/
|
||||
@@ -106,12 +106,12 @@ public class MessagePersistenceManager {
|
||||
public int getMessageCount() {
|
||||
return persistedMessages.size();
|
||||
}
|
||||
|
||||
|
||||
public List<String> getContent() {
|
||||
return persistedMessages;
|
||||
}
|
||||
|
||||
public static interface MessageRestorer {
|
||||
|
||||
public interface MessageRestorer {
|
||||
void restoreMessage(Context context, Intent messageIntent);
|
||||
}
|
||||
|
||||
@@ -125,26 +125,26 @@ public class MessagePersistenceManager {
|
||||
String callbackClassString = lineParts[3];
|
||||
|
||||
Class<? extends ServerReplyCallback> callbackClass = null;
|
||||
if (! "null".equals(callbackClassString)) {
|
||||
if (!"null".equals(callbackClassString)) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends ServerReplyCallback> tmp =
|
||||
(Class<? extends ServerReplyCallback>) Class.forName(callbackClassString);
|
||||
(Class<? extends ServerReplyCallback>) Class.forName(callbackClassString);
|
||||
callbackClass = tmp;
|
||||
} catch (ClassNotFoundException e) {
|
||||
ExLog.e(context, TAG, "Could not find class for callback name: " + callbackClassString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// We are passing no message id, because we know it used to suppress message sending and
|
||||
// we want this message to be sent.
|
||||
Intent messageIntent = MessageSendingService.createMessageIntent(context, url, callbackPayload,
|
||||
null, payload, callbackClass);
|
||||
|
||||
|
||||
if (messageRestorer != null) {
|
||||
messageRestorer.restoreMessage(context, messageIntent);
|
||||
}
|
||||
|
||||
|
||||
if (messageIntent != null) {
|
||||
delayedIntents.add(messageIntent);
|
||||
}
|
||||
@@ -166,7 +166,7 @@ public class MessagePersistenceManager {
|
||||
fileContent = FileHandlerUtils.convertStreamToString(inputStream, context);
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
ExLog.w(context, TAG, "In Method getFileContent(): " + e.getClass().getName()+" / "+e.getMessage() + " fileContent is empty");
|
||||
ExLog.w(context, TAG, "In Method getFileContent(): " + e.getClass().getName() + " / " + e.getMessage() + " fileContent is empty");
|
||||
}
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.sap.sailing.android.shared.services.sending;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
public class MessageSenderResult {
|
||||
|
||||
private final Intent mIntent;
|
||||
private final InputStream mInputStream;
|
||||
private final Exception mException;
|
||||
|
||||
public MessageSenderResult() {
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
public MessageSenderResult(Intent intent) {
|
||||
this(intent, null, null);
|
||||
}
|
||||
|
||||
public MessageSenderResult(Intent intent, InputStream inputStream) {
|
||||
this(intent, inputStream, null);
|
||||
}
|
||||
|
||||
public MessageSenderResult(Intent intent, Exception exception) {
|
||||
this(intent, null, exception);
|
||||
}
|
||||
|
||||
public MessageSenderResult(Intent intent, InputStream inputStream, Exception exception) {
|
||||
mIntent = intent;
|
||||
mInputStream = inputStream;
|
||||
mException = exception;
|
||||
}
|
||||
|
||||
public boolean isSuccessful() {
|
||||
return mException == null;
|
||||
}
|
||||
|
||||
public Intent getIntent() {
|
||||
return mIntent;
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return mInputStream;
|
||||
}
|
||||
|
||||
public Exception getException() {
|
||||
return mException;
|
||||
}
|
||||
}
|
||||
+22
-23
@@ -12,16 +12,10 @@ import android.os.Bundle;
|
||||
import com.sap.sailing.android.shared.data.http.HttpJsonPostRequest;
|
||||
import com.sap.sailing.android.shared.data.http.HttpRequest;
|
||||
import com.sap.sailing.android.shared.logging.ExLog;
|
||||
import com.sap.sse.common.Util;
|
||||
|
||||
public class MessageSenderTask extends AsyncTask<Intent, Void, Util.Triple<Intent, Boolean, InputStream>> {
|
||||
|
||||
public class MessageSenderTask extends AsyncTask<Intent, Void, MessageSenderResult> {
|
||||
|
||||
private static String TAG = MessageSenderTask.class.getName();
|
||||
|
||||
public interface MessageSendingListener {
|
||||
public void onMessageSent(Intent intent, boolean success, InputStream inputStream);
|
||||
}
|
||||
|
||||
private MessageSendingListener listener;
|
||||
private Context context;
|
||||
|
||||
@@ -30,19 +24,18 @@ public class MessageSenderTask extends AsyncTask<Intent, Void, Util.Triple<Inten
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Override
|
||||
protected Util.Triple<Intent, Boolean, InputStream> doInBackground(Intent... params) {
|
||||
Util.Triple<Intent, Boolean, InputStream> result;
|
||||
protected MessageSenderResult doInBackground(Intent... params) {
|
||||
MessageSenderResult result;
|
||||
Intent intent = params[0];
|
||||
if (intent == null) {
|
||||
return new Util.Triple<Intent, Boolean, InputStream>(intent, false, null);
|
||||
return new MessageSenderResult();
|
||||
}
|
||||
Bundle extras = intent.getExtras();
|
||||
String payload = extras.getString(MessageSendingService.PAYLOAD);
|
||||
String url = extras.getString(MessageSendingService.URL);
|
||||
if (payload == null || url == null) {
|
||||
return new Util.Triple<Intent, Boolean, InputStream>(intent, false, null);
|
||||
return new MessageSenderResult(intent);
|
||||
}
|
||||
InputStream responseStream = null;
|
||||
try {
|
||||
@@ -50,22 +43,28 @@ public class MessageSenderTask extends AsyncTask<Intent, Void, Util.Triple<Inten
|
||||
HttpRequest post = new HttpJsonPostRequest(new URL(url), payload, context);
|
||||
responseStream = post.execute();
|
||||
ExLog.i(context, TAG, "Post successful for the following message: " + payload);
|
||||
result = new Util.Triple<Intent, Boolean, InputStream>(intent, true, responseStream);
|
||||
result = new MessageSenderResult(intent, responseStream);
|
||||
} catch (IOException e) {
|
||||
if (responseStream != null) {
|
||||
try {
|
||||
responseStream.close();
|
||||
} catch (IOException ie) { }
|
||||
}
|
||||
ExLog.e(context, TAG, String.format("Post not successful, exception occured: %s", e.toString()));
|
||||
result = new Util.Triple<Intent, Boolean, InputStream>(intent, false, null);
|
||||
result = new MessageSenderResult(intent, e);
|
||||
} finally {
|
||||
try {
|
||||
if (responseStream != null) {
|
||||
responseStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Util.Triple<Intent, Boolean, InputStream> resultTriple) {
|
||||
super.onPostExecute(resultTriple);
|
||||
listener.onMessageSent(resultTriple.getA(), resultTriple.getB(), resultTriple.getC());
|
||||
protected void onPostExecute(MessageSenderResult result) {
|
||||
super.onPostExecute(result);
|
||||
listener.onMessageSent(result);
|
||||
}
|
||||
|
||||
public interface MessageSendingListener {
|
||||
void onMessageSent(MessageSenderResult result);
|
||||
}
|
||||
}
|
||||
|
||||
+47
-54
@@ -11,6 +11,7 @@ import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
|
||||
import com.sap.sailing.android.shared.R;
|
||||
import com.sap.sailing.android.shared.logging.ExLog;
|
||||
import com.sap.sailing.android.shared.services.sending.MessagePersistenceManager.MessageRestorer;
|
||||
@@ -18,7 +19,6 @@ import com.sap.sailing.android.shared.services.sending.MessageSenderTask.Message
|
||||
import com.sap.sailing.android.shared.util.PrefUtils;
|
||||
import com.sap.sailing.domain.common.racelog.RaceLogServletConstants;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
@@ -28,7 +28,7 @@ import java.util.*;
|
||||
* Service that handles sending messages to a webservice. Deals with an offline setting
|
||||
* by buffering the messages in a file, so that they can be sent when the connection is
|
||||
* re-established.<br>
|
||||
*
|
||||
* <p/>
|
||||
* <b>Use in the following way:</b> Add the service declaration to your {@code AndroidManifest.xml},
|
||||
* and also specify your class implementing the {@link MessagePersistenceManager.MessageRestorer}
|
||||
* as a meta-data tag with the key {@code com.sap.sailing.android.shared.services.sending.messageRestorer}.
|
||||
@@ -42,9 +42,9 @@ import java.util.*;
|
||||
* android:value="com.sap.sailing.racecommittee.app.services.sending.EventRestorer" />
|
||||
* </service>
|
||||
* }</pre>
|
||||
*
|
||||
*
|
||||
* Message sending example:
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Message sending example:
|
||||
* <pre>{@code
|
||||
* context.startService(MessageSendingService.createMessageIntent(
|
||||
* context, url, race.getId(), eventId, serializedEventAsJson, callbackClass));
|
||||
@@ -56,7 +56,7 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
public final static String CALLBACK_CLASS = "callback";
|
||||
public final static String CALLBACK_PAYLOAD = "callbackPayload"; // passed back to callback
|
||||
public final static String MESSAGE_ID = "messageId";
|
||||
|
||||
|
||||
public static final String charsetName = "UTF-8";
|
||||
|
||||
protected final static String TAG = MessageSendingService.class.getName();
|
||||
@@ -66,7 +66,7 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
private final IBinder mBinder = new MessageSendingBinder();
|
||||
private MessagePersistenceManager persistenceManager;
|
||||
private boolean isHandlerSet;
|
||||
|
||||
|
||||
private Set<Serializable> suppressedMessageIds = new HashSet<Serializable>();
|
||||
|
||||
private APIConnectivityListener apiConnectivityListener;
|
||||
@@ -86,9 +86,9 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
};
|
||||
|
||||
public interface MessageSendingServiceLogger {
|
||||
public void onMessageSentSuccessful();
|
||||
void onMessageSentSuccessful();
|
||||
|
||||
public void onMessageSentFailed();
|
||||
void onMessageSentFailed();
|
||||
}
|
||||
|
||||
public void setMessageSendingServiceLogger(MessageSendingServiceLogger logger) {
|
||||
@@ -107,7 +107,7 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
}
|
||||
|
||||
private Date lastSuccessfulSend;
|
||||
|
||||
|
||||
public List<String> getDelayedIntentsContent() {
|
||||
return persistenceManager.getContent();
|
||||
}
|
||||
@@ -119,16 +119,16 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
public Date getLastSuccessfulSend() {
|
||||
return lastSuccessfulSend;
|
||||
}
|
||||
|
||||
|
||||
public void clearDelayedIntents() {
|
||||
persistenceManager.removeAllMessages();
|
||||
// let's fake a successful send!
|
||||
serviceLogger.onMessageSentSuccessful();
|
||||
}
|
||||
|
||||
public static Intent createMessageIntent(Context context, String url,
|
||||
Serializable callbackPayload, Serializable messageId, String payload,
|
||||
Class<? extends ServerReplyCallback> callbackClass) {
|
||||
public static Intent createMessageIntent(Context context, String url,
|
||||
Serializable callbackPayload, Serializable messageId, String payload,
|
||||
Class<? extends ServerReplyCallback> callbackClass) {
|
||||
Intent messageIntent = new Intent(context, MessageSendingService.class);
|
||||
messageIntent.setAction(context.getString(R.string.intent_send_message));
|
||||
messageIntent.putExtra(CALLBACK_PAYLOAD, callbackPayload);
|
||||
@@ -138,7 +138,7 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
messageIntent.putExtra(CALLBACK_CLASS, callbackClass == null ? null : callbackClass.getName());
|
||||
return messageIntent;
|
||||
}
|
||||
|
||||
|
||||
public static Intent createSendDelayedIntent(Context context) {
|
||||
Intent intent = new Intent(context, MessageSendingService.class);
|
||||
intent.setAction(context.getString(R.string.intent_send_saved_intents));
|
||||
@@ -153,7 +153,7 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
ExLog.w(this, TAG, "Unable to extract message identifier from message intent.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private MessagePersistenceManager getPersistenceManager() {
|
||||
ComponentName thisService = new ComponentName(this, this.getClass());
|
||||
MessageRestorer restorer = null;
|
||||
@@ -172,7 +172,7 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
} else {
|
||||
@SuppressWarnings("unchecked")
|
||||
// checked above
|
||||
Class<MessageRestorer> castedClass = (Class<MessageRestorer>) clazz;
|
||||
Class<MessageRestorer> castedClass = (Class<MessageRestorer>) clazz;
|
||||
restorer = castedClass.getConstructor().newInstance();
|
||||
}
|
||||
}
|
||||
@@ -223,9 +223,9 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
}
|
||||
|
||||
private void handleSendMessages(Intent intent) {
|
||||
ExLog.i(this, TAG, String.format("Trying to send a message..."));
|
||||
ExLog.i(this, TAG, "Trying to send a message...");
|
||||
if (!isConnected()) {
|
||||
ExLog.i(this, TAG, String.format("Send aborted because there is no connection."));
|
||||
ExLog.i(this, TAG, "Send aborted because there is no connection.");
|
||||
try {
|
||||
persistenceManager.persistIntent(intent);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
@@ -240,10 +240,10 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
}
|
||||
|
||||
private void handleDelayedMessages() {
|
||||
ExLog.i(this, TAG, String.format("Trying to resend stored messages..."));
|
||||
ExLog.i(this, TAG, "Trying to resend stored messages...");
|
||||
isHandlerSet = false;
|
||||
if (!isConnected()) {
|
||||
ExLog.i(this, TAG, String.format("Resend aborted because there is no connection."));
|
||||
ExLog.i(this, TAG, "Resend aborted because there is no connection.");
|
||||
ConnectivityChangedReceiver.enable(this);
|
||||
serviceLogger.onMessageSentFailed();
|
||||
} else {
|
||||
@@ -281,16 +281,15 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageSent(Intent intent, boolean success, InputStream inputStream) {
|
||||
ExLog.i(this, "MS", "on message sent");
|
||||
int resendMillis = PrefUtils.getInt(this, R.string.preference_messageResendIntervalMillis_key,
|
||||
R.integer.preference_messageResendIntervalMillis_default);
|
||||
if (!success) {
|
||||
ExLog.i(this, "MS", "!success");
|
||||
public void onMessageSent(MessageSenderResult result) {
|
||||
ExLog.i(this, TAG, "onMessageSent");
|
||||
int resendMillis = PrefUtils.getInt(this, R.string.preference_messageResendIntervalMillis_key, R.integer.preference_messageResendIntervalMillis_default);
|
||||
if (!result.isSuccessful()) {
|
||||
ExLog.i(this, TAG, "!success");
|
||||
reportApiConnectivity(APIConnectivity.transmissionError);
|
||||
ExLog.w(this, TAG, "Error while posting intent to server. Will persist intent...");
|
||||
try {
|
||||
persistenceManager.persistIntent(intent);
|
||||
persistenceManager.persistIntent(result.getIntent());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
ExLog.e(this, TAG, "Could not store message (unsupported encoding)");
|
||||
}
|
||||
@@ -302,12 +301,12 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
reportUnsentGPSFixesCount();
|
||||
serviceLogger.onMessageSentFailed();
|
||||
} else {
|
||||
ExLog.i(this, "MS", "success");
|
||||
ExLog.i(this, TAG, "success");
|
||||
reportApiConnectivity(APIConnectivity.transmissionSuccess);
|
||||
ExLog.i(this, TAG, "Message successfully sent.");
|
||||
if (persistenceManager.areIntentsDelayed()) {
|
||||
try {
|
||||
persistenceManager.removeIntent(intent);
|
||||
persistenceManager.removeIntent(result.getIntent());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
ExLog.e(this, TAG, "Could not remove message (unsupported encoding)");
|
||||
}
|
||||
@@ -316,8 +315,8 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
if (serviceLogger != null) {
|
||||
serviceLogger.onMessageSentSuccessful();
|
||||
}
|
||||
|
||||
String callbackClassString = intent.getStringExtra(CALLBACK_CLASS);
|
||||
|
||||
String callbackClassString = result.getIntent().getStringExtra(CALLBACK_CLASS);
|
||||
ServerReplyCallback callback = null;
|
||||
if (callbackClassString != null) {
|
||||
try {
|
||||
@@ -328,51 +327,47 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
}
|
||||
}
|
||||
if (callback != null) {
|
||||
String raceId = intent.getStringExtra(CALLBACK_PAYLOAD);
|
||||
callback.processResponse(this, inputStream, raceId);
|
||||
String raceId = result.getIntent().getStringExtra(CALLBACK_PAYLOAD);
|
||||
callback.processResponse(this, result.getInputStream(), raceId);
|
||||
}
|
||||
ExLog.i(this, "MS", "report");
|
||||
ExLog.i(this, TAG, "report");
|
||||
reportUnsentGPSFixesCount();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if there is network connectivity
|
||||
*
|
||||
*
|
||||
* @return connectivity check value
|
||||
*/
|
||||
private boolean isConnected() {
|
||||
NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
|
||||
if (activeNetwork == null) {
|
||||
return false;
|
||||
}
|
||||
return activeNetwork.isConnected();
|
||||
return activeNetwork != null && activeNetwork.isConnected();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* a UUID that identifies this client session; can be used, e.g., to let the server identify subsequent requests coming from the same client
|
||||
*/
|
||||
public final static UUID uuid = UUID.randomUUID();
|
||||
|
||||
|
||||
public static String getRaceLogEventSendAndReceiveUrl(Context context, final String raceGroupName,
|
||||
final String raceName, final String fleetName) throws UnsupportedEncodingException {
|
||||
String url = String.format("%s/sailingserver/rc/racelog?"+
|
||||
RaceLogServletConstants.PARAMS_LEADERBOARD_NAME+"=%s&"+
|
||||
RaceLogServletConstants.PARAMS_RACE_COLUMN_NAME+"=%s&"+
|
||||
RaceLogServletConstants.PARAMS_RACE_FLEET_NAME+"=%s&"+
|
||||
RaceLogServletConstants.PARAMS_CLIENT_UUID+"=%s",
|
||||
final String raceName, final String fleetName) throws UnsupportedEncodingException {
|
||||
String url = String.format("%s/sailingserver/rc/racelog?" +
|
||||
RaceLogServletConstants.PARAMS_LEADERBOARD_NAME + "=%s&" +
|
||||
RaceLogServletConstants.PARAMS_RACE_COLUMN_NAME + "=%s&" +
|
||||
RaceLogServletConstants.PARAMS_RACE_FLEET_NAME + "=%s&" +
|
||||
RaceLogServletConstants.PARAMS_CLIENT_UUID + "=%s",
|
||||
PrefUtils.getString(context, R.string.preference_server_url_key, R.string.preference_server_url_default),
|
||||
URLEncoder.encode(raceGroupName, charsetName),
|
||||
URLEncoder.encode(raceName, charsetName),
|
||||
URLEncoder.encode(fleetName, charsetName), uuid);
|
||||
URLEncoder.encode(raceName, charsetName),
|
||||
URLEncoder.encode(fleetName, charsetName), uuid);
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register listener for API-connectivity
|
||||
*
|
||||
* @param listener
|
||||
* class that wants to be notified of api-connectivity changes
|
||||
* @param listener class that wants to be notified of api-connectivity changes
|
||||
*/
|
||||
public void registerAPIConnectivityListener(APIConnectivityListener listener) {
|
||||
apiConnectivityListener = listener;
|
||||
@@ -424,8 +419,6 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
|
||||
/**
|
||||
* Report the number of currently unsent GPS-fixes
|
||||
*
|
||||
* @param unsentGPSFixesCount
|
||||
*/
|
||||
private void reportUnsentGPSFixesCount() {
|
||||
if (apiConnectivityListener != null) {
|
||||
|
||||
+16
-17
@@ -20,7 +20,7 @@ import com.sap.sailing.android.shared.services.sending.MessageSendingService.Mes
|
||||
import com.sap.sailing.android.shared.util.PrefUtils;
|
||||
|
||||
public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
|
||||
|
||||
private class MessageSendingServiceConnection implements ServiceConnection, MessageSendingServiceLogger {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||
@@ -55,9 +55,9 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
protected boolean boundSendingService = false;
|
||||
protected MessageSendingService sendingService;
|
||||
private MessageSendingServiceConnection sendingServiceConnection;
|
||||
|
||||
|
||||
private String sendingServiceStatus = "";
|
||||
|
||||
|
||||
public SendingServiceAwareActivity() {
|
||||
this.sendingServiceConnection = new MessageSendingServiceConnection();
|
||||
}
|
||||
@@ -65,15 +65,15 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
|
||||
Intent intent = new Intent(this, MessageSendingService.class);
|
||||
bindService(intent, sendingServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
|
||||
|
||||
if (boundSendingService) {
|
||||
unbindService(sendingServiceConnection);
|
||||
boundSendingService = false;
|
||||
@@ -83,28 +83,27 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
protected void updateSendingServiceInformation() {
|
||||
if (menuItemLive == null)
|
||||
return;
|
||||
|
||||
|
||||
if (!boundSendingService)
|
||||
return;
|
||||
|
||||
int errorCount = this.sendingService.getDelayedIntentsCount();
|
||||
|
||||
int errorCount = sendingService.getDelayedIntentsCount();
|
||||
if (errorCount > 0) {
|
||||
menuItemLive.setIcon(R.drawable.ic_menu_share_red);
|
||||
Date lastSuccessfulSend = this.sendingService.getLastSuccessfulSend();
|
||||
sendingServiceStatus = String.format("Currently %d events waiting to be sent.\nLast successful sent was at %s",
|
||||
errorCount, lastSuccessfulSend == null ? "never" : lastSuccessfulSend);
|
||||
sendingServiceStatus = getString(R.string.sending_waiting, errorCount, lastSuccessfulSend == null ? "never" : lastSuccessfulSend);
|
||||
} else {
|
||||
menuItemLive.setIcon(R.drawable.ic_menu_share);
|
||||
sendingServiceStatus = String.format("Currently no event waiting to be sent.", errorCount);
|
||||
sendingServiceStatus = getString(R.string.sending_no_waiting);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the resource ID for the options menu, {@code 0} if none.
|
||||
* The menu item displaying the connection status is added automatically.
|
||||
* The menu item displaying the connection status is added automatically.
|
||||
*/
|
||||
protected abstract int getOptionsMenuResId();
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
@@ -115,7 +114,7 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (R.id.options_menu_live == item.getItemId()) {
|
||||
@@ -126,7 +125,7 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
updateSendingServiceInformation();
|
||||
|
||||
+12
-9
@@ -15,7 +15,7 @@ import com.sap.sailing.android.shared.data.http.HttpJsonGetRequest;
|
||||
import com.sap.sailing.android.shared.data.http.HttpRequest;
|
||||
import com.sap.sailing.android.shared.logging.ExLog;
|
||||
|
||||
public class AuthCheckTask extends AsyncTask<Void, Void, JSONObject> {
|
||||
public class AuthCheckTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
private static final String TAG = AuthCheckTask.class.getName();
|
||||
|
||||
@@ -37,38 +37,41 @@ public class AuthCheckTask extends AsyncTask<Void, Void, JSONObject> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject doInBackground(Void... params) {
|
||||
JSONObject result = null;
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
Boolean authenticated = false;
|
||||
if (url != null) {
|
||||
try {
|
||||
HttpRequest request = new HttpJsonGetRequest(url, context);
|
||||
InputStream responseStream = request.execute();
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
result = (JSONObject) parser.parse(new InputStreamReader(responseStream));
|
||||
JSONObject json = (JSONObject) parser.parse(new InputStreamReader(responseStream));
|
||||
if (json.containsKey("authenticated")) {
|
||||
authenticated = (Boolean) json.get("authenticated");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
exception = e;
|
||||
}
|
||||
} else {
|
||||
exception = new IllegalArgumentException();
|
||||
}
|
||||
return result;
|
||||
return authenticated;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(JSONObject json) {
|
||||
super.onPostExecute(json);
|
||||
protected void onPostExecute(Boolean authenticated) {
|
||||
super.onPostExecute(authenticated);
|
||||
if (listener != null) {
|
||||
if (exception != null) {
|
||||
listener.onException(exception);
|
||||
} else {
|
||||
listener.onRequestReceived(json);
|
||||
listener.onRequestReceived(authenticated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface AuthCheckTaskListener {
|
||||
void onRequestReceived(JSONObject json);
|
||||
void onRequestReceived(Boolean authenticated);
|
||||
|
||||
void onException(Exception exception);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".ui.activities.RacingActivity"/>
|
||||
<activity android:name=".ui.activities.PasswordActivity"/>
|
||||
<activity android:name=".ui.activities.PreferenceActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE"/>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/content_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:layout="@layout/login_backdrop" />
|
||||
@@ -12,4 +12,8 @@
|
||||
<item
|
||||
android:id="@+id/options_menu_info"
|
||||
android:title="@string/options_menu_info"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/options_menu_logout"
|
||||
android:title="@string/logout"/>
|
||||
</menu>
|
||||
@@ -174,8 +174,10 @@
|
||||
<string name="nationality">Nationalität</string>
|
||||
<string name="number">Nummer</string>
|
||||
<string name="snap">Fotos schießen</string>
|
||||
<string name="logout_dialog_title">Möchten Sie sich abmelden?</string>
|
||||
<string name="logout_dialog_message">Wenn Sie sich abmelden, wird kein Rennen mehr verwaltet.</string>
|
||||
<string name="logout_dialog_title">@string/logout</string>
|
||||
<string name="logout_dialog_message">Wollen Sie sich abmelden und als neuer Nutzer anmelden. Ihre Rennen bleiben im Hintergrund erhalten.</string>
|
||||
<string name="change_dialog_title">Ummelden</string>
|
||||
<string name="change_dialog_message">Wenn Sie sich ummelden, wird kein Rennen mehr auf der aktuellen Bahn mehr verwaltet.</string>
|
||||
<string name="logout">Abmelden</string>
|
||||
<string name="loading_configuration">Lade Konfiguration…</string>
|
||||
<string name="loading_configuration_failed">Fehler beim Laden der Konfiguration.</string>
|
||||
|
||||
@@ -185,8 +185,10 @@
|
||||
<string name="set_tracking_list">Set tracking list</string>
|
||||
<string name="confirm_tracking_list">Confirm tracking list</string>
|
||||
<string name="snap">Snap</string>
|
||||
<string name="logout_dialog_title">Are you sure want to logout?</string>
|
||||
<string name="logout_dialog_message">Logging out stops automatic monitoring for all races.</string>
|
||||
<string name="logout_dialog_title">@string/logout</string>
|
||||
<string name="logout_dialog_message">Do you want to logout and login as a new user? All your races will be still monitored.</string>
|
||||
<string name="change_dialog_title">Change Regatta</string>
|
||||
<string name="change_dialog_message">Do you want to change a regatta and/or the area? Currently monitored races will be disconnected.</string>
|
||||
<string name="logout">Logout</string>
|
||||
<string name="loading_configuration">Loading configuration…</string>
|
||||
<string name="loading_configuration_failed">There was an error loading the configuration.</string>
|
||||
|
||||
+38
-5
@@ -3,8 +3,10 @@ package com.sap.sailing.racecommittee.app.ui.activities;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
|
||||
@@ -13,6 +15,7 @@ import com.sap.sailing.android.shared.util.AppUtils;
|
||||
import com.sap.sailing.racecommittee.app.AppPreferences;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.data.DataManager;
|
||||
import com.sap.sailing.racecommittee.app.domain.BackPressListener;
|
||||
import com.sap.sailing.racecommittee.app.utils.ThemeHelper;
|
||||
|
||||
/**
|
||||
@@ -22,6 +25,7 @@ public class BaseActivity extends SendingServiceAwareActivity {
|
||||
private static final String TAG = BaseActivity.class.getName();
|
||||
|
||||
protected AppPreferences preferences;
|
||||
private BackPressListener mBackPressListener;
|
||||
|
||||
@Override
|
||||
protected int getOptionsMenuResId() {
|
||||
@@ -40,18 +44,32 @@ public class BaseActivity extends SendingServiceAwareActivity {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
Intent intent;
|
||||
switch (item.getItemId()) {
|
||||
case R.id.options_menu_settings:
|
||||
ExLog.i(this, TAG, "Clicked SETTINGS");
|
||||
intent = new Intent(this, PreferenceActivity.class);
|
||||
startActivity(intent);
|
||||
startActivity(new Intent(this, PreferenceActivity.class));
|
||||
return true;
|
||||
|
||||
case R.id.options_menu_info:
|
||||
ExLog.i(this, TAG, "Clicked INFO");
|
||||
intent = new Intent(this, SystemInformationActivity.class);
|
||||
startActivity(intent);
|
||||
startActivity(new Intent(this, SystemInformationActivity.class));
|
||||
return true;
|
||||
|
||||
case R.id.options_menu_logout:
|
||||
ExLog.i(this, TAG, "Clicked LOGOUT");
|
||||
preferences.setAccessToken(null);
|
||||
AlertDialog dialog = new AlertDialog.Builder(this, R.style.AppTheme_AlertDialog)
|
||||
.setTitle(getString(R.string.logout_dialog_title))
|
||||
.setMessage(getString(R.string.logout_dialog_message))
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
startActivity(new Intent(BaseActivity.this, PasswordActivity.class));
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null).create();
|
||||
dialog.show();
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -99,4 +117,19 @@ public class BaseActivity extends SendingServiceAwareActivity {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setBackPressListener(BackPressListener listener) {
|
||||
mBackPressListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mBackPressListener != null) {
|
||||
if (!mBackPressListener.handleBackPress()) {
|
||||
super.onBackPressed();
|
||||
}
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-21
@@ -91,8 +91,6 @@ public class LoginActivity extends BaseActivity
|
||||
private ReadonlyDataManager dataManager;
|
||||
private View progressSpinner;
|
||||
|
||||
private BackPressListener mBackPressListener;
|
||||
|
||||
private ItemSelectedListener<EventBase> eventSelectionListener = new ItemSelectedListener<EventBase>() {
|
||||
|
||||
public void itemSelected(Fragment sender, EventBase event) {
|
||||
@@ -284,9 +282,8 @@ public class LoginActivity extends BaseActivity
|
||||
ExLog.i(this, TAG, "Starting Login: " + AppUtils.with(this).getBuildInfo());
|
||||
String[] addresses = NetworkHelper.getInstance(this).getLocalIpAddress();
|
||||
if (addresses != null) {
|
||||
int len = addresses.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
ExLog.i(this, TAG, "IP-Addresses: " + addresses[i]);
|
||||
for (String address : addresses) {
|
||||
ExLog.i(this, TAG, "IP-Addresses: " + address);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +297,12 @@ public class LoginActivity extends BaseActivity
|
||||
mSelectedCourseAreaUUID = dataStore.getCourseUUID();
|
||||
mSelectedEventId = dataStore.getEventUUID();
|
||||
if (mSelectedEventId != null && mSelectedCourseAreaUUID != null) {
|
||||
switchToRacingActivity();
|
||||
if (preferences.getAccessToken() != null) {
|
||||
switchToRacingActivity();
|
||||
} else {
|
||||
startActivity(new Intent(this, PasswordActivity.class));
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
setContentView(R.layout.login_view);
|
||||
@@ -380,17 +382,6 @@ public class LoginActivity extends BaseActivity
|
||||
dismissProgressSpinner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mBackPressListener != null) {
|
||||
if (!mBackPressListener.handleBackPress()) {
|
||||
super.onBackPressed();
|
||||
}
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupDataManager() {
|
||||
showProgressSpinner();
|
||||
|
||||
@@ -457,10 +448,6 @@ public class LoginActivity extends BaseActivity
|
||||
|
||||
}
|
||||
|
||||
public void setBackPressListener(BackPressListener listener) {
|
||||
mBackPressListener = listener;
|
||||
}
|
||||
|
||||
private void slideUpBackdropDelayed() {
|
||||
Handler handler = new Handler();
|
||||
Runnable runnable = new Runnable() {
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package com.sap.sailing.racecommittee.app.ui.activities;
|
||||
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import com.sap.sailing.android.shared.util.BroadcastManager;
|
||||
import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.data.DataManager;
|
||||
import com.sap.sailing.racecommittee.app.data.DataStore;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.LoginBackdrop;
|
||||
|
||||
public class PasswordActivity extends BaseActivity {
|
||||
|
||||
private IntentReceiver mReceiver;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.password_activity);
|
||||
|
||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
transaction.replace(R.id.content_layout, LoginBackdrop.newInstance());
|
||||
transaction.commit();
|
||||
|
||||
mReceiver = new IntentReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
BroadcastManager.getInstance(this).addIntent(new Intent(AppConstants.INTENT_ACTION_CHECK_LOGIN));
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(AppConstants.INTENT_ACTION_VALID_DATA);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
private class IntentReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Intent start = new Intent(PasswordActivity.this, RacingActivity.class);
|
||||
DataStore dataStore = DataManager.create(PasswordActivity.this).getDataStore();
|
||||
start.putExtra(AppConstants.COURSE_AREA_UUID_KEY, dataStore.getCourseUUID());
|
||||
start.putExtra(AppConstants.EventIdTag, dataStore.getEventUUID());
|
||||
startActivity(start);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-9
@@ -42,19 +42,15 @@ public abstract class SessionActivity extends BaseActivity {
|
||||
public boolean logoutSession() {
|
||||
ExLog.i(this, TAG, String.format("Logging out from activity %s", this.getClass().getSimpleName()));
|
||||
AlertDialog dialog = new AlertDialog.Builder(this, R.style.AppTheme_AlertDialog)
|
||||
.setTitle(getString(R.string.logout_dialog_title))
|
||||
.setMessage(getString(R.string.logout_dialog_message))
|
||||
.setPositiveButton(getString(R.string.logout), new OnClickListener() {
|
||||
.setTitle(getString(R.string.change_dialog_title))
|
||||
.setMessage(getString(R.string.change_dialog_message))
|
||||
.setPositiveButton(android.R.string.ok, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
doLogout();
|
||||
}
|
||||
}).setNegativeButton(getString(R.string.cancel), new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
/* nothing here */
|
||||
}
|
||||
}).create();
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null).create();
|
||||
dialog.show();
|
||||
return true;
|
||||
}
|
||||
|
||||
+42
-15
@@ -4,8 +4,6 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -48,6 +46,7 @@ import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
import com.sap.sailing.racecommittee.app.AppPreferences;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.domain.BackPressListener;
|
||||
import com.sap.sailing.racecommittee.app.ui.activities.BaseActivity;
|
||||
import com.sap.sailing.racecommittee.app.ui.activities.LoginActivity;
|
||||
import com.sap.sailing.racecommittee.app.ui.activities.PreferenceActivity;
|
||||
import com.sap.sailing.racecommittee.app.ui.activities.SystemInformationActivity;
|
||||
@@ -59,6 +58,7 @@ public class LoginBackdrop extends Fragment implements LoginTask.LoginTaskListen
|
||||
|
||||
private static final String TAG = LoginBackdrop.class.getName();
|
||||
private static final int requestCodeQR = 45392;
|
||||
private static final String SHOW_BACKDROP_TEXT = "SHOW_BACKDROP_TEXT";
|
||||
|
||||
private IntentReceiver receiver;
|
||||
private View login;
|
||||
@@ -112,13 +112,22 @@ public class LoginBackdrop extends Fragment implements LoginTask.LoginTaskListen
|
||||
return layout;
|
||||
}
|
||||
|
||||
public static LoginBackdrop newInstance() {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putBoolean(SHOW_BACKDROP_TEXT, false);
|
||||
LoginBackdrop fragment = new LoginBackdrop();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
||||
if (activity instanceof LoginActivity) {
|
||||
LoginActivity login = (LoginActivity) activity;
|
||||
login.setBackPressListener(this);
|
||||
if (activity instanceof BaseActivity) {
|
||||
BaseActivity baseActivity = (BaseActivity) activity;
|
||||
baseActivity.setBackPressListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,9 +135,9 @@ public class LoginBackdrop extends Fragment implements LoginTask.LoginTaskListen
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
|
||||
if (getActivity() instanceof LoginActivity) {
|
||||
LoginActivity activity = (LoginActivity) getActivity();
|
||||
activity.setBackPressListener(null);
|
||||
if (getActivity() instanceof BaseActivity) {
|
||||
BaseActivity baseActivity = (BaseActivity) getActivity();
|
||||
baseActivity.setBackPressListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +150,13 @@ public class LoginBackdrop extends Fragment implements LoginTask.LoginTaskListen
|
||||
filter.addAction(AppConstants.INTENT_ACTION_SHOW_LOGIN);
|
||||
filter.addAction(AppConstants.INTENT_ACTION_SHOW_ONBOARDING);
|
||||
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, filter);
|
||||
|
||||
if (getArguments() != null && getView() != null && !getArguments().getBoolean(SHOW_BACKDROP_TEXT, true)) {
|
||||
View view = getView().findViewById(R.id.backdrop_title);
|
||||
if (view != null) {
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -207,7 +223,11 @@ public class LoginBackdrop extends Fragment implements LoginTask.LoginTaskListen
|
||||
AppPreferences pref = AppPreferences.on(v.getContext());
|
||||
View view = View.inflate(v.getContext(), R.layout.login_onboarding_edit, null);
|
||||
final EditText url = (EditText) view.findViewById(R.id.url);
|
||||
url.setText(pref.getServerBaseURL());
|
||||
if (TextUtils.isEmpty(pref.getServerBaseURL())) {
|
||||
url.setText(getString(R.string.preference_server_url_default));
|
||||
} else {
|
||||
url.setText(pref.getServerBaseURL());
|
||||
}
|
||||
final EditText device_id = (EditText) view.findViewById(R.id.device_id);
|
||||
device_id.setText(pref.getDeviceIdentifier());
|
||||
|
||||
@@ -217,8 +237,8 @@ public class LoginBackdrop extends Fragment implements LoginTask.LoginTaskListen
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (saveData(
|
||||
url.getText().toString() + "#" + DeviceConfigurationQRCodeUtils.deviceIdentifierKey + "=" + device_id.getText()
|
||||
.toString())) {
|
||||
url.getText().toString() + "#" + DeviceConfigurationQRCodeUtils.deviceIdentifierKey + "=" + device_id.getText()
|
||||
.toString())) {
|
||||
LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(new Intent(AppConstants.INTENT_ACTION_CHECK_LOGIN));
|
||||
}
|
||||
}
|
||||
@@ -248,6 +268,9 @@ public class LoginBackdrop extends Fragment implements LoginTask.LoginTaskListen
|
||||
|
||||
TextView url = ViewHelper.get(layout, R.id.server_url);
|
||||
if (url != null) {
|
||||
if ("\"SAP\"".equals(server)) {
|
||||
server = null;
|
||||
}
|
||||
if (TextUtils.isEmpty(server)) {
|
||||
server = AppPreferences.on(getActivity()).getServerBaseURL();
|
||||
}
|
||||
@@ -266,7 +289,7 @@ public class LoginBackdrop extends Fragment implements LoginTask.LoginTaskListen
|
||||
public void onClick(View v) {
|
||||
LoginTask task = new LoginTask(getActivity(), AppPreferences.on(getActivity()).getServerBaseURL(), LoginBackdrop.this);
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new LoginData(userName.getText().toString(), userPassword.getText()
|
||||
.toString()));
|
||||
.toString()));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -297,7 +320,7 @@ public class LoginBackdrop extends Fragment implements LoginTask.LoginTaskListen
|
||||
private boolean saveData(String content) {
|
||||
try {
|
||||
DeviceConfigurationQRCodeUtils.DeviceConfigurationDetails connectionConfiguration = DeviceConfigurationQRCodeUtils
|
||||
.splitQRContent(content);
|
||||
.splitQRContent(content);
|
||||
|
||||
final String identifier = connectionConfiguration.getDeviceIdentifier();
|
||||
final URL apkUrl = UrlHelper.tryConvertToURL(connectionConfiguration.getApkUrl());
|
||||
@@ -340,8 +363,12 @@ public class LoginBackdrop extends Fragment implements LoginTask.LoginTaskListen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestReceived(JSONObject json) {
|
||||
BroadcastManager.getInstance(getActivity()).addIntent(new Intent(AppConstants.INTENT_ACTION_VALID_DATA));
|
||||
public void onRequestReceived(Boolean authenticated) {
|
||||
if (authenticated) {
|
||||
BroadcastManager.getInstance(getActivity()).addIntent(new Intent(AppConstants.INTENT_ACTION_VALID_DATA));
|
||||
} else {
|
||||
Toast.makeText(getActivity(), "User is not authenticated", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user