https://github.com/techpro-studio/androidapparchitecture
Android App Architecture we use. Feel free to contribute.
https://github.com/techpro-studio/androidapparchitecture
android architecture jetpack-android koin livedata viewmodels
Last synced: about 2 months ago
JSON representation
Android App Architecture we use. Feel free to contribute.
- Host: GitHub
- URL: https://github.com/techpro-studio/androidapparchitecture
- Owner: techpro-studio
- License: mit
- Created: 2019-06-25T23:33:18.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-03-08T08:13:40.000Z (over 6 years ago)
- Last Synced: 2025-06-03T04:25:36.383Z (about 1 year ago)
- Topics: android, architecture, jetpack-android, koin, livedata, viewmodels
- Language: Kotlin
- Homepage:
- Size: 146 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AndroidAppArchitecture
We use MVVM in Android apps.
SOLID principles are the core of our apps.
We use Android architecture components in the apps.
Navigation component is optional, it could be used for small apps.
For injecting dependencies we prefer to use [Koin](https://github.com/InsertKoinIO/koin). It is more lightweight than Dagger2 and it has support for ViewModels. So you don't need to create Factories by yourself when you need to inject something in ViewModel.
Every screen has the following structure:
#### Activity
It's just a container for fragments.
#### Fragment
It binds viewModel and contains all view logic.
#### ViewModel
Abstract class for View Model inherited from ViewModel class in AAC.
```kotlin
abstract class MainViewModel: ViewModel() {
abstract val list: LiveData>
abstract fun refresh()
}
```
It has liveData variables. The main idea is to encapsulate all RxJava in viewModel and provide only liveData to Fragment.
```kotlin
class DefaultMainViewModel(private var modelLocalRepository: ModelLocalRepository): MainViewModel() {
override val list: MutableLiveData> = MutableLiveData()
private var disposable: Disposable?=null
init {
list.postValue(modelLocalRepository.getList())
observeList()
}
private fun observeList() {
disposable = modelLocalRepository.observeList().subscribe { new ->
list.postValue(new)
}
}
override fun refresh() {
val new = Model(UUID.randomUUID().toString(), Date().time.toString())
modelLocalRepository.save(new)
}
override fun onCleared() {
super.onCleared()
disposable?.dispose()
}
}
```
It is convenient because you can dispose disposables in onCleared method in ViewModel. Also, it will bring less crashes, etc.
Thus, every dependency you need in ViewModel is injected.
The crucial point is that all dependencies should have one responsibility and they should be abstractions.
All Dependencies for ViewModel should be built on principles of Clean Architecture.