mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-08 13:20:57 +00:00
tap on "share" icon checks if accessToken is still valid
This commit is contained in:
1 parent
27112da473
commit
40a6182d79
4 files changed
+60
-15
No files matched your search
@@ -473,5 +473,7 @@
|
||||
<string name="password">Passwort</string>
|
||||
<string name="wrong_credentials">Nutzername oder Passwort ungültig</string>
|
||||
<string name="unexpected_error">Ein unerwarteter Fehler ist aufgetreten</string>
|
||||
<string name="sending_exception_title">Warnung</string>
|
||||
<string name="sending_exception_message">Sie haben wahrscheinlich nicht die Befugniss Daten an den Server zu schicken. Möchten Sie sich als andere Nutzer anmelden?</string>
|
||||
|
||||
</resources>
|
||||
@@ -500,5 +500,7 @@
|
||||
<string name="password">Password</string>
|
||||
<string name="wrong_credentials">Username or password invalid</string>
|
||||
<string name="unexpected_error">An unexpected error occurred</string>
|
||||
<string name="sending_exception_title">Warning</string>
|
||||
<string name="sending_exception_message">You have probably not the permission to send data to the server. Do you want to change your login credentials?</string>
|
||||
|
||||
</resources>
|
||||
+1
-1
@@ -57,13 +57,13 @@ public class BaseActivity extends SendingServiceAwareActivity {
|
||||
|
||||
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) {
|
||||
preferences.setAccessToken(null);
|
||||
startActivity(new Intent(BaseActivity.this, PasswordActivity.class));
|
||||
finish();
|
||||
}
|
||||
|
||||
+55
-14
@@ -4,26 +4,33 @@ import java.util.Date;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.IBinder;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.sap.sailing.android.shared.data.http.UnauthorizedException;
|
||||
import com.sap.sailing.android.shared.logging.ExLog;
|
||||
import com.sap.sailing.android.shared.services.sending.MessageSendingService;
|
||||
import com.sap.sailing.android.shared.services.sending.MessageSendingService.MessageSendingBinder;
|
||||
import com.sap.sailing.android.shared.services.sending.MessageSendingService.MessageSendingServiceLogger;
|
||||
import com.sap.sailing.android.shared.ui.activities.ResilientActivity;
|
||||
import com.sap.sailing.android.shared.util.AuthCheckTask;
|
||||
import com.sap.sailing.android.shared.util.PrefUtils;
|
||||
import com.sap.sailing.racecommittee.app.AppPreferences;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.utils.BitmapHelper;
|
||||
import com.sap.sailing.racecommittee.app.utils.ThemeHelper;
|
||||
|
||||
public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
|
||||
public abstract class SendingServiceAwareActivity extends ResilientActivity implements AuthCheckTask.AuthCheckTaskListener {
|
||||
|
||||
private class MessageSendingServiceConnection implements ServiceConnection, MessageSendingServiceLogger {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||
@@ -51,16 +58,15 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
}
|
||||
|
||||
protected MenuItem menuItemLive;
|
||||
protected int menuItemLiveId = -1;
|
||||
|
||||
protected boolean boundSendingService = false;
|
||||
protected MessageSendingService sendingService;
|
||||
private MessageSendingServiceConnection sendingServiceConnection;
|
||||
|
||||
|
||||
private String sendingServiceStatus = "";
|
||||
|
||||
private static String TAG = SendingServiceAwareActivity.class.getName();
|
||||
|
||||
|
||||
public SendingServiceAwareActivity() {
|
||||
sendingServiceConnection = new MessageSendingServiceConnection();
|
||||
}
|
||||
@@ -68,16 +74,16 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
|
||||
Intent intent = new Intent(this, MessageSendingService.class);
|
||||
ExLog.i(this, TAG, "bindSendingService");
|
||||
bindService(intent, sendingServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
|
||||
|
||||
ExLog.i(this, TAG, "unbindSendingService");
|
||||
unbindService(sendingServiceConnection);
|
||||
boundSendingService = false;
|
||||
@@ -106,13 +112,13 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
sendingServiceStatus = getString(R.string.no_event_to_be_sent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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();
|
||||
@@ -123,17 +129,22 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (R.id.options_menu_live == item.getItemId()) {
|
||||
Toast.makeText(this, getLiveIconText(), Toast.LENGTH_LONG).show();
|
||||
if (AppPreferences.on(this).getAccessToken() == null) {
|
||||
onException(null);
|
||||
} else {
|
||||
AuthCheckTask task = new AuthCheckTask(this, AppPreferences.on(this).getServerBaseURL(), this);
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
updateSendingServiceInformation();
|
||||
@@ -144,4 +155,34 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
|
||||
return getString(R.string.connected_to_wp, PrefUtils.getString(this, R.string.preference_server_url_key,
|
||||
R.string.preference_server_url_default), sendingServiceStatus, (boundSendingService ? "bound" : "unbound"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestReceived(Boolean authenticated) {
|
||||
Toast.makeText(this, getLiveIconText(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Exception exception) {
|
||||
if (exception == null || exception instanceof UnauthorizedException) {
|
||||
Context context = this;
|
||||
if (getSupportActionBar() != null) {
|
||||
context = getSupportActionBar().getThemedContext();
|
||||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AppTheme_AlertDialog);
|
||||
builder.setTitle(getString(R.string.sending_exception_title));
|
||||
builder.setMessage(getString(R.string.sending_exception_message));
|
||||
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
AppPreferences.on(SendingServiceAwareActivity.this).setAccessToken(null);
|
||||
startActivity(new Intent(SendingServiceAwareActivity.this, PasswordActivity.class));
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.no, null);
|
||||
builder.show();
|
||||
} else {
|
||||
onRequestReceived(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user