Skip to content

Commit

Permalink
Adding FoldersAppearance
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Apr 6, 2021
1 parent 3cd380e commit 4ce2491
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 82 deletions.
58 changes: 0 additions & 58 deletions src/main/java/org/luwrain/app/contacts/FolderWrapper.java

This file was deleted.

75 changes: 75 additions & 0 deletions src/main/java/org/luwrain/app/contacts/FoldersAppearance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
LUWRAIN is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
LUWRAIN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/

package org.luwrain.app.contacts;

import java.util.*;

import org.luwrain.core.*;
import org.luwrain.controls.*;
import org.luwrain.pim.contacts.*;

final class FoldersAppearance implements ListArea.Appearance
{
private final App app;

FoldersAppearance(App app)
{
NullCheck.notNull(app, "app");
this.app = app;
}

@Override public void announceItem(Object item, Set<Flags> flags)
{
NullCheck.notNull(item, "item");
NullCheck.notNull(flags, "flags");

if (item instanceof ContactsFolder)
{
final ContactsFolder f = (ContactsFolder)item;
app.getLuwrain().setEventResponse(DefaultEventResponse.listItem(Sounds.DOC_SECTION, f.getTitle(), Suggestions.CLICKABLE_LIST_ITEM));
return;
}

if (item instanceof Contact)
{
final Contact c = (Contact)item;
app.getLuwrain().setEventResponse(DefaultEventResponse.listItem(c.getTitle(), Suggestions.CLICKABLE_LIST_ITEM));
return;
}


}

@Override public String getScreenAppearance(Object item, Set<Flags> flags)
{
NullCheck.notNull(item, "item");
NullCheck.notNull(flags, "flags");
return item.toString();
}

@Override public int getObservableLeftBound(Object item)
{
NullCheck.notNull(item, "item");
return (item instanceof ContactsFolder)?2:0;
}

@Override public int getObservableRightBound(Object item)
{
NullCheck.notNull(item, "item");
return getScreenAppearance(item, EnumSet.noneOf(Flags.class)).length() + ((item instanceof ContactsFolder)?2:0);
}
}
56 changes: 32 additions & 24 deletions src/main/java/org/luwrain/app/contacts/MainLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class MainLayout extends LayoutBase implements ListArea.ClickHandler
private final EditArea notesArea;

private ContactsFolder openedFolder = null;
private ContactsFolder[] childFolders = new ContactsFolder[0];
private final List items = new ArrayList();
private Contact currentContact = null;

MainLayout(App app)
Expand All @@ -47,19 +47,21 @@ final class MainLayout extends LayoutBase implements ListArea.ClickHandler
this.openedFolder = app.getStoring().getFolders().getRoot();
this.folders = app.getStoring().getFolders();
this.contacts = app.getStoring().getContacts();
updateItems();

final Actions foldersActions;
{
final ListArea.Params params = new ListArea.Params();
params.context = getControlContext();
params.model = new ListUtils.ArrayModel(()->{ return childFolders; });
params.appearance = new ListUtils.DefaultAppearance(getControlContext());
params.model = new ListUtils.ListModel(items);
params.appearance = new FoldersAppearance(app);
params.name = app.getStrings().foldersAreaName();
params.clickHandler = this;
this.foldersArea = new ListArea(params);
foldersActions = actions(
action("new-folder", "Новая группа", new InputEvent(InputEvent.Special.INSERT, EnumSet.of(InputEvent.Modifiers.SHIFT)), this::actNewFolder),
action("new-contact", "Новый контакт", new InputEvent(InputEvent.Special.INSERT), this::actNewContact)
);
action("new-contact", "Новый контакт", new InputEvent(InputEvent.Special.INSERT), this::actNewContact)
);
}

final Actions valuesActions;
Expand All @@ -84,23 +86,34 @@ final class MainLayout extends LayoutBase implements ListArea.ClickHandler
private boolean actNewFolder()
{
final String name = app.getConv().newFolderName();
if (name == null || name.trim().isEmpty())
return true;
final ContactsFolder f = new ContactsFolder();
f.setTitle(name.trim());
folders.save(openedFolder, f);
updateItems();
return true;
}

private boolean actNewContact()
{
final String name = app.getConv().newContactName();

if (name == null || name.trim().isEmpty())
return true;
final Contact c = new Contact();
c.setTitle(name);
contacts.save(openedFolder, c);


updateItems();
return true;
}

private void updateItems()
{
items.clear();
items.addAll(Arrays.asList(folders.load(openedFolder)));
items.addAll(Arrays.asList(contacts.load(openedFolder)));
}


void fillValuesArea(FormArea area)
{
Expand All @@ -111,22 +124,19 @@ void fillValuesArea(FormArea area)
area.addEdit("name", "Имя:", currentContact.getTitle(), null, true);
int counter = 1;
for(ContactValue v: currentContact.getValues())
if (v.getType() == ContactValue.MAIL)
if (v.getType() == ContactValue.Type.MAIL)
area.addEdit("mail" + (counter++), "Электронная почта:", v.getValue(), v, true);
for(ContactValue v: currentContact.getValues())
if (v.getType() == ContactValue.MOBILE_PHONE)
if (v.getType() == ContactValue.Type.PHONE)
area.addEdit("mobile" + (counter++), "Мобильный телефон:", v.getValue(), v, true);
for(ContactValue v: currentContact.getValues())
if (v.getType() == ContactValue.GROUND_PHONE)
area.addEdit("ground" + (counter++), "Телефон:", v.getValue(), v, true);
for(ContactValue v: currentContact.getValues())
if (v.getType() == ContactValue.ADDRESS)
if (v.getType() == ContactValue.Type.ADDRESS)
area.addEdit("address" + (counter++), "Адрес:", v.getValue(), v, true);
for(ContactValue v: currentContact.getValues())
if (v.getType() == ContactValue.BIRTHDAY)
if (v.getType() == ContactValue.Type.BIRTHDAY)
area.addEdit("birthday" + (counter++), "Дата рождения:", v.getValue(), v, true);
for(ContactValue v: currentContact.getValues())
if (v.getType() == ContactValue.SKYPE)
if (v.getType() == ContactValue.Type.SKYPE)
area.addEdit("skype" + (counter++), "Skype:", v.getValue(), v, true);
}

Expand Down Expand Up @@ -171,19 +181,17 @@ boolean insertValue()
});
if (res == null)
return false;
int type;
final ContactValue.Type type;
if (res == mailTitle)
type = ContactValue.MAIL; else
type = ContactValue.Type.MAIL; else
if (res == mobileTitle)
type = ContactValue.MOBILE_PHONE; else
if (res == phoneTitle)
type = ContactValue.GROUND_PHONE; else
type = ContactValue.Type.PHONE; else
if (res == addressTitle)
type = ContactValue.ADDRESS; else
type = ContactValue.Type.ADDRESS; else
if (res == birthdayTitle)
type = ContactValue.BIRTHDAY; else
type = ContactValue.Type.BIRTHDAY; else
if (res == skypeTitle)
type = ContactValue.SKYPE; else
type = ContactValue.Type.SKYPE; else
return false;//Should never happen
final ContactValue[] oldValues = currentContact.getValues();
final ContactValue[] newValues = new ContactValue[oldValues.length + 1];
Expand Down

0 comments on commit 4ce2491

Please sign in to comment.