SlideShare a Scribd company logo
Creating a WhatsApp Clone - Part X
The final part discussing the client side code covers the NewMessageForm class
public class NewMessageForm extends Form {
public NewMessageForm() {
super("Select Contact", BoxLayout.y());
Form current = getCurrentForm();
getToolbar().setBackCommand("", e -> current.showBack());
MultiButton newGroup = new MultiButton("New group");
MultiButton newContact = new MultiButton("New contact");
FontImage.setMaterialIcon(newGroup,
FontImage.MATERIAL_GROUP_ADD, 3.5f);
FontImage.setMaterialIcon(newContact,
FontImage.MATERIAL_PERSON_ADD, 3.5f);
add(newGroup);
add(newContact);
Server.fetchContacts(lst -> {
for(ChatContact c : lst) {
MultiButton mb = new MultiButton(c.name.get());
mb.setTextLine2(c.tagline.get());
mb.setIcon(c.getSmallIcon());
NewMessageForm
NewMessageForm is a form we see when we press the floating action button in the main form
public class NewMessageForm extends Form {
public NewMessageForm() {
super("Select Contact", BoxLayout.y());
Form current = getCurrentForm();
getToolbar().setBackCommand("", e -> current.showBack());
MultiButton newGroup = new MultiButton("New group");
MultiButton newContact = new MultiButton("New contact");
FontImage.setMaterialIcon(newGroup,
FontImage.MATERIAL_GROUP_ADD, 3.5f);
FontImage.setMaterialIcon(newContact,
FontImage.MATERIAL_PERSON_ADD, 3.5f);
add(newGroup);
add(newContact);
Server.fetchContacts(lst -> {
for(ChatContact c : lst) {
MultiButton mb = new MultiButton(c.name.get());
mb.setTextLine2(c.tagline.get());
mb.setIcon(c.getSmallIcon());
NewMessageForm
This class is trivial by comparison to the previous class. It’s just a box layout Y form that lets us pick the contact we wish to chat with
public NewMessageForm() {
super("Select Contact", BoxLayout.y());
Form current = getCurrentForm();
getToolbar().setBackCommand("", e -> current.showBack());
MultiButton newGroup = new MultiButton("New group");
MultiButton newContact = new MultiButton("New contact");
FontImage.setMaterialIcon(newGroup,
FontImage.MATERIAL_GROUP_ADD, 3.5f);
FontImage.setMaterialIcon(newContact,
FontImage.MATERIAL_PERSON_ADD, 3.5f);
add(newGroup);
add(newContact);
Server.fetchContacts(lst -> {
for(ChatContact c : lst) {
MultiButton mb = new MultiButton(c.name.get());
mb.setTextLine2(c.tagline.get());
mb.setIcon(c.getSmallIcon());
c.photo.addChangeListener(p ->
mb.setIcon(c.getSmallIcon()));
mb.addActionListener(e -> {
if(c.id.get() == null) {
Server.findRegisteredUser(
NewMessageForm
The new group and contact buttons aren’t currently mapped to anything. They are just simple buttons.
FontImage.MATERIAL_GROUP_ADD, 3.5f);
FontImage.setMaterialIcon(newContact,
FontImage.MATERIAL_PERSON_ADD, 3.5f);
add(newGroup);
add(newContact);
Server.fetchContacts(lst -> {
for(ChatContact c : lst) {
MultiButton mb = new MultiButton(c.name.get());
mb.setTextLine2(c.tagline.get());
mb.setIcon(c.getSmallIcon());
c.photo.addChangeListener(p ->
mb.setIcon(c.getSmallIcon()));
mb.addActionListener(e -> {
if(c.id.get() == null) {
Server.findRegisteredUser(
c.phone.get(), contact -> {
if(contact == null) {
current.showBack();
callSerially(() ->
ToastBar.showErrorMessage(
"Contact isn't registered"));
NewMessageForm
We use the fetch contacts method to fetch the list of contacts to show here
add(newGroup);
add(newContact);
Server.fetchContacts(lst -> {
for(ChatContact c : lst) {
MultiButton mb = new MultiButton(c.name.get());
mb.setTextLine2(c.tagline.get());
mb.setIcon(c.getSmallIcon());
c.photo.addChangeListener(p ->
mb.setIcon(c.getSmallIcon()));
mb.addActionListener(e -> {
if(c.id.get() == null) {
Server.findRegisteredUser(
c.phone.get(), contact -> {
if(contact == null) {
current.showBack();
callSerially(() ->
ToastBar.showErrorMessage(
"Contact isn't registered"));
return;
}
c.id.set(contact.id.get());
Server.saveContacts();
});
NewMessageForm
For every contact in the list of contacts we create a multi button matching the name and icon.
MultiButton mb = new MultiButton(c.name.get());
mb.setTextLine2(c.tagline.get());
mb.setIcon(c.getSmallIcon());
c.photo.addChangeListener(p ->
mb.setIcon(c.getSmallIcon()));
mb.addActionListener(e -> {
if(c.id.get() == null) {
Server.findRegisteredUser(
c.phone.get(), contact -> {
if(contact == null) {
current.showBack();
callSerially(() ->
ToastBar.showErrorMessage(
"Contact isn't registered"));
return;
}
c.id.set(contact.id.get());
Server.saveContacts();
});
return;
}
new ChatForm(c, current).show();
});
add(mb);
NewMessageForm
If a contact is clicked we check if he has an ID. If not this is someone that might not be in the app yet. So we need to contact the server and check.
MultiButton mb = new MultiButton(c.name.get());
mb.setTextLine2(c.tagline.get());
mb.setIcon(c.getSmallIcon());
c.photo.addChangeListener(p ->
mb.setIcon(c.getSmallIcon()));
mb.addActionListener(e -> {
if(c.id.get() == null) {
Server.findRegisteredUser(
c.phone.get(), contact -> {
if(contact == null) {
current.showBack();
callSerially(() ->
ToastBar.showErrorMessage(
"Contact isn't registered"));
return;
}
c.id.set(contact.id.get());
Server.saveContacts();
});
return;
}
new ChatForm(c, current).show();
});
add(mb);
NewMessageForm
findRegisteredUser finds the specific user based on his phone number
MultiButton mb = new MultiButton(c.name.get());
mb.setTextLine2(c.tagline.get());
mb.setIcon(c.getSmallIcon());
c.photo.addChangeListener(p ->
mb.setIcon(c.getSmallIcon()));
mb.addActionListener(e -> {
if(c.id.get() == null) {
Server.findRegisteredUser(
c.phone.get(), contact -> {
if(contact == null) {
current.showBack();
callSerially(() ->
ToastBar.showErrorMessage(
"Contact isn't registered"));
return;
}
c.id.set(contact.id.get());
Server.saveContacts();
});
return;
}
new ChatForm(c, current).show();
});
add(mb);
NewMessageForm
If we get null as a result it means there is no such registered user in the app. We go back to the previous form and show a toastbar message there
MultiButton mb = new MultiButton(c.name.get());
mb.setTextLine2(c.tagline.get());
mb.setIcon(c.getSmallIcon());
c.photo.addChangeListener(p ->
mb.setIcon(c.getSmallIcon()));
mb.addActionListener(e -> {
if(c.id.get() == null) {
Server.findRegisteredUser(
c.phone.get(), contact -> {
if(contact == null) {
current.showBack();
callSerially(() ->
ToastBar.showErrorMessage(
"Contact isn't registered"));
return;
}
c.id.set(contact.id.get());
Server.saveContacts();
});
return;
}
new ChatForm(c, current).show();
});
add(mb);
NewMessageForm
If there is we update the user id and save
MultiButton mb = new MultiButton(c.name.get());
mb.setTextLine2(c.tagline.get());
mb.setIcon(c.getSmallIcon());
c.photo.addChangeListener(p ->
mb.setIcon(c.getSmallIcon()));
mb.addActionListener(e -> {
if(c.id.get() == null) {
Server.findRegisteredUser(
c.phone.get(), contact -> {
if(contact == null) {
current.showBack();
callSerially(() ->
ToastBar.showErrorMessage(
"Contact isn't registered"));
return;
}
c.id.set(contact.id.get());
Server.saveContacts();
});
return;
}
new ChatForm(c, current).show();
});
add(mb);
NewMessageForm
We can then launch the chat form with this new contact
if(c.id.get() == null) {
Server.findRegisteredUser(
c.phone.get(), contact -> {
if(contact == null) {
current.showBack();
callSerially(() ->
ToastBar.showErrorMessage(
"Contact isn't registered"));
return;
}
c.id.set(contact.id.get());
Server.saveContacts();
});
return;
}
new ChatForm(c, current).show();
});
add(mb);
}
revalidate();
});
}
}
NewMessageForm
Since all the multibuttons are added asynchronously we need to revalidate so they will show on the form. As I said this is a super simple short class and with that we
finished the client side work…

More Related Content

Similar to Creating a Whatsapp Clone - Part X - Transcript.pdf

Creating a Facebook Clone - Part XXVIII - Transcript.pdf
Creating a Facebook Clone - Part XXVIII - Transcript.pdfCreating a Facebook Clone - Part XXVIII - Transcript.pdf
Creating a Facebook Clone - Part XXVIII - Transcript.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XLIII.pdf
Creating a Facebook Clone - Part XLIII.pdfCreating a Facebook Clone - Part XLIII.pdf
Creating a Facebook Clone - Part XLIII.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part VII.pdf
Creating a Facebook Clone - Part VII.pdfCreating a Facebook Clone - Part VII.pdf
Creating a Facebook Clone - Part VII.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part VI - Transcript.pdf
Creating a Facebook Clone - Part VI - Transcript.pdfCreating a Facebook Clone - Part VI - Transcript.pdf
Creating a Facebook Clone - Part VI - Transcript.pdf
ShaiAlmog1
 
Creating an Uber - Part VI - Transcript.pdf
Creating an Uber - Part VI - Transcript.pdfCreating an Uber - Part VI - Transcript.pdf
Creating an Uber - Part VI - Transcript.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XVI.pdf
Creating a Facebook Clone - Part XVI.pdfCreating a Facebook Clone - Part XVI.pdf
Creating a Facebook Clone - Part XVI.pdf
ShaiAlmog1
 
Creating an Uber Clone - Part XIV - Transcript.pdf
Creating an Uber Clone - Part XIV - Transcript.pdfCreating an Uber Clone - Part XIV - Transcript.pdf
Creating an Uber Clone - Part XIV - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part VIII - Transcript.pdf
Creating a Facebook Clone - Part VIII - Transcript.pdfCreating a Facebook Clone - Part VIII - Transcript.pdf
Creating a Facebook Clone - Part VIII - Transcript.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdfCreating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdf
ShaiAlmog1
 
please code in c#- please note that im a complete beginner- northwind.docx
please code in c#- please note that im a complete beginner-  northwind.docxplease code in c#- please note that im a complete beginner-  northwind.docx
please code in c#- please note that im a complete beginner- northwind.docx
AustinaGRPaigey
 
GWT Training - Session 3/3
GWT Training - Session 3/3GWT Training - Session 3/3
GWT Training - Session 3/3
Faiz Bashir
 
Creating an Uber Clone - Part XIV.pdf
Creating an Uber Clone - Part XIV.pdfCreating an Uber Clone - Part XIV.pdf
Creating an Uber Clone - Part XIV.pdf
ShaiAlmog1
 
New client side features - Microsoft Dynamics CRM 2016
New client side features - Microsoft Dynamics CRM 2016New client side features - Microsoft Dynamics CRM 2016
New client side features - Microsoft Dynamics CRM 2016
Naveen Kumar
 
Initial UI Mockup - Part 3.pdf
Initial UI Mockup - Part 3.pdfInitial UI Mockup - Part 3.pdf
Initial UI Mockup - Part 3.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part VI.pdf
Creating a Facebook Clone - Part VI.pdfCreating a Facebook Clone - Part VI.pdf
Creating a Facebook Clone - Part VI.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XXX.pdf
Creating a Facebook Clone - Part XXX.pdfCreating a Facebook Clone - Part XXX.pdf
Creating a Facebook Clone - Part XXX.pdf
ShaiAlmog1
 
Creating an Uber Clone - Part XXXIX.pdf
Creating an Uber Clone - Part XXXIX.pdfCreating an Uber Clone - Part XXXIX.pdf
Creating an Uber Clone - Part XXXIX.pdf
ShaiAlmog1
 
Adapting to Tablets and Desktops - Part 3 - Transcript.pdf
Adapting to Tablets and Desktops - Part 3 - Transcript.pdfAdapting to Tablets and Desktops - Part 3 - Transcript.pdf
Adapting to Tablets and Desktops - Part 3 - Transcript.pdf
ShaiAlmog1
 

Similar to Creating a Whatsapp Clone - Part X - Transcript.pdf (20)

Creating a Facebook Clone - Part XXVIII - Transcript.pdf
Creating a Facebook Clone - Part XXVIII - Transcript.pdfCreating a Facebook Clone - Part XXVIII - Transcript.pdf
Creating a Facebook Clone - Part XXVIII - Transcript.pdf
 
Creating a Facebook Clone - Part XLIII.pdf
Creating a Facebook Clone - Part XLIII.pdfCreating a Facebook Clone - Part XLIII.pdf
Creating a Facebook Clone - Part XLIII.pdf
 
Creating a Facebook Clone - Part VII.pdf
Creating a Facebook Clone - Part VII.pdfCreating a Facebook Clone - Part VII.pdf
Creating a Facebook Clone - Part VII.pdf
 
Creating a Facebook Clone - Part VI - Transcript.pdf
Creating a Facebook Clone - Part VI - Transcript.pdfCreating a Facebook Clone - Part VI - Transcript.pdf
Creating a Facebook Clone - Part VI - Transcript.pdf
 
Creating an Uber - Part VI - Transcript.pdf
Creating an Uber - Part VI - Transcript.pdfCreating an Uber - Part VI - Transcript.pdf
Creating an Uber - Part VI - Transcript.pdf
 
Creating a Facebook Clone - Part XVI.pdf
Creating a Facebook Clone - Part XVI.pdfCreating a Facebook Clone - Part XVI.pdf
Creating a Facebook Clone - Part XVI.pdf
 
Creating an Uber Clone - Part XIV - Transcript.pdf
Creating an Uber Clone - Part XIV - Transcript.pdfCreating an Uber Clone - Part XIV - Transcript.pdf
Creating an Uber Clone - Part XIV - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Facebook Clone - Part VIII - Transcript.pdf
Creating a Facebook Clone - Part VIII - Transcript.pdfCreating a Facebook Clone - Part VIII - Transcript.pdf
Creating a Facebook Clone - Part VIII - Transcript.pdf
 
Creating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdfCreating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdf
 
please code in c#- please note that im a complete beginner- northwind.docx
please code in c#- please note that im a complete beginner-  northwind.docxplease code in c#- please note that im a complete beginner-  northwind.docx
please code in c#- please note that im a complete beginner- northwind.docx
 
GWT Training - Session 3/3
GWT Training - Session 3/3GWT Training - Session 3/3
GWT Training - Session 3/3
 
Creating an Uber Clone - Part XIV.pdf
Creating an Uber Clone - Part XIV.pdfCreating an Uber Clone - Part XIV.pdf
Creating an Uber Clone - Part XIV.pdf
 
New client side features - Microsoft Dynamics CRM 2016
New client side features - Microsoft Dynamics CRM 2016New client side features - Microsoft Dynamics CRM 2016
New client side features - Microsoft Dynamics CRM 2016
 
Initial UI Mockup - Part 3.pdf
Initial UI Mockup - Part 3.pdfInitial UI Mockup - Part 3.pdf
Initial UI Mockup - Part 3.pdf
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
 
Creating a Facebook Clone - Part VI.pdf
Creating a Facebook Clone - Part VI.pdfCreating a Facebook Clone - Part VI.pdf
Creating a Facebook Clone - Part VI.pdf
 
Creating a Facebook Clone - Part XXX.pdf
Creating a Facebook Clone - Part XXX.pdfCreating a Facebook Clone - Part XXX.pdf
Creating a Facebook Clone - Part XXX.pdf
 
Creating an Uber Clone - Part XXXIX.pdf
Creating an Uber Clone - Part XXXIX.pdfCreating an Uber Clone - Part XXXIX.pdf
Creating an Uber Clone - Part XXXIX.pdf
 
Adapting to Tablets and Desktops - Part 3 - Transcript.pdf
Adapting to Tablets and Desktops - Part 3 - Transcript.pdfAdapting to Tablets and Desktops - Part 3 - Transcript.pdf
Adapting to Tablets and Desktops - Part 3 - Transcript.pdf
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
ShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part VI.pdf
Creating a Whatsapp Clone - Part VI.pdfCreating a Whatsapp Clone - Part VI.pdf
Creating a Whatsapp Clone - Part VI.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part XI - Transcript.pdf
Creating a Whatsapp Clone - Part XI - Transcript.pdfCreating a Whatsapp Clone - Part XI - Transcript.pdf
Creating a Whatsapp Clone - Part XI - Transcript.pdf
ShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 
Creating a Whatsapp Clone - Part VI.pdf
Creating a Whatsapp Clone - Part VI.pdfCreating a Whatsapp Clone - Part VI.pdf
Creating a Whatsapp Clone - Part VI.pdf
 
Creating a Whatsapp Clone - Part XI - Transcript.pdf
Creating a Whatsapp Clone - Part XI - Transcript.pdfCreating a Whatsapp Clone - Part XI - Transcript.pdf
Creating a Whatsapp Clone - Part XI - Transcript.pdf
 

Recently uploaded

AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 

Recently uploaded (20)

AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 

Creating a Whatsapp Clone - Part X - Transcript.pdf

  • 1. Creating a WhatsApp Clone - Part X The final part discussing the client side code covers the NewMessageForm class
  • 2. public class NewMessageForm extends Form { public NewMessageForm() { super("Select Contact", BoxLayout.y()); Form current = getCurrentForm(); getToolbar().setBackCommand("", e -> current.showBack()); MultiButton newGroup = new MultiButton("New group"); MultiButton newContact = new MultiButton("New contact"); FontImage.setMaterialIcon(newGroup, FontImage.MATERIAL_GROUP_ADD, 3.5f); FontImage.setMaterialIcon(newContact, FontImage.MATERIAL_PERSON_ADD, 3.5f); add(newGroup); add(newContact); Server.fetchContacts(lst -> { for(ChatContact c : lst) { MultiButton mb = new MultiButton(c.name.get()); mb.setTextLine2(c.tagline.get()); mb.setIcon(c.getSmallIcon()); NewMessageForm NewMessageForm is a form we see when we press the floating action button in the main form
  • 3. public class NewMessageForm extends Form { public NewMessageForm() { super("Select Contact", BoxLayout.y()); Form current = getCurrentForm(); getToolbar().setBackCommand("", e -> current.showBack()); MultiButton newGroup = new MultiButton("New group"); MultiButton newContact = new MultiButton("New contact"); FontImage.setMaterialIcon(newGroup, FontImage.MATERIAL_GROUP_ADD, 3.5f); FontImage.setMaterialIcon(newContact, FontImage.MATERIAL_PERSON_ADD, 3.5f); add(newGroup); add(newContact); Server.fetchContacts(lst -> { for(ChatContact c : lst) { MultiButton mb = new MultiButton(c.name.get()); mb.setTextLine2(c.tagline.get()); mb.setIcon(c.getSmallIcon()); NewMessageForm This class is trivial by comparison to the previous class. It’s just a box layout Y form that lets us pick the contact we wish to chat with
  • 4. public NewMessageForm() { super("Select Contact", BoxLayout.y()); Form current = getCurrentForm(); getToolbar().setBackCommand("", e -> current.showBack()); MultiButton newGroup = new MultiButton("New group"); MultiButton newContact = new MultiButton("New contact"); FontImage.setMaterialIcon(newGroup, FontImage.MATERIAL_GROUP_ADD, 3.5f); FontImage.setMaterialIcon(newContact, FontImage.MATERIAL_PERSON_ADD, 3.5f); add(newGroup); add(newContact); Server.fetchContacts(lst -> { for(ChatContact c : lst) { MultiButton mb = new MultiButton(c.name.get()); mb.setTextLine2(c.tagline.get()); mb.setIcon(c.getSmallIcon()); c.photo.addChangeListener(p -> mb.setIcon(c.getSmallIcon())); mb.addActionListener(e -> { if(c.id.get() == null) { Server.findRegisteredUser( NewMessageForm The new group and contact buttons aren’t currently mapped to anything. They are just simple buttons.
  • 5. FontImage.MATERIAL_GROUP_ADD, 3.5f); FontImage.setMaterialIcon(newContact, FontImage.MATERIAL_PERSON_ADD, 3.5f); add(newGroup); add(newContact); Server.fetchContacts(lst -> { for(ChatContact c : lst) { MultiButton mb = new MultiButton(c.name.get()); mb.setTextLine2(c.tagline.get()); mb.setIcon(c.getSmallIcon()); c.photo.addChangeListener(p -> mb.setIcon(c.getSmallIcon())); mb.addActionListener(e -> { if(c.id.get() == null) { Server.findRegisteredUser( c.phone.get(), contact -> { if(contact == null) { current.showBack(); callSerially(() -> ToastBar.showErrorMessage( "Contact isn't registered")); NewMessageForm We use the fetch contacts method to fetch the list of contacts to show here
  • 6. add(newGroup); add(newContact); Server.fetchContacts(lst -> { for(ChatContact c : lst) { MultiButton mb = new MultiButton(c.name.get()); mb.setTextLine2(c.tagline.get()); mb.setIcon(c.getSmallIcon()); c.photo.addChangeListener(p -> mb.setIcon(c.getSmallIcon())); mb.addActionListener(e -> { if(c.id.get() == null) { Server.findRegisteredUser( c.phone.get(), contact -> { if(contact == null) { current.showBack(); callSerially(() -> ToastBar.showErrorMessage( "Contact isn't registered")); return; } c.id.set(contact.id.get()); Server.saveContacts(); }); NewMessageForm For every contact in the list of contacts we create a multi button matching the name and icon.
  • 7. MultiButton mb = new MultiButton(c.name.get()); mb.setTextLine2(c.tagline.get()); mb.setIcon(c.getSmallIcon()); c.photo.addChangeListener(p -> mb.setIcon(c.getSmallIcon())); mb.addActionListener(e -> { if(c.id.get() == null) { Server.findRegisteredUser( c.phone.get(), contact -> { if(contact == null) { current.showBack(); callSerially(() -> ToastBar.showErrorMessage( "Contact isn't registered")); return; } c.id.set(contact.id.get()); Server.saveContacts(); }); return; } new ChatForm(c, current).show(); }); add(mb); NewMessageForm If a contact is clicked we check if he has an ID. If not this is someone that might not be in the app yet. So we need to contact the server and check.
  • 8. MultiButton mb = new MultiButton(c.name.get()); mb.setTextLine2(c.tagline.get()); mb.setIcon(c.getSmallIcon()); c.photo.addChangeListener(p -> mb.setIcon(c.getSmallIcon())); mb.addActionListener(e -> { if(c.id.get() == null) { Server.findRegisteredUser( c.phone.get(), contact -> { if(contact == null) { current.showBack(); callSerially(() -> ToastBar.showErrorMessage( "Contact isn't registered")); return; } c.id.set(contact.id.get()); Server.saveContacts(); }); return; } new ChatForm(c, current).show(); }); add(mb); NewMessageForm findRegisteredUser finds the specific user based on his phone number
  • 9. MultiButton mb = new MultiButton(c.name.get()); mb.setTextLine2(c.tagline.get()); mb.setIcon(c.getSmallIcon()); c.photo.addChangeListener(p -> mb.setIcon(c.getSmallIcon())); mb.addActionListener(e -> { if(c.id.get() == null) { Server.findRegisteredUser( c.phone.get(), contact -> { if(contact == null) { current.showBack(); callSerially(() -> ToastBar.showErrorMessage( "Contact isn't registered")); return; } c.id.set(contact.id.get()); Server.saveContacts(); }); return; } new ChatForm(c, current).show(); }); add(mb); NewMessageForm If we get null as a result it means there is no such registered user in the app. We go back to the previous form and show a toastbar message there
  • 10. MultiButton mb = new MultiButton(c.name.get()); mb.setTextLine2(c.tagline.get()); mb.setIcon(c.getSmallIcon()); c.photo.addChangeListener(p -> mb.setIcon(c.getSmallIcon())); mb.addActionListener(e -> { if(c.id.get() == null) { Server.findRegisteredUser( c.phone.get(), contact -> { if(contact == null) { current.showBack(); callSerially(() -> ToastBar.showErrorMessage( "Contact isn't registered")); return; } c.id.set(contact.id.get()); Server.saveContacts(); }); return; } new ChatForm(c, current).show(); }); add(mb); NewMessageForm If there is we update the user id and save
  • 11. MultiButton mb = new MultiButton(c.name.get()); mb.setTextLine2(c.tagline.get()); mb.setIcon(c.getSmallIcon()); c.photo.addChangeListener(p -> mb.setIcon(c.getSmallIcon())); mb.addActionListener(e -> { if(c.id.get() == null) { Server.findRegisteredUser( c.phone.get(), contact -> { if(contact == null) { current.showBack(); callSerially(() -> ToastBar.showErrorMessage( "Contact isn't registered")); return; } c.id.set(contact.id.get()); Server.saveContacts(); }); return; } new ChatForm(c, current).show(); }); add(mb); NewMessageForm We can then launch the chat form with this new contact
  • 12. if(c.id.get() == null) { Server.findRegisteredUser( c.phone.get(), contact -> { if(contact == null) { current.showBack(); callSerially(() -> ToastBar.showErrorMessage( "Contact isn't registered")); return; } c.id.set(contact.id.get()); Server.saveContacts(); }); return; } new ChatForm(c, current).show(); }); add(mb); } revalidate(); }); } } NewMessageForm Since all the multibuttons are added asynchronously we need to revalidate so they will show on the form. As I said this is a super simple short class and with that we finished the client side work…