From 029988fc719029a5a5b1799b1ad72cca37930827 Mon Sep 17 00:00:00 2001 From: Pierre Date: Thu, 2 Nov 2017 09:18:30 +0100 Subject: [PATCH] User can sign out of the application --- .../android/comunic/client/Account.java | 8 ++++ .../android/comunic/client/MainActivity.java | 40 +++++++++++++++++-- app/src/main/res/values/strings.xml | 4 ++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/communiquons/android/comunic/client/Account.java b/app/src/main/java/org/communiquons/android/comunic/client/Account.java index dd3002f..7cfec7f 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/Account.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/Account.java @@ -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 * diff --git a/app/src/main/java/org/communiquons/android/comunic/client/MainActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/MainActivity.java index 92a149f..a0b2e9b 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/MainActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/MainActivity.java @@ -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(); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 678d6ad..8e7377d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,4 +10,8 @@ No Internet connexion ! The server sent an unexcepted response… Sign out + Sign out + Are you sure do you want to sign out ? + Sign out + Cancel