Giter Site home page Giter Site logo

bachhoan88 / cleanarchitecture Goto Github PK

View Code? Open in Web Editor NEW
282.0 5.0 70.0 4.1 MB

Android Kotlin Clean Architecture

License: Apache License 2.0

Java 1.73% Kotlin 97.79% Ruby 0.48%
kotlin-android code-base cleanarchitecture android-components data-flow architecture viewmodel navigation android model-mapper

cleanarchitecture's Introduction

Android Kotlin Clean Architecture & Components Example

CircleCI codecov.io

This is a sample app & basic code that uses Clean Architecture & Components, that is part of a blog post I have written about how to architect android application using the Uncle Bob's clean architecture approach.

NOTE It is a relatively more complex and complete example so if you are not familiar with [Architecture Components][arch], you are highly recommended to check other examples in this repository first.

Introduction

Data-Flow

Structure

Work-Flow

Structure

Handler-Error-Flow

Structure

Domain Layer

  • Contains business model
  • Contains business RULEs
  • Repository interface adapt

Data Layer

  • Implementation Repository
  • Executor API data
  • Storage data to local: Share preferences, database, external storage
  • Mapper data model to domain model
  • Contains data service, third party data service

Presentation Layer

  • View (Activity/Fragment/Layout) Adapt data to view
  • Validate/Submit data input from view via UseCase

Base Code

Base code designed one Activity and multiple Fragment, using Navigation Component to UI navigate Use Dagger2 (version 2.23.2) for Dependencies Injection, You can easily switch to using Koin (I suggestion Dagger for big, super projects) Base code

  • Has created a flow that handles all of the corner cases, you can easily customize them via CleanException, it extends Throwable
  • Added Authorization, Interceptor easily handler and implementations for your project if needed
  • Use ktlint, kotlin-offical for check code conventions, you can run ./gradlew ktlint
  • Use jacoco for full Unit and Instrument test
  • Added basically circle-ci, gitlab-ci with some work-flows
  • Report bugs into Crashlytics via Timber.e

Building

Work from Android Studio 3.2 and above

Unit Test

You can easily write Unit Test up to 70% code coverage lines of code (LOC), if you write focus on

  • Data: API service, Local (database, share preferences), RepositoryImpl, Model Mapper
  • Domain: UseCases, Repository, Exception handlers
  • Presentation: ViewModel, Model Mapper

Libraries used


  • Foundation - Components for core system capabilities, Kotlin extensions and support for multidex and automated testing.
    • AppCompat - Degrade gracefully on older versions of Android.
    • Android KTX - Write more concise, idiomatic Kotlin code.
    • Test - An Android testing framework for unit and runtime UI tests.
  • Architecture - A collection of libraries that help you design robust, testable, and maintainable apps. Start with classes for managing your UI component lifecycle and handling data persistence.
    • Data Binding - Declaratively bind observable data to UI elements.
    • Lifecycles - Create a UI that automatically responds to lifecycle events.
    • LiveData - Build data objects that notify views when the underlying database changes.
    • Navigation - Handle everything needed for in-app navigation.
    • Room - Access your app's SQLite database with in-app objects and compile-time checks.
    • ViewModel - Store UI-related data that isn't destroyed on app rotations. Easily schedule asynchronous tasks for optimal execution.
    • WorkManager - Manage your Android background jobs.
  • UI - Details on why and how to use UI Components in your apps - together or separate
  • Third party
    • Glide for image loading
    • Kotlin Coroutines for managing background threads with simplified code and reducing needs for callbacks
    • ReactiveX library for composing asynchronous and event-based programs by using observable sequences.
    • Dagger2 for dependencies injection
    • Retrofit Type-safe HTTP client for Android
    • EasyPermission is a wrapper library to simplify basic system permissions logic when targeting Android M or higher.

Upcoming features

  • Build layer for library aar

  • Make design support for all application: styles, fonts, theme

  • Interested in seeing a particular feature of the Architecture or Base Code implemented in this app? Please open a new issue.

License

Copyright 2017 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

cleanarchitecture's People

Contributors

bachhoan88 avatar hoaibn-0332 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

cleanarchitecture's Issues

Screaming Architecture

I'll quote from the book. Chapter 21. Screaming Architecture:

So what does the architecture of your application scream? When you look at the top-level directory structure, and the source files in the highest-level package, do they scream “Health Care System,” or “Accounting System,” or “Inventory Management System”? Or do they scream “Rails,” or “Spring/Hibernate,” or “ASP”?

Looking at the domain package's src directory. We'll see these directories:

  • annotation
  • exception
  • model
  • repository
  • usecase

It screams "Blogger's Clean Architecture". It doesn't scream what this app does. Is it a note app? Is it a blogging app? It does have owner and contributor in model. The top directory separate by types not by features.

Keep showing snackBar

Is your feature request related to a problem? Please describe.
Turn off the mobile network first, and then click search on the main screen. At this time, snackBar will be shown
Then open the mobile phone network, then click search on the main screen to jump to the contributor screen, and then press the return key to jump back to the main screen, this time will automatically show snackBar
Screenshot_20200314-232714

Describe the solution you'd like
Same as above

Describe alternatives you've considered
The picture below is my solution, maybe you can refer to it
2020-03-14_233106
2020-03-14_234559

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.