SlideShare a Scribd company logo
1 of 12
Download to read offline
Creating an Uber Clone - Part XXIX
public class Ride implements PropertyBusinessObject {
public final LongProperty<Ride> userId = new LongProperty<>("userId");
public final Property<String, Ride> name = new Property<>("name");
public final Property<String, Ride> from = new Property<>("from");
public final Property<String, Ride> destination = new Property<>("destination");
private final PropertyIndex idx = new PropertyIndex(this, "Ride",
userId, name, from, destination);
@Override
public PropertyIndex getPropertyIndex() {
return idx;
}
}
Ride (Client Side)
public class DriverService {
private static String currentRide;
public static void fetchRideDetails(long id,
SuccessCallback<Ride> rideDetails) {
Rest.get(SERVER_URL + "ride/get").
acceptJson().queryParam("id", "" + id).
getAsJsonMap(response -> {
Map data = response.getResponseData();
if(data != null) {
Ride r = new Ride();
r.getPropertyIndex().populateFromMap(data);
rideDetails.onSucess(r);
}
});
}
public static boolean acceptRide(long id) {
Response<String> response =
Rest.get(SERVER_URL + "ride/accept").
acceptJson().
queryParam("token", UserService.getToken()).
queryParam("userId", "" + id).
getAsString();
if(response.getResponseCode() == 200) {
currentRide = response.getResponseData();
return true;
}
return false;
DriverService
public class DriverService {
private static String currentRide;
public static void fetchRideDetails(long id,
SuccessCallback<Ride> rideDetails) {
Rest.get(SERVER_URL + "ride/get").
acceptJson().queryParam("id", "" + id).
getAsJsonMap(response -> {
Map data = response.getResponseData();
if(data != null) {
Ride r = new Ride();
r.getPropertyIndex().populateFromMap(data);
rideDetails.onSucess(r);
}
});
}
public static boolean acceptRide(long id) {
Response<String> response =
Rest.get(SERVER_URL + "ride/accept").
acceptJson().
queryParam("token", UserService.getToken()).
queryParam("userId", "" + id).
getAsString();
if(response.getResponseCode() == 200) {
currentRide = response.getResponseData();
return true;
}
return false;
DriverService
public class DriverService {
private static String currentRide;
public static void fetchRideDetails(long id,
SuccessCallback<Ride> rideDetails) {
Rest.get(SERVER_URL + "ride/get").
acceptJson().queryParam("id", "" + id).
getAsJsonMap(response -> {
Map data = response.getResponseData();
if(data != null) {
Ride r = new Ride();
r.getPropertyIndex().populateFromMap(data);
rideDetails.onSucess(r);
}
});
}
public static boolean acceptRide(long id) {
Response<String> response =
Rest.get(SERVER_URL + "ride/accept").
acceptJson().
queryParam("token", UserService.getToken()).
queryParam("userId", "" + id).
getAsString();
if(response.getResponseCode() == 200) {
currentRide = response.getResponseData();
return true;
}
return false;
DriverService
}
public static boolean acceptRide(long id) {
Response<String> response =
Rest.get(SERVER_URL + "ride/accept").
acceptJson().
queryParam("token", UserService.getToken()).
queryParam("userId", "" + id).
getAsString();
if(response.getResponseCode() == 200) {
currentRide = response.getResponseData();
return true;
}
return false;
}
public static void startRide() {
Rest.post(SERVER_URL + "ride/start").
acceptJson().
queryParam("id", currentRide).
getAsString();
}
public static void finishRide() {
Rest.post(SERVER_URL + "ride/finish").
acceptJson().
queryParam("id", currentRide).
getAsString();
}
}
DriverService
public static void findLocation(String name,
SuccessCallback<Coord> location) {
Rest.get("https://maps.googleapis.com/maps/api/geocode/json").
queryParam("address", name).
queryParam("key", Globals.GOOGLE_GEOCODING_KEY).
getAsJsonMap(callbackMap -> {
Map data = callbackMap.getResponseData();
if(data != null) {
List results = (List)data.get("results");
if(results != null && results.size() > 0) {
Map firstResult = (Map)results.get(0);
Map geometryMap = (Map)firstResult.get("geometry");
Map locationMap = (Map)geometryMap.get("location");
double lat = Util.toDoubleValue(locationMap.get("lat"));
double lon = Util.toDoubleValue(locationMap.get("lng"));
location.onSucess(new Coord(lat, lon));
}
}
});
}
SearchService
public class UserService {
private static User me;
public static User getUser() {
return me;
}
public static String getToken() {
if(UberClone.isDriverMode()) {
return Preferences.get("driver-token", null);
} else {
return Preferences.get("token", null);
}
}
public static void loadUser() {
me = new User();
if(UberClone.isDriverMode()) {
PreferencesObject.create(me).setPrefix("driver").bind();
} else {
PreferencesObject.create(me).bind();
}
if(Display.getInstance().isSimulator()) {
Log.p("User details: " + me.getPropertyIndex().toString());
}
}
UserService
public class UserService {
private static User me;
public static User getUser() {
return me;
}
public static String getToken() {
if(UberClone.isDriverMode()) {
return Preferences.get("driver-token", null);
} else {
return Preferences.get("token", null);
}
}
public static void loadUser() {
me = new User();
if(UberClone.isDriverMode()) {
PreferencesObject.create(me).setPrefix("driver").bind();
} else {
PreferencesObject.create(me).bind();
}
if(Display.getInstance().isSimulator()) {
Log.p("User details: " + me.getPropertyIndex().toString());
}
}
UserService
public class UserService {
private static User me;
public static User getUser() {
return me;
}
public static String getToken() {
if(UberClone.isDriverMode()) {
return Preferences.get("driver-token", null);
} else {
return Preferences.get("token", null);
}
}
public static void loadUser() {
me = new User();
if(UberClone.isDriverMode()) {
PreferencesObject.create(me).setPrefix("driver").bind();
} else {
PreferencesObject.create(me).bind();
}
if(Display.getInstance().isSimulator()) {
Log.p("User details: " + me.getPropertyIndex().toString());
}
}
UserService
public static void registerPushToken(String pushToken) {
Rest.get(SERVER_URL + "user/setPushToken").
queryParam("token", getToken()).
queryParam("pushToken", pushToken).getAsStringAsync(
new Callback<Response<String>>() {
@Override
public void onSucess(Response<String> value) {
}
@Override
public void onError(Object sender, Throwable err, int errorCode,
String errorMessage) {
}
});
}
public static boolean addNewUser(User u) {
Response<String> token = Rest.post(SERVER_URL + "user/add").
jsonContent().
body(u.getPropertyIndex().toJSON()).getAsString();
if(token.getResponseCode() != 200) {
return false;
}
UserService
public static boolean addNewUser(User u) {
Response<String> token = Rest.post(SERVER_URL + "user/add").
jsonContent().
body(u.getPropertyIndex().toJSON()).getAsString();
if(token.getResponseCode() != 200) {
return false;
}
if(UberClone.isDriverMode()) {
Preferences.set("driver-token", token.getResponseData());
registerPush();
} else {
Preferences.set("token", token.getResponseData());
}
return true;
}
public static void loginWithPhone(String phoneNumber,
String password, final SuccessCallback<User> onSuccess,
final FailureCallback<Object> onError) {
Rest.get(SERVER_URL + "user/login").
acceptJson().
queryParam("password", password).
queryParam("phone", phoneNumber).
UserService

More Related Content

Similar to Creating an Uber Clone - Part XXIX.pdf

Creating an Uber Clone - Part XVI.pdf
Creating an Uber Clone - Part XVI.pdfCreating an Uber Clone - Part XVI.pdf
Creating an Uber Clone - Part XVI.pdfShaiAlmog1
 
Creating an Uber Clone - Part XXX - Transcript.pdf
Creating an Uber Clone - Part XXX - Transcript.pdfCreating an Uber Clone - Part XXX - Transcript.pdf
Creating an Uber Clone - Part XXX - Transcript.pdfShaiAlmog1
 
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Astrails
 
Creating an Uber Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part XV - Transcript.pdfCreating an Uber Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part XV - Transcript.pdfShaiAlmog1
 
Developing Apps for Emerging Markets
Developing Apps for Emerging MarketsDeveloping Apps for Emerging Markets
Developing Apps for Emerging MarketsAnnyce Davis
 
React Native: Developing an app similar to Uber in JavaScript
React Native: Developing an app similar to Uber in JavaScriptReact Native: Developing an app similar to Uber in JavaScript
React Native: Developing an app similar to Uber in JavaScriptCaio Ariede
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced RoutingAlexe Bogdan
 
import java-util--- import java-io--- class Vertex { -- Constructo.docx
import java-util--- import java-io---   class Vertex {   -- Constructo.docximport java-util--- import java-io---   class Vertex {   -- Constructo.docx
import java-util--- import java-io--- class Vertex { -- Constructo.docxBlake0FxCampbelld
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxssuser562afc1
 
Spca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_serviceSpca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_serviceNCCOMMS
 
Web2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API RESTWeb2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API RESTNicolas Faugout
 
No internet? No Problem!
No internet? No Problem!No internet? No Problem!
No internet? No Problem!Annyce Davis
 
Assignment7.pdf
Assignment7.pdfAssignment7.pdf
Assignment7.pdfdash41
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013Laurent_VB
 
Web+GISという視点から見たGISの方向性
Web+GISという視点から見たGISの方向性Web+GISという視点から見たGISの方向性
Web+GISという視点から見たGISの方向性Hidenori Fujimura
 
AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS ServicesEyal Vardi
 

Similar to Creating an Uber Clone - Part XXIX.pdf (20)

Creating an Uber Clone - Part XVI.pdf
Creating an Uber Clone - Part XVI.pdfCreating an Uber Clone - Part XVI.pdf
Creating an Uber Clone - Part XVI.pdf
 
Creating an Uber Clone - Part XXX - Transcript.pdf
Creating an Uber Clone - Part XXX - Transcript.pdfCreating an Uber Clone - Part XXX - Transcript.pdf
Creating an Uber Clone - Part XXX - Transcript.pdf
 
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
 
Creating an Uber Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part XV - Transcript.pdfCreating an Uber Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part XV - Transcript.pdf
 
Developing Apps for Emerging Markets
Developing Apps for Emerging MarketsDeveloping Apps for Emerging Markets
Developing Apps for Emerging Markets
 
React Native: Developing an app similar to Uber in JavaScript
React Native: Developing an app similar to Uber in JavaScriptReact Native: Developing an app similar to Uber in JavaScript
React Native: Developing an app similar to Uber in JavaScript
 
Express JS
Express JSExpress JS
Express JS
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced Routing
 
import java-util--- import java-io--- class Vertex { -- Constructo.docx
import java-util--- import java-io---   class Vertex {   -- Constructo.docximport java-util--- import java-io---   class Vertex {   -- Constructo.docx
import java-util--- import java-io--- class Vertex { -- Constructo.docx
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
 
Spca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_serviceSpca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_service
 
Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2
 
Web2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API RESTWeb2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API REST
 
No internet? No Problem!
No internet? No Problem!No internet? No Problem!
No internet? No Problem!
 
Assignment7.pdf
Assignment7.pdfAssignment7.pdf
Assignment7.pdf
 
app.js.docx
app.js.docxapp.js.docx
app.js.docx
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013
 
Web+GISという視点から見たGISの方向性
Web+GISという視点から見たGISの方向性Web+GISという視点から見たGISの方向性
Web+GISという視点から見たGISの方向性
 
AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS Services
 

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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 

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 - 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
 

Recently uploaded

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Recently uploaded (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Creating an Uber Clone - Part XXIX.pdf

  • 1. Creating an Uber Clone - Part XXIX
  • 2. public class Ride implements PropertyBusinessObject { public final LongProperty<Ride> userId = new LongProperty<>("userId"); public final Property<String, Ride> name = new Property<>("name"); public final Property<String, Ride> from = new Property<>("from"); public final Property<String, Ride> destination = new Property<>("destination"); private final PropertyIndex idx = new PropertyIndex(this, "Ride", userId, name, from, destination); @Override public PropertyIndex getPropertyIndex() { return idx; } } Ride (Client Side)
  • 3. public class DriverService { private static String currentRide; public static void fetchRideDetails(long id, SuccessCallback<Ride> rideDetails) { Rest.get(SERVER_URL + "ride/get"). acceptJson().queryParam("id", "" + id). getAsJsonMap(response -> { Map data = response.getResponseData(); if(data != null) { Ride r = new Ride(); r.getPropertyIndex().populateFromMap(data); rideDetails.onSucess(r); } }); } public static boolean acceptRide(long id) { Response<String> response = Rest.get(SERVER_URL + "ride/accept"). acceptJson(). queryParam("token", UserService.getToken()). queryParam("userId", "" + id). getAsString(); if(response.getResponseCode() == 200) { currentRide = response.getResponseData(); return true; } return false; DriverService
  • 4. public class DriverService { private static String currentRide; public static void fetchRideDetails(long id, SuccessCallback<Ride> rideDetails) { Rest.get(SERVER_URL + "ride/get"). acceptJson().queryParam("id", "" + id). getAsJsonMap(response -> { Map data = response.getResponseData(); if(data != null) { Ride r = new Ride(); r.getPropertyIndex().populateFromMap(data); rideDetails.onSucess(r); } }); } public static boolean acceptRide(long id) { Response<String> response = Rest.get(SERVER_URL + "ride/accept"). acceptJson(). queryParam("token", UserService.getToken()). queryParam("userId", "" + id). getAsString(); if(response.getResponseCode() == 200) { currentRide = response.getResponseData(); return true; } return false; DriverService
  • 5. public class DriverService { private static String currentRide; public static void fetchRideDetails(long id, SuccessCallback<Ride> rideDetails) { Rest.get(SERVER_URL + "ride/get"). acceptJson().queryParam("id", "" + id). getAsJsonMap(response -> { Map data = response.getResponseData(); if(data != null) { Ride r = new Ride(); r.getPropertyIndex().populateFromMap(data); rideDetails.onSucess(r); } }); } public static boolean acceptRide(long id) { Response<String> response = Rest.get(SERVER_URL + "ride/accept"). acceptJson(). queryParam("token", UserService.getToken()). queryParam("userId", "" + id). getAsString(); if(response.getResponseCode() == 200) { currentRide = response.getResponseData(); return true; } return false; DriverService
  • 6. } public static boolean acceptRide(long id) { Response<String> response = Rest.get(SERVER_URL + "ride/accept"). acceptJson(). queryParam("token", UserService.getToken()). queryParam("userId", "" + id). getAsString(); if(response.getResponseCode() == 200) { currentRide = response.getResponseData(); return true; } return false; } public static void startRide() { Rest.post(SERVER_URL + "ride/start"). acceptJson(). queryParam("id", currentRide). getAsString(); } public static void finishRide() { Rest.post(SERVER_URL + "ride/finish"). acceptJson(). queryParam("id", currentRide). getAsString(); } } DriverService
  • 7. public static void findLocation(String name, SuccessCallback<Coord> location) { Rest.get("https://maps.googleapis.com/maps/api/geocode/json"). queryParam("address", name). queryParam("key", Globals.GOOGLE_GEOCODING_KEY). getAsJsonMap(callbackMap -> { Map data = callbackMap.getResponseData(); if(data != null) { List results = (List)data.get("results"); if(results != null && results.size() > 0) { Map firstResult = (Map)results.get(0); Map geometryMap = (Map)firstResult.get("geometry"); Map locationMap = (Map)geometryMap.get("location"); double lat = Util.toDoubleValue(locationMap.get("lat")); double lon = Util.toDoubleValue(locationMap.get("lng")); location.onSucess(new Coord(lat, lon)); } } }); } SearchService
  • 8. public class UserService { private static User me; public static User getUser() { return me; } public static String getToken() { if(UberClone.isDriverMode()) { return Preferences.get("driver-token", null); } else { return Preferences.get("token", null); } } public static void loadUser() { me = new User(); if(UberClone.isDriverMode()) { PreferencesObject.create(me).setPrefix("driver").bind(); } else { PreferencesObject.create(me).bind(); } if(Display.getInstance().isSimulator()) { Log.p("User details: " + me.getPropertyIndex().toString()); } } UserService
  • 9. public class UserService { private static User me; public static User getUser() { return me; } public static String getToken() { if(UberClone.isDriverMode()) { return Preferences.get("driver-token", null); } else { return Preferences.get("token", null); } } public static void loadUser() { me = new User(); if(UberClone.isDriverMode()) { PreferencesObject.create(me).setPrefix("driver").bind(); } else { PreferencesObject.create(me).bind(); } if(Display.getInstance().isSimulator()) { Log.p("User details: " + me.getPropertyIndex().toString()); } } UserService
  • 10. public class UserService { private static User me; public static User getUser() { return me; } public static String getToken() { if(UberClone.isDriverMode()) { return Preferences.get("driver-token", null); } else { return Preferences.get("token", null); } } public static void loadUser() { me = new User(); if(UberClone.isDriverMode()) { PreferencesObject.create(me).setPrefix("driver").bind(); } else { PreferencesObject.create(me).bind(); } if(Display.getInstance().isSimulator()) { Log.p("User details: " + me.getPropertyIndex().toString()); } } UserService
  • 11. public static void registerPushToken(String pushToken) { Rest.get(SERVER_URL + "user/setPushToken"). queryParam("token", getToken()). queryParam("pushToken", pushToken).getAsStringAsync( new Callback<Response<String>>() { @Override public void onSucess(Response<String> value) { } @Override public void onError(Object sender, Throwable err, int errorCode, String errorMessage) { } }); } public static boolean addNewUser(User u) { Response<String> token = Rest.post(SERVER_URL + "user/add"). jsonContent(). body(u.getPropertyIndex().toJSON()).getAsString(); if(token.getResponseCode() != 200) { return false; } UserService
  • 12. public static boolean addNewUser(User u) { Response<String> token = Rest.post(SERVER_URL + "user/add"). jsonContent(). body(u.getPropertyIndex().toJSON()).getAsString(); if(token.getResponseCode() != 200) { return false; } if(UberClone.isDriverMode()) { Preferences.set("driver-token", token.getResponseData()); registerPush(); } else { Preferences.set("token", token.getResponseData()); } return true; } public static void loginWithPhone(String phoneNumber, String password, final SuccessCallback<User> onSuccess, final FailureCallback<Object> onError) { Rest.get(SERVER_URL + "user/login"). acceptJson(). queryParam("password", password). queryParam("phone", phoneNumber). UserService