Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions lift-app-challenge/_create_and_edit_lift.html.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
## Creating and editing a lift
Now that we have designed the basic layout for MainActivity we will proceed to design an UI for creating and editing a lift in **CreateLiftActivity**.
A lift entity consists of four attributes:
* Phone number: The phone number of the car owner.
* Location: The initial location of the lift.
* Start time from home : The departure time from the location.
* Start time from office : The departure time from the office.

For the UI of **CreateLiftActivity**, create a new xml file called **activity_create_lift.xml** and paste the code into the file shown below.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >

<ScrollView
android:id="@+id/Scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout
android:id="@+id/LLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<LinearLayout
android:id="@+id/phn_block"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="horizontal" >

<TextView
android:id="@+id/phn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="35"
android:text="@string/lbl_phn" />

<EditText
android:id="@+id/fld_phn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="65"
android:hint="@string/lbl_enter_phn"
android:inputType="textPhonetic" />
</LinearLayout>

<LinearLayout
android:id="@+id/location_block"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
android:id="@+id/location"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="35"
android:text="@string/lbl_location" />

<EditText
android:id="@+id/fld_location"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="65"
android:hint="@string/lbl_enter_location"
android:inputType="textPhonetic" />
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#666666" />

<LinearLayout
android:id="@+id/stime_block"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
android:id="@+id/stime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="20"
android:text="@string/lbl_stime" />

<TimePicker
android:id="@+id/fld_stime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="80" />
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#666666" />

<LinearLayout
android:id="@+id/etime_block"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
android:id="@+id/etime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="20"
android:text="@string/lbl_etime" />

<TimePicker
android:id="@+id/fld_etime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="80" />
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#666666" />

<Button
android:id="@+id/lift_submit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/lbl_create" />
</LinearLayout>
</ScrollView>
</RelativeLayout>

You should now have a layout looking like this:


##Tasks

1. Make MainActivity a one time post-install activty. When the user opens the app for the second time the MainActivity should be skipped to the LiftListActivity.
2. In CreateLiftActivity, store the lift details entered by the user in SharedPreference. We need to mandate that you store the token details in your app in **codelearn_liftapp** SharedPreference with keys **key_pref_phone** for the phone number, **key_pref_location** for the location, **key_pref_stime** for the start time from home & **key_pref_etime** for the start time from office.
3. Add a menu item to LiftListActivity which allows the user to edit/create the lift details. The user should be presented with the create lift screen with the fields populated with the lift details if a lift has already been created or left empty if not. The user should then be able to edit the lift details or create a new one.

##Restrictions
1. The lift data must be stored in a SharedPreference file named "codelearn_liftapp".
2. The start from home and start from office values retrieved from the TimePicker views must be stored in the format: **"HH:mm"**.
3. The resource file for populating the menu in LiftListActivity should be named **lift_list.xml**.
17 changes: 17 additions & 0 deletions lift-app-challenge/_create_codelearn_project.html.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

This challenge involves creating a basic car lift app for office-goers. We will be fetching the list of lifts and submitting new lifts using network calls.
In this level, we will create a new Android project, **CodelearnLiftApp** with the following attributes:
* **Package name:** org.codelearn.liftapp
* **Minimum SDK required:** 9 (Android 2.3)
* **Target SDK :** The latest android SDK
* **Initial Activity:** The initial activity of the app should be called **MainActivity**

## Designing the basic layout

The app should now have MainActivity as the initial screen. We need to design the basic layout for MainAcitivty in it's corresponding layout file, **main_acitivity.xml**. We need to link two other activites from the MainActivity to create/edit a lift and fetch the list of all lifts created by other users.


##Tasks

1. Create two blank activites called **CreateLiftActivity** and **LiftListActivity.**
2. Create two buttons in the MainActivity layout with ids, **R.id.create** and **R.id.skip** which launch intents to the **CreateLiftActivity** and **LiftListActivity**, respectively.
76 changes: 76 additions & 0 deletions lift-app-challenge/_fetching_lifts_with_http_get.html.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
##Fetching lifts using HTTP GET calls.

This level focuses on fetching lifts using the Codelearn Test API and displaying them in list in *LiftListActivity* and firing up a new activity *LiftDetailActivity* which displays all the lift data when a lift item is clicked on the list.

###API

Make an HTTP **GET** request call to fetch lift using-
<pre>
http://codelearn-liftapp.herokuapp.com/api/lifts
</pre>

###Request

**Fetching lifts**: A simple GET request without any request parameters is sufficient to get a response.

###Response

**Fetching lifts**: The endpoint will provide an array of lifts as a JSON response when a GET call is received.

<pre>
[
{
"etime": "17:20",
"stime": "14:20",
"location": "narnia",
"phone": "9876543210"
},
{
"etime": "17:32",
"stime": "14:32",
"location": "hogwarts",
"phone": "1234567890"
},
{
"etime": "14:35",
"stime": "8:35",
"location": "mordor",
"phone": "9999988888"
},
{
"etime": "18:14",
"stime": "10:14",
"location": "pandora",
"phone": "9538384545"
}
]
</pre>

## Example

In the JSON response above, the first lift has location narnia followed by hogwarts, mordor & pandora. It should appear as the order below in LiftListScreen

`order of lifts on LiftListActivity`
<pre>
narnia
hogwarts
mordor
pandora
</pre>

##Lift Details

While displaying minimal details about the lifts in the LiftListScreen, we need to fire up a new activity which diplays all the information of the lift when the corresponding lift is clicked on the list. We need to also allow the user to call or message the lift number if the user needs to contact the lift owner. The layout of the lift detail activity can be as follows.


###Tasks

1. Modify LiftListActivity to make an HTTP GET call when the Activity is created to fetch lifts. Handle the received Lift objects and render them in the ListView.

2. Register an **onListItemClick** listener which, on clicking a list item, fires up the activity **LiftDetailAcitivty** to display the corresponding lift details.

2. Add two buttons with ids **R.id.call** and **R.id.message** to call or message the lift phone number repectively. The button click should launch the proper intents.

###Restrictions
* You must only use **AndroidHttpClient** or **DefaultHttpClient** to do network calls as they can only be mocked & tested with Robolectric. Any other library is not supported.
* For JSON parsing, you can use **GSON** & **Jackson** libraries only
75 changes: 75 additions & 0 deletions lift-app-challenge/_http_requests.html.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
## Executing HTTP requests
In this level, your task is to send different types HTTP requests to the Codelearn Test API and handle the response appropriately. We will be submitting and updating lift data and deleting a lift enitiy using the API endpoint.

###Lift creation API
The Codelearn LiftApp API endpoint for submitting the lift data is available at:

<pre>
http://codelearn-liftapp.herokuapp.com/api/create
</pre>

####Request
The JSON request object for the HTTP **POST** request can be as follows.
<pre>
{
"phone" : "9876543219",
"location" : "narnia",
"stime" : "8:15",
"etime" : 16:30"
}
</pre>

Note that the field names must be same as the ones given above.

####Response
The API will provide you with the lift id as a JSON response
Note that this id is unique for each lift entity stored in the database.
<pre>
{
"id" : "_sfdf3rcfht4t553"
}
</pre>

==================================================================================
###Lift updating API
For updating the lift data in the database, a **PUT** request encoded with the lift id can be sent to the API endpoint as follows:
<pre>
http://codelearn-liftapp.herokuapp.com/api/lifts/{{id}}
</pre>
Where ``{{id}}`` should be replaced with your lift id. For example:
<pre>
http://codelearn-liftapp.herokuapp.com/api/lifts/_sfdf3rcfht4t553
</pre>

####Request

The JSON request object for the HTTP **PUT** request should be similar to the **POST** request.
<pre>
{
"phone" : "9876543219",
"location" : "narnia_new",
"stime" : "8:20",
"etime" : 16:40"
}
</pre>

===================================================================================
###Lift deletion API
For deleting a lift enitiy from the database a **DELETE** request encoded with the lift id could be sent to the API endpoint as follows:

<pre>
http://codelearn-liftapp.herokuapp.com/api/lifts/_sfdf3rcfht4t553
</pre>


##Tasks

1. Modify the app the send the lift data to the API endpoint as a HTTP POST call on creating a lift in the CreateLiftActivity.
2. Once you receive a successful response, store the received id in SharedPreference, specifying the name of the preference file as **codelearn_liftapp** and the name of the preference key as **pref_lift_id**
3. For updating the lift data from the edit/create lift screen, a HTTP PUT call must be sent to the API endpoint.
4. Add a menu item to LiftListActivity which allows the user to delete the lift. On clicking the menu item a HTTP DELETE call should be made to the API endpoint.

##Restrictions
1. The lift id must be stored in a SharedPreference file named "codelearn_liftapp" with preference key, *"pref_lift_id".
2. You must use only DefaultHttpClient or AndroidHttpClient for HTTP calls
3. There must be exactly two items i.e edit and delete in the menu of LiftListActivity.