More Related Content
Similar to Creating a Facebook Clone - Part XXX.pdf (20)
More from ShaiAlmog1 (20)
Creating a Facebook Clone - Part XXX.pdf
- 2. public class MainForm extends Form {
private Tabs mainUI = new Tabs();
public MainForm() {
super("", new BorderLayout());
mainUI.addTab("", MATERIAL_WEB, 5f, new NewsfeedContainer());
FloatingActionButton fab =
FloatingActionButton.createFAB(MATERIAL_IMPORT_CONTACTS);
Container friends = fab.bindFabToContainer(new FriendsContainer());
fab.addActionListener(e -> uploadContacts());
mainUI.addTab("", MATERIAL_PEOPLE_OUTLINE, 5f,
friends);
mainUI.addTab("", MATERIAL_NOTIFICATIONS_NONE,
5f, new NotificationsContainer());
mainUI.addTab("", MATERIAL_MENU, 5f,
new MoreContainer());
add(CENTER, mainUI);
getToolbar().addMaterialCommandToLeftBar("",
MATERIAL_CAMERA_ALT, 4, e -> {});
MainForm
- 3. public class MainForm extends Form {
private Tabs mainUI = new Tabs();
public MainForm() {
super("", new BorderLayout());
mainUI.addTab("", MATERIAL_WEB, 5f, new NewsfeedContainer());
FloatingActionButton fab =
FloatingActionButton.createFAB(MATERIAL_IMPORT_CONTACTS);
Container friends = fab.bindFabToContainer(new FriendsContainer());
fab.addActionListener(e -> uploadContacts());
mainUI.addTab("", MATERIAL_PEOPLE_OUTLINE, 5f,
friends);
mainUI.addTab("", MATERIAL_NOTIFICATIONS_NONE,
5f, new NotificationsContainer());
mainUI.addTab("", MATERIAL_MENU, 5f,
new MoreContainer());
add(CENTER, mainUI);
getToolbar().addMaterialCommandToLeftBar("",
MATERIAL_CAMERA_ALT, 4, e -> {});
MainForm
- 4. public class MainForm extends Form {
private Tabs mainUI = new Tabs();
public MainForm() {
super("", new BorderLayout());
mainUI.addTab("", MATERIAL_WEB, 5f, new NewsfeedContainer());
FloatingActionButton fab =
FloatingActionButton.createFAB(MATERIAL_IMPORT_CONTACTS);
Container friends = fab.bindFabToContainer(new FriendsContainer());
fab.addActionListener(e -> uploadContacts());
mainUI.addTab("", MATERIAL_PEOPLE_OUTLINE, 5f,
friends);
mainUI.addTab("", MATERIAL_NOTIFICATIONS_NONE,
5f, new NotificationsContainer());
mainUI.addTab("", MATERIAL_MENU, 5f,
new MoreContainer());
add(CENTER, mainUI);
getToolbar().addMaterialCommandToLeftBar("",
MATERIAL_CAMERA_ALT, 4, e -> {});
MainForm
- 5. public class MainForm extends Form {
private Tabs mainUI = new Tabs();
public MainForm() {
super("", new BorderLayout());
mainUI.addTab("", MATERIAL_WEB, 5f, new NewsfeedContainer());
FloatingActionButton fab =
FloatingActionButton.createFAB(MATERIAL_IMPORT_CONTACTS);
Container friends = fab.bindFabToContainer(new FriendsContainer());
fab.addActionListener(e -> uploadContacts());
mainUI.addTab("", MATERIAL_PEOPLE_OUTLINE, 5f,
friends);
mainUI.addTab("", MATERIAL_NOTIFICATIONS_NONE,
5f, new NotificationsContainer());
mainUI.addTab("", MATERIAL_MENU, 5f,
new MoreContainer());
add(CENTER, mainUI);
getToolbar().addMaterialCommandToLeftBar("",
MATERIAL_CAMERA_ALT, 4, e -> {});
MainForm
- 6. mainUI.addTab("", MATERIAL_NOTIFICATIONS_NONE,
5f, new NotificationsContainer());
mainUI.addTab("", MATERIAL_MENU, 5f,
new MoreContainer());
add(CENTER, mainUI);
getToolbar().addMaterialCommandToLeftBar("",
MATERIAL_CAMERA_ALT, 4, e -> {});
getToolbar().addMaterialCommandToRightBar("",
MATERIAL_CHAT, 4, e -> {});
Button searchButton = new Button("Search", "TitleSearch");
setMaterialIcon(searchButton, MATERIAL_SEARCH);
getToolbar().setTitleComponent(searchButton);
searchButton.addActionListener(e -> new SearchForm().show());
}
private void uploadContacts() {
startThread(() -> {
Contact[] cnt = Display.getInstance().
getAllContacts(true, true, false, true, true, false);
ServerAPI.uploadContacts(cnt);
}, "ContactUploader").start();
}
}
MainForm
- 7. mainUI.addTab("", MATERIAL_NOTIFICATIONS_NONE,
5f, new NotificationsContainer());
mainUI.addTab("", MATERIAL_MENU, 5f,
new MoreContainer());
add(CENTER, mainUI);
getToolbar().addMaterialCommandToLeftBar("",
MATERIAL_CAMERA_ALT, 4, e -> {});
getToolbar().addMaterialCommandToRightBar("",
MATERIAL_CHAT, 4, e -> {});
Button searchButton = new Button("Search", "TitleSearch");
setMaterialIcon(searchButton, MATERIAL_SEARCH);
getToolbar().setTitleComponent(searchButton);
searchButton.addActionListener(e -> new SearchForm().show());
}
private void uploadContacts() {
startThread(() -> {
Contact[] cnt = Display.getInstance().
getAllContacts(true, true, false, true, true, false);
ServerAPI.uploadContacts(cnt);
}, "ContactUploader").start();
}
}
MainForm
- 8. mainUI.addTab("", MATERIAL_NOTIFICATIONS_NONE,
5f, new NotificationsContainer());
mainUI.addTab("", MATERIAL_MENU, 5f,
new MoreContainer());
add(CENTER, mainUI);
getToolbar().addMaterialCommandToLeftBar("",
MATERIAL_CAMERA_ALT, 4, e -> {});
getToolbar().addMaterialCommandToRightBar("",
MATERIAL_CHAT, 4, e -> {});
Button searchButton = new Button("Search", "TitleSearch");
setMaterialIcon(searchButton, MATERIAL_SEARCH);
getToolbar().setTitleComponent(searchButton);
searchButton.addActionListener(e -> new SearchForm().show());
}
private void uploadContacts() {
startThread(() -> {
Contact[] cnt = Display.getInstance().
getAllContacts(true, true, false, true, true, false);
ServerAPI.uploadContacts(cnt);
}, "ContactUploader").start();
}
}
MainForm
- 9. mainUI.addTab("", MATERIAL_NOTIFICATIONS_NONE,
5f, new NotificationsContainer());
mainUI.addTab("", MATERIAL_MENU, 5f,
new MoreContainer());
add(CENTER, mainUI);
getToolbar().addMaterialCommandToLeftBar("",
MATERIAL_CAMERA_ALT, 4, e -> {});
getToolbar().addMaterialCommandToRightBar("",
MATERIAL_CHAT, 4, e -> {});
Button searchButton = new Button("Search", "TitleSearch");
setMaterialIcon(searchButton, MATERIAL_SEARCH);
getToolbar().setTitleComponent(searchButton);
searchButton.addActionListener(e -> new SearchForm().show());
}
private void uploadContacts() {
startThread(() -> {
Contact[] cnt = Display.getInstance().
getAllContacts(true, true, false, true, true, false);
ServerAPI.uploadContacts(cnt);
}, "ContactUploader").start();
}
}
MainForm
- 10. padding: 1.5mm;
text-align: center;
font-family: "native:MainRegular";
font-size: 3.5mm;
}
SmallLabel {
font-family: "native:MainLight";
font-size: 2mm;
}
FloatingActionButton {
background: #587EBE;
padding: 1.5mm;
text-align: center;
}
Comment {
color: black;
font-family: "native:MainThin";
font-size: 2.6mm;
border: cn1-pill-border;
background-color: #dbdbdb;
padding: 1mm 3mm 1mm 3mm;
theme.css
- 11. add(UIUtils.createHalfSpace());
}
}
private Container friendRequestEntry(User u, Image avatar,
boolean request) {
Label name = new Label(u.fullName(), "FriendName");
Button confirm;
Button delete;
if(request) {
confirm = new Button("Confirm", "FriendConfirm");
delete = new Button("Delete", "FriendDelete");
bindConfirmDeleteEvent(u, confirm, delete);
} else {
confirm = new Button("Add Friend", "FriendConfirm");
delete = new Button("Remove", "FriendDelete");
bindAddRemoveFriendEvent(u, confirm, delete);
}
Container cnt =
BoxLayout.encloseY(name,
GridLayout.encloseIn(2, confirm, delete));
cnt.setUIID("PaddedContainer");
return BorderLayout.centerEastWest(cnt, null,
new Label(avatar, "Container"));
FriendsContainer
- 12. confirm = new Button("Add Friend", "FriendConfirm");
delete = new Button("Remove", "FriendDelete");
bindAddRemoveFriendEvent(u, confirm, delete);
}
Container cnt =
BoxLayout.encloseY(name,
GridLayout.encloseIn(2, confirm, delete));
cnt.setUIID("PaddedContainer");
return BorderLayout.centerEastWest(cnt, null,
new Label(avatar, "Container"));
}
private Container findParent(Container button) {
if(button.getParent() != this) {
return findParent(button.getParent());
}
return button;
}
private void bindAddRemoveFriendEvent(
User u, Button add, Button remove) {
add.addActionListener(e -> {
ServerAPI.sendFriendRequest(u.id.get());
findParent(remove.getParent()).remove();
FriendsContainer
- 13. if(button.getParent() != this) {
return findParent(button.getParent());
}
return button;
}
private void bindAddRemoveFriendEvent(
User u, Button add, Button remove) {
add.addActionListener(e -> {
ServerAPI.sendFriendRequest(u.id.get());
findParent(remove.getParent()).remove();
animateLayout(150);
ToastBar.showMessage("Sent friend request",
FontImage.MATERIAL_INFO);
ServerAPI.refreshMe();
});
remove.addActionListener(e -> {
findParent(remove.getParent()).remove();
animateLayout(150);
ServerAPI.me().peopleYouMayKnow.remove(u);
ServerAPI.update(ServerAPI.me());
});
}
FriendsContainer
- 14. if(button.getParent() != this) {
return findParent(button.getParent());
}
return button;
}
private void bindAddRemoveFriendEvent(
User u, Button add, Button remove) {
add.addActionListener(e -> {
ServerAPI.sendFriendRequest(u.id.get());
findParent(remove.getParent()).remove();
animateLayout(150);
ToastBar.showMessage("Sent friend request",
FontImage.MATERIAL_INFO);
ServerAPI.refreshMe();
});
remove.addActionListener(e -> {
findParent(remove.getParent()).remove();
animateLayout(150);
ServerAPI.me().peopleYouMayKnow.remove(u);
ServerAPI.update(ServerAPI.me());
});
}
FriendsContainer
- 15. if(button.getParent() != this) {
return findParent(button.getParent());
}
return button;
}
private void bindAddRemoveFriendEvent(
User u, Button add, Button remove) {
add.addActionListener(e -> {
ServerAPI.sendFriendRequest(u.id.get());
findParent(remove.getParent()).remove();
animateLayout(150);
ToastBar.showMessage("Sent friend request",
FontImage.MATERIAL_INFO);
ServerAPI.refreshMe();
});
remove.addActionListener(e -> {
findParent(remove.getParent()).remove();
animateLayout(150);
ServerAPI.me().peopleYouMayKnow.remove(u);
ServerAPI.update(ServerAPI.me());
});
}
FriendsContainer
- 16. if(button.getParent() != this) {
return findParent(button.getParent());
}
return button;
}
private void bindAddRemoveFriendEvent(
User u, Button add, Button remove) {
add.addActionListener(e -> {
ServerAPI.sendFriendRequest(u.id.get());
findParent(remove.getParent()).remove();
animateLayout(150);
ToastBar.showMessage("Sent friend request",
FontImage.MATERIAL_INFO);
ServerAPI.refreshMe();
});
remove.addActionListener(e -> {
findParent(remove.getParent()).remove();
animateLayout(150);
ServerAPI.me().peopleYouMayKnow.remove(u);
ServerAPI.update(ServerAPI.me());
});
}
FriendsContainer
- 17. ServerAPI.update(ServerAPI.me());
});
}
private void bindConfirmDeleteEvent(
User u, Button add, Button remove) {
add.addActionListener(e -> {
findParent(remove.getParent()).remove();
animateLayout(150);
if(ServerAPI.acceptFriendRequest(u.id.get())) {
ServerAPI.refreshMe();
ToastBar.showMessage("You are now friends with " +
u.fullName(),
FontImage.MATERIAL_INFO);
}
});
remove.addActionListener(e -> {
findParent(remove.getParent()).remove();
animateLayout(150);
ServerAPI.me().friendRequests.remove(u);
ServerAPI.update(ServerAPI.me());
});
}
FriendsContainer
- 18. public class NotificationsContainer extends InfiniteContainer {
@Override
public Component[] fetchComponents(int index, int amount) {
int page = index / amount;
if(index % amount > 0) {
page++;
}
List<Notification> response = ServerAPI.listNotifications(page,
amount);
if(response == null) {
return null;
}
Component[] notifications = new Component[response.size()];
int iter = 0;
for(Notification n : response) {
notifications[iter] = createNotificationEntry(n);
iter++;
}
return notifications;
}
NotificationContainer
- 19. public class NotificationsContainer extends InfiniteContainer {
@Override
public Component[] fetchComponents(int index, int amount) {
int page = index / amount;
if(index % amount > 0) {
page++;
}
List<Notification> response = ServerAPI.listNotifications(page,
amount);
if(response == null) {
return null;
}
Component[] notifications = new Component[response.size()];
int iter = 0;
for(Notification n : response) {
notifications[iter] = createNotificationEntry(n);
iter++;
}
return notifications;
}
NotificationContainer
- 20. public class NotificationsContainer extends InfiniteContainer {
@Override
public Component[] fetchComponents(int index, int amount) {
int page = index / amount;
if(index % amount > 0) {
page++;
}
List<Notification> response = ServerAPI.listNotifications(page,
amount);
if(response == null) {
return null;
}
Component[] notifications = new Component[response.size()];
int iter = 0;
for(Notification n : response) {
notifications[iter] = createNotificationEntry(n);
iter++;
}
return notifications;
}
NotificationContainer