# Project 1 (Flicks Client) Helpful Hints
Below is a list of useful notes you may find helps save you time while developing the Flicks client or running into problems:
* **Tip #1**: Make sure to review the [Movie API](https://www.themoviedb.org/documentation/api) and what the expected response looks like.
* [Now Playing API response](https://api.themoviedb.org/3/movie/now_playing?api_key=a07e22bc18f5cb106bfe4cc1f83ad8ed)
* [Configurations API response](https://api.themoviedb.org/3/configuration?api_key=a07e22bc18f5cb106bfe4cc1f83ad8ed) to see what image sizes can be used. For instance, movie posters come back with URLs prefixed as `https://image.tmdb.org/t/p/[IMAGE_SIZE]` (i.e. <https://image.tmdb.org/t/p/w342/aKx1ARwG55zZ0GpRvU2WrGrCG9o.jpg>).
* [Videos API Response](https://api.themoviedb.org/3/movie/209112/videos?api_key=a07e22bc18f5cb106bfe4cc1f83ad8ed)
* [Trailer API response](https://api.themoviedb.org/3/movie/209112/trailers?api_key=a07e22bc18f5cb106bfe4cc1f83ad8ed)
* **Tip #2**: Scrolling vertically on Android emulator is done via pushing down on the left mouse and dragging up as you would do to scroll with your finger on the device.
* **Problem #1**: Can't get back the JSON Response! A number of people always run into issues with their emulator and not being able to access the Movie Database API. If you are pretty sure you have the code right and you can't seem to get any response back from the API, try these steps:
* Getting `No address associated with hostname` exception? Emulator doesn't have internet, try a restart.
* Check the URL to ensure that you are passing the correct `client_id` with the request.
* Make sure you have added the internet permission
`<uses-permission android:name="android.permission.INTERNET" />` to your manifest.
* Ensure the emulator has [access to the internet](http://i.imgur.com/kZqZko6.gif), otherwise all network requests fail.
* Restart the emulator (close window and relaunch) until you have verified internet access above.
* Obtain the exact url (by breakpointing or logging) that you are going to send a request to and paste the url into your browser to verify the API response is coming back correctly.
* Make sure you are using the `new JsonHttpResponseHandler()`([source](https://github.com/codepath/AsyncHttpClient/blob/master/library/src/main/java/com/codepath/asynchttpclient/callback/JsonHttpResponseHandler.java)) in your AsyncHttpClient network call and make sure you are sending
`client.get(url, new JsonHttpResponseHandler() { ... })`
* Verify that the onSuccess signature is correct. The Movie Database API returns a JSON dictionary so make sure the onSuccess is using JSONObject and not JSONArray in this case. This is entirely dependent on whether a dictionary or array is the root object i.e
`public void onSuccess(int statusCode, Headers headers, JSON response)`
* Add an `onFailure` to the `JsonHttpResponseHandler` callbacks and log there to ensure that its not being hit
* Check your LogCat to make sure there are no specific error messages, use filters to more easily read the log.
* [Uninstall the app](http://stackoverflow.com/questions/12447839/how-to-uninstall-my-app-from-android-emulator-on-a-mac-10-7-4) from the emulator and allow it to be fully re-installed by relaunching it from within Android Studio.
* **Problem #2**: Parsing JSON data can raise an exception if certain keys are null! When parsing JSON data, you want to program defensively and verify that keys exist and are not null. You can verify that a key exists with the `notNull` method or optionally extract a key (only if it exists) with the `opt` prefix method. For example, `if (movieJSON.optString("title") != null) { ... }` will extract the title as a string only if the value is not null and will return null otherwise.
* **Problem #3**: If you see that the placeholder() or transformation() methods doesn't exist for Glide, double check to see that you've followed the [setup instructions here](https://guides.codepath.org/android/Displaying-Images-with-the-Glide-Library#setup).
* **Problem #4**: If you get a StatusCode 500 error when making an API call, it may be a glitch on your emulator. Here are some solutions that have resolved this issue for other students in the past: (1) quit and restart your emulator, then try again; or, (2) quit the emulator, then clear your emulator by clicking the "Wipe Data" button in the AVD Manager tool on Android Studio, then try again; or, (3) in your computer's network/Internet connection settings, manually set your DNS to "8.8.8.8", then try again.
* **Tip #3**: To make the UI of your Flicks client, switch to XML view of your activity layout and play around with different [attributes](http://guides.codepath.org/android/Defining-Views-and-their-Attributes). Read more about this in our [RelativeLayout Cliffnotes](http://guides.codepath.org/android/Constructing-View-Layouts#relativelayout).
* **Tip #4**: To provide an alternate resource layout for landscape mode, simply place the layout file in a `res/layout-land` directory. You can also reuse layouts using `<merge>` or `<include>` tags.
* **Tip #5**: Making the photo appear properly allows for experimentation with a few different properties.
* First, check out the different [scale types](http://guides.codepath.org/android/Working-with-the-ImageView#scale-types) for the ImageView and make sure to set `adjustViewBounds` to true.
* When loading with Picasso, experiment with different loading behaviors such as `.fit().centerInside()` or `.resize(x, y)` specified before the `.into(...)` command.
* To resize an image and preserve aspect ratio, as of Picasso 2.5.2 you can simply supply `0` for one of the arguments i.e `.resize(150, 0)`
* If you want to determine the width of the screen, you can check the width of the layout item or use this [device dimensions helper](https://gist.github.com/nesquena/318b6930aac3a56f96a4)
* In the adapter, you can calculate the aspect ratio of the image (`width / height`) and then set the ImageView width to screen width and the height to correct calculated height to maintain the aspect ratio of the image.
* **Tip #6**: To use a custom launcher icon for the app, you can first download an .SVG image from [IconFinder](https://www.iconfinder.com/). Within the Android project select `New → Vector Image Asset` and browse to find the image file. You can use this tool which will generate the icon in a Vector Drawable format.