Skip to content

amitittyerah/Android-Training

 
 

Repository files navigation

Gridstone Android Training

A starting point for those interested in learning the ways of the little green robot. This README provides details on a small training app that you will build. This is not a step-by-step tutorial, but rather a set of requirements, restrictions, and tips on how you should go about building an app.

This means that you'll be doing a lot of learning on your own to build this training app, but it should set you on the path of learning what Android development is like. If you need a bit more of a leg-up before attempting something like this, consider undertaking Google's Udacity course on beginning Android development.

However, if this is the droid you're looking for, read on.

Your Task

You will be building an app that interfaces with the Imgur API to download a collection of trending images and display them in a list. The user must be able to tap on each item in the list to view a larger version of that image and some details about it.

Getting Started

Fork this repository! This repository contains a bare-bones empty app that doesn't do anything. (It's even more bare-bones than what Android Studio gives you for a new project, and that's very deliberate).

It is however already set up to use app-compat, which you'll need to achieve a material design look and feel on older devices. The application theme has already been set up for you, so you just need to think about actually building the app, not configuring styles.

During your development, feel free to throw questions at any Android developer at Gridstone. They should be able to help you out, and don't bite often.

When you've finished, give a Gridstone Android developer read access to your repository. You can also ask @chris-horner for access to his implementation.

Here are the states your app will need to display. Loading the list, displaying the list, and displaying item details.

The Requirements

###Code Style

At Gridstone, we make use of Square's code styles for our Java and XML. Your repository must adhere to those styles, so run the install script from the aforementioned link and make sure you're using it to format your code in Android Studio.

###General Android-y Stuff

  • Your app must run on Android 4.1 Jelly Bean and up. (That's API level 16).
  • All network requests must execute off the main UI thread.
  • The list must be displayed using a RecyclerView.
  • The app must work in both portrait and landscape orientations
    • It must remember the list's scroll position between orientation changes. (Harder than it sounds).
    • It must not re-download the list of images on an orientation change.

###The Data

To get the list of images, you'll need to make a network request to Imgur's API. Specifically, you'll be calling:

https://api.imgur.com/3/gallery/

You will also need to insert a client ID for authorization in the header of your network request. To save you time, you can simply ensure you are appending this header name-value:

"Authorization" "Client-ID 3436c108ccc17d3"

As per the documentation on this call, there are a few parameters that you can use to tweak what kind of gallery is delivered back to you. In the interest of keeping things simple for this app however, we'll stick to the defaults.

The response you get from Imgur will be in JSON, which is perfect. The structure of each Image object is described here in Imgur's API documentation. There are quite a few fields here, but for the purposes of this demo we can focus on just a few. Specifically:

title
datetime
width
height
views
link
is_album

This API does have one shortcoming for our simple training app: Albums are returned alongside regular images, and there is no mechanism in the REST API to filter those out. This is something you must do yourself in your app.

###The User Interface

This app will be composed of two screens. The list screen and the details screen.

####For the list

  • In the list screen, each image must be 200dp tall, and as wide as the screen.
  • There must be a gap of 1dp between each image.
  • Each image should be centre-cropped, meaning that within the bounds of width * height, the image cannot be stretched or show any blank areas.
  • The title of the image must be displayed on top of each image (as shown in the screenshot above)
  • While the list of images is downloading, you must display an indeterminate ProgressBar.
    • You do not need to display the progress bar while the images themselves download (as that's a lot of images), just while you retrieve the list.

####For the details

  • You must display the image to take up the entire screen
  • You must display the title, time ago, width, height, and view count as shown in the sample screenshot.

Some Tips

Downloading images, caching them, and putting them into ImageViews is crazy complex! Thankfully, a library called Picasso developed by Square turns that process into a single line of code.

Since you'll be interfacing with a REST API, you'll need to execute HTTP requests and parse response data. If you'd like a simple way to execute a request and map it simple model objects, consider Retrofit, another library by Square. It does have a learning curve, but it makes interfacing with web services much simpler!

Beware AsyncTask! It might seem like a convenient way to do work off the main thread, but it has many shortcomings! (Chiefly, it's very easy to leak memory like a sieve). Consider the callback options Retrofit provides, or an IntentService, or even RxJava if you're feeling adventurous.

When structuring the navigation between two screens, you have many options available to you. You could use multiple Activities, or a single Activity that moves between Fragments. Or you could even go nuts and use a library like Conductor. Whatever you choose, you're going to discover that architecting data-flow is one of the hardest parts to Android development. Consider executing and caching your network request in something that isn't your Activity or Fragment.

If you're super keen, you can also try writing this app in Kotlin. It will make your job much harder if you're still learning, but the option is there for those who want a challenge, cleaner codebase, and a modern language.

About

Learning the ways of the little green men.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%