Skip to content

Commit

Permalink
Message marking
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Jan 4, 2023
1 parent 5df2966 commit 0397e70
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 14 deletions.
90 changes: 76 additions & 14 deletions src/main/java/org/luwrain/app/mail/MainLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import static org.luwrain.app.mail.App.*;
import static org.luwrain.app.mail.Utils.*;
import static org.luwrain.core.DefaultEventResponse.*;

final class MainLayout extends LayoutBase implements TreeListArea.LeafClickHandler<MailFolder>, ClickHandler<SummaryItem>
{
Expand Down Expand Up @@ -77,6 +78,7 @@ final class MainLayout extends LayoutBase implements TreeListArea.LeafClickHandl
params.model = new ListModel<>(summaryItems);
params.clickHandler = this;
params.appearance = new DoubleLevelAppearance<SummaryItem>(getControlContext()){
@Override public void announceNonSection(SummaryItem summaryItem) { announceSummaryMessage(summaryItem); }
@Override public boolean isSectionItem(SummaryItem item) { return item.type == SummaryItem.Type.SECTION; }
};
params.transition = new DoubleLevelTransition<SummaryItem>(params.model){
Expand All @@ -95,6 +97,14 @@ final class MainLayout extends LayoutBase implements TreeListArea.LeafClickHandl
fetchIncomingBkg),
summaryArea, actions(
action("reply", app.getStrings().actionReply(), HOT_KEY_REPLY, this::actSummaryReply),
action("mark", app.getStrings().actionMarkMessage(), new InputEvent(InputEvent.Special.INSERT), this::actMarkMessage, ()->{
final SummaryItem item = summaryArea.selected();
return item != null && item.message != null && item.message.getState() != MailMessage.State.MARKED;
}),
action("unmark", app.getStrings().actionUnmarkMessage(), new InputEvent(InputEvent.Special.INSERT), this::actUnmarkMessage, ()->{
final SummaryItem item = summaryArea.selected();
return item != null && item.message != null && item.message.getState() == MailMessage.State.MARKED;
}),
action("delete", app.getStrings().actionDeleteMessage(), new InputEvent(InputEvent.Special.DELETE), this::actDeleteMessage),
action("delete-forever", app.getStrings().actionDeleteMessageForever(), new InputEvent(InputEvent.Special.DELETE, EnumSet.of(InputEvent.Modifiers.SHIFT)), this::actDeleteMessage),
fetchIncomingBkg
Expand All @@ -114,20 +124,6 @@ messageArea, actions(
return true;
}

@Override public boolean onListClick(ListArea area, int index, SummaryItem item)
{
final MailMessage message = item.message;
if (message == null)
return false;
if (message.getState() == MailMessage.State.NEW)
{
message.setState(MailMessage.State.READ);
summaryArea.refresh();
}
messageArea.setDocument(createDocForMessage(message, app.getStrings()), 128);
setActiveArea(messageArea);
return true;
}

private boolean actNewFolder()
{
Expand Down Expand Up @@ -177,6 +173,46 @@ private boolean onFolderProps()
return true;
}

@Override public boolean onListClick(ListArea area, int index, SummaryItem item)
{
final MailMessage message = item.message;
if (message == null)
return false;
if (message.getState() == MailMessage.State.NEW)
{
message.setState(MailMessage.State.READ);
app.getStoring().getMessages().update(message);
summaryArea.refresh();
}
messageArea.setDocument(createDocForMessage(message, app.getStrings()), 128);
setActiveArea(messageArea);
return true;
}


private boolean actMarkMessage()
{
final SummaryItem item = summaryArea.selected();
if (item == null || item.message == null)
return false;
item.message.setState(MailMessage.State.MARKED);
app.getStoring().getMessages().update(item.message);
app.setEventResponse(text(Sounds.SELECTED, app.getStrings().messageMarked()));
return true;
}

private boolean actUnmarkMessage()
{
final SummaryItem item = summaryArea.selected();
if (item == null || item.message == null)
return false;
item.message.setState(MailMessage.State.READ);
app.getStoring().getMessages().update(item.message);
app.setEventResponse(text(Sounds.SELECTED, app.getStrings().messageUnmarked()));
return true;
}


private boolean actSummaryReply()
{
final SummaryItem item = summaryArea.selected();
Expand All @@ -196,6 +232,32 @@ private boolean actDeleteMessage()
return true;
}

private void announceSummaryMessage(SummaryItem summaryItem)
{
final MailMessage m = summaryItem.message;
if (m == null)
return;
if (m.getState() == null)
{
app.setEventResponse(listItem(Sounds.LIST_ITEM, m.getFrom(), Suggestions.CLICKABLE_LIST_ITEM));
return;
}
switch(m.getState())
{
case NEW:
app.setEventResponse(listItem(Sounds.ATTENTION, m.getFrom(), Suggestions.CLICKABLE_LIST_ITEM));
break;
case READ:
app.setEventResponse(listItem(Sounds.LIST_ITEM, m.getFrom(), Suggestions.CLICKABLE_LIST_ITEM));
break;
case MARKED:
app.setEventResponse(listItem(Sounds.SELECTED, m.getFrom(), Suggestions.CLICKABLE_LIST_ITEM));
break;
default:
app.setEventResponse(listItem(Sounds.LIST_ITEM, m.getFrom(), Suggestions.CLICKABLE_LIST_ITEM));
}
}

private boolean actDeleteMessageForever()
{
final SummaryItem item = summaryArea.selected();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/luwrain/app/mail/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public interface Strings
String actionReplyAll();
String actionDeleteMessage();
String actionDeleteMessageForever();
String actionMarkMessage();
String messageMarked();
String actionUnmarkMessage();
String messageUnmarked();


String messageAreaAttachment();
String messageAreaCc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ ActionDeleteMessage = Удалить сообщение
ActionReply = Ответить
ActionReplyAll = Ответить всем
ActionForward = Переслать
ActionMarkMessage = Пометить
ActionUnmarkMessage = Снять отметку
MessageMarked = Помечено
MessageUnmarked = Пометка снята



MessageAreaName = Сообщение
Expand Down

0 comments on commit 0397e70

Please sign in to comment.