mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-12-28 14:39:00 +00:00
Conversations can be deleted
This commit is contained in:
parent
eee570993a
commit
2c29b49c24
@ -155,6 +155,28 @@ public class ConversationsListHelper {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a conversation specified by its ID
|
||||
*
|
||||
* @param convID The ID of the conversation to delete
|
||||
* @return True in case of success / false else
|
||||
*/
|
||||
public boolean delete(int convID){
|
||||
|
||||
//Delete the conversation on the API
|
||||
APIRequestParameters params = new APIRequestParameters(mContext, "conversations/delete");
|
||||
params.addParameter("conversationID", ""+convID);
|
||||
|
||||
try {
|
||||
new APIRequest().exec(params);
|
||||
} catch (Exception e){
|
||||
return false;
|
||||
}
|
||||
|
||||
//Success
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get online (download) the list of all the conversations
|
||||
*
|
||||
|
@ -111,23 +111,8 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O
|
||||
//Get progress bar wheel
|
||||
progressBar = view.findViewById(R.id.fragment_conversationslist_progressbar);
|
||||
|
||||
//Get the list of conversations
|
||||
new AsyncTask<Void, Void, ArrayList<ConversationsInfo>>(){
|
||||
@Override
|
||||
protected ArrayList<ConversationsInfo> doInBackground(Void... params) {
|
||||
|
||||
//Get the list of conversations
|
||||
ArrayList<ConversationsInfo> list = conversationsListHelper.get();
|
||||
process_conversations_list(list);
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ArrayList<ConversationsInfo> list) {
|
||||
display_conversations_list(list);
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
//Refresh conversations list
|
||||
refresh_conversations_list();
|
||||
|
||||
//Set the open conversation listener
|
||||
try {
|
||||
@ -150,6 +135,34 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O
|
||||
.setSelectedNavigationItem(R.id.main_bottom_navigation_conversations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the list of conversations
|
||||
*/
|
||||
private void refresh_conversations_list(){
|
||||
|
||||
//Display loading wheel
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
//Get the list of conversations
|
||||
new AsyncTask<Void, Void, ArrayList<ConversationsInfo>>(){
|
||||
@Override
|
||||
protected ArrayList<ConversationsInfo> doInBackground(Void... params) {
|
||||
|
||||
//Get the list of conversations
|
||||
ArrayList<ConversationsInfo> list = conversationsListHelper.get();
|
||||
process_conversations_list(list);
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ArrayList<ConversationsInfo> list) {
|
||||
display_conversations_list(list);
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the conversation list
|
||||
*
|
||||
@ -157,7 +170,7 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O
|
||||
*
|
||||
* @param list The list of conversations
|
||||
*/
|
||||
public void process_conversations_list(ArrayList<ConversationsInfo> list){
|
||||
private void process_conversations_list(ArrayList<ConversationsInfo> list){
|
||||
|
||||
//Check if got the list
|
||||
if(list == null){
|
||||
@ -361,7 +374,19 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O
|
||||
*
|
||||
* @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();
|
||||
private void delete_conversation(final int convID){
|
||||
new AsyncTask<Void, Void, Void>(){
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
conversationsListHelper.delete(convID);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
refresh_conversations_list();
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
|
@ -72,4 +72,5 @@
|
||||
<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>
|
||||
<string name="fragment_conversationslist_err_del_conversation">Could not delete conversation !</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user