Skip to content

dev-cloverlab/Kloveroid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kloveroid

GitHub release license

Kloveroid

This is an basic architecture of MVP and clean architecture for android. This project provides a complete components and the necessary MVP code in the beginning. To build an android app rapidly is this is project purpose.

Architecture

We're using Uncle Bob's Clean Architecture for this basic project. There are the components as the below

  • MVP
    • View
    • Presenter
    • Model
  • Use Case
  • Repository pattern
    • Remote Repository
    • Local Repository

There is an image for this project.

Architecture

img MVP Architecture

How to use

  1. You should fork this repo to yours
  2. We use the two types of the activity and the fragment. The scenario isn't always that we have to implement with a presenter. When you need a presenter, you just inherit the normal MvpActivity or MvpFragment; otherwise you'd better use BaseActivity or BaseFragment because we've prepared a good base class for you!

If you implement the BaseActivitym you just implement this two methods, then done!

override fun init(savedInstanceState: Bundle?) { }

// activity layout id.
override fun provideLayoutId(): Int = R.layout.activity_main

Or using MvpFragment

override fun init(savedInstanceState: Bundle?) { }

// fragment layout id.
override fun provideInflateView(): Int = R.layout.fragment_main

// This is for the presenter.
override fun provideCurrentFragmentView(): MainContract.View = this
  1. Each presenters is for a specific activity or fragment. We're considering how to separate or reuse the presenter conveniently.
  2. The usecases are really easy to implement. The purpose is that decoupling from the data layer and presenter layer, and with individual business logic. For example, getMemberList, removeMemberList, editMember, ... etc.
  3. The most difficult part is repository, we'll have some strategies for how to retrieve the data from remote or local or cache.

This is simple example for just only retrieving the data from remote database.

Here we should judge we need to use cache or local data or the newest data from the remote.

class DataRepository @Inject constructor(@Local private var local: IDataStore,
                                         @Remote private var remote: IDataStore): IDataStore {
    override fun createEntity(fakeModel: FakeModel): Observable<FakeModel> {
        // Implement retrieving the data from cache, local, or remote.
        return remote.createEntity(fakeModel)
    }
}
  1. Due to the needs, you must have some components which aren't including here. Now we're still processing this repository. Basically we're following the clean architecture's folder structure. If you'd like it them now, please give us good suggestions or PR. Also, you can check Uncle Bob's clean architecture here.

Third-party Library

We're using some libraries for building a testable and module architecture.

UI

AndroidX Anko

Streaming

RxJava RxKotlin

Dependency Injection

Dagger

Parser

Gson

Network

Retrofit Glide

Utils

We provide a tool kit for kotlin and this repo. You can find the detail from KotlinKnifer.