Skip to content

Commit eeb12ce

Browse files
committed
Initial version tracking setup
1 parent 66132d9 commit eeb12ce

File tree

117 files changed

+2654
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+2654
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ fastlane/Preview.html
6363
fastlane/screenshots
6464
fastlane/test_output
6565
fastlane/readme.md
66+
67+
# Gradle reports
68+
reports/

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# POC Of a Modularized Architecture
2+
3+
```
4+
+---------------------+
5+
| |
6+
| |
7+
+--------------+| app +-----------+
8+
| | | |
9+
| | | |
10+
| | | |
11+
| +----------+----------+ |
12+
| | |
13+
| | |
14+
| | |
15+
| | |
16+
| | |
17+
+------+------+ +-------+------+ +------+------+
18+
| | | | | |
19+
| :users | | :user | | :login |
20+
| +---+ | | +---+ |
21+
| | | | | | | |
22+
+------+------+ | +-------+------+ | +--------+----+
23+
| | | | |
24+
| | | | |
25+
| | | | |
26+
| | | | |
27+
| | +----------+--------+ | |
28+
| | | | | |
29+
| +----+ :user-model +--+ |
30+
| | | |
31+
| +-------------------+ |
32+
| |
33+
| |
34+
| |
35+
| |
36+
+------+---------------------------------------------------+-----+
37+
| |
38+
| |
39+
| :base |
40+
| |
41+
| |
42+
+----------------------------------------------------------------+
43+
44+
```
45+
46+
47+
**app:** The composed application that would be built and packaged as apk. It has all the feature related modules.
48+
49+
**user-model:** A **shared** module to be used by `user` related feature. Essentially a `user` model class.
50+
51+
**user:** A feature module for showing a particular user details. This module has the `base` and `user-model` modules.
52+
53+
**users:** A feature module for showing a list of users. This module has the `base` and `user-model` modules as well.
54+
55+
**login:** A feature module for allowing a user to login. This module has the `base` and `user-model` modules.
56+
57+
**base:** A shared module to be used by all feature related modules.
58+
59+
60+
# Navigation
61+
62+
[Deep link](https://developer.android.com/training/app-links/deep-linking) handles all the navigations
63+
64+
There's an `AppNavigation` class in the base module navigating users to the different screens. This is solely using deep links for launching all `Activities`
65+
66+
# Sample Demo

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle.kts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
plugins {
2+
id("com.android.application")
3+
id("kotlin-android")
4+
id("kotlin-kapt")
5+
}
6+
7+
android {
8+
compileSdkVersion(Versions.COMPILE_SDK)
9+
dataBinding.isEnabled = true
10+
defaultConfig {
11+
applicationId = Versions.APPLICATION_ID
12+
minSdkVersion(Versions.MIN_SDK)
13+
targetSdkVersion(Versions.TARGET_SDK)
14+
testApplicationId = "${Versions.APPLICATION_ID}.test"
15+
vectorDrawables.useSupportLibrary = true
16+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
17+
versionCode = 1
18+
versionName = "1.0"
19+
val baseUrl = "https://api.github.com/"
20+
buildConfigField("String", "BASE_URL", "\"${baseUrl}\"")
21+
}
22+
23+
buildTypes {
24+
getByName("release") {
25+
isMinifyEnabled = false
26+
isShrinkResources = false
27+
proguardFile(getDefaultProguardFile("proguard-android.txt"))
28+
proguardFile(file("proguard-rules.pro"))
29+
}
30+
}
31+
compileOptions {
32+
setSourceCompatibility(Versions.SOURCE_COMPATIBILITY)
33+
setTargetCompatibility(Versions.SOURCE_COMPATIBILITY)
34+
}
35+
dexOptions {
36+
preDexLibraries = "true" != System.getenv("CI")
37+
}
38+
lintOptions {
39+
isCheckDependencies = true
40+
isIgnoreTestSources = true
41+
}
42+
}
43+
44+
dependencies {
45+
implementation(project(":base"))
46+
implementation(project(":user"))
47+
implementation(project(":users"))
48+
implementation(project(":login"))
49+
kapt(Dependencies.Databinding.compiler)
50+
kapt(Dependencies.Dagger.compiler)
51+
kapt(Dependencies.Dagger.processor)
52+
kapt(Dependencies.Lifecycle.compiler)
53+
kapt(Dependencies.Glide.compiler)
54+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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.kts.
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

app/src/main/AndroidManifest.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools" package="com.addhen.github">
4+
<uses-permission android:name="android.permission.INTERNET"/>
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:name=".App"
12+
android:theme="@style/AppTheme.NoActionBar" tools:ignore="GoogleAppIndexingWarning">
13+
14+
</application>
15+
</manifest>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.addhen.github
2+
3+
import com.addhen.github.di.DaggerAppComponent
4+
import dagger.android.DaggerApplication
5+
6+
class App : DaggerApplication() {
7+
8+
override fun applicationInjector() = DaggerAppComponent.builder().create(this)
9+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.addhen.github.di
2+
3+
import com.addhen.github.login.LoginActivity
4+
import com.addhen.github.user.UserActivity
5+
import com.addhen.github.users.UsersActivity
6+
import dagger.Module
7+
import dagger.android.ContributesAndroidInjector
8+
9+
@Module
10+
internal abstract class ActivityBuilder {
11+
12+
@ContributesAndroidInjector
13+
internal abstract fun usersActivity(): UsersActivity
14+
15+
@ContributesAndroidInjector
16+
internal abstract fun userActivity(): UserActivity
17+
18+
@ContributesAndroidInjector
19+
internal abstract fun loginActivity(): LoginActivity
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.addhen.github.di
2+
3+
import com.addhen.github.App
4+
import com.addhen.github.user.UserModule
5+
import com.addhen.github.users.UsersModule
6+
import dagger.Component
7+
import dagger.android.AndroidInjector
8+
import dagger.android.support.AndroidSupportInjectionModule
9+
import javax.inject.Singleton
10+
11+
@Singleton
12+
@Component(modules = [
13+
AndroidSupportInjectionModule::class,
14+
ActivityBuilder::class,
15+
AppModule::class,
16+
UsersModule::class,
17+
UserModule::class
18+
])
19+
interface AppComponent : AndroidInjector<App> {
20+
21+
@Component.Builder
22+
abstract class Builder : AndroidInjector.Builder<App>()
23+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.addhen.github.di
2+
3+
import android.content.Context
4+
import com.addhen.github.App
5+
import com.addhen.github.AppRxSchedulers
6+
import com.addhen.github.BuildConfig
7+
import com.addhen.github.RxSchedulers
8+
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.experimental.CoroutineCallAdapterFactory
9+
import com.squareup.moshi.Moshi
10+
import com.squareup.moshi.Rfc3339DateJsonAdapter
11+
import dagger.Module
12+
import dagger.Provides
13+
import okhttp3.Cache
14+
import okhttp3.OkHttpClient
15+
import okhttp3.logging.HttpLoggingInterceptor
16+
import retrofit2.Retrofit
17+
import retrofit2.converter.moshi.MoshiConverterFactory
18+
import timber.log.Timber
19+
import java.io.File
20+
import java.util.Date
21+
import java.util.concurrent.TimeUnit
22+
import javax.inject.Singleton
23+
24+
@Module(includes = [
25+
ViewModelBuilder::class]
26+
)
27+
object AppModule {
28+
29+
private val DISK_CACHE_SIZE: Long = 50 * 1024 * 1024 // 50MB
30+
31+
private val HTTP_TIMEOUT = 15L
32+
33+
@Singleton
34+
@Provides
35+
@JvmStatic
36+
fun provideAppContext(app: App) = app.applicationContext
37+
38+
@Singleton
39+
@Provides
40+
@JvmStatic
41+
fun provideLoggingInterceptor(): HttpLoggingInterceptor {
42+
val loggingInterceptor = HttpLoggingInterceptor { message ->
43+
Timber.tag("OkHttp").d(message)
44+
}
45+
loggingInterceptor.level = if (BuildConfig.DEBUG) {
46+
HttpLoggingInterceptor.Level.BODY
47+
} else {
48+
HttpLoggingInterceptor.Level.BASIC
49+
}
50+
return loggingInterceptor
51+
}
52+
53+
@Singleton
54+
@Provides
55+
@JvmStatic
56+
fun provideOkHttpClient(
57+
context: Context,
58+
loggingInterceptor: HttpLoggingInterceptor
59+
): OkHttpClient {
60+
val okHttpClientBuilder = OkHttpClient.Builder()
61+
val cacheDir = File(context.applicationContext.cacheDir, "app-http-cache")
62+
val cache = Cache(cacheDir, DISK_CACHE_SIZE)
63+
okHttpClientBuilder.cache(cache)
64+
initOkHttpBuilder(okHttpClientBuilder, loggingInterceptor)
65+
return okHttpClientBuilder.build()
66+
}
67+
68+
69+
@Singleton
70+
@Provides
71+
@JvmStatic
72+
fun provideMoshi(): Moshi {
73+
return Moshi.Builder()
74+
.add(Date::class.java, Rfc3339DateJsonAdapter())
75+
.build()
76+
}
77+
78+
@Singleton
79+
@Provides
80+
@JvmStatic
81+
fun provideRetrofit(okHttpClient: OkHttpClient, moshi: Moshi): Retrofit {
82+
return Retrofit.Builder()
83+
.baseUrl(BuildConfig.BASE_URL)
84+
.addConverterFactory(MoshiConverterFactory.create(moshi))
85+
.addCallAdapterFactory(CoroutineCallAdapterFactory())
86+
.client(okHttpClient)
87+
.build()
88+
}
89+
90+
91+
@Singleton
92+
@Provides
93+
@JvmStatic
94+
fun provideRxScheduler(): RxSchedulers {
95+
return AppRxSchedulers()
96+
}
97+
98+
private fun initOkHttpBuilder(
99+
okHttpClientBuilder: OkHttpClient.Builder,
100+
loggingInterceptor: HttpLoggingInterceptor
101+
) {
102+
okHttpClientBuilder.connectTimeout(HTTP_TIMEOUT, TimeUnit.SECONDS)
103+
okHttpClientBuilder.writeTimeout(HTTP_TIMEOUT, TimeUnit.SECONDS)
104+
okHttpClientBuilder.readTimeout(HTTP_TIMEOUT, TimeUnit.SECONDS)
105+
okHttpClientBuilder.addInterceptor(loggingInterceptor)
106+
}
107+
}

0 commit comments

Comments
 (0)