diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..77fce5d --- /dev/null +++ b/.gitignore @@ -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 diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..3061028 --- /dev/null +++ b/app/build.gradle @@ -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') +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..14ca71a --- /dev/null +++ b/app/proguard-rules.pro @@ -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 *; +#} diff --git a/app/src/androidTest/java/com/ragdroid/mockstar/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/ragdroid/mockstar/ExampleInstrumentedTest.java new file mode 100644 index 0000000..521324e --- /dev/null +++ b/app/src/androidTest/java/com/ragdroid/mockstar/ExampleInstrumentedTest.java @@ -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 Testing documentation + */ +@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()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..56ad5af --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/ragdroid/mockstar/MainActivity.java b/app/src/main/java/com/ragdroid/mockstar/MainActivity.java new file mode 100644 index 0000000..4907c38 --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/MainActivity.java @@ -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 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); + } +} diff --git a/app/src/main/java/com/ragdroid/mockstar/MainPresenterImpl.java b/app/src/main/java/com/ragdroid/mockstar/MainPresenterImpl.java new file mode 100644 index 0000000..fc83c4d --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/MainPresenterImpl.java @@ -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 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() { + @Override + public void accept(@NonNull Pokemon pokemon) throws Exception { + if (getScene() != null) { + getScene().setApiText("Id : " + pokemon.getId()); + } + } + }, new Consumer() { + @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(); + } + + +} diff --git a/app/src/main/java/com/ragdroid/mockstar/MockstarApplication.java b/app/src/main/java/com/ragdroid/mockstar/MockstarApplication.java new file mode 100644 index 0000000..7e33a8a --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/MockstarApplication.java @@ -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; + } +} diff --git a/app/src/main/java/com/ragdroid/mockstar/api/LocalResponseDispatcher.java b/app/src/main/java/com/ragdroid/mockstar/api/LocalResponseDispatcher.java new file mode 100644 index 0000000..39ea525 --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/api/LocalResponseDispatcher.java @@ -0,0 +1,70 @@ +package com.ragdroid.mockstar.api; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.QueueDispatcher; +import okhttp3.mockwebserver.RecordedRequest; + +/** + * Created by garimajain on 05/03/17. + */ + +public class LocalResponseDispatcher extends QueueDispatcher { + + @Override + public MockResponse dispatch(RecordedRequest request) throws InterruptedException { + MockResponse mockResponse = new MockResponse(); + String scenario = getScenario(request); + if (scenario != null) { + try { + mockResponse.setBody(readFile(scenario)); + mockResponse.setResponseCode(200); + } catch (IOException e) { + e.printStackTrace(); + } + } + return mockResponse; + } + + private String getScenario(RecordedRequest request) { + String scenario = ""; + + String path = request.getPath(); + String requestedMethod = request.getMethod().toLowerCase(); + + scenario += requestedMethod + path.replace("/", "_") + ".json"; + return scenario; + } + + private String readFile(String jsonFileName) throws IOException { + InputStream inputStream = LocalResponseDispatcher.class.getResourceAsStream("/" + + jsonFileName); + if (inputStream == null) { + throw new NullPointerException("Have you added the local resource correctly?, " + + "Hint: name it as: " + jsonFileName); + } + StringBuilder sb = new StringBuilder(); + InputStreamReader isr = null; + try { + isr = new InputStreamReader(inputStream); + BufferedReader rdr = new BufferedReader(isr); + for (int c; (c = rdr.read()) != -1;) { + sb.append((char) c); + + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + inputStream.close(); + if (isr != null) { + isr.close(); + } + } + return sb.toString(); + } +} + diff --git a/app/src/main/java/com/ragdroid/mockstar/api/Pokemon.java b/app/src/main/java/com/ragdroid/mockstar/api/Pokemon.java new file mode 100644 index 0000000..d202b3f --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/api/Pokemon.java @@ -0,0 +1,873 @@ +package com.ragdroid.mockstar.api; + + +import java.util.List; + + + +public class Pokemon { + + + private Integer id; + private String name; + private Integer baseExperience; + private Integer height; + private Boolean isDefault; + private Integer order; + private Integer weight; + private List abilities = null; + private List
forms = null; + private List gameIndices = null; + private List heldItems = null; + private String locationAreaEncounters = null; + private List moves = null; + private Species species; + private Sprites sprites; + private List stats = null; + private List types = null; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getBaseExperience() { + return baseExperience; + } + + public void setBaseExperience(Integer baseExperience) { + this.baseExperience = baseExperience; + } + + public Integer getHeight() { + return height; + } + + public void setHeight(Integer height) { + this.height = height; + } + + public Boolean getIsDefault() { + return isDefault; + } + + public void setIsDefault(Boolean isDefault) { + this.isDefault = isDefault; + } + + public Integer getOrder() { + return order; + } + + public void setOrder(Integer order) { + this.order = order; + } + + public Integer getWeight() { + return weight; + } + + public void setWeight(Integer weight) { + this.weight = weight; + } + + public List getAbilities() { + return abilities; + } + + public void setAbilities(List abilities) { + this.abilities = abilities; + } + + public List getForms() { + return forms; + } + + public void setForms(List forms) { + this.forms = forms; + } + + public List getGameIndices() { + return gameIndices; + } + + public void setGameIndices(List gameIndices) { + this.gameIndices = gameIndices; + } + + public List getHeldItems() { + return heldItems; + } + + public void setHeldItems(List heldItems) { + this.heldItems = heldItems; + } + + public String getLocationAreaEncounters() { + return locationAreaEncounters; + } + + public void setLocationAreaEncounters(String locationAreaEncounters) { + this.locationAreaEncounters = locationAreaEncounters; + } + + public List getMoves() { + return moves; + } + + public void setMoves(List moves) { + this.moves = moves; + } + + public Species getSpecies() { + return species; + } + + public void setSpecies(Species species) { + this.species = species; + } + + public Sprites getSprites() { + return sprites; + } + + public void setSprites(Sprites sprites) { + this.sprites = sprites; + } + + public List getStats() { + return stats; + } + + public void setStats(List stats) { + this.stats = stats; + } + + public List getTypes() { + return types; + } + + public void setTypes(List types) { + this.types = types; + } + + + + public static class Ability { + + private Boolean isHidden; + private Integer slot; + + + private AbilityDetail ability; + + public Boolean getIsHidden() { + return isHidden; + } + + public void setIsHidden(Boolean isHidden) { + this.isHidden = isHidden; + } + + public Integer getSlot() { + return slot; + } + + public void setSlot(Integer slot) { + this.slot = slot; + } + + public AbilityDetail getAbility() { + return ability; + } + + public void setAbility(AbilityDetail ability) { + this.ability = ability; + } + + } + + public static class AbilityDetail { + + private String name; + + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + } + + + public static class ConditionValue { + + private String name; + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + } + + + public static class EncounterDetail { + + private Integer minLevel; + private Integer maxLevel; + private List conditionValues = null; + private Integer chance; + private Method method; + + public Integer getMinLevel() { + return minLevel; + } + + public void setMinLevel(Integer minLevel) { + this.minLevel = minLevel; + } + + public Integer getMaxLevel() { + return maxLevel; + } + + public void setMaxLevel(Integer maxLevel) { + this.maxLevel = maxLevel; + } + + public List getConditionValues() { + return conditionValues; + } + + public void setConditionValues(List conditionValues) { + this.conditionValues = conditionValues; + } + + public Integer getChance() { + return chance; + } + + public void setChance(Integer chance) { + this.chance = chance; + } + + public Method getMethod() { + return method; + } + + public void setMethod(Method method) { + this.method = method; + } + + } + + + public static class Form { + + private String name; + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + } + + public static class GameIndex { + + private Integer gameIndex; + private Version version; + + public Integer getGameIndex() { + return gameIndex; + } + + public void setGameIndex(Integer gameIndex) { + this.gameIndex = gameIndex; + } + + public Version getVersion() { + return version; + } + + public void setVersion(Version version) { + this.version = version; + } + + } + + + public static class HeldItem { + + private Item item; + private List versionDetails = null; + + public Item getItem() { + return item; + } + + public void setItem(Item item) { + this.item = item; + } + + public List getVersionDetails() { + return versionDetails; + } + + public void setVersionDetails(List versionDetails) { + this.versionDetails = versionDetails; + } + + } + + + public static class Item { + + private String name; + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + } + + public static class Method { + + private String name; + + + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + } + + + public static class Move { + + + private MoveDetail move; + + + private List versionGroupDetails = null; + + public MoveDetail getMove() { + return move; + } + + public void setMove(MoveDetail move) { + this.move = move; + } + + public List getVersionGroupDetails() { + return versionGroupDetails; + } + + public void setVersionGroupDetails(List versionGroupDetails) { + this.versionGroupDetails = versionGroupDetails; + } + + } + + public static class MoveLearnMethod { + + private String name; + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + } + + public static class MoveDetail { + + private String name; + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + } + + + public static class Species { + + private String name; + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + } + + + + public static class Sprites { + + + private String backFemale; + private String backShinyFemale; + private String backDefault; + private String frontFemale; + private String frontShinyFemale; + private String backShiny; + private String frontDefault; + private String frontShiny; + + public String getBackFemale() { + return backFemale; + } + + public void setBackFemale(String backFemale) { + this.backFemale = backFemale; + } + + public String getBackShinyFemale() { + return backShinyFemale; + } + + public void setBackShinyFemale(String backShinyFemale) { + this.backShinyFemale = backShinyFemale; + } + + public String getBackDefault() { + return backDefault; + } + + public void setBackDefault(String backDefault) { + this.backDefault = backDefault; + } + + public String getFrontFemale() { + return frontFemale; + } + + public void setFrontFemale(String frontFemale) { + this.frontFemale = frontFemale; + } + + public String getFrontShinyFemale() { + return frontShinyFemale; + } + + public void setFrontShinyFemale(String frontShinyFemale) { + this.frontShinyFemale = frontShinyFemale; + } + + public String getBackShiny() { + return backShiny; + } + + public void setBackShiny(String backShiny) { + this.backShiny = backShiny; + } + + public String getFrontDefault() { + return frontDefault; + } + + public void setFrontDefault(String frontDefault) { + this.frontDefault = frontDefault; + } + + public String getFrontShiny() { + return frontShiny; + } + + public void setFrontShiny(String frontShiny) { + this.frontShiny = frontShiny; + } + + } + + + + public static class Stat { + + private Integer baseStat; + private Integer effort; + private StatDetail stat; + + public Integer getBaseStat() { + return baseStat; + } + + public void setBaseStat(Integer baseStat) { + this.baseStat = baseStat; + } + + public Integer getEffort() { + return effort; + } + + public void setEffort(Integer effort) { + this.effort = effort; + } + + public StatDetail getStat() { + return stat; + } + + public void setStat(StatDetail stat) { + this.stat = stat; + } + + } + + + + + public static class StatDetail { + + + private String name; + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + } + + + + public static class Type { + + + + private Integer slot; + private TypeDetail type; + + public Integer getSlot() { + return slot; + } + + public void setSlot(Integer slot) { + this.slot = slot; + } + + public TypeDetail getType() { + return type; + } + + public void setType(TypeDetail type) { + this.type = type; + } + + } + + + + + public static class TypeDetail { + + + + private String name; + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + } + + + + public static class Version { + + + private String name; + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + } + + + + public static class VersionDetail { + + + private Integer rarity; + private Version version; + + public Integer getRarity() { + return rarity; + } + + public void setRarity(Integer rarity) { + this.rarity = rarity; + } + + public Version getVersion() { + return version; + } + + public void setVersion(Version version) { + this.version = version; + } + + } + + + + + public static class VersionDetails { + + + + private Integer maxChance; + + + private List encounterDetails = null; + + + private Version version; + + public Integer getMaxChance() { + return maxChance; + } + + public void setMaxChance(Integer maxChance) { + this.maxChance = maxChance; + } + + public List getEncounterDetails() { + return encounterDetails; + } + + public void setEncounterDetails(List encounterDetails) { + this.encounterDetails = encounterDetails; + } + + public Version getVersion() { + return version; + } + + public void setVersion(Version version) { + this.version = version; + } + + } + + + + + public static class VersionGroup { + + + private String name; + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + } + + + + + public static class VersionGroupDetail { + + private Integer levelLearnedAt; + private VersionGroup versionGroup; + private MoveLearnMethod moveLearnMethod; + + public Integer getLevelLearnedAt() { + return levelLearnedAt; + } + + public void setLevelLearnedAt(Integer levelLearnedAt) { + this.levelLearnedAt = levelLearnedAt; + } + + public VersionGroup getVersionGroup() { + return versionGroup; + } + + public void setVersionGroup(VersionGroup versionGroup) { + this.versionGroup = versionGroup; + } + + public MoveLearnMethod getMoveLearnMethod() { + return moveLearnMethod; + } + + public void setMoveLearnMethod(MoveLearnMethod moveLearnMethod) { + this.moveLearnMethod = moveLearnMethod; + } + + } + +} + + + + + diff --git a/app/src/main/java/com/ragdroid/mockstar/api/PokemonService.java b/app/src/main/java/com/ragdroid/mockstar/api/PokemonService.java new file mode 100644 index 0000000..2ae1547 --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/api/PokemonService.java @@ -0,0 +1,18 @@ +package com.ragdroid.mockstar.api; + +import io.reactivex.Observable; +import retrofit2.http.GET; +import retrofit2.http.Headers; +import retrofit2.http.Path; + +/** + * Created by garimajain on 05/03/17. + */ + +public interface PokemonService { + + @Headers("Content-Type: application/json") + @GET("pokemon/{id}") + public Observable getPokemon(@Path("id") String id); + +} diff --git a/app/src/main/java/com/ragdroid/mockstar/base/BaseActivity.java b/app/src/main/java/com/ragdroid/mockstar/base/BaseActivity.java new file mode 100644 index 0000000..5f5fff0 --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/base/BaseActivity.java @@ -0,0 +1,63 @@ +package com.ragdroid.mockstar.base; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; + +import com.ragdroid.mockstar.MockstarApplication; +import com.ragdroid.mockstar.R; +import com.ragdroid.mockstar.dagger.ActivityComponent; +import com.ragdroid.mockstar.dagger.ActivityModule; +import com.ragdroid.mockstar.dagger.AppComponent; +import com.ragdroid.mockstar.dagger.DaggerActivityComponent; +import com.ragdroid.mockstar.mvp.Presenter; +import com.ragdroid.mockstar.mvp.Scene; + +import javax.inject.Inject; + +/** + * Created by garimajain on 05/03/17. + */ + +abstract public class BaseActivity

extends AppCompatActivity implements Scene { + + @Inject protected P presenter; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(getLayoutId()); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + AppComponent appComponent = ((MockstarApplication) getApplication()).getAppComponent(); + ActivityComponent activityComponent = DaggerActivityComponent.builder() + .appComponent(appComponent) + .activityModule(new ActivityModule()) + .build(); + injectFrom(activityComponent); + setupActivity(savedInstanceState); + } + + protected abstract void setupActivity(Bundle savedInstanceState); + + protected abstract int getLayoutId(); + + protected abstract void injectFrom(ActivityComponent activityComponent); + + + @Override + protected void onPause() { + presenter.onSceneRemoved(); + super.onPause(); + } + + @Override + protected void onResume() { + super.onResume(); + presenter.onSceneAdded(this, getIntent().getExtras()); + } + + + +} diff --git a/app/src/main/java/com/ragdroid/mockstar/base/BasePresenter.java b/app/src/main/java/com/ragdroid/mockstar/base/BasePresenter.java new file mode 100644 index 0000000..fad00a0 --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/base/BasePresenter.java @@ -0,0 +1,35 @@ +package com.ragdroid.mockstar.base; + +import android.os.Bundle; + +import com.ragdroid.mockstar.mvp.Presenter; +import com.ragdroid.mockstar.mvp.Scene; + +/** + * Created by garimajain on 05/03/17. + */ + +public class BasePresenter implements Presenter { + + protected BaseSchedulerProvider provider; + + public BasePresenter(BaseSchedulerProvider provider) { + this.provider = provider; + } + + protected S getScene() { + return scene; + } + + private S scene; + + @Override + public void onSceneAdded(S scene, Bundle data) { + this.scene = scene; + } + + @Override + public void onSceneRemoved() { + this.scene = null; + } +} diff --git a/app/src/main/java/com/ragdroid/mockstar/base/BaseSchedulerProvider.java b/app/src/main/java/com/ragdroid/mockstar/base/BaseSchedulerProvider.java new file mode 100644 index 0000000..d0df13b --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/base/BaseSchedulerProvider.java @@ -0,0 +1,22 @@ +package com.ragdroid.mockstar.base; + +import android.support.annotation.NonNull; + +import io.reactivex.Scheduler; + +/** + * Created by garimajain on 05/03/17. + */ + +public interface BaseSchedulerProvider { + + @NonNull + Scheduler computation(); + + @NonNull + Scheduler io(); + + @NonNull + Scheduler ui(); +} + diff --git a/app/src/main/java/com/ragdroid/mockstar/contracts/MainPresenter.java b/app/src/main/java/com/ragdroid/mockstar/contracts/MainPresenter.java new file mode 100644 index 0000000..49f26e7 --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/contracts/MainPresenter.java @@ -0,0 +1,10 @@ +package com.ragdroid.mockstar.contracts; + +import com.ragdroid.mockstar.mvp.Presenter; + +/** + * Created by garimajain on 05/03/17. + */ + +public interface MainPresenter extends Presenter { +} diff --git a/app/src/main/java/com/ragdroid/mockstar/contracts/MainScene.java b/app/src/main/java/com/ragdroid/mockstar/contracts/MainScene.java new file mode 100644 index 0000000..02e9de0 --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/contracts/MainScene.java @@ -0,0 +1,13 @@ +package com.ragdroid.mockstar.contracts; + +import com.ragdroid.mockstar.mvp.Scene; + +/** + * Created by garimajain on 05/03/17. + */ + +public interface MainScene extends Scene { + void setApiText(String id); + + void showErrorDialog(String string); +} diff --git a/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityComponent.java b/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityComponent.java new file mode 100644 index 0000000..26427f9 --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityComponent.java @@ -0,0 +1,17 @@ +package com.ragdroid.mockstar.dagger; + +import com.ragdroid.mockstar.MainActivity; + +import dagger.Component; + +/** + * Created by garimajain on 05/03/17. + */ +@Component(dependencies = {AppComponent.class}, + modules = ActivityModule.class) +@ActivityScope +public interface ActivityComponent { + + void inject(MainActivity mainActivity); + +} diff --git a/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityModule.java b/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityModule.java new file mode 100644 index 0000000..d8b99dd --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityModule.java @@ -0,0 +1,22 @@ +package com.ragdroid.mockstar.dagger; + +import com.ragdroid.mockstar.MainPresenterImpl; +import com.ragdroid.mockstar.contracts.MainPresenter; + +import dagger.Module; +import dagger.Provides; + +/** + * Created by garimajain on 05/03/17. + */ +@Module +@ActivityScope +public class ActivityModule { + + @ActivityScope + @Provides + public MainPresenter provideHomePresenter(MainPresenterImpl presenter) { + return presenter; + } + +} diff --git a/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityScope.java b/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityScope.java new file mode 100644 index 0000000..ff52eed --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityScope.java @@ -0,0 +1,16 @@ +package com.ragdroid.mockstar.dagger; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.inject.Scope; + +/** + * Created by garimajain on 05/03/17. + */ +@Scope +@Documented +@Retention(value = RetentionPolicy.RUNTIME) +public @interface ActivityScope { +} diff --git a/app/src/main/java/com/ragdroid/mockstar/dagger/ApiModule.java b/app/src/main/java/com/ragdroid/mockstar/dagger/ApiModule.java new file mode 100644 index 0000000..f9eb668 --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/dagger/ApiModule.java @@ -0,0 +1,87 @@ +package com.ragdroid.mockstar.dagger; + +import com.google.gson.FieldNamingPolicy; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.ragdroid.mockstar.api.PokemonService; + +import java.util.concurrent.TimeUnit; + +import javax.inject.Singleton; + +import dagger.Module; +import dagger.Provides; +import okhttp3.OkHttpClient; +import okhttp3.logging.HttpLoggingInterceptor; +import retrofit2.Retrofit; +import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; +import retrofit2.converter.gson.GsonConverterFactory; + +/** + * Created by garimajain on 05/03/17. + */ + +@Module +public class ApiModule { + + public ApiModule() { + + } + + @Provides + @Singleton + public HttpLoggingInterceptor getLoggingInterceptor() { + HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); + loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); + return loggingInterceptor; + } + + + @Provides + @Singleton + Gson provideGson() { + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); + return gsonBuilder.create(); + } + + @Provides + @Singleton + OkHttpClient provideOkHttpClient(HttpLoggingInterceptor loggingInterceptor) { + OkHttpClient.Builder builder = new OkHttpClient.Builder() + .addInterceptor(loggingInterceptor) + .connectTimeout(60, TimeUnit.SECONDS) + .readTimeout(60, TimeUnit.SECONDS) + .writeTimeout(60, TimeUnit.SECONDS); + addOkHttpConfig(builder); + return builder + .build(); + + } + + protected void addOkHttpConfig(OkHttpClient.Builder builder) { + + } + + @Provides + @Singleton + Retrofit provideRetrofit(Gson gson, OkHttpClient okHttpClient) { + return new Retrofit.Builder() + .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) + .addConverterFactory(GsonConverterFactory.create(gson)) + .baseUrl(getBaseUrl()) + .client(okHttpClient) + .build(); + } + + protected String getBaseUrl() { + return "http://pokeapi.co/api/v2/"; + } + + @Provides + @Singleton + public PokemonService providePokemonService(Retrofit retrofit) { + return retrofit.create(PokemonService.class); + } + +} diff --git a/app/src/main/java/com/ragdroid/mockstar/dagger/AppComponent.java b/app/src/main/java/com/ragdroid/mockstar/dagger/AppComponent.java new file mode 100644 index 0000000..0ccd6e7 --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/dagger/AppComponent.java @@ -0,0 +1,21 @@ +package com.ragdroid.mockstar.dagger; + +import com.ragdroid.mockstar.api.PokemonService; +import com.ragdroid.mockstar.base.BaseSchedulerProvider; + +import javax.inject.Singleton; + +import dagger.Component; + +/** + * Created by garimajain on 05/03/17. + */ +@Singleton +@Component(modules = {AppModule.class, ApiModule.class}) +public interface AppComponent { + + BaseSchedulerProvider getSchedulerProvider(); + + PokemonService providePokemonService(); + +} diff --git a/app/src/main/java/com/ragdroid/mockstar/dagger/AppModule.java b/app/src/main/java/com/ragdroid/mockstar/dagger/AppModule.java new file mode 100644 index 0000000..f7be794 --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/dagger/AppModule.java @@ -0,0 +1,38 @@ +package com.ragdroid.mockstar.dagger; + +import android.app.Application; + +import com.ragdroid.mockstar.base.BaseSchedulerProvider; +import com.ragdroid.mockstar.logic.SchedulerProvider; + +import javax.inject.Singleton; + +import dagger.Module; +import dagger.Provides; + +/** + * Created by garimajain on 05/03/17. + */ +@Module +public class AppModule { + + Application application; + + public AppModule(Application application) { + this.application = application; + } + + @Provides + @Singleton + Application providesApplication() { + return application; + } + + @Provides + @Singleton + BaseSchedulerProvider providerSchedulerProvider(SchedulerProvider provider) { + return provider; + } + + +} diff --git a/app/src/main/java/com/ragdroid/mockstar/logic/SchedulerProvider.java b/app/src/main/java/com/ragdroid/mockstar/logic/SchedulerProvider.java new file mode 100644 index 0000000..0481f7b --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/logic/SchedulerProvider.java @@ -0,0 +1,43 @@ +package com.ragdroid.mockstar.logic; + +import android.support.annotation.NonNull; + +import com.ragdroid.mockstar.base.BaseSchedulerProvider; + +import javax.inject.Inject; + +import io.reactivex.Scheduler; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.schedulers.Schedulers; + +/** + * Created by garimajain on 05/03/17. + */ + +public class SchedulerProvider implements BaseSchedulerProvider { + + @Inject + public SchedulerProvider() { + + } + + @Override + @NonNull + public Scheduler computation() { + return Schedulers.computation(); + } + + @Override + @NonNull + public Scheduler io() { + return Schedulers.io(); + } + + @Override + @NonNull + public Scheduler ui() { + return AndroidSchedulers.mainThread(); + } + +} + diff --git a/app/src/main/java/com/ragdroid/mockstar/mvp/Presenter.java b/app/src/main/java/com/ragdroid/mockstar/mvp/Presenter.java new file mode 100644 index 0000000..fee6e4a --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/mvp/Presenter.java @@ -0,0 +1,14 @@ +package com.ragdroid.mockstar.mvp; + +import android.os.Bundle; + +/** + * Created by garimajain on 05/03/17. + */ + +public interface Presenter { + + void onSceneAdded(T scene, Bundle data); + void onSceneRemoved(); + +} diff --git a/app/src/main/java/com/ragdroid/mockstar/mvp/Scene.java b/app/src/main/java/com/ragdroid/mockstar/mvp/Scene.java new file mode 100644 index 0000000..b9bf832 --- /dev/null +++ b/app/src/main/java/com/ragdroid/mockstar/mvp/Scene.java @@ -0,0 +1,9 @@ +package com.ragdroid.mockstar.mvp; + +/** + * Created by garimajain on 05/03/17. + */ + +public interface Scene { + +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..10ba373 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..aee44e1 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..0347943 --- /dev/null +++ b/app/src/main/res/values-v21/styles.xml @@ -0,0 +1,9 @@ + +> + + diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..47c8224 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..8235bd1 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Mockstar + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..a29fbbc --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,21 @@ + + + + + + + +