-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
185 changed files
with
5,714 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'kotlin-kapt' | ||
|
||
dependencies { | ||
def rootExt = rootProject.ext | ||
def componentDependencies = rootExt.coreComponent | ||
def unitTestDependencies = rootExt.unitTesting | ||
def acceptanceTestDependencies = rootExt.acceptanceTesting | ||
|
||
// Base | ||
implementation project(':tim') | ||
implementation project(':util') | ||
|
||
// Android | ||
implementation componentDependencies.appCompat | ||
implementation componentDependencies.coreKtx | ||
implementation componentDependencies.collectionKtx | ||
implementation componentDependencies.lifecycle | ||
kapt componentDependencies.lifecycleProcessor | ||
implementation componentDependencies.material | ||
|
||
// Reactive | ||
implementation componentDependencies.rxJava | ||
implementation componentDependencies.rxAndroid | ||
implementation componentDependencies.rxKotlin | ||
implementation componentDependencies.rxBindingKtx | ||
|
||
// Other | ||
implementation componentDependencies.dagger | ||
implementation componentDependencies.daggerAndroid | ||
kapt componentDependencies.daggerProcessor | ||
|
||
// Unit/Integration tests | ||
testImplementation unitTestDependencies.kotlin | ||
testImplementation unitTestDependencies.kotlinTest | ||
testImplementation unitTestDependencies.junit | ||
|
||
// Acceptance tests | ||
androidTestImplementation acceptanceTestDependencies.testRunner | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<manifest package="com.socros.android.app.base" /> |
19 changes: 19 additions & 0 deletions
19
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/ACApp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.socros.android.lib.androidcore | ||
|
||
import com.socros.android.lib.androidcore.di.AppComponent | ||
import com.socros.android.lib.androidcore.di.DaggerAppComponent | ||
import dagger.android.support.DaggerApplication | ||
|
||
abstract class ACApp : DaggerApplication() { | ||
|
||
private lateinit var appComponent: AppComponent | ||
|
||
override fun applicationInjector() = appComponent | ||
internal fun provideAppModuleSubComponent() = appComponent.appModuleSubComponentBuilder.build() | ||
|
||
override fun onCreate() { | ||
appComponent = DaggerAppComponent.builder().create(this) as AppComponent | ||
super.onCreate() | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/di/ActivityContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.socros.android.lib.androidcore.di | ||
|
||
import javax.inject.Qualifier | ||
|
||
@Qualifier | ||
annotation class ActivityContext |
15 changes: 15 additions & 0 deletions
15
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/di/ActivityScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.socros.android.lib.androidcore.di | ||
|
||
import javax.inject.Scope | ||
|
||
/** | ||
* In Dagger, an unscoped component cannot depend on a scoped component. As | ||
* {@link AppComponent} is a scoped component ({@code @Singleton}, we create a custom | ||
* scope to be used by all fragment components. Additionally, a component with a specific scope | ||
* cannot have a sub component with the same scope. | ||
* | ||
* @see <a href="https://github.com/googlesamples/android-architecture-components">Android Architecture Components samples</a> | ||
*/ | ||
@Scope | ||
@Retention | ||
annotation class ActivityScope |
20 changes: 20 additions & 0 deletions
20
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/di/AppComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.socros.android.lib.androidcore.di | ||
|
||
import com.socros.android.lib.androidcore.ACApp | ||
import dagger.Component | ||
import dagger.android.AndroidInjector | ||
import dagger.android.support.AndroidSupportInjectionModule | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
@Component(modules = [AppModule::class, AndroidSupportInjectionModule::class]) | ||
interface AppComponent : AndroidInjector<ACApp> { | ||
|
||
val appModuleSubComponentBuilder: AppModuleSubComponent.Builder | ||
|
||
@Component.Builder | ||
abstract class Builder : AndroidInjector.Builder<ACApp>() { | ||
abstract override fun build(): AppComponent | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/di/AppContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.socros.android.lib.androidcore.di | ||
|
||
import javax.inject.Qualifier | ||
|
||
@Qualifier | ||
annotation class AppContext |
23 changes: 23 additions & 0 deletions
23
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/di/AppModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.socros.android.lib.androidcore.di | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import dagger.Binds | ||
import dagger.Module | ||
|
||
/** | ||
* This is a Dagger module. We use this to bind our Application class as a Context in the AppComponent | ||
* By using Dagger Android we do not need to pass our Application instance to any module, | ||
* we simply need to expose our Application as Context. | ||
* One of the advantages of Dagger.Android is that your | ||
* Application & Activities are provided into your graph for you. | ||
* [AppComponent]. | ||
* | ||
* @see <a href="https://github.com/googlesamples/android-architecture-components">Android Architecture Components samples</a> | ||
*/ | ||
@Module | ||
abstract class AppModule { | ||
@AppContext | ||
@Binds | ||
abstract fun bindContext(application: Application): Context | ||
} |
28 changes: 28 additions & 0 deletions
28
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/di/AppModuleInjector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.socros.android.lib.androidcore.di | ||
|
||
import android.app.Application | ||
import dagger.BindsInstance | ||
import dagger.android.AndroidInjector | ||
|
||
/** | ||
* @see <a href="https://medium.com/@luigi.papino/dagger2-for-modular-architecture-332e1250a85f">Dagger2 for Modular Architecture</a> | ||
*/ | ||
interface AppModuleInjector<T : AppProvider> : AndroidInjector<T> { | ||
|
||
abstract class Builder<T : AppProvider> : AndroidInjector.Builder<T>() { | ||
|
||
@BindsInstance | ||
abstract operator fun plus(application: Application): Builder<T> | ||
|
||
abstract operator fun plus(component: AppModuleSubComponent): Builder<T> | ||
|
||
fun inject(objectToInject: T) { | ||
objectToInject.provideApp().also { | ||
plus(it) | ||
plus(it.provideAppModuleSubComponent()) | ||
} | ||
|
||
create(objectToInject).inject(objectToInject) | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/di/AppModuleSubComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.socros.android.lib.androidcore.di | ||
|
||
import dagger.Subcomponent | ||
|
||
/** | ||
* Created by luigipapino on 18/02/2018, previously named BaseSubComponent | ||
*/ | ||
@Subcomponent | ||
interface AppModuleSubComponent { | ||
@Subcomponent.Builder | ||
interface Builder { | ||
fun build(): AppModuleSubComponent | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/di/AppProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.socros.android.lib.androidcore.di | ||
|
||
import com.socros.android.lib.androidcore.ACApp | ||
|
||
interface AppProvider { | ||
fun provideApp(): ACApp | ||
} |
10 changes: 10 additions & 0 deletions
10
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/di/FragmentScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.socros.android.lib.androidcore.di | ||
|
||
import javax.inject.Scope | ||
|
||
/** | ||
* @see <a href="https://github.com/googlesamples/android-architecture-components">Android Architecture Components samples</a> | ||
*/ | ||
@Scope | ||
@Retention | ||
annotation class FragmentScope |
39 changes: 39 additions & 0 deletions
39
...dcore/src/main/kotlin/com/socros/android/lib/androidcore/di/viewmodel/ViewModelFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (C) 2018 Fernando Cejas Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.socros.android.lib.androidcore.di.viewmodel | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import javax.inject.Inject | ||
import javax.inject.Provider | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
class ViewModelFactory | ||
@Inject constructor(private val creators: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>) | ||
: ViewModelProvider.Factory { | ||
|
||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
val creator = creators[modelClass] | ||
?: creators.asIterable().firstOrNull { modelClass.isAssignableFrom(it.key) }?.value | ||
?: throw IllegalArgumentException("Unknown ViewModel class $modelClass") | ||
|
||
return try { | ||
creator.get() as T | ||
} catch (e: Exception) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/di/viewmodel/ViewModelKey.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.socros.android.lib.androidcore.di.viewmodel | ||
|
||
import androidx.lifecycle.ViewModel | ||
import dagger.MapKey | ||
import kotlin.annotation.AnnotationTarget.FUNCTION | ||
import kotlin.reflect.KClass | ||
|
||
@MapKey | ||
@Target(FUNCTION) | ||
annotation class ViewModelKey(val value: KClass<out ViewModel>) |
12 changes: 12 additions & 0 deletions
12
...ore/src/main/kotlin/com/socros/android/lib/androidcore/di/viewmodel/ViewModelModuleExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.socros.android.lib.androidcore.di.viewmodel | ||
|
||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentActivity | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProviders | ||
|
||
inline fun <reified VM : ViewModel> ViewModelFactory.create(target: FragmentActivity) = | ||
ViewModelProviders.of(target, this)[VM::class.java] | ||
|
||
inline fun <reified VM : ViewModel> ViewModelFactory.create(target: Fragment) = | ||
ViewModelProviders.of(target, this)[VM::class.java] |
25 changes: 25 additions & 0 deletions
25
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/view/ACActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.socros.android.lib.androidcore.view | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.socros.android.lib.androidcore.ACApp | ||
import com.socros.android.lib.androidcore.di.AppProvider | ||
|
||
abstract class ACActivity : AppCompatActivity(), AppProvider { | ||
|
||
/** | ||
* You can pass a `null` value if your activity doesn't need to draw itself, | ||
* eg. when you set activity theme to `"@android:style/Theme.NoDisplay"` in manifest | ||
*/ | ||
protected abstract val layoutResId: Int? | ||
|
||
final override fun provideApp() = application as ACApp | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
layoutResId?.let { | ||
setContentView(it) | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/view/ACFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.socros.android.lib.androidcore.view | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import com.socros.android.lib.androidcore.ACApp | ||
import com.socros.android.lib.androidcore.di.AppProvider | ||
|
||
abstract class ACFragment : Fragment(), AppProvider { | ||
|
||
/** | ||
* You can pass a `null` value if your fragment doesn't need to draw itself | ||
*/ | ||
protected abstract val layoutResId: Int? | ||
|
||
final override fun provideApp() = activity?.application as ACApp | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return layoutResId?.let { | ||
inflater.inflate(it, container, false) | ||
} | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
androidcore/src/main/kotlin/com/socros/android/lib/androidcore/view/LayoutContainer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.socros.android.lib.androidcore.view | ||
|
||
import android.view.View | ||
import kotlinx.android.extensions.LayoutContainer | ||
|
||
open class LayoutContainer(override val containerView: View) : LayoutContainer |
19 changes: 19 additions & 0 deletions
19
...re/src/main/kotlin/com/socros/android/lib/androidcore/view/launcher/ACLauncherActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.socros.android.lib.androidcore.view.launcher | ||
|
||
import android.app.Activity | ||
import android.os.Bundle | ||
|
||
/** | ||
* Fist app activity that decide which activity should be run as first depends on user logged in status. | ||
* | ||
* Use with `android:theme="@android:style/Theme.NoDisplay"` | ||
*/ | ||
abstract class ACLauncherActivity : Activity(), Launcher { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
startActivity(provideNextActivity()) | ||
finish() | ||
super.onCreate(savedInstanceState) | ||
} | ||
|
||
} |
Oops, something went wrong.