User can sign out of the application

This commit is contained in:
Pierre 2017-11-02 09:18:30 +01:00
parent b7a07ab2ed
commit 029988fc71
3 changed files with 48 additions and 4 deletions

View File

@ -66,6 +66,14 @@ class Account {
return true;
}
/**
* Sign out user
* @return True in case of success / false else
*/
boolean sign_out(){
return remove_login_tokens();
}
/**
* Try to load tokens in tokens array
*

View File

@ -1,5 +1,7 @@
package org.communiquons.android.comunic.client;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@ -7,6 +9,8 @@ import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import org.communiquons.android.comunic.client.api.APIRequestTask;
public class MainActivity extends AppCompatActivity {
/**
@ -26,13 +30,16 @@ public class MainActivity extends AppCompatActivity {
//Initialize account object
account = new Account(this);
}
@Override
protected void onStart() {
super.onStart();
//Check if user is signed in or not
if(!account.signed_in()){
//Open the login activity
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
startActivity(new Intent(this, LoginActivity.class));
}
}
@ -65,6 +72,31 @@ public class MainActivity extends AppCompatActivity {
* Ask user to confirm if he really what to sign out or not
*/
void confirmUserLogout(){
Toast.makeText(this, "Do you really want to signout ???", Toast.LENGTH_SHORT).show();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.popup_signout_title)
.setMessage(R.string.popup_signout_message)
.setCancelable(true)
.setPositiveButton(R.string.popup_signout_confirm_button,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Sign out user
account.sign_out();
//Redirect to login activity
startActivity(new Intent(MainActivity.this, LoginActivity.class));
}
})
.setNegativeButton(R.string.popup_signout_cancel_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Nothing now
}
})
//Show popup
.create().show();
}
}

View File

@ -10,4 +10,8 @@
<string name="err_no_internet_connection">No Internet connexion !</string>
<string name="activity_login_err_server_response">The server sent an unexcepted response…</string>
<string name="main_menu_logout">Sign out</string>
<string name="popup_signout_title">Sign out</string>
<string name="popup_signout_message">Are you sure do you want to sign out ?</string>
<string name="popup_signout_confirm_button">Sign out</string>
<string name="popup_signout_cancel_button">Cancel</string>
</resources>