bind(view: View): T = DataBindingUtil.bind(view)!!
47 |
48 | }
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/base/BaseViewModel.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.base
2 |
3 | import androidx.lifecycle.ViewModel
4 | import com.developersancho.manager.IDataManager
5 | import java.lang.ref.WeakReference
6 |
7 | abstract class BaseViewModel(val dataManager: IDataManager) : ViewModel() {
8 |
9 | private lateinit var presenter: WeakReference
10 |
11 | fun getPresenter(): P? {
12 | return presenter.get()
13 | }
14 |
15 | fun setPresenter(presenter: P) {
16 | this.presenter = WeakReference(presenter)
17 | }
18 |
19 | }
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/base/IBasePresenter.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.base
2 |
3 | interface IBasePresenter {
4 |
5 | fun showLoading()
6 | fun hideLoading()
7 | fun showError(code: Int, message: String)
8 | fun showSuccess(title: String, message: String)
9 | }
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/di/AppModule.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.di
2 |
3 | import com.developersancho.local.di.localModule
4 | import com.developersancho.manager.di.managerModule
5 | import com.developersancho.remote.di.remoteModule
6 | import developersancho.mvvm.BuildConfig
7 |
8 | val appModule = listOf(
9 | remoteModule(BuildConfig.BASE_URL, isDebug = BuildConfig.DEBUG),
10 | localModule(BuildConfig.DB_NAME),
11 | managerModule,
12 | viewModelModule
13 | )
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/di/ViewModelModule.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.di
2 |
3 | import developersancho.mvvm.ui.databindingtest.DViewModel
4 | import developersancho.mvvm.ui.main.MainViewModel
5 | import developersancho.mvvm.ui.viewbindingtest.VViewModel
6 | import org.koin.androidx.viewmodel.dsl.viewModel
7 | import org.koin.dsl.module
8 |
9 | val viewModelModule = module {
10 | viewModel { MainViewModel(get()) }
11 | viewModel { DViewModel(get()) }
12 | viewModel { VViewModel(get()) }
13 | }
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/ui/databindingtest/DViewModel.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.ui.databindingtest
2 |
3 | import com.developersancho.manager.IDataManager
4 | import developersancho.mvvm.base.BaseViewModel
5 | import developersancho.mvvm.base.IBasePresenter
6 |
7 | class DViewModel(dataManager: IDataManager) : BaseViewModel(dataManager)
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/ui/databindingtest/DataBindingTestActivity.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.ui.databindingtest
2 |
3 | import androidx.navigation.findNavController
4 | import developersancho.mvvm.R
5 | import developersancho.mvvm.base.BaseActivity
6 | import developersancho.mvvm.base.dataBinding
7 | import developersancho.mvvm.databinding.ActivityDataBindingTestBinding
8 |
9 | class DataBindingTestActivity : BaseActivity() {
10 |
11 | private val binding by dataBinding()
12 |
13 | override val layoutId: Int?
14 | get() = R.layout.activity_data_binding_test
15 |
16 | override fun initPresenter() {
17 |
18 | }
19 |
20 | override fun initUI() {
21 | binding.textDataBindingDsc.text = "DataBindingTestActivity"
22 | }
23 |
24 | override fun initListener() {
25 |
26 | }
27 |
28 | override fun onSupportNavigateUp(): Boolean =
29 | findNavController(R.id.data_nav_host_fragment).navigateUp()
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/ui/databindingtest/DataBindingTestFragment.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.ui.databindingtest
2 |
3 | import android.view.View
4 | import developersancho.mvvm.R
5 | import developersancho.mvvm.base.BaseFragment
6 | import developersancho.mvvm.base.dataBinding
7 | import developersancho.mvvm.databinding.FragmentDataBindingTestBinding
8 | import org.koin.androidx.viewmodel.ext.android.sharedViewModel
9 |
10 |
11 | class DataBindingTestFragment : BaseFragment() {
12 |
13 | private val viewModel by sharedViewModel()
14 |
15 | private val binding by dataBinding()
16 |
17 | override val layoutId: Int?
18 | get() = R.layout.fragment_data_binding_test
19 |
20 | override fun initPresenter() {
21 | viewModel.setPresenter(this)
22 | }
23 |
24 | override fun initUI(view: View) {
25 | binding.textFragDataBinding.text = "DataBindingFragment"
26 | }
27 |
28 | override fun initListener() {
29 |
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/ui/main/IMainPresenter.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.ui.main
2 |
3 | import developersancho.mvvm.base.IBasePresenter
4 |
5 | interface IMainPresenter : IBasePresenter {
6 |
7 | fun showRepoSize(size: Int)
8 |
9 | }
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/ui/main/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.ui.main
2 |
3 | import android.content.Intent
4 | import androidx.lifecycle.Observer
5 | import com.developersancho.util.extensions.longToast
6 | import developersancho.mvvm.R
7 | import developersancho.mvvm.base.BaseActivity
8 | import developersancho.mvvm.base.viewBinding
9 | import developersancho.mvvm.databinding.ActivityMainBinding
10 | import developersancho.mvvm.ui.databindingtest.DataBindingTestActivity
11 | import developersancho.mvvm.ui.viewbindingtest.ViewBindingTestActivity
12 | import org.koin.androidx.viewmodel.ext.android.viewModel
13 |
14 | class MainActivity : BaseActivity(), IMainPresenter {
15 |
16 | private val binding by viewBinding { ActivityMainBinding.bind(it) }
17 |
18 | private val viewModel by viewModel()
19 |
20 | override val layoutId: Int?
21 | get() = R.layout.activity_main
22 |
23 | override fun initPresenter() {
24 | viewModel.setPresenter(this)
25 | }
26 |
27 | override fun initUI() {
28 | observeViewModel()
29 | initData()
30 | }
31 |
32 | private fun initData() {
33 | viewModel.getRepos(user = "developersancho")
34 | }
35 |
36 | private fun observeViewModel() {
37 | viewModel.repos.observe(this, Observer {
38 | longToast("repo adı: --> ${it.first().fullName}")
39 | })
40 | }
41 |
42 | override fun initListener() {
43 | binding.btnD.setOnClickListener {
44 | startActivity(Intent(this, DataBindingTestActivity::class.java))
45 | }
46 |
47 | binding.btnV.setOnClickListener {
48 | startActivity(Intent(this, ViewBindingTestActivity::class.java))
49 | }
50 | }
51 |
52 |
53 | override fun showRepoSize(size: Int) {
54 | binding.textCenter.text = "Toplam repo $size tanedir."
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/ui/main/MainViewModel.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.ui.main
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.lifecycle.MutableLiveData
5 | import androidx.lifecycle.viewModelScope
6 | import com.developersancho.local.entity.FavEntity
7 | import com.developersancho.manager.IDataManager
8 | import com.developersancho.remote.model.Repos
9 | import com.developersancho.remote.network.NetworkState
10 | import developersancho.mvvm.base.BaseViewModel
11 | import kotlinx.coroutines.Dispatchers
12 | import kotlinx.coroutines.flow.collect
13 | import kotlinx.coroutines.launch
14 |
15 | class MainViewModel(dataManager: IDataManager) : BaseViewModel(dataManager) {
16 |
17 | private val _repos: MutableLiveData> = MutableLiveData()
18 |
19 | var repos: LiveData> = _repos
20 |
21 | fun getRepos(user: String) = viewModelScope.launch {
22 | getPresenter()?.showLoading()
23 | dataManager.getRepos(userName = user).collect { state ->
24 | when (state) {
25 | is NetworkState.Success -> {
26 | getPresenter()?.hideLoading()
27 | getPresenter()?.showRepoSize(state.response.size)
28 | _repos.value = state.response
29 | }
30 | is NetworkState.Error -> {
31 | getPresenter()?.hideLoading()
32 | getPresenter()?.showError(state.exception.code, state.exception.message)
33 | }
34 | }
35 |
36 | }
37 | }
38 |
39 | fun insertFavData(favEntity: FavEntity) = viewModelScope.launch(Dispatchers.IO) {
40 | dataManager.insertFav(favEntity = favEntity)
41 | }
42 |
43 | fun getFavList() = viewModelScope.launch(Dispatchers.IO) {
44 | dataManager.favList()
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/ui/viewbindingtest/VViewModel.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.ui.viewbindingtest
2 |
3 | import com.developersancho.manager.IDataManager
4 | import developersancho.mvvm.base.BaseViewModel
5 | import developersancho.mvvm.base.IBasePresenter
6 |
7 | class VViewModel(dataManager: IDataManager) : BaseViewModel(dataManager)
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/ui/viewbindingtest/ViewBindingTestActivity.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.ui.viewbindingtest
2 |
3 | import androidx.navigation.findNavController
4 | import developersancho.mvvm.R
5 | import developersancho.mvvm.base.BaseActivity
6 | import developersancho.mvvm.base.viewBinding
7 | import developersancho.mvvm.databinding.ActivityViewBindingTestBinding
8 |
9 | class ViewBindingTestActivity : BaseActivity() {
10 |
11 |
12 | private val binding by viewBinding { ActivityViewBindingTestBinding.bind(it) }
13 |
14 | override val layoutId: Int?
15 | get() = R.layout.activity_view_binding_test
16 |
17 | override fun initPresenter() {
18 |
19 | }
20 |
21 | override fun initUI() {
22 | binding.textViewBindingDsc.text = "ViewBindingTestActivity"
23 | }
24 |
25 | override fun initListener() {
26 |
27 | }
28 |
29 | override fun onSupportNavigateUp(): Boolean =
30 | findNavController(R.id.view_nav_host_fragment).navigateUp()
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/developersancho/mvvm/ui/viewbindingtest/ViewBindingTestFragment.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm.ui.viewbindingtest
2 |
3 | import android.view.View
4 | import developersancho.mvvm.R
5 | import developersancho.mvvm.base.BaseFragment
6 | import developersancho.mvvm.base.viewBinding
7 | import developersancho.mvvm.databinding.FragmentViewBindingTestBinding
8 | import org.koin.androidx.viewmodel.ext.android.sharedViewModel
9 |
10 |
11 | class ViewBindingTestFragment : BaseFragment() {
12 |
13 | private val viewModel by sharedViewModel()
14 |
15 | private val binding by viewBinding { FragmentViewBindingTestBinding.bind(it) }
16 |
17 | override val layoutId: Int?
18 | get() = R.layout.fragment_view_binding_test
19 |
20 | override fun initPresenter() {
21 | viewModel.setPresenter(this)
22 | }
23 |
24 | override fun initUI(view: View) {
25 | binding.textFragViewBinding.text = "ViewBindingFragment"
26 | }
27 |
28 | override fun initListener() {
29 |
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ripple_light_with_border.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | -
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_data_binding_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
15 |
16 |
22 |
23 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
28 |
29 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_view_binding_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
18 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_data_binding_test.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_view_binding_test.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/navigation/nav_graph_data_binding.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/navigation/nav_graph_view_binding.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
8 | @color/black_12
9 |
10 | #000000
11 | #DE000000
12 | #8A000000
13 | #80000000
14 | #52000000
15 | #33000000
16 | #1F000000
17 |
18 | #FFFFFF
19 | #DEFFFFFF
20 | #8AFFFFFF
21 | #8FFFFFF0
22 | #52FFFFFF
23 | #33FFFFFF
24 | #1FFFFFFF
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Hello blank fragment
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/network_security_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
--------------------------------------------------------------------------------
/app/src/test/java/developersancho/mvvm/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package developersancho.mvvm
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.3.61'
5 |
6 |
7 | repositories {
8 | google()
9 | jcenter()
10 | mavenCentral()
11 | maven { url = BuildPlugins.jitpack }
12 | }
13 |
14 | dependencies {
15 | classpath(BuildPlugins.androidGradlePlugin)
16 | classpath(BuildPlugins.kotlinGradlePlugin)
17 | classpath(BuildPlugins.safeArgsGradlePlugin)
18 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
19 | }
20 |
21 |
22 | }
23 |
24 | allprojects {
25 | repositories {
26 | google()
27 | jcenter()
28 | mavenCentral()
29 | maven { url = BuildPlugins.jitpack }
30 | }
31 | }
32 |
33 | task clean(type: Delete) {
34 | delete rootProject.buildDir
35 | }
36 |
--------------------------------------------------------------------------------
/buildSrc/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.gradle.kotlin.dsl.`kotlin-dsl`
2 |
3 | plugins {
4 | `kotlin-dsl`
5 | }
6 |
7 | kotlinDslPluginOptions {
8 | experimentalWarning.set(false)
9 | }
10 |
11 | // Required since Gradle 4.10+.
12 | repositories {
13 | jcenter()
14 | gradlePluginPortal()
15 | mavenCentral()
16 | }
--------------------------------------------------------------------------------
/buildSrc/src/main/java/Dependencies.kt:
--------------------------------------------------------------------------------
1 | object Modules {
2 | const val app = ":app"
3 | const val remote = ":core:remote"
4 | const val local = ":core:local"
5 | const val manager = ":core:manager"
6 | const val util = ":common:util"
7 | const val widget = ":common:widget"
8 | }
9 |
10 | object ApplicationId {
11 | val id = "developersancho.mvvm"
12 | }
13 |
14 | object Versions {
15 | const val minSdk = 19
16 | const val compileSdk = 29
17 | const val targetSdk = 29
18 | const val buildTools = "29.0.2"
19 | const val kotlinPlugin = "1.3.61"
20 | const val androidPlugin = "3.6.0-rc01"
21 |
22 | const val navigation = "2.1.0"
23 | const val appCompat = "1.1.0"
24 | const val coreKtx = "1.1.0"
25 | const val constraintLayout = "1.1.3"
26 | const val material = "1.1.0-beta02"
27 | const val preference = "1.1.0"
28 |
29 | const val legacy = "1.0.0"
30 | const val coroutines = "1.3.3"
31 | const val gson = "2.8.6"
32 | /* 21+
33 | const val retrofit = "2.7.0"
34 | const val okhttp = "4.3.0"
35 | const val mockWebServer = "4.3.0"
36 | */
37 | // 19+
38 | // important coroutines with retrofit only get directly response min 2.6.0
39 | const val retrofit = "2.6.0"
40 | const val okhttp = "3.12.6"
41 | const val mockWebServer = "3.12.6"
42 |
43 | const val multidex = "2.0.1"
44 |
45 | const val lifecycle = "2.1.0"
46 | const val lifeCycleKtx = "2.2.0-rc03"
47 | const val firebaseMessage = "20.1.0"
48 | const val firebaseCore = "17.2.1"
49 |
50 | const val koin = "2.0.1"
51 | const val room = "2.2.1"
52 | const val glide = "4.10.0"
53 |
54 | const val junit = "4.13"
55 | const val junitExt = "1.1.1"
56 | const val espresso = "3.2.0"
57 | const val retrofitCoroutines = "0.9.2"
58 | const val robolectric = "4.3.1"
59 | const val timber = "4.7.1"
60 | }
61 |
62 | object Libraries {
63 | // kotlin - coroutine
64 | val kotlinStdLib = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${Versions.kotlinPlugin}"
65 | val kotlinCoroutineCore = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutines}"
66 | val kotlinCoroutineAndroid =
67 | "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutines}"
68 | val kotlinReflection = "org.jetbrains.kotlin:kotlin-reflect:${Versions.kotlinPlugin}"
69 |
70 | // android
71 | val appCompat = "androidx.appcompat:appcompat:${Versions.appCompat}"
72 | val coreKtx = "androidx.core:core-ktx:${Versions.coreKtx}"
73 | val constraintLayout = "androidx.constraintlayout:constraintlayout:${Versions.constraintLayout}"
74 | val material = "com.google.android.material:material:${Versions.material}"
75 | val legacy = "androidx.legacy:legacy-support-v4:${Versions.legacy}"
76 | val dynamicAnimation = "androidx.dynamicanimation:dynamicanimation:${Versions.legacy}"
77 | val preference = "androidx.preference:preference:${Versions.preference}"
78 |
79 | // multidex
80 | val multidex = "androidx.multidex:multidex:${Versions.multidex}"
81 |
82 | // databinding
83 | val databinding = "com.android.databinding:compiler:${Versions.androidPlugin}"
84 |
85 | // firebase
86 | val firebaseCore = "com.google.firebase:firebase-core:${Versions.firebaseCore}"
87 | val firebaseMessage = "com.google.firebase:firebase-messaging:${Versions.firebaseMessage}"
88 |
89 | // glide for image
90 | val glide = "com.github.bumptech.glide:glide:${Versions.glide}"
91 | val glideCompiler = "com.github.bumptech.glide:compiler:${Versions.glide}"
92 |
93 | val timber = "com.jakewharton.timber:timber:${Versions.timber}"
94 |
95 | // room database for local
96 | val room = "androidx.room:room-runtime:${Versions.room}"
97 | val roomCompiler = "androidx.room:room-compiler:${Versions.room}"
98 | val roomKtx = "androidx.room:room-ktx:${Versions.room}"
99 |
100 | // koin for di
101 | val koinCore = "org.koin:koin-core:${Versions.koin}"
102 | val koinAndroid = "org.koin:koin-android:${Versions.koin}"
103 | val koinScope = "org.koin:koin-androidx-scope:${Versions.koin}"
104 | val koinViewModel = "org.koin:koin-androidx-viewmodel:${Versions.koin}"
105 |
106 | // lifecycle
107 | val lifeCycleLiveData = "androidx.lifecycle:lifecycle-livedata:${Versions.lifecycle}"
108 | val lifeCycleViewModel = "androidx.lifecycle:lifecycle-viewmodel:${Versions.lifecycle}"
109 | val lifeCycleExtension = "androidx.lifecycle:lifecycle-extensions:${Versions.lifecycle}"
110 |
111 | val lifeCycleLiveDataKtx = "androidx.lifecycle:lifecycle-livedata-ktx:${Versions.lifeCycleKtx}"
112 | val lifeCycleRunTimeKtx = "androidx.lifecycle:lifecycle-runtime-ktx:${Versions.lifeCycleKtx}"
113 | val lifeCycleViewModelKtx = "androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.lifecycle}"
114 | val lifeCycleCommon = "androidx.lifecycle:lifecycle-common-java8:${Versions.lifecycle}"
115 |
116 | // retrofit
117 | val gson = "com.google.code.gson:gson:${Versions.gson}"
118 | val retrofit = "com.squareup.retrofit2:retrofit:${Versions.retrofit}"
119 | val retrofitConvertorGson = "com.squareup.retrofit2:converter-gson:${Versions.retrofit}"
120 | val retrofitCoroutineAdapter =
121 | "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:${Versions.retrofitCoroutines}"
122 |
123 | // okhttp
124 | val okhttp = "com.squareup.okhttp3:okhttp:${Versions.okhttp}"
125 | val okhttpLogging = "com.squareup.okhttp3:logging-interceptor:${Versions.okhttp}"
126 |
127 | // navigation
128 | val navFragment = "androidx.navigation:navigation-fragment:${Versions.navigation}"
129 | val navUi = "androidx.navigation:navigation-ui:${Versions.navigation}"
130 |
131 | val navFragmentKtx = "androidx.navigation:navigation-fragment-ktx:${Versions.navigation}"
132 | val navUiKtx = "androidx.navigation:navigation-ui-ktx:${Versions.navigation}"
133 |
134 |
135 | // test
136 | val koinTest = "org.koin:koin-test:${Versions.koin}"
137 | val lifeCycleTest = "androidx.arch.core:core-testing:${Versions.lifecycle}"
138 | val junit = "junit:junit:${Versions.junit}"
139 | val junitExt = "androidx.test.ext:junit:${Versions.junitExt}"
140 | val espressoCore = "androidx.test.espresso:espresso-core:${Versions.espresso}"
141 | val mockWebServer = "com.squareup.okhttp3:mockwebserver:${Versions.mockWebServer}"
142 | val coroutineTest = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.coroutines}"
143 | val roboelectric = "org.robolectric:robolectric:${Versions.robolectric}"
144 | }
145 |
146 | object BuildPlugins {
147 | val jitpack = "https://jitpack.io"
148 |
149 | val androidGradlePlugin = "com.android.tools.build:gradle:${Versions.androidPlugin}"
150 | val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlinPlugin}"
151 | val safeArgsGradlePlugin =
152 | "androidx.navigation:navigation-safe-args-gradle-plugin:${Versions.navigation}"
153 |
154 | val supportLibraryVectorDrawables = true
155 | val multidexEnable = true
156 | val testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
157 | }
--------------------------------------------------------------------------------
/common/util/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/common/util/build.gradle:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | id("com.android.library")
4 | id("kotlin-android")
5 | id("kotlin-android-extensions")
6 | }
7 |
8 | android {
9 | compileSdkVersion(Versions.compileSdk)
10 |
11 | defaultConfig {
12 | minSdkVersion(Versions.minSdk)
13 | targetSdkVersion(Versions.targetSdk)
14 | testInstrumentationRunner(BuildPlugins.testInstrumentationRunner)
15 | consumerProguardFiles 'consumer-rules.pro'
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | compileOptions {
26 | sourceCompatibility = JavaVersion.VERSION_1_8
27 | targetCompatibility = JavaVersion.VERSION_1_8
28 | }
29 |
30 | kotlinOptions {
31 | jvmTarget = JavaVersion.VERSION_1_8.toString()
32 | }
33 |
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(dir: 'libs', include: ['*.jar'])
38 | implementation(Libraries.kotlinStdLib)
39 | implementation(Libraries.appCompat)
40 | implementation(Libraries.coreKtx)
41 | implementation(Libraries.constraintLayout)
42 |
43 | implementation(Libraries.firebaseMessage)
44 | implementation(Libraries.kotlinCoroutineCore)
45 |
46 | testImplementation(Libraries.junit)
47 | androidTestImplementation(Libraries.junitExt)
48 | androidTestImplementation(Libraries.espressoCore)
49 |
50 | implementation(Libraries.glide)
51 |
52 | // Navigation component
53 | implementation(Libraries.navFragmentKtx)
54 | implementation(Libraries.navUiKtx)
55 | }
56 |
--------------------------------------------------------------------------------
/common/util/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/common/util/consumer-rules.pro
--------------------------------------------------------------------------------
/common/util/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/common/util/src/androidTest/java/com/developersancho/util/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.util
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.developersancho.util.test", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/common/util/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/common/util/src/main/java/com/developersancho/util/NetworkUtils.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.util
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Context
5 | import android.net.ConnectivityManager
6 | import android.net.NetworkCapabilities
7 | import android.os.Build
8 |
9 | object NetworkUtils {
10 |
11 | @SuppressLint("MissingPermission")
12 | @JvmStatic
13 | fun hasInternet(context: Context): Boolean {
14 | val connectivityManager =
15 | context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
16 | return if (Build.VERSION.SDK_INT < 23) {
17 | val activeNetworkInfo = connectivityManager.activeNetworkInfo
18 | activeNetworkInfo != null && activeNetworkInfo.isConnected
19 | } else {
20 | val nc =
21 | connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
22 | if (nc == null) {
23 | false
24 | } else {
25 | nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) ||
26 | nc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
27 | }
28 | }
29 | }
30 |
31 | @SuppressLint("MissingPermission")
32 | @JvmStatic
33 | fun isNetworkAvailable(context: Context): Boolean {
34 | val connectivityManager =
35 | context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
36 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
37 | val nw = connectivityManager.activeNetwork ?: return false
38 | val actNw = connectivityManager.getNetworkCapabilities(nw) ?: return false
39 | return when {
40 | actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true
41 | actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true
42 | //for other device how are able to connect with Ethernet
43 | actNw.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> true
44 | else -> false
45 | }
46 | } else {
47 | val nwInfo = connectivityManager.activeNetworkInfo ?: return false
48 | return nwInfo.isConnected
49 | }
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/common/util/src/main/java/com/developersancho/util/extensions/ActivityExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.util.extensions
2 |
3 | import android.app.Activity
4 | import android.widget.Toast
5 |
6 | fun Activity.toast(message: String) {
7 | Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
8 | }
9 |
10 |
11 | fun Activity.longToast(message: String) {
12 | Toast.makeText(this, message, Toast.LENGTH_LONG).show()
13 | }
--------------------------------------------------------------------------------
/common/util/src/test/java/com/developersancho/util/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.util
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/common/widget/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/common/widget/build.gradle:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | id("com.android.library")
4 | id("kotlin-android")
5 | id("kotlin-android-extensions")
6 | }
7 |
8 | android {
9 | compileSdkVersion(Versions.compileSdk)
10 |
11 | defaultConfig {
12 | minSdkVersion(Versions.minSdk)
13 | targetSdkVersion(Versions.targetSdk)
14 | testInstrumentationRunner(BuildPlugins.testInstrumentationRunner)
15 | vectorDrawables.useSupportLibrary = BuildPlugins.supportLibraryVectorDrawables
16 | consumerProguardFiles 'consumer-rules.pro'
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | compileOptions {
27 | sourceCompatibility = JavaVersion.VERSION_1_8
28 | targetCompatibility = JavaVersion.VERSION_1_8
29 | }
30 |
31 | kotlinOptions {
32 | jvmTarget = JavaVersion.VERSION_1_8.toString()
33 | }
34 |
35 | }
36 |
37 | dependencies {
38 | implementation fileTree(dir: 'libs', include: ['*.jar'])
39 | implementation(Libraries.kotlinStdLib)
40 | implementation(Libraries.appCompat)
41 | implementation(Libraries.coreKtx)
42 | implementation(Libraries.constraintLayout)
43 | implementation(Libraries.material)
44 | implementation(Libraries.legacy)
45 | implementation(Libraries.dynamicAnimation)
46 |
47 | testImplementation(Libraries.junit)
48 | androidTestImplementation(Libraries.junitExt)
49 | androidTestImplementation(Libraries.espressoCore)
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/common/widget/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/common/widget/consumer-rules.pro
--------------------------------------------------------------------------------
/common/widget/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/common/widget/src/androidTest/java/com/developersancho/widget/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.widget
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.developersancho.widget.test", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/common/widget/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/common/widget/src/main/java/com/developersancho/widget/ProgressLoadingDialog.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.widget
2 |
3 | import android.app.Dialog
4 | import android.content.Context
5 | import android.graphics.Color
6 | import android.graphics.drawable.ColorDrawable
7 | import android.view.Window
8 | import android.view.WindowManager
9 | import androidx.core.content.ContextCompat
10 | import androidx.lifecycle.Lifecycle
11 | import androidx.lifecycle.LifecycleObserver
12 | import androidx.lifecycle.OnLifecycleEvent
13 | import kotlinx.android.synthetic.main.dialog_progress_loading.*
14 |
15 | class ProgressLoadingDialog(context: Context) : Dialog(context), LifecycleObserver {
16 |
17 | init {
18 | requestWindowFeature(Window.FEATURE_NO_TITLE)
19 | setCancelable(true)
20 | window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
21 | setContentView(R.layout.dialog_progress_loading)
22 | val lp = WindowManager.LayoutParams()
23 | lp.copyFrom(window?.attributes)
24 | lp.width = WindowManager.LayoutParams.MATCH_PARENT
25 | lp.height = WindowManager.LayoutParams.MATCH_PARENT
26 | window?.attributes = lp
27 | progressBar.indeterminateDrawable.setColorFilter(
28 | ContextCompat.getColor(context, android.R.color.holo_red_dark),
29 | android.graphics.PorterDuff.Mode.MULTIPLY
30 | )
31 | }
32 |
33 | fun toggle(status: Boolean = true) {
34 | if (status) {
35 | if (!isShowing) {
36 | show()
37 | }
38 | } else {
39 | cancel()
40 | }
41 | }
42 |
43 | @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
44 | fun release() {
45 | cancel()
46 | }
47 | }
--------------------------------------------------------------------------------
/common/widget/src/main/res/layout/dialog_progress_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
21 |
22 |
--------------------------------------------------------------------------------
/common/widget/src/test/java/com/developersancho/widget/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.widget
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/core/local/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/core/local/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.library")
3 | id("kotlin-android")
4 | id("kotlin-android-extensions")
5 | id("kotlin-kapt")
6 | }
7 |
8 | android {
9 | compileSdkVersion(Versions.compileSdk)
10 |
11 | defaultConfig {
12 | minSdkVersion(Versions.minSdk)
13 | targetSdkVersion(Versions.targetSdk)
14 | testInstrumentationRunner(BuildPlugins.testInstrumentationRunner)
15 | multiDexEnabled(BuildPlugins.multidexEnable)
16 | consumerProguardFiles 'consumer-rules.pro'
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | compileOptions {
27 | sourceCompatibility = JavaVersion.VERSION_1_8
28 | targetCompatibility = JavaVersion.VERSION_1_8
29 | }
30 |
31 | kotlinOptions {
32 | jvmTarget = JavaVersion.VERSION_1_8.toString()
33 | }
34 |
35 | androidExtensions {
36 | experimental = true
37 | }
38 |
39 | kapt {
40 | useBuildCache = true
41 | }
42 |
43 | testOptions {
44 | unitTests {
45 | includeAndroidResources = true
46 | }
47 | }
48 |
49 | }
50 |
51 | dependencies {
52 | implementation fileTree(dir: 'libs', include: ['*.jar'])
53 | implementation(Libraries.kotlinStdLib)
54 | implementation(Libraries.appCompat)
55 | implementation(Libraries.coreKtx)
56 |
57 | // coroutines
58 | implementation(Libraries.kotlinCoroutineAndroid)
59 | implementation(Libraries.kotlinCoroutineCore)
60 |
61 | implementation(Libraries.roomKtx)
62 | kapt(Libraries.roomCompiler)
63 |
64 | implementation(Libraries.timber)
65 |
66 | implementation(Libraries.koinAndroid)
67 | implementation(Libraries.koinCore)
68 | implementation(Libraries.koinScope)
69 |
70 | testImplementation(Libraries.junit)
71 | testImplementation(Libraries.junitExt)
72 | testImplementation(Libraries.espressoCore)
73 | testImplementation(Libraries.roboelectric)
74 |
75 | testImplementation(Libraries.koinTest)
76 | testImplementation(Libraries.coroutineTest)
77 |
78 | implementation project(Modules.util)
79 | }
80 |
--------------------------------------------------------------------------------
/core/local/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/core/local/consumer-rules.pro
--------------------------------------------------------------------------------
/core/local/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/core/local/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/core/local/src/main/java/com/developersancho/local/dao/BaseDao.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.local.dao
2 |
3 | import androidx.room.*
4 |
5 | @Dao
6 | interface BaseDao {
7 | @Insert(onConflict = OnConflictStrategy.REPLACE)
8 | suspend fun insert(data: List)
9 |
10 | @Insert(onConflict = OnConflictStrategy.REPLACE)
11 | suspend fun insert(data: T)
12 | }
--------------------------------------------------------------------------------
/core/local/src/main/java/com/developersancho/local/dao/FavDao.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.local.dao
2 |
3 | import androidx.room.Dao
4 | import androidx.room.Query
5 | import com.developersancho.local.entity.FavEntity
6 |
7 | @Dao
8 | interface FavDao : BaseDao {
9 |
10 | @Query("DELETE FROM Fav_Table")
11 | suspend fun deleteAll()
12 |
13 | @Query("select * from Fav_Table")
14 | suspend fun favList(): List
15 |
16 | @Query("select * from Fav_Table where favId= :id")
17 | suspend fun getFavById(id: Int): FavEntity
18 |
19 | }
--------------------------------------------------------------------------------
/core/local/src/main/java/com/developersancho/local/db/CoreDatabase.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.local.db
2 |
3 | import androidx.room.Database
4 | import androidx.room.RoomDatabase
5 | import com.developersancho.local.dao.FavDao
6 | import com.developersancho.local.entity.FavEntity
7 |
8 | @Database(
9 | entities = [FavEntity::class],
10 | version = 1,
11 | exportSchema = false
12 | )
13 | abstract class CoreDatabase : RoomDatabase() {
14 | abstract fun favDao(): FavDao
15 | }
--------------------------------------------------------------------------------
/core/local/src/main/java/com/developersancho/local/di/LocalModule.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.local.di
2 |
3 | import androidx.room.Room
4 | import com.developersancho.local.db.CoreDatabase
5 | import org.koin.android.ext.koin.androidApplication
6 | import org.koin.dsl.module
7 |
8 | fun localModule(dbName: String) = module {
9 |
10 | single {
11 | Room.databaseBuilder(androidApplication(), CoreDatabase::class.java, dbName)
12 | .fallbackToDestructiveMigration()
13 | .build()
14 | }
15 |
16 |
17 | factory { get().favDao() }
18 | }
--------------------------------------------------------------------------------
/core/local/src/main/java/com/developersancho/local/entity/FavEntity.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.local.entity
2 |
3 | import androidx.room.Entity
4 | import androidx.room.PrimaryKey
5 |
6 | @Entity(tableName = "Fav_Table")
7 | class FavEntity(
8 | @PrimaryKey
9 | var favId: Int = 0,
10 | var isFav: Boolean = false
11 | )
--------------------------------------------------------------------------------
/core/local/src/test/java/com/developersancho/local/BaseLocalTest.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.local
2 |
3 | import androidx.room.Room
4 | import androidx.test.platform.app.InstrumentationRegistry
5 | import com.developersancho.local.db.CoreDatabase
6 | import org.junit.After
7 | import org.junit.Before
8 | import org.koin.core.context.startKoin
9 | import org.koin.core.context.stopKoin
10 | import org.koin.dsl.module
11 | import org.koin.test.KoinTest
12 | import org.koin.test.inject
13 |
14 | abstract class BaseLocalTest : KoinTest {
15 |
16 | private val coreDB: CoreDatabase by inject()
17 |
18 | @Before
19 | open fun setUp() {
20 | this.configureDi()
21 | }
22 |
23 | @After
24 | open fun tearDown() {
25 | coreDB.close()
26 | stopKoin()
27 | }
28 |
29 | private fun configureDi() {
30 | startKoin { modules(localTestModule) }
31 | }
32 |
33 | }
34 |
35 | val localTestModule = module {
36 | /* val context = ApplicationProvider.getApplicationContext() */
37 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
38 |
39 | single {
40 | Room.inMemoryDatabaseBuilder(appContext, CoreDatabase::class.java)
41 | .allowMainThreadQueries()
42 | .build()
43 | }
44 |
45 | factory { get().favDao() }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/core/local/src/test/java/com/developersancho/local/FavDaoTest.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.local
2 |
3 | import android.os.Build
4 | import com.developersancho.local.dao.FavDao
5 | import com.developersancho.local.entity.FavEntity
6 | import kotlinx.coroutines.ExperimentalCoroutinesApi
7 | import kotlinx.coroutines.runBlocking
8 | import org.junit.Assert
9 | import org.junit.Test
10 | import org.junit.runner.RunWith
11 | import org.koin.test.inject
12 | import org.robolectric.RobolectricTestRunner
13 | import org.robolectric.annotation.Config
14 | import timber.log.Timber
15 |
16 |
17 | @ExperimentalCoroutinesApi
18 | @RunWith(RobolectricTestRunner::class)
19 | @Config(sdk = [Build.VERSION_CODES.O_MR1])
20 | class FavDaoTest : BaseLocalTest() {
21 |
22 | private val favDao by inject()
23 |
24 | @Test
25 | fun insertFav() = runBlocking {
26 |
27 | favDao.insert(FavEntity(favId = 1, isFav = true))
28 |
29 | val favList = favDao.favList()
30 |
31 | Timber.d("size ------> ${favList.size}")
32 |
33 | Assert.assertEquals(1, favList.size)
34 |
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/core/manager/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/core/manager/build.gradle:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | id("com.android.library")
4 | id("kotlin-android")
5 | id("kotlin-android-extensions")
6 | id("kotlin-kapt")
7 | }
8 |
9 | android {
10 | compileSdkVersion(Versions.compileSdk)
11 |
12 | defaultConfig {
13 | minSdkVersion(Versions.minSdk)
14 | targetSdkVersion(Versions.targetSdk)
15 | testInstrumentationRunner(BuildPlugins.testInstrumentationRunner)
16 | multiDexEnabled(BuildPlugins.multidexEnable)
17 | consumerProguardFiles 'consumer-rules.pro'
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 |
27 | compileOptions {
28 | sourceCompatibility = JavaVersion.VERSION_1_8
29 | targetCompatibility = JavaVersion.VERSION_1_8
30 | }
31 |
32 | kotlinOptions {
33 | jvmTarget = JavaVersion.VERSION_1_8.toString()
34 | }
35 |
36 | androidExtensions {
37 | experimental = true
38 | }
39 |
40 | kapt {
41 | useBuildCache = true
42 | }
43 |
44 | testOptions {
45 | unitTests {
46 | includeAndroidResources = true
47 | }
48 | }
49 |
50 | }
51 |
52 | dependencies {
53 | implementation fileTree(dir: 'libs', include: ['*.jar'])
54 | implementation(Libraries.kotlinStdLib)
55 | implementation(Libraries.appCompat)
56 | implementation(Libraries.coreKtx)
57 |
58 | // retrofit
59 | implementation(Libraries.gson)
60 | implementation(Libraries.retrofit)
61 | implementation(Libraries.retrofitConvertorGson)
62 | implementation(Libraries.okhttp)
63 | implementation(Libraries.okhttpLogging)
64 | implementation(Libraries.retrofitCoroutineAdapter)
65 |
66 | // koin
67 | implementation(Libraries.koinAndroid)
68 | implementation(Libraries.koinCore)
69 | implementation(Libraries.koinScope)
70 |
71 | implementation(Libraries.roomKtx)
72 | kapt(Libraries.roomCompiler)
73 |
74 | implementation(Libraries.timber)
75 |
76 | // testing
77 | androidTestImplementation(Libraries.junit)
78 | androidTestImplementation(Libraries.koinTest)
79 | testImplementation(Libraries.mockWebServer)
80 |
81 | androidTestImplementation(Libraries.junitExt)
82 | androidTestImplementation(Libraries.espressoCore)
83 |
84 | testImplementation(Libraries.roboelectric)
85 |
86 | implementation project(Modules.remote)
87 | implementation project(Modules.local)
88 | }
89 |
--------------------------------------------------------------------------------
/core/manager/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/core/manager/consumer-rules.pro
--------------------------------------------------------------------------------
/core/manager/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/core/manager/src/androidTest/java/com/developersancho/manager/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.manager
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.developersancho.manager.test", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/core/manager/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/core/manager/src/main/java/com/developersancho/manager/DataManager.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.manager
2 |
3 | import com.developersancho.local.dao.FavDao
4 | import com.developersancho.local.entity.FavEntity
5 | import com.developersancho.manager.base.BaseDataManager
6 | import com.developersancho.remote.model.RepoResponse
7 | import com.developersancho.remote.network.NetworkState
8 | import com.developersancho.remote.service.IRepoService
9 | import kotlinx.coroutines.flow.Flow
10 | import kotlinx.coroutines.flow.flow
11 |
12 | class DataManager(
13 | private val repoService: IRepoService,
14 | private val favDao: FavDao
15 | ) : BaseDataManager(), IDataManager {
16 |
17 | override fun getRepos(userName: String): Flow> = flow {
18 | emit(apiCall { repoService.repos(userName) })
19 | }
20 |
21 | override suspend fun insertFav(favEntity: FavEntity) = favDao.insert(favEntity)
22 |
23 | override suspend fun favList(): List = favDao.favList()
24 | }
--------------------------------------------------------------------------------
/core/manager/src/main/java/com/developersancho/manager/IDataManager.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.manager
2 |
3 | import com.developersancho.local.entity.FavEntity
4 | import com.developersancho.remote.model.RepoResponse
5 | import com.developersancho.remote.network.NetworkState
6 | import kotlinx.coroutines.flow.Flow
7 |
8 | interface IDataManager {
9 |
10 | fun getRepos(userName: String): Flow>
11 |
12 | suspend fun insertFav(favEntity: FavEntity)
13 |
14 | suspend fun favList(): List
15 |
16 | }
--------------------------------------------------------------------------------
/core/manager/src/main/java/com/developersancho/manager/base/BaseDataManager.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.manager.base
2 |
3 | import com.developersancho.remote.network.NetworkState
4 | import com.developersancho.remote.network.RemoteDataException
5 | import kotlinx.coroutines.Deferred
6 | import kotlinx.coroutines.delay
7 | import retrofit2.Response
8 | import java.io.IOException
9 |
10 | abstract class BaseDataManager {
11 |
12 | // TODO("add retry policy and local(db) cache via remote service method")
13 |
14 | protected suspend fun apiCallResponse(call: suspend () -> Response): NetworkState {
15 | return try {
16 | val response = call()
17 | if (response.isSuccessful) {
18 | val body = response.body()
19 | if (body != null)
20 | NetworkState.Success(body)
21 | else
22 | NetworkState.Empty("no json body")
23 | } else {
24 | NetworkState.Error(RemoteDataException(response.errorBody()))
25 | }
26 |
27 | } catch (ex: Throwable) {
28 | NetworkState.Error(RemoteDataException(ex))
29 | }
30 | }
31 |
32 | protected suspend fun apiCall(call: suspend () -> T): NetworkState {
33 | return try {
34 | val response = call()
35 | NetworkState.Success(response)
36 | } catch (ex: Throwable) {
37 | NetworkState.Error(RemoteDataException(ex))
38 | }
39 | }
40 |
41 | protected suspend fun apiCallRetry(
42 | times: Int = 3,
43 | call: suspend () -> T
44 | ): NetworkState {
45 | return try {
46 | val response = apiCallIO(timesValue = times, block = call)
47 | NetworkState.Success(response)
48 | } catch (ex: Throwable) {
49 | NetworkState.Error(RemoteDataException(ex))
50 | }
51 | }
52 |
53 | private suspend fun apiCallIO(
54 | timesValue: Int = 4,
55 | initialDelay: Long = 100, // 0.1 second
56 | maxDelay: Long = 1000, // 1 second
57 | factor: Double = 2.0,
58 | block: suspend () -> T
59 | ): T {
60 | var currentDelay = initialDelay
61 | repeat(timesValue - 1) {
62 | try {
63 | return block()
64 | } catch (e: IOException) {
65 | // you can log an error here and/or make a more finer-grained
66 | // analysis of the cause to see if retry is needed
67 | }
68 | delay(currentDelay)
69 | currentDelay = (currentDelay * factor).toLong().coerceAtMost(maxDelay)
70 | }
71 | return block() // last attempt
72 | }
73 |
74 | protected suspend inline fun apiCallDeferred(request: Deferred>): NetworkState {
75 | return try {
76 | val response = request.await()
77 | if (response.isSuccessful) {
78 | val body = response.body()
79 | if (body != null)
80 | NetworkState.Success(body)
81 | else
82 | NetworkState.Empty("no json body")
83 | } else {
84 | NetworkState.Error(RemoteDataException(response.errorBody()))
85 | }
86 | } catch (ex: Throwable) {
87 | NetworkState.Error(RemoteDataException(ex))
88 | }
89 | }
90 | }
--------------------------------------------------------------------------------
/core/manager/src/main/java/com/developersancho/manager/di/ManagerModule.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.manager.di
2 |
3 | import com.developersancho.manager.DataManager
4 | import com.developersancho.manager.IDataManager
5 | import org.koin.dsl.module
6 |
7 | val managerModule = module {
8 | factory {
9 | DataManager(get(), get()) as IDataManager
10 | }
11 | }
--------------------------------------------------------------------------------
/core/manager/src/test/java/com/developersancho/manager/BaseManagerTest.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.manager
2 |
3 | import androidx.room.Room
4 | import androidx.test.platform.app.InstrumentationRegistry
5 | import com.developersancho.local.db.CoreDatabase
6 | import com.developersancho.remote.service.IRepoService
7 | import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
8 | import okhttp3.OkHttpClient
9 | import okhttp3.logging.HttpLoggingInterceptor
10 | import okhttp3.mockwebserver.MockWebServer
11 | import org.junit.After
12 | import org.junit.Before
13 | import org.koin.core.context.startKoin
14 | import org.koin.core.context.stopKoin
15 | import org.koin.dsl.module
16 | import org.koin.test.KoinTest
17 | import org.koin.test.inject
18 | import retrofit2.Retrofit
19 | import retrofit2.converter.gson.GsonConverterFactory
20 | import java.util.concurrent.TimeUnit
21 |
22 | abstract class BaseManagerTest : KoinTest {
23 | protected lateinit var mockServer: MockWebServer
24 | protected lateinit var dataManager: DataManager
25 |
26 | private val db: CoreDatabase by inject()
27 |
28 | @Before
29 | open fun setUp() {
30 | this.configureMockServer()
31 | this.configureDi()
32 | }
33 |
34 | @After
35 | open fun tearDown() {
36 | this.stopMockServer()
37 | db.close()
38 | stopKoin()
39 | }
40 |
41 | private fun configureDi() {
42 | startKoin { modules(managerTestModule) }
43 | }
44 |
45 | private fun configureMockServer() {
46 | mockServer = MockWebServer()
47 | mockServer.start()
48 | }
49 |
50 | private fun stopMockServer() {
51 | mockServer.shutdown()
52 | }
53 | }
54 |
55 | val managerTestModule = module {
56 |
57 | // local
58 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
59 |
60 | single {
61 | Room.inMemoryDatabaseBuilder(appContext, CoreDatabase::class.java)
62 | .allowMainThreadQueries()
63 | .build()
64 | }
65 |
66 | factory { get().favDao() }
67 |
68 |
69 | // remote
70 | single {
71 | OkHttpClient.Builder()
72 | .connectTimeout(30, TimeUnit.SECONDS)
73 | .readTimeout(30, TimeUnit.SECONDS)
74 | .writeTimeout(30, TimeUnit.SECONDS)
75 | .addInterceptor(HttpLoggingInterceptor().apply {
76 | level = HttpLoggingInterceptor.Level.BODY
77 | })
78 | .build()
79 | }
80 |
81 | single {
82 | Retrofit.Builder()
83 | .client(get())
84 | .baseUrl("https://api.github.com/")
85 | .addConverterFactory(GsonConverterFactory.create())
86 | .addCallAdapterFactory(CoroutineCallAdapterFactory())
87 | .build()
88 | }
89 |
90 | factory {
91 | get().create(IRepoService::class.java)
92 | }
93 | }
94 |
95 |
96 |
--------------------------------------------------------------------------------
/core/manager/src/test/java/com/developersancho/manager/ManagerTest.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.manager
2 |
3 | import android.os.Build
4 | import com.developersancho.local.dao.FavDao
5 | import com.developersancho.remote.network.NetworkState
6 | import com.developersancho.remote.service.IRepoService
7 | import kotlinx.coroutines.ExperimentalCoroutinesApi
8 | import kotlinx.coroutines.flow.collect
9 | import kotlinx.coroutines.runBlocking
10 | import org.junit.Assert
11 | import org.junit.Before
12 | import org.junit.Test
13 | import org.junit.runner.RunWith
14 | import org.koin.test.inject
15 | import org.mockito.MockitoAnnotations
16 | import org.robolectric.RobolectricTestRunner
17 | import org.robolectric.annotation.Config
18 | import timber.log.Timber
19 |
20 |
21 | @ExperimentalCoroutinesApi
22 | @RunWith(RobolectricTestRunner::class)
23 | @Config(sdk = [Build.VERSION_CODES.O_MR1])
24 | class ManagerTest : BaseManagerTest() {
25 |
26 | private val repoService by inject()
27 | private val favDao by inject()
28 |
29 |
30 | @Before
31 | fun setUpData() {
32 | MockitoAnnotations.initMocks(this)
33 | dataManager = DataManager(repoService, favDao)
34 | }
35 |
36 | @Test
37 | fun `Get Repos By UserName`() = runBlocking {
38 | dataManager.getRepos("developersancho").collect {
39 | when (it) {
40 | is NetworkState.Success -> {
41 | Assert.assertEquals(30, it.response?.size)
42 | Assert.assertEquals(117545989, it.response?.first()?.id)
43 | Assert.assertEquals("a4app", it.response?.first()?.name)
44 | }
45 |
46 | is NetworkState.Error -> {
47 | Timber.d("NetworkState.Error : ${it.exception.message}")
48 | }
49 | }
50 | }
51 | }
52 |
53 | }
--------------------------------------------------------------------------------
/core/remote/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/core/remote/build.gradle:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | id("com.android.library")
4 | id("kotlin-android")
5 | id("kotlin-android-extensions")
6 | }
7 |
8 | android {
9 | compileSdkVersion(Versions.compileSdk)
10 |
11 | defaultConfig {
12 | minSdkVersion(Versions.minSdk)
13 | targetSdkVersion(Versions.targetSdk)
14 | testInstrumentationRunner(BuildPlugins.testInstrumentationRunner)
15 | consumerProguardFiles 'consumer-rules.pro'
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | compileOptions {
26 | sourceCompatibility = JavaVersion.VERSION_1_8
27 | targetCompatibility = JavaVersion.VERSION_1_8
28 | }
29 |
30 | kotlinOptions {
31 | jvmTarget = JavaVersion.VERSION_1_8.toString()
32 | }
33 |
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(dir: 'libs', include: ['*.jar'])
38 | implementation(Libraries.kotlinStdLib)
39 | implementation(Libraries.appCompat)
40 | implementation(Libraries.coreKtx)
41 |
42 | // coroutines
43 | implementation(Libraries.kotlinCoroutineAndroid)
44 | implementation(Libraries.kotlinCoroutineCore)
45 |
46 | // retrofit
47 | implementation(Libraries.gson)
48 | implementation(Libraries.retrofit)
49 | implementation(Libraries.retrofitConvertorGson)
50 | implementation(Libraries.okhttp)
51 | implementation(Libraries.okhttpLogging)
52 | implementation(Libraries.retrofitCoroutineAdapter)
53 |
54 | // koin
55 | implementation(Libraries.koinAndroid)
56 | implementation(Libraries.koinCore)
57 | implementation(Libraries.koinScope)
58 |
59 | testImplementation(Libraries.junit)
60 | testImplementation(Libraries.junitExt)
61 | testImplementation(Libraries.koinTest)
62 | testImplementation(Libraries.mockWebServer)
63 | testImplementation(Libraries.koinTest)
64 |
65 |
66 | implementation project(Modules.util)
67 | }
68 |
--------------------------------------------------------------------------------
/core/remote/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/core/remote/consumer-rules.pro
--------------------------------------------------------------------------------
/core/remote/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/core/remote/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/core/remote/src/main/java/com/developersancho/remote/di/RemoteModule.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.remote.di
2 |
3 | import com.developersancho.remote.network.AuthInterceptor
4 | import com.developersancho.remote.service.IRepoService
5 | import com.developersancho.util.NetworkUtils
6 | import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
7 | import okhttp3.Cache
8 | import okhttp3.OkHttpClient
9 | import okhttp3.logging.HttpLoggingInterceptor
10 | import org.koin.android.ext.koin.androidContext
11 | import org.koin.dsl.module
12 | import retrofit2.Retrofit
13 | import retrofit2.converter.gson.GsonConverterFactory
14 | import java.io.File
15 | import java.util.*
16 | import java.util.concurrent.TimeUnit
17 |
18 | fun remoteModule(baseUrl: String, isDebug: Boolean = true) = module {
19 |
20 | single { File(androidContext().cacheDir, UUID.randomUUID().toString()) }
21 |
22 | single { Cache(get(), 5 * 1024 * 1024) }
23 |
24 | single {
25 | OkHttpClient.Builder()
26 | .cache(get())
27 | .connectTimeout(30, TimeUnit.SECONDS)
28 | .readTimeout(30, TimeUnit.SECONDS)
29 | .writeTimeout(30, TimeUnit.SECONDS)
30 | .followSslRedirects(true)
31 | .addInterceptor { chain ->
32 | var request = chain.request().newBuilder()
33 |
34 | // for offline request that we caching
35 | if (NetworkUtils.hasInternet(androidContext())) {
36 | request.addHeader("Cache-Control", "public, max-age=" + 1)
37 | } else {
38 | request.addHeader(
39 | "Cache-Control",
40 | "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 7
41 | )
42 | }
43 |
44 |
45 | chain.proceed(request.build())
46 | }
47 | .addInterceptor(HttpLoggingInterceptor().apply {
48 | level = if (isDebug)
49 | HttpLoggingInterceptor.Level.BODY
50 | else
51 | HttpLoggingInterceptor.Level.NONE
52 | })
53 | //.addInterceptor(AuthInterceptor(tokenType = "Bearer", accessToken = "*********"))
54 | .build()
55 | }
56 |
57 | single {
58 | Retrofit.Builder()
59 | .client(get())
60 | .baseUrl(baseUrl)
61 | .addConverterFactory(GsonConverterFactory.create())
62 | .addCallAdapterFactory(CoroutineCallAdapterFactory())
63 | .build()
64 | }
65 |
66 | factory { get().create(IRepoService::class.java) }
67 | }
--------------------------------------------------------------------------------
/core/remote/src/main/java/com/developersancho/remote/model/License.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.remote.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 | import java.io.Serializable
5 |
6 | data class License(
7 |
8 | @SerializedName("key")
9 | var key: String? = null,
10 |
11 | @SerializedName("name")
12 | var name: String? = null,
13 |
14 | @SerializedName("node_id")
15 | var nodeId: String? = null,
16 |
17 | @SerializedName("spdx_id")
18 | var spdxId: String? = null,
19 |
20 | @SerializedName("url")
21 | var url: String? = null
22 |
23 | ) : Serializable
--------------------------------------------------------------------------------
/core/remote/src/main/java/com/developersancho/remote/model/Owner.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.remote.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 | import java.io.Serializable
5 |
6 | data class Owner(
7 |
8 | @SerializedName("avatar_url")
9 | var avatarUrl: String? = null,
10 |
11 | @SerializedName("events_url")
12 | var eventsUrl: String? = null,
13 |
14 | @SerializedName("followers_url")
15 | var followersUrl: String? = null,
16 |
17 | @SerializedName("following_url")
18 | var followingUrl: String? = null,
19 |
20 | @SerializedName("gists_url")
21 | var gistsUrl: String? = null,
22 |
23 | @SerializedName("gravatar_id")
24 | var gravatarId: String? = null,
25 |
26 | @SerializedName("html_url")
27 | var htmlUrl: String? = null,
28 |
29 | @SerializedName("id")
30 | var id: Int = 0,
31 |
32 | @SerializedName("login")
33 | var login: String? = null,
34 |
35 | @SerializedName("node_id")
36 | var nodeId: String? = null,
37 |
38 | @SerializedName("organizations_url")
39 | var organizationsUrl: String? = null,
40 |
41 | @SerializedName("received_events_url")
42 | var receivedEventsUrl: String? = null,
43 |
44 | @SerializedName("repos_url")
45 | var reposUrl: String? = null,
46 |
47 | @SerializedName("site_admin")
48 | var siteAdmin: Boolean = false,
49 |
50 | @SerializedName("starred_url")
51 | var starredUrl: String? = null,
52 |
53 | @SerializedName("subscriptions_url")
54 | var subscriptionsUrl: String? = null,
55 |
56 | @SerializedName("type")
57 | var type: String? = null,
58 |
59 | @SerializedName("url")
60 | var url: String? = null
61 |
62 | ) : Serializable
--------------------------------------------------------------------------------
/core/remote/src/main/java/com/developersancho/remote/model/RepoResponse.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.remote.model
2 |
3 | class RepoResponse : ArrayList()
--------------------------------------------------------------------------------
/core/remote/src/main/java/com/developersancho/remote/model/Repos.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.remote.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 | import java.io.Serializable
5 |
6 | data class Repos(
7 |
8 | @SerializedName("archive_url")
9 | var archiveUrl: String? = null,
10 |
11 | @SerializedName("archived")
12 | var archived: Boolean = false,
13 |
14 | @SerializedName("assignees_url")
15 | var assigneesUrl: String? = null,
16 |
17 | @SerializedName("blobs_url")
18 | var blobsUrl: String? = null,
19 |
20 | @SerializedName("branches_url")
21 | var branchesUrl: String? = null,
22 |
23 | @SerializedName("clone_url")
24 | var cloneUrl: String? = null,
25 |
26 | @SerializedName("collaborators_url")
27 | var collaboratorsUrl: String? = null,
28 |
29 | @SerializedName("comments_url")
30 | var commentsUrl: String? = null,
31 |
32 | @SerializedName("commits_url")
33 | var commitsUrl: String? = null,
34 |
35 | @SerializedName("compare_url")
36 | var compareUrl: String? = null,
37 |
38 | @SerializedName("contents_url")
39 | var contentsUrl: String? = null,
40 |
41 | @SerializedName("contributors_url")
42 | var contributorsUrl: String? = null,
43 |
44 | @SerializedName("created_at")
45 | var createdAt: String? = null,
46 |
47 | @SerializedName("default_branch")
48 | var defaultBranch: String? = null,
49 |
50 | @SerializedName("deployments_url")
51 | var deploymentsUrl: String? = null,
52 |
53 | @SerializedName("description")
54 | var description: String? = null,
55 |
56 | @SerializedName("disabled")
57 | var disabled: Boolean = false,
58 |
59 | @SerializedName("downloads_url")
60 | var downloadsUrl: String? = null,
61 |
62 | @SerializedName("events_url")
63 | var eventsUrl: String? = null,
64 |
65 | @SerializedName("fork")
66 | var fork: Boolean = false,
67 |
68 | @SerializedName("forks")
69 | var forks: Int = 0,
70 |
71 | @SerializedName("forks_count")
72 | var forksCount: Int = 0,
73 |
74 | @SerializedName("forks_url")
75 | var forksUrl: String? = null,
76 |
77 | @SerializedName("full_name")
78 | var fullName: String? = null,
79 |
80 | @SerializedName("git_commits_url")
81 | var gitCommitsUrl: String? = null,
82 |
83 | @SerializedName("git_refs_url")
84 | var gitRefsUrl: String? = null,
85 |
86 | @SerializedName("git_tags_url")
87 | var gitTagsUrl: String? = null,
88 |
89 | @SerializedName("git_url")
90 | var gitUrl: String? = null,
91 |
92 | @SerializedName("has_downloads")
93 | var hasDownloads: Boolean = false,
94 |
95 | @SerializedName("has_issues")
96 | var hasIssues: Boolean = false,
97 |
98 | @SerializedName("has_pages")
99 | var hasPages: Boolean = false,
100 |
101 | @SerializedName("has_projects")
102 | var hasProjects: Boolean = false,
103 |
104 | @SerializedName("has_wiki")
105 | var hasWiki: Boolean = false,
106 |
107 | @SerializedName("homepage")
108 | var homepage: String? = null,
109 |
110 | @SerializedName("hooks_url")
111 | var hooksUrl: String? = null,
112 |
113 | @SerializedName("html_url")
114 | var htmlUrl: String? = null,
115 |
116 | @SerializedName("id")
117 | var id: Int = 0,
118 |
119 | @SerializedName("issue_comment_url")
120 | var issueCommentUrl: String? = null,
121 |
122 | @SerializedName("issue_events_url")
123 | var issueEventsUrl: String? = null,
124 |
125 | @SerializedName("issues_url")
126 | var issuesUrl: String? = null,
127 |
128 | @SerializedName("keys_url")
129 | var keysUrl: String? = null,
130 |
131 | @SerializedName("labels_url")
132 | var labelsUrl: String? = null,
133 |
134 | @SerializedName("language")
135 | var language: String? = null,
136 |
137 | @SerializedName("languages_url")
138 | var languagesUrl: String? = null,
139 |
140 | @SerializedName("license")
141 | var license: License? = null,
142 |
143 | @SerializedName("merges_url")
144 | var mergesUrl: String? = null,
145 |
146 | @SerializedName("milestones_url")
147 | var milestonesUrl: String? = null,
148 |
149 | @SerializedName("mirror_url")
150 | var mirrorUrl: String? = null,
151 |
152 | @SerializedName("name")
153 | var name: String? = null,
154 |
155 | @SerializedName("node_id")
156 | var nodeId: String? = null,
157 |
158 | @SerializedName("notifications_url")
159 | var notificationsUrl: String? = null,
160 |
161 | @SerializedName("open_issues")
162 | var openIssues: Int = 0,
163 |
164 | @SerializedName("open_issues_count")
165 | var openIssuesCount: Int = 0,
166 |
167 | @SerializedName("owner")
168 | var owner: Owner? = null,
169 |
170 | @SerializedName("private")
171 | var private: Boolean = false,
172 |
173 | @SerializedName("pulls_url")
174 | var pullsUrl: String? = null,
175 |
176 | @SerializedName("pushed_at")
177 | var pushedAt: String? = null,
178 |
179 | @SerializedName("releases_url")
180 | var releasesUrl: String? = null,
181 |
182 | @SerializedName("size")
183 | var size: Int = 0,
184 |
185 | @SerializedName("ssh_url")
186 | var sshUrl: String? = null,
187 |
188 | @SerializedName("stargazers_count")
189 | var stargazersCount: Int = 0,
190 |
191 | @SerializedName("stargazers_url")
192 | var stargazersUrl: String? = null,
193 |
194 | @SerializedName("statuses_url")
195 | var statusesUrl: String? = null,
196 |
197 | @SerializedName("subscribers_url")
198 | var subscribersUrl: String? = null,
199 |
200 | @SerializedName("subscription_url")
201 | var subscriptionUrl: String? = null,
202 |
203 | @SerializedName("svn_url")
204 | var svnUrl: String? = null,
205 |
206 | @SerializedName("tags_url")
207 | var tagsUrl: String? = null,
208 |
209 | @SerializedName("teams_url")
210 | var teamsUrl: String? = null,
211 |
212 | @SerializedName("trees_url")
213 | var treesUrl: String? = null,
214 |
215 | @SerializedName("updated_at")
216 | var updatedAt: String? = null,
217 |
218 | @SerializedName("url")
219 | var url: String? = null,
220 |
221 | @SerializedName("watchers")
222 | var watchers: Int = 0,
223 |
224 | @SerializedName("watchers_count")
225 | var watchersCount: Int = 0,
226 |
227 | @Transient
228 | var isFav: Boolean = false
229 |
230 | ) : Serializable
--------------------------------------------------------------------------------
/core/remote/src/main/java/com/developersancho/remote/network/AuthInterceptor.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.remote.network
2 |
3 | import okhttp3.Interceptor
4 |
5 | class AuthInterceptor(
6 | private val tokenType: String,
7 | private val accessToken: String
8 | ) : Interceptor {
9 |
10 | override fun intercept(chain: Interceptor.Chain): okhttp3.Response {
11 | var request = chain.request()
12 | request = request.newBuilder().header("Authorization", "$tokenType $accessToken").build()
13 | return chain.proceed(request)
14 | }
15 | }
--------------------------------------------------------------------------------
/core/remote/src/main/java/com/developersancho/remote/network/NetworkState.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.remote.network
2 |
3 | sealed class NetworkState {
4 | class Success(val response: T) : NetworkState()
5 | class Empty(val empty: String) : NetworkState()
6 | class Error(val exception: RemoteDataException) : NetworkState()
7 | }
--------------------------------------------------------------------------------
/core/remote/src/main/java/com/developersancho/remote/network/RemoteDataException.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.remote.network
2 |
3 | import android.util.Log
4 | import com.google.gson.Gson
5 | import okhttp3.ResponseBody
6 | import retrofit2.HttpException
7 | import java.io.IOException
8 | import java.net.SocketTimeoutException
9 | import java.net.UnknownHostException
10 |
11 |
12 | // TODO("do refactor")
13 | class RemoteDataException {
14 | var code: Int = 0
15 | var message: String = ""
16 | lateinit var errorStatus: ErrorStatus
17 |
18 | constructor(throwable: Throwable) {
19 | when (throwable) {
20 | // if throwable is an instance of HttpException
21 | // then attempt to parse error data from response body
22 | is HttpException -> {
23 | // handle UNAUTHORIZED situation (when token expired)
24 | if (throwable.code() == 401) {
25 | errorStatus =
26 | ErrorStatus.UNAUTHORIZED
27 | code = throwable.code()
28 | message = "Lütfen Giriş Yapınız."
29 | } else {
30 | getHttpError(throwable.response()?.errorBody())
31 | }
32 | }
33 |
34 | // handle api call timeout error
35 | is SocketTimeoutException -> {
36 | errorStatus =
37 | ErrorStatus.TIMEOUT
38 | code = 0
39 | message = "Bağlantı Zaman Aşımına Uğradı."
40 | }
41 |
42 | // handle connection error
43 | is IOException -> {
44 | errorStatus =
45 | ErrorStatus.NO_CONNECTION
46 | code = 0
47 | message = "İnternet Bağlantınızı Kontrol Ediniz."
48 | }
49 |
50 | is UnknownHostException -> {
51 | errorStatus =
52 | ErrorStatus.NO_CONNECTION
53 | code = 0
54 | message = "İnternet Bağlantınızı Kontrol Ediniz."
55 | }
56 | else -> {
57 | errorStatus =
58 | ErrorStatus.EMPTY_RESPONSE
59 | code = 1453
60 | message = throwable.localizedMessage
61 | }
62 | }
63 | }
64 |
65 | constructor(responseBody: ResponseBody?) {
66 | getHttpError(responseBody)
67 | }
68 |
69 |
70 | /**
71 | * attempts to parse http response body and get error data from it
72 | *
73 | * @param body retrofit response body
74 | * @return returns an instance of [ErrorModel] with parsed data or NOT_DEFINED status
75 | */
76 | private fun getHttpError(body: ResponseBody?) {
77 | return try {
78 | // use response body to get error detail
79 | val result = body?.string()
80 | Log.d("getHttpError", "getErrorMessage() called with: errorBody = [$result]")
81 | val json = Gson().fromJson(result, Any::class.java)
82 | errorStatus =
83 | ErrorStatus.BAD_RESPONSE
84 | code = 400
85 | message = json.toString()
86 | } catch (e: Throwable) {
87 | //e.printStackTrace()
88 | errorStatus =
89 | ErrorStatus.NOT_DEFINED
90 | code = -1
91 | message = e.localizedMessage
92 | }
93 |
94 | }
95 | }
96 |
97 | enum class ErrorStatus {
98 | /**
99 | * error in connecting to repository (Server or Database)
100 | */
101 | NO_CONNECTION,
102 | /**
103 | * error in getting value (Json Error, Server Error, etc)
104 | */
105 | BAD_RESPONSE,
106 | /**
107 | * Time out error
108 | */
109 | TIMEOUT,
110 | /**
111 | * no data available in repository
112 | */
113 | EMPTY_RESPONSE,
114 | /**
115 | * an unexpected error
116 | */
117 | NOT_DEFINED,
118 | /**
119 | * bad credential
120 | */
121 | UNAUTHORIZED
122 | }
--------------------------------------------------------------------------------
/core/remote/src/main/java/com/developersancho/remote/service/IRepoService.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.remote.service
2 |
3 | import com.developersancho.remote.model.RepoResponse
4 | import retrofit2.http.GET
5 | import retrofit2.http.Path
6 |
7 | interface IRepoService {
8 |
9 | @GET("users/{user}/repos")
10 | suspend fun repos(@Path("user") user: String): RepoResponse
11 |
12 | }
--------------------------------------------------------------------------------
/core/remote/src/test/java/com/developersancho/remote/BaseRemoteTest.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.remote
2 |
3 | import com.developersancho.remote.service.IRepoService
4 | import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
5 | import okhttp3.OkHttpClient
6 | import okhttp3.logging.HttpLoggingInterceptor
7 | import okhttp3.mockwebserver.MockResponse
8 | import okhttp3.mockwebserver.MockWebServer
9 | import org.junit.After
10 | import org.junit.Before
11 | import org.koin.core.context.startKoin
12 | import org.koin.core.context.stopKoin
13 | import org.koin.dsl.module
14 | import org.koin.test.KoinTest
15 | import retrofit2.Retrofit
16 | import retrofit2.converter.gson.GsonConverterFactory
17 | import java.io.File
18 | import java.util.concurrent.TimeUnit
19 |
20 | abstract class BaseRemoteTest : KoinTest {
21 | protected lateinit var mockServer: MockWebServer
22 |
23 | @Before
24 | open fun setUp() {
25 | this.configureMockServer()
26 | this.configureDi()
27 | }
28 |
29 | @After
30 | open fun tearDown() {
31 | this.stopMockServer()
32 | stopKoin()
33 | }
34 |
35 | private fun configureDi() {
36 | startKoin { modules(remoteTestModule) }
37 | }
38 |
39 | private fun configureMockServer() {
40 | mockServer = MockWebServer()
41 | mockServer.start()
42 | }
43 |
44 | private fun stopMockServer() {
45 | mockServer.shutdown()
46 | }
47 |
48 | fun mockHttpResponse(mockServer: MockWebServer, fileName: String, responseCode: Int) =
49 | mockServer.enqueue(
50 | MockResponse()
51 | .setResponseCode(responseCode)
52 | .setBody(getJson(fileName))
53 | )
54 |
55 | private fun getJson(path: String): String {
56 | val uri = this.javaClass.classLoader?.getResource(path)
57 | val file = File(uri?.path)
58 | return String(file.readBytes())
59 | }
60 | }
61 |
62 | val remoteTestModule = module {
63 | single {
64 | OkHttpClient.Builder()
65 | .connectTimeout(30, TimeUnit.SECONDS)
66 | .readTimeout(30, TimeUnit.SECONDS)
67 | .writeTimeout(30, TimeUnit.SECONDS)
68 | .addInterceptor(HttpLoggingInterceptor().apply {
69 | level = HttpLoggingInterceptor.Level.BODY
70 | })
71 | .build()
72 | }
73 |
74 | single {
75 | Retrofit.Builder()
76 | .client(get())
77 | .baseUrl("https://api.github.com/")
78 | .addConverterFactory(GsonConverterFactory.create())
79 | .addCallAdapterFactory(CoroutineCallAdapterFactory())
80 | .build()
81 | }
82 |
83 | factory {
84 | get().create(IRepoService::class.java)
85 | }
86 | }
--------------------------------------------------------------------------------
/core/remote/src/test/java/com/developersancho/remote/RepoServiceTest.kt:
--------------------------------------------------------------------------------
1 | package com.developersancho.remote
2 |
3 | import com.developersancho.remote.service.IRepoService
4 | import kotlinx.coroutines.runBlocking
5 | import org.junit.Assert
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 | import org.junit.runners.JUnit4
9 | import org.koin.test.inject
10 |
11 |
12 | @RunWith(JUnit4::class)
13 | class RepoServiceTest : BaseRemoteTest() {
14 |
15 | private val service by inject()
16 |
17 | @Test
18 | fun search_repo() = runBlocking {
19 | val response = service.repos(user = "developersancho")
20 |
21 | Assert.assertEquals(30, response?.size)
22 | Assert.assertEquals(117545989, response?.first()?.id)
23 | Assert.assertEquals("a4app", response?.first()?.name)
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Nov 02 21:00:10 EET 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/screenshots/module-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/screenshots/module-1.png
--------------------------------------------------------------------------------
/screenshots/module-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developersancho/CleanArchitectureMVVM/ec7cb891450cebc72f73205fdbedbd3436b5990f/screenshots/module-2.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'CleanArchitectureMVVM'
2 |
3 | include(Modules.app)
4 | include(Modules.local)
5 | include(Modules.remote)
6 | include(Modules.manager)
7 | include(Modules.util)
8 | include(Modules.widget)
9 |
--------------------------------------------------------------------------------