Skip to content

Commit

Permalink
Added menu with settings (unregister) and sign out options
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiberiu Iustin Zulean committed Nov 13, 2019
1 parent cc26baa commit f64260e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Android/app/src/main/java/teamzero/chat/mobile/ChatList.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,6 +13,7 @@

import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

Expand All @@ -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;
Expand Down Expand Up @@ -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();
}

}
9 changes: 9 additions & 0 deletions Android/app/src/main/res/menu/menu_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@
android:icon="@android:drawable/ic_menu_search"
app:showAsAction="collapseActionView|ifRoom"
app:actionViewClass="android.widget.SearchView" />
<item android:id="@+id/settings"
android:title="@string/settings_menu_text" >
<menu>
<item android:id="@+id/unregister"
android:title="@string/unregister_text" />
</menu>
</item>
<item android:id="@+id/sign_out"
android:title="@string/sign_out_text" />
</menu>
3 changes: 3 additions & 0 deletions Android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
<string name="message_box_hint_text"> Type your message </string>
<string name="search_users_hint_text"> Type username to start a new chat with </string>
<string name="search_users_suggestive_text"> Type in the box down below to search for a user to chat with </string>
<string name="settings_menu_text"> Settings </string>
<string name="sign_out_text"> Sign Out </string>
<string name="unregister_text"> Unregister </string>
</resources>

0 comments on commit f64260e

Please sign in to comment.