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.
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.
- You should fork this repo to yours
- 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 BaseActivity
m 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
- Each presenters is for a specific
activity
orfragment
. We're considering how to separate or reuse the presenter conveniently. - 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.
- 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)
}
}
- 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.
We're using some libraries for building a testable and module architecture.
We provide a tool kit for kotlin and this repo. You can find the detail from KotlinKnifer.