Remember decision option for "Remove all from inbox" dialog (#6186)

This commit is contained in:
Tong Liu 2022-11-30 15:15:38 -05:00 committed by GitHub
parent f91d536ab9
commit bec1eaa679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,16 +1,21 @@
package de.danoeh.antennapod.fragment;
import android.content.DialogInterface;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.model.feed.FeedItem;
@ -25,6 +30,8 @@ import java.util.List;
public class InboxFragment extends EpisodesListFragment {
public static final String TAG = "NewEpisodesFragment";
private static final String PREF_NAME = "PrefNewEpisodesFragment";
private static final String PREF_DO_NOT_PROMPT_REMOVE_ALL_FROM_INBOX = "prefDoNotPromptRemovalAllFromInbox";
private SharedPreferences prefs;
@NonNull
@Override
@ -32,6 +39,7 @@ public class InboxFragment extends EpisodesListFragment {
final View root = super.onCreateView(inflater, container, savedInstanceState);
toolbar.inflateMenu(R.menu.inbox);
toolbar.setTitle(R.string.inbox_label);
prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
updateToolbar();
emptyView.setIcon(R.drawable.ic_inbox);
emptyView.setTitle(R.string.no_inbox_head_label);
@ -63,19 +71,11 @@ public class InboxFragment extends EpisodesListFragment {
return true;
}
if (item.getItemId() == R.id.remove_all_inbox_item) {
ConfirmationDialog removeAllNewFlagsConfirmationDialog = new ConfirmationDialog(getActivity(),
R.string.remove_all_inbox_label,
R.string.remove_all_inbox_confirmation_msg) {
@Override
public void onConfirmButtonPressed(DialogInterface dialog) {
dialog.dismiss();
DBWriter.removeAllNewFlags();
((MainActivity) getActivity()).showSnackbarAbovePlayer(
R.string.removed_all_inbox_msg, Toast.LENGTH_SHORT);
}
};
removeAllNewFlagsConfirmationDialog.createNewDialog().show();
if (prefs.getBoolean(PREF_DO_NOT_PROMPT_REMOVE_ALL_FROM_INBOX, false)) {
removeAllFromInbox();
} else {
showRemoveAllDialog();
}
return true;
}
return false;
@ -97,4 +97,27 @@ public class InboxFragment extends EpisodesListFragment {
protected int loadTotalItemCount() {
return DBReader.getTotalEpisodeCount(new FeedItemFilter(FeedItemFilter.NEW));
}
private void removeAllFromInbox() {
DBWriter.removeAllNewFlags();
((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.removed_all_inbox_msg, Toast.LENGTH_SHORT);
}
private void showRemoveAllDialog() {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext());
builder.setTitle(R.string.remove_all_inbox_label);
builder.setMessage(R.string.remove_all_inbox_confirmation_msg);
View view = View.inflate(getContext(), R.layout.checkbox_do_not_show_again, null);
CheckBox checkNeverAskAgain = view.findViewById(R.id.checkbox_do_not_show_again);
builder.setView(view);
builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
dialog.dismiss();
removeAllFromInbox();
prefs.edit().putBoolean(PREF_DO_NOT_PROMPT_REMOVE_ALL_FROM_INBOX, checkNeverAskAgain.isChecked()).apply();
});
builder.setNegativeButton(R.string.cancel_label, null);
builder.show();
}
}