Added delete conversation confirmation popup

This commit is contained in:
Pierre 2017-12-31 12:10:29 +01:00
parent 7315ebbced
commit 95844e8ba2
4 changed files with 94 additions and 2 deletions

View File

@ -257,7 +257,7 @@ public class ConversationFragment extends Fragment
new Thread(refreshRunnable).start(); new Thread(refreshRunnable).start();
//Update conversation title //Update conversation title
getActivity().setTitle(R.string.fragement_conversation_title); getActivity().setTitle(R.string.fragment_conversation_title);
//Update the bottom navigation menu //Update the bottom navigation menu
((MainActivity) getActivity()) ((MainActivity) getActivity())
@ -369,6 +369,14 @@ public class ConversationFragment extends Fragment
*/ */
private void onGotConversationInfos(ConversationsInfo infos){ private void onGotConversationInfos(ConversationsInfo infos){
//Check for errors
if(infos == null){
Toast.makeText(getActivity(), R.string.fragment_conversation_err_getconvinfos,
Toast.LENGTH_SHORT).show();
return;
}
//Save conversation informations //Save conversation informations
conversationInfo = infos; conversationInfo = infos;

View File

@ -1,14 +1,19 @@
package org.communiquons.android.comunic.client.fragments; package org.communiquons.android.comunic.client.fragments;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment; import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.Log; import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -265,10 +270,44 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O
//Add click listener //Add click listener
conversationsListView.setOnItemClickListener(this); conversationsListView.setOnItemClickListener(this);
conversationsListView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.menu_fragment_conserationslist_item, menu);
}
});
//Remove progress bar //Remove progress bar
display_progress_bar(false); display_progress_bar(false);
} }
@Override
public boolean onContextItemSelected(MenuItem item) {
//Fetch source item
AdapterView.AdapterContextMenuInfo src
= (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
//Get conversation ID
int convID = convList.size() > src.position ? convList.get(src.position).getID() : -1;
if(convID != -1) {
//Check which action was chosen
switch (item.getItemId()) {
case R.id.menu_fragment_conversationslist_item_delete:
confirmDeleteConversation(convID);
return true;
}
}
return super.onContextItemSelected(item);
}
/** /**
* Handles the click on a conversation to open it * Handles the click on a conversation to open it
* *
@ -293,4 +332,36 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O
private void display_progress_bar(boolean show){ private void display_progress_bar(boolean show){
progressBar.setVisibility(show ? View.VISIBLE : View.GONE); progressBar.setVisibility(show ? View.VISIBLE : View.GONE);
} }
/**
* Display a popup window to ask user to confirm the deletion of a conversation
*
* @param convID The ID of the conversation to delete
*/
private void confirmDeleteConversation(final int convID){
new AlertDialog.Builder(getActivity())
.setTitle(R.string.popup_deleteconversation_title)
.setMessage(R.string.popup_deleteconversation_messsage)
.setNegativeButton(R.string.popup_deleteconversation_cancel, null)
.setPositiveButton(R.string.popup_deleteconversation_confirm, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
delete_conversation(convID);
}
})
.show();
}
/**
* Delete a conversation
*
* @param convID The ID of the conversation to delete
*/
private void delete_conversation(int convID){
Toast.makeText(getActivity(), "Delete conversation: " + convID, Toast.LENGTH_SHORT).show();
}
} }

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_fragment_conversationslist_item_delete"
android:title="@string/action_conversation_delete" />
</menu>

View File

@ -65,5 +65,11 @@
<string name="fragment_friendslist_title">Friends</string> <string name="fragment_friendslist_title">Friends</string>
<string name="fragment_conversationslist_title">Conversations</string> <string name="fragment_conversationslist_title">Conversations</string>
<string name="fragment_userinfos_title">About me</string> <string name="fragment_userinfos_title">About me</string>
<string name="fragement_conversation_title">Title</string> <string name="fragment_conversation_title">Title</string>
<string name="fragment_conversation_err_getconvinfos">Could not get information about the conversation !</string>
<string name="action_conversation_delete">Delete</string>
<string name="popup_deleteconversation_title">Remove conversation</string>
<string name="popup_deleteconversation_messsage">Are you sure do you want to remove this conversation ? All the messages you posted will be deleted. If you are the owner of the conversation, all the messages will be removed.</string>
<string name="popup_deleteconversation_confirm">Delete</string>
<string name="popup_deleteconversation_cancel">Cancel</string>
</resources> </resources>