Giter Site home page Giter Site logo

akoufa / coolweather Goto Github PK

View Code? Open in Web Editor NEW
195.0 10.0 20.0 6.79 MB

Weather App that uses Android best practices. Android Jetpack, clean architecture. Written in Kotlin

License: Apache License 2.0

Kotlin 100.00%
android kotlin clean-architecture retrofit2 java android-architecture mvvm databinding android-development architecture-components

coolweather's Introduction

CoolWeather

An Android Clean Architecture app written in Kotlin, using Kotlin Coroutines and Android Architecture Components using Hilt for Dependency Injection.

Presentation Layer

The presentation layer was implemented using:

MVVM with ViewModels exposing LiveData that the Views consume. The ViewModel does not know anything about it's consumers. It exposes a single source of truth as a LiveData that the consumers can observe to get the events emitted. These events consist of entities, that are wrapped in a Result class that leverages the powerful Kotlin feature of sealed classes. This enables us to express the different states of the application's individual screens in an concise an expressive manner.

Domain Layer

The domain layer contains the UseCases that encapsulate a single and very specific task that can be performed. This task is part of the business logic of the application. A UseCase exposes suspend operator fun invoke that returns a Result after invocation. The ViewModels of the presentation layer use the UseCases to complete a business case. This layer also contains the Repository interfaces and the domain entities. These are the basic building blocks of the application and the ones that are least likely to change when something external changes. That also means that this layer should not depend on any other layer. The other layers must depend and reference the domain layer.

Data Layer

The data layer implements the repository interface that the domain layer defines. The components in this layer provide a single source of truth for data and hide the origin of the data. This allows effective caching using a custom cache implementation or/and the Sqlite Db without polluting the other layers with the implementation details.

Clean architecture layers

cleanrings

Architecture overview and rules

architecture

Build Instructions

In order to run this project, you'll need to setup several things beforehand:

  • This application uses the OpenWeatherMap API to obtain information about current weather and forecasts, you'll need to register and obtain an API Key

  • You'll need to set the values found in the gradle.properties file. This involves the OpenWeatherMap Api Key (apiToken)

License

See LICENSE file

coolweather's People

Contributors

akoufa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coolweather's Issues

Not sure why you don't need `withContext(Dispatchers.IO){ }` when invoke UseCase method

I see in WeatherViewModel, here is the method to show weather:

fun showWeather() = viewModelScope.launch {
	showLoading()
	val weatherResult = weatherUseCase()
	val tempUnit = getTemperatureUnit()
        ...

Since weatherUseCase() is a method to get weather which should be run in network thread, I wonder why don't you wrap it inside withContext(Dispatchers.IO) { }, like this:

fun showWeather() = viewModelScope.launch {
	showLoading()
	val weatherResult = withContext(Dispatchers.IO) {  weatherUseCase() }
	val tempUnit = getTemperatureUnit()
        ...

Add error handling

For the moment when a request is not successful the datastore returns an error observable of throwable. TODO: Improve this wrapping the datastore return type to a custom Result object that has the entity and the states of the request response cycle namely: idle, loading, error, and the entity

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.