Skip to content

Commit d0a009d

Browse files
author
Kshitij Jain
committed
Initial commit
0 parents  commit d0a009d

Some content is hidden

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

56 files changed

+1263
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

app/.gitignore

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

app/build.gradle

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
apply plugin: 'kotlin-kapt'
5+
6+
android {
7+
compileSdkVersion 27
8+
defaultConfig {
9+
applicationId "in.co.kshitijjain.pokemonkotlin"
10+
minSdkVersion 15
11+
targetSdkVersion 27
12+
versionCode 1
13+
versionName "1.0"
14+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
multiDexEnabled true
16+
}
17+
18+
androidExtensions {
19+
experimental = true
20+
}
21+
22+
buildTypes {
23+
release {
24+
minifyEnabled false
25+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26+
}
27+
}
28+
}
29+
30+
dependencies {
31+
implementation fileTree(include: ['*.jar'], dir: 'libs')
32+
implementation supportLibs
33+
implementation kotlinLibs
34+
implementation networkLibs
35+
implementation rxJavaLibs
36+
implementation otherLibs
37+
38+
// APT dependencies
39+
kapt annotationProcessorLibs
40+
kaptTest daggerCompiler
41+
kaptTest daggerAndroidProcessor
42+
kaptAndroidTest daggerCompiler
43+
kaptAndroidTest daggerAndroidProcessor
44+
45+
testImplementation unitTestLibs
46+
androidTestImplementation androidTestsLibs
47+
testImplementation unitTestLibs
48+
49+
// Use Core Inside APP
50+
implementation project(':core')
51+
}
52+
53+
tasks.matching { it instanceof Test }.all {
54+
testLogging.events = ["failed", "passed", "skipped"]
55+
}

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.
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
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package `in`.co.kshitijjain.pokemonkotlin
2+
3+
import android.support.test.InstrumentationRegistry
4+
import android.support.test.runner.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.getTargetContext()
22+
assertEquals("in.co.kshitijjain.pokemonkotlin", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="in.co.kshitijjain.pokemonkotlin">
4+
5+
<application
6+
android:name=".common.PokemonApplication"
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
<activity
14+
android:name=".pokemon.PokemonActivity"
15+
android:screenOrientation="portrait">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package `in`.co.kshitijjain.pokemonkotlin.common
2+
3+
import dagger.Module
4+
import dagger.android.ContributesAndroidInjector
5+
import `in`.co.kshitijjain.pokemonkotlin.pokemon.PokemonActivity
6+
import `in`.co.kshitijjain.pokemonkotlin.pokemon.PokemonActivityModule
7+
8+
9+
@Module
10+
abstract class ActivityBindingModule {
11+
12+
@ContributesAndroidInjector(modules = [(PokemonActivityModule::class)])
13+
abstract fun bindMainActivity(): PokemonActivity
14+
15+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package `in`.co.kshitijjain.pokemonkotlin.common
2+
3+
import android.app.Application
4+
import dagger.Component
5+
import dagger.android.AndroidInjectionModule
6+
import dagger.android.support.AndroidSupportInjectionModule
7+
import javax.inject.Singleton
8+
import dagger.BindsInstance
9+
10+
11+
@Singleton
12+
@Component(modules = [
13+
(AppModule::class),
14+
(AndroidInjectionModule::class),
15+
(AndroidSupportInjectionModule::class),
16+
(ActivityBindingModule::class)])
17+
interface AppComponent {
18+
19+
@Component.Builder
20+
interface Builder {
21+
22+
@BindsInstance
23+
fun application(application: Application): Builder
24+
25+
fun build(): AppComponent
26+
27+
}
28+
29+
fun inject(application: PokemonApplication)
30+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package `in`.co.kshitijjain.pokemonkotlin.common
2+
3+
import android.app.Application
4+
import android.content.Context
5+
import dagger.Module
6+
import javax.inject.Singleton
7+
import dagger.Provides
8+
9+
@Module
10+
class AppModule {
11+
12+
@Provides
13+
@Singleton
14+
fun Context(application: Application): Context {
15+
return application
16+
}
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package `in`.co.kshitijjain.pokemonkotlin.common
2+
3+
import android.app.Activity
4+
import android.app.Application
5+
import android.content.Context
6+
import android.support.multidex.MultiDex
7+
import dagger.android.AndroidInjector
8+
import dagger.android.DispatchingAndroidInjector
9+
import dagger.android.HasActivityInjector
10+
import timber.log.Timber
11+
import javax.inject.Inject
12+
13+
open class PokemonApplication : Application(), HasActivityInjector {
14+
15+
@Inject
16+
lateinit var activityInjector: DispatchingAndroidInjector<Activity>
17+
18+
override fun onCreate() {
19+
super.onCreate()
20+
Timber.plant(Timber.DebugTree())
21+
DaggerAppComponent.builder()
22+
.application(this)
23+
.build()
24+
.inject(this)
25+
}
26+
27+
override fun activityInjector(): AndroidInjector<Activity> {
28+
return activityInjector
29+
}
30+
31+
override fun attachBaseContext(base: Context?) {
32+
super.attachBaseContext(base)
33+
MultiDex.install(this)
34+
}
35+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package `in`.co.kshitijjain.pokemonkotlin.common.base
2+
3+
import android.os.Bundle
4+
import android.support.v7.app.AppCompatActivity
5+
6+
abstract class BaseActivity : AppCompatActivity() {
7+
8+
protected abstract fun initView()
9+
protected abstract val layout: Int
10+
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
setContentView(layout)
14+
initView()
15+
}
16+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package `in`.co.kshitijjain.pokemonkotlin.pokemon
2+
3+
import `in`.co.kshitijjain.pokemonkotlin.R
4+
import `in`.co.kshitijjain.pokemonkotlin.common.base.BaseActivity
5+
import javax.inject.Inject
6+
7+
class PokemonActivity : BaseActivity() {
8+
9+
@Inject lateinit var presenter: PokemonPresenter
10+
11+
override fun initView() {
12+
presenter.startPresenting()
13+
}
14+
15+
override val layout: Int = R.layout.activity_main
16+
17+
override fun onDestroy() {
18+
presenter.stopPresenting()
19+
super.onDestroy()
20+
}
21+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package `in`.co.kshitijjain.pokemonkotlin.pokemon
2+
3+
import `in`.co.kshitijjain.pokemonkotlin.rx.AndroidSchedulingStrategyFactory
4+
import com.squareup.moshi.Moshi
5+
import dagger.Module
6+
import dagger.Provides
7+
import retrofit2.Retrofit
8+
9+
10+
@Module
11+
class PokemonActivityModule {
12+
13+
@Provides
14+
fun pokemonFetcher(
15+
retrofit: Retrofit,
16+
moshi: Moshi,
17+
pokemonConverter: PokemonConverter): PokemonFetcher {
18+
return PokemonFetcher.from(retrofit, moshi, pokemonConverter)
19+
}
20+
21+
@Provides
22+
fun pokemonViewStateConverter(): PokemonViewStateConverter {
23+
return PokemonViewStateConverter()
24+
}
25+
26+
@Provides
27+
fun mainActivityViewStateUseCase(
28+
pokemonFetcher: PokemonFetcher,
29+
pokemonViewStateConverter: PokemonViewStateConverter): PokemonViewStateUseCase {
30+
val schedulingStrategyFactory = AndroidSchedulingStrategyFactory.io()
31+
return PokemonViewStateUseCase(pokemonFetcher,
32+
pokemonViewStateConverter,
33+
schedulingStrategyFactory)
34+
}
35+
36+
@Provides
37+
fun mainActivityPresenter(pokemonViewStateUseCase: PokemonViewStateUseCase): PokemonPresenter {
38+
return PokemonPresenter(pokemonViewStateUseCase)
39+
}
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package `in`.co.kshitijjain.pokemonkotlin.pokemon
2+
3+
import android.util.Log
4+
import io.reactivex.disposables.CompositeDisposable
5+
import io.reactivex.rxkotlin.plusAssign
6+
7+
class PokemonPresenter(private val useCase: PokemonViewStateUseCase) {
8+
9+
private val disposables = CompositeDisposable()
10+
11+
fun startPresenting() {
12+
disposables += useCase.observeViewState().subscribe({
13+
Log.d("HELLO", it.toString())
14+
})
15+
disposables += (useCase.loadFromNetwork().subscribe())
16+
}
17+
18+
fun stopPresenting() {
19+
disposables.clear()
20+
}
21+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package `in`.co.kshitijjain.pokemonkotlin.pokemon
2+
3+
class PokemonViewState
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package `in`.co.kshitijjain.pokemonkotlin.pokemon
2+
3+
import `in`.co.kshitijjain.pokemonkotlin.rx.Converter
4+
5+
class PokemonViewStateConverter : Converter<Pokemon, PokemonViewState> {
6+
override fun apply(t: Pokemon): PokemonViewState {
7+
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
8+
}
9+
}

0 commit comments

Comments
 (0)