mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-08 20:12:23 +00:00
logout in overflow
This commit is contained in:
1 parent
102f701a1a
commit
f56087ab5d
18 files changed
+299
-118
No files matched your search
@@ -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>
|
||||
+10
-1
@@ -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);
|
||||
|
||||
+4
-4
@@ -14,6 +14,7 @@ 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;
|
||||
|
||||
@@ -30,7 +31,7 @@ public class MessagePersistenceManager {
|
||||
|
||||
public MessagePersistenceManager(Context context, MessageRestorer messageRestorer) {
|
||||
this.context = context;
|
||||
persistedMessages = new ArrayList<String>();
|
||||
persistedMessages = new ArrayList<>();
|
||||
this.messageRestorer = messageRestorer;
|
||||
initializeFileAndPersistedMessages();
|
||||
}
|
||||
@@ -64,10 +65,9 @@ public class MessagePersistenceManager {
|
||||
*/
|
||||
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,
|
||||
return String.format("%s;%s;%s;%s", callbackPayload, URLEncoder.encode(payload,
|
||||
MessageSendingService.charsetName),
|
||||
url, callbackClass);
|
||||
return messageLine;
|
||||
}
|
||||
|
||||
public void removeIntent(Intent intent) throws UnsupportedEncodingException {
|
||||
@@ -111,7 +111,7 @@ public class MessagePersistenceManager {
|
||||
return persistedMessages;
|
||||
}
|
||||
|
||||
public static interface MessageRestorer {
|
||||
public interface MessageRestorer {
|
||||
void restoreMessage(Context context, Intent messageIntent);
|
||||
}
|
||||
|
||||
|
||||
+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;
|
||||
}
|
||||
}
|
||||
+21
-22
@@ -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);
|
||||
}
|
||||
}
|
||||
+24
-31
@@ -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,8 +42,8 @@ import java.util.*;
|
||||
* android:value="com.sap.sailing.racecommittee.app.services.sending.EventRestorer" />
|
||||
* </service>
|
||||
* }</pre>
|
||||
*
|
||||
*
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Message sending example:
|
||||
* <pre>{@code
|
||||
* context.startService(MessageSendingService.createMessageIntent(
|
||||
@@ -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) {
|
||||
@@ -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)");
|
||||
}
|
||||
@@ -317,7 +316,7 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
serviceLogger.onMessageSentSuccessful();
|
||||
}
|
||||
|
||||
String callbackClassString = intent.getStringExtra(CALLBACK_CLASS);
|
||||
String callbackClassString = result.getIntent().getStringExtra(CALLBACK_CLASS);
|
||||
ServerReplyCallback callback = null;
|
||||
if (callbackClassString != null) {
|
||||
try {
|
||||
@@ -328,10 +327,10 @@ 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();
|
||||
}
|
||||
}
|
||||
@@ -343,10 +342,7 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
*/
|
||||
private boolean isConnected() {
|
||||
NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
|
||||
if (activeNetwork == null) {
|
||||
return false;
|
||||
}
|
||||
return activeNetwork.isConnected();
|
||||
return activeNetwork != null && activeNetwork.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,8 +367,7 @@ public class MessageSendingService extends Service implements MessageSendingList
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
+3
-4
@@ -87,15 +87,14 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+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();
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-20
@@ -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) {
|
||||
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;
|
||||
}
|
||||
|
||||
+36
-9
@@ -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);
|
||||
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());
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -340,8 +363,12 @@ public class LoginBackdrop extends Fragment implements LoginTask.LoginTaskListen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestReceived(JSONObject json) {
|
||||
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