Added button dialog

pull/194/head
M66B 4 years ago
parent 6565f6dee1
commit c21e17e9ed

@ -4041,39 +4041,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean full = properties.getValue("full", message.id);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean button_junk = prefs.getBoolean("button_junk", true);
boolean button_trash = prefs.getBoolean("button_trash", true);
boolean button_archive = prefs.getBoolean("button_archive", true);
boolean button_move = prefs.getBoolean("button_move", true);
boolean button_copy = prefs.getBoolean("button_copy", false);
boolean button_keywords = prefs.getBoolean("button_keywords", false);
boolean button_notes = prefs.getBoolean("button_notes", false);
boolean button_seen = prefs.getBoolean("button_seen", false);
boolean button_search = prefs.getBoolean("button_search", false);
boolean button_event = prefs.getBoolean("button_event", false);
boolean button_share = prefs.getBoolean("button_share", false);
boolean button_print = prefs.getBoolean("button_print", false);
boolean button_unsubscribe = prefs.getBoolean("button_unsubscribe", true);
boolean button_rule = prefs.getBoolean("button_rule", false);
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, ibMore);
popupMenu.inflate(R.menu.popup_message_more);
popupMenu.getMenu().findItem(R.id.menu_button_junk).setChecked(button_junk);
popupMenu.getMenu().findItem(R.id.menu_button_trash).setChecked(button_trash);
popupMenu.getMenu().findItem(R.id.menu_button_archive).setChecked(button_archive);
popupMenu.getMenu().findItem(R.id.menu_button_move).setChecked(button_move);
popupMenu.getMenu().findItem(R.id.menu_button_copy).setChecked(button_copy);
popupMenu.getMenu().findItem(R.id.menu_button_keywords).setChecked(button_keywords);
popupMenu.getMenu().findItem(R.id.menu_button_notes).setChecked(button_notes);
popupMenu.getMenu().findItem(R.id.menu_button_seen).setChecked(button_seen);
popupMenu.getMenu().findItem(R.id.menu_button_search).setChecked(button_search);
popupMenu.getMenu().findItem(R.id.menu_button_event).setChecked(button_event);
popupMenu.getMenu().findItem(R.id.menu_button_share).setChecked(button_share);
popupMenu.getMenu().findItem(R.id.menu_button_print).setChecked(button_print);
popupMenu.getMenu().findItem(R.id.menu_button_unsubscribe).setChecked(button_unsubscribe);
popupMenu.getMenu().findItem(R.id.menu_button_rule).setChecked(button_rule);
popupMenu.getMenu().findItem(R.id.menu_unseen).setTitle(message.ui_seen ? R.string.title_unseen : R.string.title_seen);
popupMenu.getMenu().findItem(R.id.menu_unseen).setEnabled(
(message.uid != null && !message.folderReadOnly) || message.accountProtocol != EntityAccount.TYPE_IMAP);
@ -4126,48 +4097,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override
public boolean onMenuItemClick(MenuItem target) {
int itemId = target.getItemId();
if (itemId == R.id.menu_button_junk) {
onMenuButton(message, "junk", target.isChecked());
return true;
} else if (itemId == R.id.menu_button_trash) {
onMenuButton(message, "trash", target.isChecked());
return true;
} else if (itemId == R.id.menu_button_archive) {
onMenuButton(message, "archive", target.isChecked());
return true;
} else if (itemId == R.id.menu_button_move) {
onMenuButton(message, "move", target.isChecked());
return true;
} else if (itemId == R.id.menu_button_copy) {
onMenuButton(message, "copy", target.isChecked());
return true;
} else if (itemId == R.id.menu_button_keywords) {
onMenuButton(message, "keywords", target.isChecked());
return true;
} else if (itemId == R.id.menu_button_notes) {
onMenuButton(message, "notes", target.isChecked());
return true;
} else if (itemId == R.id.menu_button_seen) {
onMenuButton(message, "seen", target.isChecked());
return true;
} else if (itemId == R.id.menu_button_search) {
onMenuButton(message, "search", target.isChecked());
bindAddresses(message);
return true;
} else if (itemId == R.id.menu_button_event) {
onMenuButton(message, "event", target.isChecked());
return true;
} else if (itemId == R.id.menu_button_share) {
onMenuButton(message, "share", target.isChecked());
return true;
} else if (itemId == R.id.menu_button_print) {
onMenuButton(message, "print", target.isChecked());
return true;
} else if (itemId == R.id.menu_button_unsubscribe) {
onMenuButton(message, "unsubscribe", target.isChecked());
return true;
} else if (itemId == R.id.menu_button_rule) {
onMenuButton(message, "rule", target.isChecked());
if (itemId == R.id.menu_button) {
FragmentDialogButtons buttons = new FragmentDialogButtons();
buttons.setTargetFragment(parentFragment, FragmentMessages.REQUEST_BUTTONS);
buttons.show(parentFragment.getParentFragmentManager(), "dialog:buttons");
return true;
} else if (itemId == R.id.menu_unseen) {
onMenuUnseen(message);
@ -4434,12 +4367,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Helper.reportNoViewer(context, uri);
}
private void onMenuButton(final TupleMessageEx message, String button, boolean isChecked) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putBoolean("button_" + button, !isChecked).apply();
setupTools(message, false, false);
}
private void onMenuUnseen(final TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
@ -7032,4 +6959,76 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
.create();
}
}
public static class FragmentDialogButtons extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final Context context = getContext();
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final View dview = LayoutInflater.from(context).inflate(R.layout.dialog_buttons, null);
final CheckBox cbJunk = dview.findViewById(R.id.cbJunk);
final CheckBox cbTrash = dview.findViewById(R.id.cbTrash);
final CheckBox cbArchive = dview.findViewById(R.id.cbArchive);
final CheckBox cbMove = dview.findViewById(R.id.cbMove);
final CheckBox cbCopy = dview.findViewById(R.id.cbCopy);
final CheckBox cbKeywords = dview.findViewById(R.id.cbKeywords);
final CheckBox cbNotes = dview.findViewById(R.id.cbNotes);
final CheckBox cbSeen = dview.findViewById(R.id.cbSeen);
final CheckBox cbSearch = dview.findViewById(R.id.cbSearch);
final CheckBox cbEvent = dview.findViewById(R.id.cbEvent);
final CheckBox cbShare = dview.findViewById(R.id.cbShare);
final CheckBox cbPrint = dview.findViewById(R.id.cbPrint);
final CheckBox cbUnsubscribe = dview.findViewById(R.id.cbUnsubscribe);
final CheckBox cbRule = dview.findViewById(R.id.cbRule);
cbJunk.setChecked(prefs.getBoolean("button_junk", true));
cbTrash.setChecked(prefs.getBoolean("button_trash", true));
cbArchive.setChecked(prefs.getBoolean("button_archive", true));
cbMove.setChecked(prefs.getBoolean("button_move", true));
cbCopy.setChecked(prefs.getBoolean("button_copy", false));
cbKeywords.setChecked(prefs.getBoolean("button_keywords", false));
cbNotes.setChecked(prefs.getBoolean("button_notes", false));
cbSeen.setChecked(prefs.getBoolean("button_seen", false));
cbSearch.setChecked(prefs.getBoolean("button_search", false));
cbEvent.setChecked(prefs.getBoolean("button_event", false));
cbShare.setChecked(prefs.getBoolean("button_share", false));
cbPrint.setChecked(prefs.getBoolean("button_print", false));
cbUnsubscribe.setChecked(prefs.getBoolean("button_unsubscribe", true));
cbRule.setChecked(prefs.getBoolean("button_rule", false));
return new AlertDialog.Builder(getContext())
.setView(dview)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("button_junk", cbJunk.isChecked());
editor.putBoolean("button_trash", cbTrash.isChecked());
editor.putBoolean("button_archive", cbArchive.isChecked());
editor.putBoolean("button_move", cbMove.isChecked());
editor.putBoolean("button_copy", cbCopy.isChecked());
editor.putBoolean("button_keywords", cbKeywords.isChecked());
editor.putBoolean("button_notes", cbNotes.isChecked());
editor.putBoolean("button_seen", cbSeen.isChecked());
editor.putBoolean("button_search", cbSearch.isChecked());
editor.putBoolean("button_event", cbEvent.isChecked());
editor.putBoolean("button_share", cbShare.isChecked());
editor.putBoolean("button_print", cbPrint.isChecked());
editor.putBoolean("button_unsubscribe", cbUnsubscribe.isChecked());
editor.putBoolean("button_rule", cbRule.isChecked());
editor.apply();
sendResult(Activity.RESULT_OK);
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
sendResult(Activity.RESULT_CANCELED);
}
})
.create();
}
}
}

@ -346,6 +346,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private static final int REQUEST_EMPTY_FOLDER = 21;
private static final int REQUEST_BOUNDARY_RETRY = 22;
static final int REQUEST_PICK_CONTACT = 23;
static final int REQUEST_BUTTONS = 24;
static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW";
static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT";
@ -5939,6 +5940,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (resultCode == RESULT_OK && data != null)
onPickContact(data.getData());
break;
case REQUEST_BUTTONS:
adapter.notifyDataSetChanged();
break;
}
} catch (Throwable ex) {
Log.e(ex);

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="utf-8"?>
<eu.faircode.email.ScrollViewEx xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="24dp"
android:scrollbarStyle="outsideOverlay">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<eu.faircode.email.FixedTextView
android:id="@+id/tvTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:text="@string/title_buttons"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/cbJunk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_spam"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />
<CheckBox
android:id="@+id/cbTrash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_trash"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbJunk" />
<CheckBox
android:id="@+id/cbArchive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_archive"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbTrash" />
<CheckBox
android:id="@+id/cbMove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_move"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbArchive" />
<CheckBox
android:id="@+id/cbCopy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_copy_btn"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbMove" />
<CheckBox
android:id="@+id/cbKeywords"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_keywords_btn"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbCopy" />
<CheckBox
android:id="@+id/cbNotes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_edit_notes"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbKeywords" />
<CheckBox
android:id="@+id/cbSeen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_toggle_seen"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbNotes" />
<CheckBox
android:id="@+id/cbSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_search"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSeen" />
<CheckBox
android:id="@+id/cbEvent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_event"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSearch" />
<CheckBox
android:id="@+id/cbShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_share"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbEvent" />
<CheckBox
android:id="@+id/cbPrint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_print"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbShare" />
<CheckBox
android:id="@+id/cbUnsubscribe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_unsubscribe"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPrint" />
<CheckBox
android:id="@+id/cbRule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_message_rule"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbUnsubscribe" />
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>

@ -2,66 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_button"
android:title="@string/title_buttons">
<menu>
<item
android:id="@+id/menu_button_junk"
android:checkable="true"
android:title="@string/title_spam" />
<item
android:id="@+id/menu_button_trash"
android:checkable="true"
android:title="@string/title_trash" />
<item
android:id="@+id/menu_button_archive"
android:checkable="true"
android:title="@string/title_archive" />
<item
android:id="@+id/menu_button_move"
android:checkable="true"
android:title="@string/title_move" />
<item
android:id="@+id/menu_button_copy"
android:checkable="true"
android:title="@string/title_copy_btn" />
<item
android:id="@+id/menu_button_keywords"
android:checkable="true"
android:title="@string/title_keywords_btn" />
<item
android:id="@+id/menu_button_notes"
android:checkable="true"
android:title="@string/title_edit_notes" />
<item
android:id="@+id/menu_button_seen"
android:checkable="true"
android:title="@string/title_toggle_seen" />
<item
android:id="@+id/menu_button_search"
android:checkable="true"
android:title="@string/title_search" />
<item
android:id="@+id/menu_button_event"
android:checkable="true"
android:title="@string/title_event" />
<item
android:id="@+id/menu_button_share"
android:checkable="true"
android:title="@string/title_share" />
<item
android:id="@+id/menu_button_print"
android:checkable="true"
android:title="@string/title_print" />
<item
android:id="@+id/menu_button_unsubscribe"
android:checkable="true"
android:title="@string/title_unsubscribe" />
<item
android:id="@+id/menu_button_rule"
android:checkable="true"
android:title="@string/title_message_rule" />
</menu>
</item>
android:title="@string/title_configure_buttons" />
<item
android:id="@+id/menu_unseen"

@ -834,7 +834,6 @@
<string name="title_subject_reply">Re: %1$s</string>
<string name="title_subject_forward">Fwd: %1$s</string>
<string name="title_buttons">Buttons</string>
<string name="title_seen">Mark read</string>
<string name="title_unseen">Mark unread</string>
<string name="title_toggle_seen">Toggle read</string>
@ -869,6 +868,8 @@
<string name="title_save_all">Save all</string>
<string name="title_save_eml">Save raw message file</string>
<string name="title_buttons">Select buttons</string>
<string name="title_configure_buttons">Configure buttons &#8230;</string>
<string name="title_trash">Trash</string>
<string name="title_copy">Copy &#8230;</string>
<string name="title_copy_to">Copy to &#8230;</string>

Loading…
Cancel
Save