Giter VIP home page Giter VIP logo

coincap's Introduction

CoinCap - (I'm not maintaining this project anymore)

Best practice (Modularization) - built entirely with Jetpack Compose and cutting-edge libraries like Coroutines, Flow, Hilt, Coil, etc.

This project is using Material 3 components, as well as the Compose navigation library. It also has an integrated Static Analysis tool (Detekt) and CI/CD pipeline (Github Actions) + web scraping using a python script.

Libraries and Tools

  • Jetpack Compose
  • Hilt
  • Retrofit (with a deserializer for another API)
  • Coroutines
  • Coil
  • Detekt
  • GitHub Actions
  • Material 3
  • Compose Navigation

CI/CD

  • I've used GitHub Actions, and Bitrise just to see different results from different platforms, and so far, IMO, GitHub Actions is nicer, Bitrise already has everything but I'd like to have some flexibility and write some scripts :)

  • There was an issue with the previous local rates API, from bonbast.com which I replaced that with a new strategy. I've used a new script to scrap the data with Github Actions and store it in a file called currencies.json. The script is available in the project.

Showcase

device-2023-01-05-224942.mp4

Architecture

I've used the best practices from Google's official repository NowInAndroid, and used Modularization to make the app more scalable and maintainable.

Modules

Features

  1. The logic behind searching is to get the data only after the last character is entered (using flatMapLatest() flow operator).
  2. For the home screen, I am planning to get some data from the server for showing on the LineChart, but for now, I am using dummy data.
  3. Unfortunately, the API doesn't provide the data for the LineChart, so I am using dummy data for now.
  4. Iran (my home country) has been facing inflation for the last decade, and surprisingly, because of protests and the lack of management, the inflation rate is increasing day by day. So, I took the chance and put a logic for showing the rates in different currencies as Local Currency, with a refresh policy between Saturday to Thursday, and the rates will be updated every 5 minutes. For Friday, the rates will be retrieved from the previous day.

Implementation

This section is for those who are interested in the implementation details.

Home Screen

I had to combine two flows into one to avoid unnecessary network calls and extra logics inside views. So here is how I did it:

The implementation is pretty simple. I am using the combine operator to combine the two flows into one. The combine operator will emit a new [Rate] model after multiplying the two values. The logic and code is available in the GetRatesUseCaseImpl class.

API calls and deserialization

I am using Retrofit for making API calls, and I am using a custom deserializer for the local currency API. The problem that I faced at first was that the original API was not free so I had to use an already made API instead. Another problem was that the API was returning the data in a different format, something like this format:

{
  "usd": {
    "sell": 43000,
    "buy": 42900
  },
  "eur": {
    "sell": 45870,
    "buy": 45720
  }
}

It was pretty hard to deserialize the data, so I had to write a custom deserializer for it. The deserializer is basically converting all those three objects into a list of [LocalRate] objects. Here you can find the deserializer: CurrencyDeserializer

I am sure this is one of the major problems that all Android developers might face while using GSON and Retrofit, so I hope this will help you.

API

For this project, I am using CoinCap API for rates, as well as This API for live Iranian exchange rates.

Also, I am using https://coinicons-api.vercel.app/api/icon/ for getting the icons of the coins.

Continuous Integration

The project is using GitHub Actions to build and test the app on every push and pull request on two devices. Also, it is using Renovate to keep the dependencies up to date.

Static Code Analysis

The project is using Detekt for static code analysis, and it is using GitHub Actions to run the analysis on every push and pull request.

I also used Detekt formatter to format the code automatically which is somehow a wrapper for ktLint as well.

Please see: https://detekt.dev/docs/rules/formatting

TODO

  • Add Offline first support
  • Unit Tests
  • Get data from Server for LineChart
  • Add more features

coincap's People

Contributors

actions-user avatar linx64 avatar renovate[bot] 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.