mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 13:59:29 +00:00
Can delete the entire list of notifications.
This commit is contained in:
parent
bcc747ee5f
commit
8227cb0355
@ -64,4 +64,25 @@ public class NotificationsHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Intend to delete the entire list of notifications
|
||||
*
|
||||
* @return TRUE in case of success / FALSE else
|
||||
*/
|
||||
public boolean deleteAllNotifs(){
|
||||
|
||||
//Perform a request on the server
|
||||
APIRequestParameters params = new APIRequestParameters(mContext,
|
||||
"notifications/delete_all");
|
||||
|
||||
//Try to perform the request on the server
|
||||
try {
|
||||
APIResponse response = new APIRequest().exec(params);
|
||||
return response.getResponse_code() == 200;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -112,9 +112,9 @@ public class MainActivity extends AppCompatActivity
|
||||
//Initialize conversation list helper
|
||||
conversationsListHelper = new ConversationsListHelper(this, dbHelper);
|
||||
|
||||
//If it is the first time the application is launched, start the user friends tab
|
||||
//If it is the first time the application is launched, open notifications fragment
|
||||
if(savedInstanceState == null){
|
||||
openFriendsFragment();
|
||||
openNotificationsFragment();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,19 @@
|
||||
package org.communiquons.android.comunic.client.ui.fragments;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.data.notifications.NotificationsHelper;
|
||||
import org.communiquons.android.comunic.client.ui.activities.MainActivity;
|
||||
|
||||
/**
|
||||
@ -19,12 +25,44 @@ import org.communiquons.android.comunic.client.ui.activities.MainActivity;
|
||||
|
||||
public class NotificationsFragment extends Fragment {
|
||||
|
||||
/**
|
||||
* Notifications helper
|
||||
*/
|
||||
private NotificationsHelper mNotificationsHelper;
|
||||
|
||||
/**
|
||||
* Delete all the notifications button
|
||||
*/
|
||||
private View mDeleteNotificationsBtn;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
//Create notifications helper
|
||||
mNotificationsHelper = new NotificationsHelper(context);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_notifications, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
//Delete all the notifications action
|
||||
mDeleteNotificationsBtn = view.findViewById(R.id.delete_all_notif_btn);
|
||||
mDeleteNotificationsBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
confirmNotificationsDeletion();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
@ -36,4 +74,62 @@ public class NotificationsFragment extends Fragment {
|
||||
((MainActivity) getActivity())
|
||||
.setSelectedNavigationItem(R.id.main_bottom_navigation_notif);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the user to confirm the deletion of all the notifications
|
||||
*/
|
||||
private void confirmNotificationsDeletion(){
|
||||
|
||||
//Create and display a confirmation dialog
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.dialog_deleteallnotifs_title)
|
||||
.setMessage(R.string.dialog_deleteallnotifs_message)
|
||||
.setNegativeButton(R.string.dialog_deleteallnotifs_cancel, null)
|
||||
|
||||
.setPositiveButton(R.string.dialog_deleteallnotifs_confirm,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
processAllNotificationsDeletion();
|
||||
}
|
||||
})
|
||||
|
||||
.show();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the deletion of all the notifications
|
||||
*/
|
||||
private void processAllNotificationsDeletion(){
|
||||
|
||||
//Perform the operation in the background
|
||||
new AsyncTask<Void, Void, Boolean>(){
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
return mNotificationsHelper.deleteAllNotifs();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
|
||||
//Check if the activity has been destroyed
|
||||
if(getActivity() == null)
|
||||
return;
|
||||
|
||||
//Check for error
|
||||
if(!result) {
|
||||
Toast.makeText(getActivity(), R.string.err_delete_all_notifs,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
//Success
|
||||
Toast.makeText(getActivity(), R.string.success_delete_all_notifs,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,4 +3,26 @@
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- Notification loading progress -->
|
||||
<ProgressBar
|
||||
android:id="@+id/loading_progress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="10dp"/>
|
||||
|
||||
<!-- Notifications list -->
|
||||
<ListView
|
||||
android:id="@+id/notificcation_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<!-- Delete all the notifications button -->
|
||||
<Button
|
||||
android:id="@+id/delete_all_notif_btn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/action_delete_all_notifications"/>
|
||||
|
||||
</LinearLayout>
|
@ -149,4 +149,11 @@
|
||||
<string name="preference_background_notif_summary">This allow you to stay informed about the latest notifications on Comunic by checking at a regular interval the existence of notifications, even if the application is closed.</string>
|
||||
<string name="notification_notif_available_title">New activity on Comunic</string>
|
||||
<string name="notification_notif_available_content"> %1$d notification(s) and %2$d unread conversations(s)</string>
|
||||
<string name="action_delete_all_notifications">Delete all the notifications</string>
|
||||
<string name="dialog_deleteallnotifs_title">Delete all the notifications</string>
|
||||
<string name="dialog_deleteallnotifs_message">Are you sure do you want to delete all the notifications ? This can not be undone!</string>
|
||||
<string name="dialog_deleteallnotifs_cancel">No</string>
|
||||
<string name="dialog_deleteallnotifs_confirm">Yes</string>
|
||||
<string name="err_delete_all_notifs">An error occurred while trying to delete the entire list of notifications!</string>
|
||||
<string name="success_delete_all_notifs">All the notifications have been deleted!</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user