-
Notifications
You must be signed in to change notification settings - Fork 10
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
53 changed files
with
2,509 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
|
||
# Built application files | ||
*.apk | ||
*.ap_ | ||
|
||
# Files for the ART/Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
out/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Log Files | ||
*.log | ||
|
||
# Android Studio Navigation editor temp files | ||
.navigation/ | ||
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
# Intellij | ||
*.iml | ||
.idea/ | ||
|
||
# Keystore files | ||
*.jks |
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,50 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.2" | ||
defaultConfig { | ||
applicationId "com.ragdroid.mockstar" | ||
minSdkVersion 16 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.google.dagger:dagger:2.9' | ||
annotationProcessor 'com.google.dagger:dagger-compiler:2.9' | ||
testAnnotationProcessor 'com.google.dagger:dagger-compiler:2.9' | ||
compile 'com.squareup.retrofit2:retrofit:2.2.0' | ||
compile 'com.squareup.retrofit2:converter-gson:2.2.0' | ||
compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0' | ||
compile 'com.squareup.okhttp3:okhttp:3.6.0' | ||
compile 'com.squareup.okhttp3:logging-interceptor:3.6.0' | ||
compile 'com.squareup.okhttp3:mockwebserver:3.6.0' | ||
compile 'io.reactivex.rxjava2:rxjava:2.0.6' | ||
compile 'io.reactivex.rxjava2:rxandroid:2.0.1' | ||
compile 'com.jakewharton:butterknife:8.5.1' | ||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' | ||
provided 'javax.annotation:jsr250-api:1.0' | ||
|
||
|
||
|
||
compile 'com.android.support:appcompat-v7:25.1.1' | ||
compile 'com.android.support:design:25.1.1' | ||
|
||
testCompile 'junit:junit:4.12' | ||
testCompile 'org.mockito:mockito-core:2.1.0' | ||
testCompile project(':mocks') | ||
} |
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,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/garimajain/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/ragdroid/mockstar/ExampleInstrumentedTest.java
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.ragdroid.mockstar; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.ragdroid.mockstar", appContext.getPackageName()); | ||
} | ||
} |
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,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.ragdroid.mockstar"> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
|
||
<application | ||
android:name=".MockstarApplication" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity" | ||
android:theme="@style/AppTheme.NoActionBar"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
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 @@ | ||
package com.ragdroid.mockstar; | ||
|
||
import android.os.Bundle; | ||
import android.widget.TextView; | ||
|
||
import com.ragdroid.mockstar.base.BaseActivity; | ||
import com.ragdroid.mockstar.contracts.MainPresenter; | ||
import com.ragdroid.mockstar.contracts.MainScene; | ||
import com.ragdroid.mockstar.dagger.ActivityComponent; | ||
|
||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
|
||
public class MainActivity extends BaseActivity<MainPresenter> implements MainScene { | ||
|
||
@BindView(R.id.main_text) TextView textView; | ||
|
||
@Override | ||
protected void setupActivity(Bundle savedInstanceState) { | ||
ButterKnife.bind(this); | ||
} | ||
|
||
@Override | ||
protected int getLayoutId() { | ||
return R.layout.activity_main; | ||
} | ||
|
||
@Override | ||
protected void injectFrom(ActivityComponent activityComponent) { | ||
activityComponent.inject(this); | ||
} | ||
|
||
@Override | ||
public void setApiText(String id) { | ||
textView.setText(id); | ||
} | ||
|
||
@Override | ||
public void showErrorDialog(String string) { | ||
textView.setText(string); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
app/src/main/java/com/ragdroid/mockstar/MainPresenterImpl.java
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,86 @@ | ||
package com.ragdroid.mockstar; | ||
|
||
|
||
import android.os.Bundle; | ||
|
||
import com.ragdroid.mockstar.api.Pokemon; | ||
import com.ragdroid.mockstar.api.PokemonService; | ||
import com.ragdroid.mockstar.base.BasePresenter; | ||
import com.ragdroid.mockstar.base.BaseSchedulerProvider; | ||
import com.ragdroid.mockstar.contracts.MainPresenter; | ||
import com.ragdroid.mockstar.contracts.MainScene; | ||
|
||
import java.net.HttpURLConnection; | ||
|
||
import javax.inject.Inject; | ||
|
||
import io.reactivex.annotations.NonNull; | ||
import io.reactivex.disposables.Disposable; | ||
import io.reactivex.functions.Consumer; | ||
import retrofit2.HttpException; | ||
|
||
/** | ||
* Created by garimajain on 05/03/17. | ||
*/ | ||
|
||
public class MainPresenterImpl extends BasePresenter<MainScene> implements MainPresenter { | ||
|
||
private final PokemonService pokemonService; | ||
private Disposable disposable; | ||
|
||
@Inject | ||
public MainPresenterImpl(BaseSchedulerProvider schedulerProvider, PokemonService service) { | ||
super(schedulerProvider); | ||
this.pokemonService = service; | ||
} | ||
|
||
@Override | ||
public void onSceneAdded(MainScene scene, Bundle data) { | ||
super.onSceneAdded(scene, data); | ||
disposable = pokemonService.getPokemon("12") | ||
.subscribeOn(provider.io()) | ||
.observeOn(provider.ui()) | ||
.subscribe(new Consumer<Pokemon>() { | ||
@Override | ||
public void accept(@NonNull Pokemon pokemon) throws Exception { | ||
if (getScene() != null) { | ||
getScene().setApiText("Id : " + pokemon.getId()); | ||
} | ||
} | ||
}, new Consumer<Throwable>() { | ||
@Override | ||
public void accept(@NonNull Throwable throwable) throws Exception { | ||
if (throwable instanceof HttpException) { | ||
if (((HttpException) throwable).code() == HttpURLConnection.HTTP_NOT_FOUND) { | ||
if (getScene() != null) { | ||
getScene().showErrorDialog("Lost!"); | ||
} | ||
} else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAVAILABLE) { | ||
if (getScene() != null) { | ||
getScene().showErrorDialog("Fire on the Server"); | ||
} | ||
} else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAUTHORIZED) { | ||
if (getScene() != null) { | ||
getScene().showErrorDialog("You shall not pass!"); | ||
} | ||
} | ||
} else { | ||
if (getScene() != null) { | ||
getScene().showErrorDialog(throwable.getMessage()); | ||
} | ||
} | ||
throwable.printStackTrace(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onSceneRemoved() { | ||
if (disposable != null && !disposable.isDisposed()) { | ||
disposable.dispose(); | ||
} | ||
super.onSceneRemoved(); | ||
} | ||
|
||
|
||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/ragdroid/mockstar/MockstarApplication.java
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,34 @@ | ||
package com.ragdroid.mockstar; | ||
|
||
import android.app.Application; | ||
|
||
import com.ragdroid.mockstar.dagger.ApiModule; | ||
import com.ragdroid.mockstar.dagger.AppComponent; | ||
import com.ragdroid.mockstar.dagger.AppModule; | ||
import com.ragdroid.mockstar.dagger.DaggerAppComponent; | ||
|
||
/** | ||
* Created by garimajain on 05/03/17. | ||
*/ | ||
|
||
public class MockstarApplication extends Application { | ||
|
||
private AppComponent appComponent; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
initComponent(); | ||
} | ||
|
||
private void initComponent() { | ||
this.appComponent = DaggerAppComponent.builder() | ||
.appModule(new AppModule(this)) | ||
.apiModule(new ApiModule()) | ||
.build(); | ||
} | ||
|
||
public AppComponent getAppComponent() { | ||
return appComponent; | ||
} | ||
} |
Oops, something went wrong.