From f64260e0ac358f514b441f0c4a7aeeed2e25b231 Mon Sep 17 00:00:00 2001 From: Tiberiu Iustin Zulean Date: Wed, 13 Nov 2019 14:35:17 +0000 Subject: [PATCH] Added menu with settings (unregister) and sign out options --- .../java/teamzero/chat/mobile/ChatList.java | 58 +++++++++++++++++++ Android/app/src/main/res/menu/menu_layout.xml | 9 +++ Android/app/src/main/res/values/strings.xml | 3 + 3 files changed, 70 insertions(+) diff --git a/Android/app/src/main/java/teamzero/chat/mobile/ChatList.java b/Android/app/src/main/java/teamzero/chat/mobile/ChatList.java index dc17cc0..e1e1b9b 100644 --- a/Android/app/src/main/java/teamzero/chat/mobile/ChatList.java +++ b/Android/app/src/main/java/teamzero/chat/mobile/ChatList.java @@ -1,7 +1,9 @@ package teamzero.chat.mobile; +import android.app.AlertDialog; import android.app.ProgressDialog; +import android.content.DialogInterface; import android.content.Intent; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; @@ -11,6 +13,7 @@ import android.view.Menu; import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -19,6 +22,7 @@ import android.widget.ListView; import android.widget.SearchView; import android.widget.TextView; +import android.widget.Toast; import com.android.volley.Request; import com.android.volley.RequestQueue; @@ -177,4 +181,58 @@ public boolean onCreateOptionsMenu(Menu menu) { return true; } + // Called when the user selects any item from the menu + @Override + public boolean onOptionsItemSelected(MenuItem item) { + + // Get the id of the selected menu item to determine what the user clicked + switch (item.getItemId()) { + + case R.id.sign_out: + signOutOrUnregister("Sign Out"); + return true; + + case R.id.unregister: + signOutOrUnregister("Unregister"); + return true; + + default: + return super.onOptionsItemSelected(item); + } + } + + public void signOutOrUnregister(final String choice) { + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + + builder.setPositiveButton(choice, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // User clicked Sign Out OR Unregister + + if(choice.equalsIgnoreCase("Sign Out")) { + // TODO: Build and send JSON to server stating that the user signed out + } + + if(choice.equalsIgnoreCase("Unregister")) { + // TODO: Build and send JSON to server stating that the user wants to unregister + } + + // Go back to home login/register screen + startActivity(new Intent(ChatList.this, MainActivity.class)); + } + }); + + builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // User cancelled the dialog, go back + } + }); + + // Create the AlertDialog + AlertDialog dialog = builder.create(); + dialog.setTitle(choice); + dialog.setMessage("Are you sure you want to " + choice.toLowerCase() + "?"); + dialog.show(); + } + } \ No newline at end of file diff --git a/Android/app/src/main/res/menu/menu_layout.xml b/Android/app/src/main/res/menu/menu_layout.xml index 8c5cbad..970eae0 100644 --- a/Android/app/src/main/res/menu/menu_layout.xml +++ b/Android/app/src/main/res/menu/menu_layout.xml @@ -7,4 +7,13 @@ android:icon="@android:drawable/ic_menu_search" app:showAsAction="collapseActionView|ifRoom" app:actionViewClass="android.widget.SearchView" /> + + + + + + \ No newline at end of file diff --git a/Android/app/src/main/res/values/strings.xml b/Android/app/src/main/res/values/strings.xml index a7c9b94..074ff91 100644 --- a/Android/app/src/main/res/values/strings.xml +++ b/Android/app/src/main/res/values/strings.xml @@ -17,4 +17,7 @@ Type your message Type username to start a new chat with Type in the box down below to search for a user to chat with + Settings + Sign Out + Unregister