Loading...

"The solution often turns out more beautiful than the puzzle."

Arushi Pant

Always eager to learn. Determined to make the best of the time I've got on Earth.

Project 2 - Android Developer Nanodegree

Posted on June 19, 2018

I am currently pursuing an Android Developer Nanodegree by Udacity[1] & Google. This post is about the 2nd Project I created as part of the Nanodegree.

Each project is bringing us further learning. I implemented endless scrolling for a recyclerview the first time. Also, the recyclerview had a Grid layout, with the number of items per row changing according to orientation.

 

Project screenshot 

The major concepts covered in this project were -

1. Use of Retrofit to get data from API

2. Use of Glide to display images from URLs

3. Recyclerview and GridLayoutManager

4. Handling of no network connectivity cases

5. Intents to navigate to new activities

6. Layout changes according to device orientation change

7. Gif as loading image

8. Endless scroll for recyclerview

9. onSaveInstanceState() to restore state after orientation change

 

You can view my code here - Github link

Apart from all the learning I got while creating the app, there was more coming my way with the code review. I love their code reviews. Always a great suggestion on how to make the app better.

Below is the code I had used in order to show a different grid column count for the different orientations.

/* Grid layout column count according to orientation */
int spanCount = 2;
if(getResources().getConfiguration().orientation 
                             == Configuration.ORIENTATION_LANDSCAPE){
            spanCount = 3;
}

 

The reviewer suggested a better way.

We need a variable that depends on a current orientation - the spanCount. Just like all other resources that can be defined differently for the portrait/landscape orientation, we can create a integer variable here too.

So, in the resources folder, we have integers.xml with the below code:

<integer name="span_count">2</integer>

 

And for landscape orientation, we override the value to 3 in the values-land package

<integer name="span_count">3</integer>

 

In this way, we can access this value without checking current orientation manually:

int spanCount = getResources().getInteger(R.integer.span_count);

 

Makes perfect sense! Yet, I had not thought of it even though I use the different qualifier packages for different layouts, strings, etc. You can read more about this here - Supporting orientation, screen sizes and localization 

 

Well, still got a lot to learn!   👩‍💻

 

By the way, here's the video of my app -

[1] Referral link - Will give you a Rs. 1000 cashback on your first Nanodegree enrollment


Liked the post?

Show your appreciation, and share with others.