• Home
  • Quick Bytes
  • Algorithms
  • Java
  • iOS
  • Android
  • Certifications
  • About Me

Lets Code Them Up!

  • [DD App] Day 2 – Switching to RecyclerView

    January 14th, 2018

    Hi all,

     

    Today I went further in Delightfull Discoveries application development. And instead of a single textview, switched to a RecyclerView. That involved the following updations –

     

    1. Replacing ScrollView with RecyclerView.
    2. Creating a list item XML with LinearLayout and TextView to hold post titles inside and a view to display a line.
    3. Creating the RecyclerViewAdapter and ViewHolder classes with the required methods.
    4. Updating the MainActivity with RecyclerView object. Using LinearLayoutManager to set the RecyclerView’s orientation to vertical. Setting the Adapter on the object.
    5. Adding item click by making the ViewHolder class implement the View.OnClickListener interface. For now, when we click an item, Toast message is displayed.

    Files Created:

    • PostAdapter [which extends RecyclerView.Adapter class. It creates view holder for each item and binds data to them],
    • PostAdapterViewHolder [as an inner class inside PostAdapter. Extends RecyclerView.ViewHolder class. It creates the view objects and binds them to the item’s layout file. It also handles click actions, for which we implement View.OnCLickListener]
    • PostAdapterOnClickListener [an interface to receive onCLick messages.]
    • post_list_item.xml [layout file for an item inside RecyclerView.]

    Files Edited:

    • MainActivity.java,
    • activity_main.xml

    This is how the app looks right now –

     

    dd-app-day-2-switching-recyclerview RecyclerView showing post titles
    RecyclerView showing post titles
    dd-app-day-2-switching-recyclerview RecyclerView
    Toast message on clicking an item

     

    Today I spent 3 Pomodoros, ie, 1 hour and 15 minutes on this application development. You can follow the progress of this development by going through Day 0 and Day 1 posts.

    That’s all for today,

    See you in next update.

     

  • [DD App] Day 1 – Connecting to WP REST API

    January 13th, 2018

    Hi All,

    I am back as promised with another update regarding my Delightfull Discoveries App. You can check the [DD App] Day 0 post for more details.

    We left last day with the app displaying a placeholder text as you can see in the below image.

     

     

    The next step is to access these posts using the WordPress REST API from my blog and display their titles as a list. Earlier we needed to download a plugin to interact with our site using JSON objects. But that changed from WordPress version 4.7+. Now the REST API is integrated within the WordPress. And we can directly talk to the WordPress site using JSON.

    So here is how I progressed today –

    1. The URL to access WordPress blog’s posts as a list according to the API’s documentation is – “http://example.com/wp-json/wp/v2/posts”. I modified this URL according to the address of my blog to access the content.               
    2. I started with building the URL. It’s a two-step process. First, generating the URI using Android’s Uri class build method. Then converting the URI to URL by passing URI as a parameter to the URL object. This went fine. For testing, I displayed the URL in the TextView. The result displayed the right URL.
    3. Next, I added the internet permission to the Android Manifest file. This makes sure our app has access to the internet. Otherwise, we will get SecurityException.
    4. Now I needed to access the Http response from the URL and store it as a string. I used InputStreamReader and Scanner for this purpose.
    5. To avoid NetworkOnMainThread Exception, I used AsyncTask‘s doInBackground() method to get the contents from the URL. Then it’s postExecute to display the JSON received in the textview. This step was also successful.

      dd-app-day-1-connecting-wp-rest-api
      JSON Response

    6. I don’t need the JSON with all the data. I only need the title of each post. This requires to parse the JSON string and extract the required fields. Which I did and extracted the titles into a string array.
    7. Then updated the AsynTask class’s doInBackground method to return String array instead of a string. And displayed the contents of this array in the textview. But, there is an issue, the titles are displaying special characters weirdly as you can see in the screenshot.

      dd-app-day-1-connecting-wp-rest-api
      List of Post Titles

    8. Next, I changed the main_layout from LinearLayout to FrameLayout and added a textview to display error messages and a ProgressBar to display the loading progress. Currently, both of these views were set to invisible. If there is a problem in retrieving data from the API then the error message with become visible and the main textview will become invisible. The progress bar will be visible while the app is getting data from the API. Once it has the data, the progress bar will be invisible. Made necessary changes to the main activity to reflect this behavior.

     

    Files Created:

    • NetworkUtils.java [Create URL, Get data from the internet],
    • DDJsonUtils.java [Parse JSON to get the required string],
    • DDQueryTask [inner class inside MainActivity.java to create a background thread on which network access will take place]

     

    Files Edited:

    • MainActivity.java,
    • activity_main.xml

     

    Today I spent 6 pomodoros on the development, ie, 150 minutes = 2 hours and 30 minutes.

    That’s all for today, see you in the next post.

    Thanks for stopping by!

  • [DD App] Day 0 – Introduction

    January 10th, 2018

    Hi All,

    I am back from a vacation. I would get back and complete my Android Tutorial series soon. But meanwhile, I have started to work on my android application called “DelightfullDiscoveries”.

    If you guys follow me, I have another blog called Delightfull Discoveries where I publish recipes and book reviews. I decided to create an app for that blog and publish it on Google App Store. It is one of my goals for this year.

    In this series DD App, I will be publishing my progress. The posts will be published on every alternate day.

    Since I am building this app incrementally, the final app will be totally different from the interim screenshots we will see in each post.

    Today I employed 2 Pomodoros, i.e. 50 minutes for the application development.

    Here is what I did today:

    1. Created a new project “DelightfullDiscoveries“.
    2. Changed the ConstraintsLayout to LinearLayout in the layout_main.xml.
    3. Added ScrollView as the main element in LinearLayout.
    4. Then added a TextView to the ScrollView. This TextView is going to hold the test data for now.
    5. Implemented the menu, will add more functionality later.
    6. Using git for version control. Created a local git repository for the project. Then added initial code to the master branch. Next created a working branch where I am committing the changes I make.

     

    Files Edited: MainActivity.java, activity_main.xml.

     

    This is how the app looks right now.

     

    dd-app-day-0-introduction
    PlaceHolder Text

     

    Thanks for reading, see you all in the next post.

  • [Android Tutorial #9] Padding and Margin

    October 23rd, 2017

    Some Useful Links –

    Android Tutorial Playlist

    Project Initial Code

    Changes made to the project after this video

  • [Android Tutorial #8] Layouts (Part B)

    October 12th, 2017

    Some Useful Links –

    Android Tutorial Playlist

    Layout Part A

    Project Initial Code 

    Changes made to the project at the starting of this video

    Changes made to the project after this video

  • [Android Tutorial #7] Layouts (Part A)

    October 10th, 2017

    Some Useful Links –

    Android Tutorial Playlist

    Project Initial Code

    Introduction

    Activity Basics

    Changes made to the project after this video

←Previous Page
1 … 14 15 16 17 18 … 22
Next Page→

Proudly powered by WordPress

 

Loading Comments...