SlideShare a Scribd company logo
Creating a Facebook Clone - Part XI
It will take a bit of work to implement the server and proper abstraction. However, it's a good idea to put things in the right place to begin with. Using a ServerAPI class
will help us organize things correctly piece by piece. We can then replace mockups with implementations and see things working almost instantaneously!
public class ServerAPI {
private static User me;
private static final String avatarUrl =
"https://www.codenameone.com/images/diverseui-avatars/";
private static final long initTime =
System.currentTimeMillis();
private final static User[] dummyUsers;
static {
dummyUsers = new User[] {
new User().id.set("TODO-2").
firstName.set("David").
familyName.set("Something").
avatar.set(avatarUrl + "image-1.png"),
new User().id.set("TODO-3").
firstName.set("Dana").
familyName.set("Something Else").
avatar.set(avatarUrl + "image-3.png"),
new User().id.set("TODO-4").
firstName.set("Carl").
familyName.set("Not Something").
ServerAPI
Currently the ServerAPI class serves as a mockup. It's a static class that hides the server connection. I'm blocking API calls within this class as they are easier to
integrate into the InfiniteContainer which I will introduce soon.

The currently logged in user is a global state in the application which is a pretty standard practice
public class ServerAPI {
private static User me;
private static final String avatarUrl =
"https://www.codenameone.com/images/diverseui-avatars/";
private static final long initTime =
System.currentTimeMillis();
private final static User[] dummyUsers;
static {
dummyUsers = new User[] {
new User().id.set("TODO-2").
firstName.set("David").
familyName.set("Something").
avatar.set(avatarUrl + "image-1.png"),
new User().id.set("TODO-3").
firstName.set("Dana").
familyName.set("Something Else").
avatar.set(avatarUrl + "image-3.png"),
new User().id.set("TODO-4").
firstName.set("Carl").
familyName.set("Not Something").
ServerAPI
I've setup a few images from the diverseui project so we can have fake users with Avatars in the app. Check out the divrseui project diverseui.com its goal is to feature
more diversity in app mockups
public class ServerAPI {
private static User me;
private static final String avatarUrl =
"https://www.codenameone.com/images/diverseui-avatars/";
private static final long initTime =
System.currentTimeMillis();
private final static User[] dummyUsers;
static {
dummyUsers = new User[] {
new User().id.set("TODO-2").
firstName.set("David").
familyName.set("Something").
avatar.set(avatarUrl + "image-1.png"),
new User().id.set("TODO-3").
firstName.set("Dana").
familyName.set("Something Else").
avatar.set(avatarUrl + "image-3.png"),
new User().id.set("TODO-4").
firstName.set("Carl").
familyName.set("Not Something").
ServerAPI
We need times in the timeline etc. to start from a reasonable enough date so I use "now" as the baseline
private static final long initTime =
System.currentTimeMillis();
private final static User[] dummyUsers;
static {
dummyUsers = new User[] {
new User().id.set("TODO-2").
firstName.set("David").
familyName.set("Something").
avatar.set(avatarUrl + "image-1.png"),
new User().id.set("TODO-3").
firstName.set("Dana").
familyName.set("Something Else").
avatar.set(avatarUrl + "image-3.png"),
new User().id.set("TODO-4").
firstName.set("Carl").
familyName.set("Not Something").
avatar.set(avatarUrl + "image-2.png"),
new User().id.set("TODO-5").
firstName.set("Donna").
familyName.set("Enough with Something").
avatar.set(avatarUrl + "image-4.png")
};
}
public static User me() {
if(me == null) {
ServerAPI
We'll setup 4 User objects that we can use soon
avatar.set(avatarUrl + "image-3.png"),
new User().id.set("TODO-4").
firstName.set("Carl").
familyName.set("Not Something").
avatar.set(avatarUrl + "image-2.png"),
new User().id.set("TODO-5").
firstName.set("Donna").
familyName.set("Enough with Something").
avatar.set(avatarUrl + "image-4.png")
};
}
public static User me() {
if(me == null) {
me = new User().
id.set("TODO-1").
firstName.set("Shai").
familyName.set("Almog");
me.friendRequests.add(dummyUsers[0]);
me.friendRequests.add(dummyUsers[1]);
me.peopleYouMayKnow.add(dummyUsers[2]);
me.peopleYouMayKnow.add(dummyUsers[3]);
}
return me;
}
public static List<Post> fetchTimelinePosts(long since, int amount) {
ServerAPI
This method returns the current user after lazily initializing it
avatar.set(avatarUrl + "image-3.png"),
new User().id.set("TODO-4").
firstName.set("Carl").
familyName.set("Not Something").
avatar.set(avatarUrl + "image-2.png"),
new User().id.set("TODO-5").
firstName.set("Donna").
familyName.set("Enough with Something").
avatar.set(avatarUrl + "image-4.png")
};
}
public static User me() {
if(me == null) {
me = new User().
id.set("TODO-1").
firstName.set("Shai").
familyName.set("Almog");
me.friendRequests.add(dummyUsers[0]);
me.friendRequests.add(dummyUsers[1]);
me.peopleYouMayKnow.add(dummyUsers[2]);
me.peopleYouMayKnow.add(dummyUsers[3]);
}
return me;
}
public static List<Post> fetchTimelinePosts(long since, int amount) {
ServerAPI
This is the shorthand "builder" constructor where I set a hardcoded user
familyName.set("Not Something").
avatar.set(avatarUrl + "image-2.png"),
new User().id.set("TODO-5").
firstName.set("Donna").
familyName.set("Enough with Something").
avatar.set(avatarUrl + "image-4.png")
};
}
public static User me() {
if(me == null) {
me = new User().
id.set("TODO-1").
firstName.set("Shai").
familyName.set("Almog");
me.friendRequests.add(dummyUsers[0]);
me.friendRequests.add(dummyUsers[1]);
me.peopleYouMayKnow.add(dummyUsers[2]);
me.peopleYouMayKnow.add(dummyUsers[3]);
}
return me;
}
public static List<Post> fetchTimelinePosts(long since, int amount) {
if(since >= initTime) {
Comment firstPost = new Comment().
date.set(System.currentTimeMillis()).
text.set("First post!!!").
ServerAPI
I add friends and people I may know which I'll use later in the friends view
me.peopleYouMayKnow.add(dummyUsers[3]);
}
return me;
}
public static List<Post> fetchTimelinePosts(long since, int amount) {
if(since >= initTime) {
Comment firstPost = new Comment().
date.set(System.currentTimeMillis()).
text.set("First post!!!").
id.set("Comment1").
userId.set(ServerAPI.me().id.get());
Post dummyPost = new Post().
user.set(ServerAPI.me()).
content.set("This is a <b>POST</b> that includes HTML").
date.set(System.currentTimeMillis() - 60000).
id.set("Post1").
likes.add(ServerAPI.me()).
comments.add(firstPost);
List<Post> response = new ArrayList<>();
response.add(dummyPost);
return response;
}
return null;
}
ServerAPI
This method fetches the posts in the current timeline
me.peopleYouMayKnow.add(dummyUsers[3]);
}
return me;
}
public static List<Post> fetchTimelinePosts(long since, int amount) {
if(since >= initTime) {
Comment firstPost = new Comment().
date.set(System.currentTimeMillis()).
text.set("First post!!!").
id.set("Comment1").
userId.set(ServerAPI.me().id.get());
Post dummyPost = new Post().
user.set(ServerAPI.me()).
content.set("This is a <b>POST</b> that includes HTML").
date.set(System.currentTimeMillis() - 60000).
id.set("Post1").
likes.add(ServerAPI.me()).
comments.add(firstPost);
List<Post> response = new ArrayList<>();
response.add(dummyPost);
return response;
}
return null;
}
ServerAPI
The method accepts the time of the last post so we can fetch the posts "since" that time
return me;
}
public static List<Post> fetchTimelinePosts(long since, int amount) {
if(since >= initTime) {
Comment firstPost = new Comment().
date.set(System.currentTimeMillis()).
text.set("First post!!!").
id.set("Comment1").
userId.set(ServerAPI.me().id.get());
Post dummyPost = new Post().
user.set(ServerAPI.me()).
content.set("This is a <b>POST</b> that includes HTML").
date.set(System.currentTimeMillis() - 60000).
id.set("Post1").
likes.add(ServerAPI.me()).
comments.add(firstPost);
List<Post> response = new ArrayList<>();
response.add(dummyPost);
return response;
}
return null;
}
}
ServerAPI
We add a comment so the comment count wouldn't be 0. There is still no comment view though
return me;
}
public static List<Post> fetchTimelinePosts(long since, int amount) {
if(since >= initTime) {
Comment firstPost = new Comment().
date.set(System.currentTimeMillis()).
text.set("First post!!!").
id.set("Comment1").
userId.set(ServerAPI.me().id.get());
Post dummyPost = new Post().
user.set(ServerAPI.me()).
content.set("This is a <b>POST</b> that includes HTML").
date.set(System.currentTimeMillis() - 60000).
id.set("Post1").
likes.add(ServerAPI.me()).
comments.add(firstPost);
List<Post> response = new ArrayList<>();
response.add(dummyPost);
return response;
}
return null;
}
}
ServerAPI
The post itself doesn't include much either, just some HTML for the post content
}
public static List<Post> fetchTimelinePosts(long since, int amount) {
if(since >= initTime) {
Comment firstPost = new Comment().
date.set(System.currentTimeMillis()).
text.set("First post!!!").
id.set("Comment1").
userId.set(ServerAPI.me().id.get());
Post dummyPost = new Post().
user.set(ServerAPI.me()).
content.set("This is a <b>POST</b> that includes HTML").
date.set(System.currentTimeMillis() - 60000).
id.set("Post1").
likes.add(ServerAPI.me()).
comments.add(firstPost);
List<Post> response = new ArrayList<>();
response.add(dummyPost);
return response;
}
return null;
}
}
ServerAPI
We return null when there is no further information. That's it, we are almost ready to implement the newsfeed!
public class UIUtils {
public static final long HOUR = 60 * 60000;
public static final long DAY = 24 * HOUR;
public static Label createSpace() {
Label l = new Label("", "PaddedSeparator");
l.setShowEvenIfBlank(true);
return l;
}
public static Label createHalfSpace() {
Label l = new Label("", "HalfPaddedSeparator");
l.setShowEvenIfBlank(true);
return l;
}
public static String formatTimeAgo(long time) {
long current = System.currentTimeMillis() - time;
if(current < HOUR) {
long minutes = current / 60000;
if(minutes < 2) {
return "Just now";
}
return minutes + " minutes ago";
}
UIUtils
Before I start with the newsfeed itself I'd like a couple of utility methods. For that I'll add a UIUtils class as such.

I use these to present time logic more effectively
public class UIUtils {
public static final long HOUR = 60 * 60000;
public static final long DAY = 24 * HOUR;
public static Label createSpace() {
Label l = new Label("", "PaddedSeparator");
l.setShowEvenIfBlank(true);
return l;
}
public static Label createHalfSpace() {
Label l = new Label("", "HalfPaddedSeparator");
l.setShowEvenIfBlank(true);
return l;
}
public static String formatTimeAgo(long time) {
long current = System.currentTimeMillis() - time;
if(current < HOUR) {
long minutes = current / 60000;
if(minutes < 2) {
return "Just now";
}
return minutes + " minutes ago";
}
UIUtils
These create a gray spacer that's used in several places in the Facebook UI
l.setShowEvenIfBlank(true);
return l;
}
public static Label createHalfSpace() {
Label l = new Label("", "HalfPaddedSeparator");
l.setShowEvenIfBlank(true);
return l;
}
public static String formatTimeAgo(long time) {
long current = System.currentTimeMillis() - time;
if(current < HOUR) {
long minutes = current / 60000;
if(minutes < 2) {
return "Just now";
}
return minutes + " minutes ago";
}
if(current < HOUR * 10) {
return (current / HOUR) + " hours ago";
}
return L10NManager.getInstance().
formatDateTimeShort(new Date(time));
}
}
UIUtils
This method formats time as statements such as "just now", "15 minutes ago" etc. then falls back to standard date & time values. We use this when displaying time on
posts. We'll use these in the NewsfeedContainer class.
PaddedSeparator {
background: #DCDEE3;
padding: 0.5mm;
margin: 0px;
}
HalfPaddedSeparator {
cn1-derive: PaddedSeparator;
padding: 0.25mm;
}
theme.css
But before we get there there we have the missing CSS statements for the UIID's we used in the listing. These separators have the gray background and right amount of
padding to match the UI

More Related Content

Similar to Creating a Facebook Clone - Part XI - Transcript.pdf

Salesforce, APEX Concepts
Salesforce, APEX ConceptsSalesforce, APEX Concepts
Salesforce, APEX Concepts
Gaurish Goel
 
MySQL User Conference 2009: Python and MySQL
MySQL User Conference 2009: Python and MySQLMySQL User Conference 2009: Python and MySQL
MySQL User Conference 2009: Python and MySQL
Ted Leung
 
Creating a Facebook Clone - Part XL - Transcript.pdf
Creating a Facebook Clone - Part XL - Transcript.pdfCreating a Facebook Clone - Part XL - Transcript.pdf
Creating a Facebook Clone - Part XL - Transcript.pdf
ShaiAlmog1
 
Java programs
Java programsJava programs
Java programs
jojeph
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4
JoeDinaso
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
karymadelaneyrenne19
 
define a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdfdefine a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdf
fashioncollection2
 
Military time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdfMilitary time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdf
marketing413921
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
Fahad Shaikh
 
Team pdf ionic
Team pdf ionicTeam pdf ionic
Team pdf ionic
Godofredo Poccori Umeres
 
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
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
Tsuyoshi Yamamoto
 
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
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
MuhammadTalha436
 
Greach, GroovyFx Workshop
Greach, GroovyFx WorkshopGreach, GroovyFx Workshop
Greach, GroovyFx Workshop
Dierk König
 
Creating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdfCreating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdf
ShaiAlmog1
 
Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015
Jiayun Zhou
 
Intro programacion funcional
Intro programacion funcionalIntro programacion funcional
Intro programacion funcional
NSCoder Mexico
 
Sql server-function
Sql server-functionSql server-function
Sql server-function
AnkushAgrawal56
 
14709302.ppt
14709302.ppt14709302.ppt
14709302.ppt
SunilChaluvaiah
 

Similar to Creating a Facebook Clone - Part XI - Transcript.pdf (20)

Salesforce, APEX Concepts
Salesforce, APEX ConceptsSalesforce, APEX Concepts
Salesforce, APEX Concepts
 
MySQL User Conference 2009: Python and MySQL
MySQL User Conference 2009: Python and MySQLMySQL User Conference 2009: Python and MySQL
MySQL User Conference 2009: Python and MySQL
 
Creating a Facebook Clone - Part XL - Transcript.pdf
Creating a Facebook Clone - Part XL - Transcript.pdfCreating a Facebook Clone - Part XL - Transcript.pdf
Creating a Facebook Clone - Part XL - Transcript.pdf
 
Java programs
Java programsJava programs
Java programs
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
 
define a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdfdefine a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdf
 
Military time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdfMilitary time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdf
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
 
Team pdf ionic
Team pdf ionicTeam pdf ionic
Team pdf ionic
 
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
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
 
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
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Greach, GroovyFx Workshop
Greach, GroovyFx WorkshopGreach, GroovyFx Workshop
Greach, GroovyFx Workshop
 
Creating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdfCreating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdf
 
Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015
 
Intro programacion funcional
Intro programacion funcionalIntro programacion funcional
Intro programacion funcional
 
Sql server-function
Sql server-functionSql server-function
Sql server-function
 
14709302.ppt
14709302.ppt14709302.ppt
14709302.ppt
 

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 IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.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 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 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 IX.pdf
Creating a Whatsapp Clone - Part IX.pdfCreating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.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 IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.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 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 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 IX.pdf
Creating a Whatsapp Clone - Part IX.pdfCreating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdf
 

Recently uploaded

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
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
Vadym Kazulkin
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
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
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
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
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
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
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
Enterprise Knowledge
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
DanBrown980551
 

Recently uploaded (20)

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
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
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
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
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
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
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)
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
 

Creating a Facebook Clone - Part XI - Transcript.pdf

  • 1. Creating a Facebook Clone - Part XI It will take a bit of work to implement the server and proper abstraction. However, it's a good idea to put things in the right place to begin with. Using a ServerAPI class will help us organize things correctly piece by piece. We can then replace mockups with implementations and see things working almost instantaneously!
  • 2. public class ServerAPI { private static User me; private static final String avatarUrl = "https://www.codenameone.com/images/diverseui-avatars/"; private static final long initTime = System.currentTimeMillis(); private final static User[] dummyUsers; static { dummyUsers = new User[] { new User().id.set("TODO-2"). firstName.set("David"). familyName.set("Something"). avatar.set(avatarUrl + "image-1.png"), new User().id.set("TODO-3"). firstName.set("Dana"). familyName.set("Something Else"). avatar.set(avatarUrl + "image-3.png"), new User().id.set("TODO-4"). firstName.set("Carl"). familyName.set("Not Something"). ServerAPI Currently the ServerAPI class serves as a mockup. It's a static class that hides the server connection. I'm blocking API calls within this class as they are easier to integrate into the InfiniteContainer which I will introduce soon. The currently logged in user is a global state in the application which is a pretty standard practice
  • 3. public class ServerAPI { private static User me; private static final String avatarUrl = "https://www.codenameone.com/images/diverseui-avatars/"; private static final long initTime = System.currentTimeMillis(); private final static User[] dummyUsers; static { dummyUsers = new User[] { new User().id.set("TODO-2"). firstName.set("David"). familyName.set("Something"). avatar.set(avatarUrl + "image-1.png"), new User().id.set("TODO-3"). firstName.set("Dana"). familyName.set("Something Else"). avatar.set(avatarUrl + "image-3.png"), new User().id.set("TODO-4"). firstName.set("Carl"). familyName.set("Not Something"). ServerAPI I've setup a few images from the diverseui project so we can have fake users with Avatars in the app. Check out the divrseui project diverseui.com its goal is to feature more diversity in app mockups
  • 4. public class ServerAPI { private static User me; private static final String avatarUrl = "https://www.codenameone.com/images/diverseui-avatars/"; private static final long initTime = System.currentTimeMillis(); private final static User[] dummyUsers; static { dummyUsers = new User[] { new User().id.set("TODO-2"). firstName.set("David"). familyName.set("Something"). avatar.set(avatarUrl + "image-1.png"), new User().id.set("TODO-3"). firstName.set("Dana"). familyName.set("Something Else"). avatar.set(avatarUrl + "image-3.png"), new User().id.set("TODO-4"). firstName.set("Carl"). familyName.set("Not Something"). ServerAPI We need times in the timeline etc. to start from a reasonable enough date so I use "now" as the baseline
  • 5. private static final long initTime = System.currentTimeMillis(); private final static User[] dummyUsers; static { dummyUsers = new User[] { new User().id.set("TODO-2"). firstName.set("David"). familyName.set("Something"). avatar.set(avatarUrl + "image-1.png"), new User().id.set("TODO-3"). firstName.set("Dana"). familyName.set("Something Else"). avatar.set(avatarUrl + "image-3.png"), new User().id.set("TODO-4"). firstName.set("Carl"). familyName.set("Not Something"). avatar.set(avatarUrl + "image-2.png"), new User().id.set("TODO-5"). firstName.set("Donna"). familyName.set("Enough with Something"). avatar.set(avatarUrl + "image-4.png") }; } public static User me() { if(me == null) { ServerAPI We'll setup 4 User objects that we can use soon
  • 6. avatar.set(avatarUrl + "image-3.png"), new User().id.set("TODO-4"). firstName.set("Carl"). familyName.set("Not Something"). avatar.set(avatarUrl + "image-2.png"), new User().id.set("TODO-5"). firstName.set("Donna"). familyName.set("Enough with Something"). avatar.set(avatarUrl + "image-4.png") }; } public static User me() { if(me == null) { me = new User(). id.set("TODO-1"). firstName.set("Shai"). familyName.set("Almog"); me.friendRequests.add(dummyUsers[0]); me.friendRequests.add(dummyUsers[1]); me.peopleYouMayKnow.add(dummyUsers[2]); me.peopleYouMayKnow.add(dummyUsers[3]); } return me; } public static List<Post> fetchTimelinePosts(long since, int amount) { ServerAPI This method returns the current user after lazily initializing it
  • 7. avatar.set(avatarUrl + "image-3.png"), new User().id.set("TODO-4"). firstName.set("Carl"). familyName.set("Not Something"). avatar.set(avatarUrl + "image-2.png"), new User().id.set("TODO-5"). firstName.set("Donna"). familyName.set("Enough with Something"). avatar.set(avatarUrl + "image-4.png") }; } public static User me() { if(me == null) { me = new User(). id.set("TODO-1"). firstName.set("Shai"). familyName.set("Almog"); me.friendRequests.add(dummyUsers[0]); me.friendRequests.add(dummyUsers[1]); me.peopleYouMayKnow.add(dummyUsers[2]); me.peopleYouMayKnow.add(dummyUsers[3]); } return me; } public static List<Post> fetchTimelinePosts(long since, int amount) { ServerAPI This is the shorthand "builder" constructor where I set a hardcoded user
  • 8. familyName.set("Not Something"). avatar.set(avatarUrl + "image-2.png"), new User().id.set("TODO-5"). firstName.set("Donna"). familyName.set("Enough with Something"). avatar.set(avatarUrl + "image-4.png") }; } public static User me() { if(me == null) { me = new User(). id.set("TODO-1"). firstName.set("Shai"). familyName.set("Almog"); me.friendRequests.add(dummyUsers[0]); me.friendRequests.add(dummyUsers[1]); me.peopleYouMayKnow.add(dummyUsers[2]); me.peopleYouMayKnow.add(dummyUsers[3]); } return me; } public static List<Post> fetchTimelinePosts(long since, int amount) { if(since >= initTime) { Comment firstPost = new Comment(). date.set(System.currentTimeMillis()). text.set("First post!!!"). ServerAPI I add friends and people I may know which I'll use later in the friends view
  • 9. me.peopleYouMayKnow.add(dummyUsers[3]); } return me; } public static List<Post> fetchTimelinePosts(long since, int amount) { if(since >= initTime) { Comment firstPost = new Comment(). date.set(System.currentTimeMillis()). text.set("First post!!!"). id.set("Comment1"). userId.set(ServerAPI.me().id.get()); Post dummyPost = new Post(). user.set(ServerAPI.me()). content.set("This is a <b>POST</b> that includes HTML"). date.set(System.currentTimeMillis() - 60000). id.set("Post1"). likes.add(ServerAPI.me()). comments.add(firstPost); List<Post> response = new ArrayList<>(); response.add(dummyPost); return response; } return null; } ServerAPI This method fetches the posts in the current timeline
  • 10. me.peopleYouMayKnow.add(dummyUsers[3]); } return me; } public static List<Post> fetchTimelinePosts(long since, int amount) { if(since >= initTime) { Comment firstPost = new Comment(). date.set(System.currentTimeMillis()). text.set("First post!!!"). id.set("Comment1"). userId.set(ServerAPI.me().id.get()); Post dummyPost = new Post(). user.set(ServerAPI.me()). content.set("This is a <b>POST</b> that includes HTML"). date.set(System.currentTimeMillis() - 60000). id.set("Post1"). likes.add(ServerAPI.me()). comments.add(firstPost); List<Post> response = new ArrayList<>(); response.add(dummyPost); return response; } return null; } ServerAPI The method accepts the time of the last post so we can fetch the posts "since" that time
  • 11. return me; } public static List<Post> fetchTimelinePosts(long since, int amount) { if(since >= initTime) { Comment firstPost = new Comment(). date.set(System.currentTimeMillis()). text.set("First post!!!"). id.set("Comment1"). userId.set(ServerAPI.me().id.get()); Post dummyPost = new Post(). user.set(ServerAPI.me()). content.set("This is a <b>POST</b> that includes HTML"). date.set(System.currentTimeMillis() - 60000). id.set("Post1"). likes.add(ServerAPI.me()). comments.add(firstPost); List<Post> response = new ArrayList<>(); response.add(dummyPost); return response; } return null; } } ServerAPI We add a comment so the comment count wouldn't be 0. There is still no comment view though
  • 12. return me; } public static List<Post> fetchTimelinePosts(long since, int amount) { if(since >= initTime) { Comment firstPost = new Comment(). date.set(System.currentTimeMillis()). text.set("First post!!!"). id.set("Comment1"). userId.set(ServerAPI.me().id.get()); Post dummyPost = new Post(). user.set(ServerAPI.me()). content.set("This is a <b>POST</b> that includes HTML"). date.set(System.currentTimeMillis() - 60000). id.set("Post1"). likes.add(ServerAPI.me()). comments.add(firstPost); List<Post> response = new ArrayList<>(); response.add(dummyPost); return response; } return null; } } ServerAPI The post itself doesn't include much either, just some HTML for the post content
  • 13. } public static List<Post> fetchTimelinePosts(long since, int amount) { if(since >= initTime) { Comment firstPost = new Comment(). date.set(System.currentTimeMillis()). text.set("First post!!!"). id.set("Comment1"). userId.set(ServerAPI.me().id.get()); Post dummyPost = new Post(). user.set(ServerAPI.me()). content.set("This is a <b>POST</b> that includes HTML"). date.set(System.currentTimeMillis() - 60000). id.set("Post1"). likes.add(ServerAPI.me()). comments.add(firstPost); List<Post> response = new ArrayList<>(); response.add(dummyPost); return response; } return null; } } ServerAPI We return null when there is no further information. That's it, we are almost ready to implement the newsfeed!
  • 14. public class UIUtils { public static final long HOUR = 60 * 60000; public static final long DAY = 24 * HOUR; public static Label createSpace() { Label l = new Label("", "PaddedSeparator"); l.setShowEvenIfBlank(true); return l; } public static Label createHalfSpace() { Label l = new Label("", "HalfPaddedSeparator"); l.setShowEvenIfBlank(true); return l; } public static String formatTimeAgo(long time) { long current = System.currentTimeMillis() - time; if(current < HOUR) { long minutes = current / 60000; if(minutes < 2) { return "Just now"; } return minutes + " minutes ago"; } UIUtils Before I start with the newsfeed itself I'd like a couple of utility methods. For that I'll add a UIUtils class as such. I use these to present time logic more effectively
  • 15. public class UIUtils { public static final long HOUR = 60 * 60000; public static final long DAY = 24 * HOUR; public static Label createSpace() { Label l = new Label("", "PaddedSeparator"); l.setShowEvenIfBlank(true); return l; } public static Label createHalfSpace() { Label l = new Label("", "HalfPaddedSeparator"); l.setShowEvenIfBlank(true); return l; } public static String formatTimeAgo(long time) { long current = System.currentTimeMillis() - time; if(current < HOUR) { long minutes = current / 60000; if(minutes < 2) { return "Just now"; } return minutes + " minutes ago"; } UIUtils These create a gray spacer that's used in several places in the Facebook UI
  • 16. l.setShowEvenIfBlank(true); return l; } public static Label createHalfSpace() { Label l = new Label("", "HalfPaddedSeparator"); l.setShowEvenIfBlank(true); return l; } public static String formatTimeAgo(long time) { long current = System.currentTimeMillis() - time; if(current < HOUR) { long minutes = current / 60000; if(minutes < 2) { return "Just now"; } return minutes + " minutes ago"; } if(current < HOUR * 10) { return (current / HOUR) + " hours ago"; } return L10NManager.getInstance(). formatDateTimeShort(new Date(time)); } } UIUtils This method formats time as statements such as "just now", "15 minutes ago" etc. then falls back to standard date & time values. We use this when displaying time on posts. We'll use these in the NewsfeedContainer class.
  • 17. PaddedSeparator { background: #DCDEE3; padding: 0.5mm; margin: 0px; } HalfPaddedSeparator { cn1-derive: PaddedSeparator; padding: 0.25mm; } theme.css But before we get there there we have the missing CSS statements for the UIID's we used in the listing. These separators have the gray background and right amount of padding to match the UI