Code Monkey home page Code Monkey logo

fetch-exercise's Introduction

Build instructions

Right click on MainActivity class and run the program in Android Studio. You can run it on your own physical device if you'd like, but if you want to use a emulator, I recommend the Pixel 2 in Android Studio because it has a fairly large screen.

For Android Studio, I used Android Studio Flamingo | 2022.2.1

  • JDK 17.
  • SDK 33.

Notes

I tried making the code as modular as possible, which is why one class deals mostly with UI (MainActivity) and the other class deals with the JSON data (JSONDataHandler). I could have put all of my code into the MainActivity class but I want the code to be modular, easy to read, and to adhere to the Single Responsibility Principle.

The program is multithreaded since Android doesn't allow you to do network operation on the UI thread. I have two functions in the JSON class that are important: one that fetches the data, and one that sorts the data. These two methods and their respective threads are done sequentially in order to not have any data inconsistencies/errors. The method that fetches the JSON data opens a thread and handles that, then at the end of that method, the sort method is called. The sort method takes in an jsonArray parameter (the fetched JSON data) and also opens a thread. I did it this way because if I call both threads in MainActivity, then they can run concurrently and that can cause problems with data inconsistency. Also, I could have done the fetching and sorting all in one function in one thread rather than two, but like I said, I am trying to have my code be as modular as possible, so that's just a trade-off I made.

In terms of how the data is displayed on screen, I just used a table. You can see what it looks like in the screenshot at the bottom of this README file. You obviously can't tell from a screenshot alone, but you can scroll down the table to view the rest of the JSON data. Here's a hyperlink to the relevant XML file

Testing Notes

I had trouble developing unit tests for my methods because of how the program is multithreaded and having to mock the behavior in order to unit test. I did try to mock the behavior using Mockito and I also tried with Robolectric but I didn't have any success.

In terms of manual testing, I did do emulation tests on the following devices that target the current OS release (Android 13) without a problem:

  • Pixel 2 API 33 (Emulation) - 1080 x 1920 pixels
  • Nexus S API 33 (Emulation) - 480 x 800 pixels
  • Samsung Galaxy S10 (Physical device) - 2280 x 1080 pixels (FHD+)

Additionally, I also verified output by pasting and then filtering the JSON data into Google Sheets and comparing that to my output in the App and it was identical.

Screenshot1

Screenshot2

fetch-exercise's People

Contributors

gcmaidana avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.