mirror of
				https://github.com/pierre42100/ComunicAndroid
				synced 2025-11-04 11:34:06 +00:00 
			
		
		
		
	User can sign out of the application
This commit is contained in:
		@@ -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
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user