Skip to content

Commit

Permalink
Adding Conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Apr 6, 2021
1 parent f5388b6 commit 3cd380e
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 19 deletions.
37 changes: 21 additions & 16 deletions src/main/java/org/luwrain/app/contacts/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,38 @@
import org.luwrain.pim.contacts.*;
import org.luwrain.app.base.*;

final class App extends AppBase<Strings> implements MonoApp
public final class App extends AppBase<Strings> implements MonoApp
{
private MainLayout mainLayout = null;
private ContactsStoring storing = null;
private ContactsFolder foldersRoot = null;
private Conversations conv = null;
private MainLayout mainLayout = null;

App()
public App()
{
super(Strings.NAME, Strings.class, "luwrain.contacts");
}

@Override protected boolean onAppInit() throws Exception
{
this.conv = new Conversations(this);
this.storing = org.luwrain.pim.Connections.getContactsStoring(getLuwrain(), true);
this.foldersRoot = storing.getFolders().getRoot();
this.mainLayout = new MainLayout(this);
setAppName(getStrings().appName());
return true;
}

void ensureEverythingSaved()
@Override public boolean onEscape(InputEvent event)
{
closeApp();
return true;
}

@Override protected AreaLayout getDefaultAreaLayout()
{
return mainLayout.getAreaLayout();
}

void ensureEverythingSaved()
{
/*
if (!base.hasCurrentContact())
Expand All @@ -52,11 +63,6 @@ void ensureEverythingSaved()
*/
}

@Override protected AreaLayout getDefaultAreaLayout()
{
return mainLayout.getAreaLayout();
}

/*
@Override public void closeApp()
{
Expand All @@ -71,14 +77,13 @@ void ensureEverythingSaved()
return MonoApp.Result.BRING_FOREGROUND;
}

ContactsStoring getStoring()
Conversations getConv()
{
return this.storing;
return this.conv;
}

ContactsFolder getFoldersRoot()
ContactsStoring getStoring()
{
return this.foldersRoot;
return this.storing;
}

}
47 changes: 47 additions & 0 deletions src/main/java/org/luwrain/app/contacts/Conversations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
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.popups.*;

final class Conversations
{
private final App app;
private final Luwrain luwrain;
private final Strings strings;

Conversations(App app)
{
NullCheck.notNull(app, "app");
this.app = app;
this.luwrain = app.getLuwrain();
this.strings = app.getStrings();
}

String newContactName()
{
return Popups.textNotEmpty(luwrain, "Новый контакт", "Имя нового контакта:", "");
}

String newFolderName()
{
return Popups.textNotEmpty(luwrain, "Новая группа", "Имя новой группы контактов:", "");
}
}
39 changes: 36 additions & 3 deletions src/main/java/org/luwrain/app/contacts/MainLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,44 @@
import org.luwrain.core.events.*;
import org.luwrain.controls.*;
import org.luwrain.pim.contacts.*;
import org.luwrain.pim.contacts.*;
import org.luwrain.app.base.*;
import org.luwrain.popups.*;

final class MainLayout extends LayoutBase implements ListArea.ClickHandler
{
private final App app;
private final ContactsFolders folders;
private final Contacts contacts;

private final ListArea foldersArea;
private final FormArea valuesArea;
private final EditArea notesArea;

private ContactsFolder[] folders = new ContactsFolder[0];
private ContactsFolder openedFolder = null;
private ContactsFolder[] childFolders = new ContactsFolder[0];
private Contact currentContact = null;

MainLayout(App app)
{
super(app);
this.app = app;
this.openedFolder = app.getStoring().getFolders().getRoot();
this.folders = app.getStoring().getFolders();
this.contacts = app.getStoring().getContacts();
final Actions foldersActions;
{
final ListArea.Params params = new ListArea.Params();
params.context = getControlContext();
params.model = new ListUtils.ArrayModel(()->{ return folders; });
params.model = new ListUtils.ArrayModel(()->{ return childFolders; });
params.appearance = new ListUtils.DefaultAppearance(getControlContext());
params.name = app.getStrings().foldersAreaName();
params.clickHandler = this;
this.foldersArea = new ListArea(params);
foldersActions = actions();
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)
);
}

final Actions valuesActions;
Expand All @@ -62,13 +73,35 @@ final class MainLayout extends LayoutBase implements ListArea.ClickHandler
final EditArea.Params params = new EditArea.Params();
params.context = getControlContext();
params.name = app.getStrings().notesAreaName();
params.appearance = new EditUtils.DefaultEditAreaAppearance(getControlContext());
this.notesArea = new EditArea(params);
notesActions = actions();
}

setAreaLayout(AreaLayout.LEFT_TOP_BOTTOM, foldersArea, foldersActions, valuesArea, valuesActions, notesArea, notesActions);
}

private boolean actNewFolder()
{
final String name = app.getConv().newFolderName();
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);


return true;
}


void fillValuesArea(FormArea area)
{
NullCheck.notNull(area, "area");
Expand Down

0 comments on commit 3cd380e

Please sign in to comment.