Skip to content

Commit

Permalink
Conductor mvp with sample
Browse files Browse the repository at this point in the history
  • Loading branch information
harshitbangar123 committed Jun 25, 2017
0 parents commit 01f8711
Show file tree
Hide file tree
Showing 89 changed files with 2,233 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
.idea
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
55 changes: 55 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.harshitbangar.conductormvp"
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'
}
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.google.dagger:dagger:2.10'
annotationProcessor 'com.google.dagger:dagger-compiler:2.10'
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
compile 'com.squareup.retrofit2:converter-jackson:2.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.6.0'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
compile project(':mvp.conductor')
compile project(':rx2mvpconductor')
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:2.7.21"
testCompile "org.robolectric:robolectric:3.3.2"
}
25 changes: 25 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/harshitbangar/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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.harshitbangar.conductormvp;

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.harshitbangar.conductormvp", appContext.getPackageName());
}
}
23 changes: 23 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.harshitbangar.conductormvp">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".DemoApplication"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
14 changes: 14 additions & 0 deletions app/src/main/java/com/harshitbangar/conductormvp/AppComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.harshitbangar.conductormvp;

import com.harshitbangar.conductormvp.details.TideDetailsController;
import dagger.Component;
import javax.inject.Singleton;

@Component(modules = AppModule.class)
@Singleton
public interface AppComponent {

void inject(MainActivity activity);

void inject(TideDetailsController screen);
}
43 changes: 43 additions & 0 deletions app/src/main/java/com/harshitbangar/conductormvp/AppModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.harshitbangar.conductormvp;

import dagger.Module;
import dagger.Provides;
import io.reactivex.schedulers.Schedulers;
import javax.inject.Singleton;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.jackson.JacksonConverterFactory;

@Module
final class AppModule {

private static final String NOAA_API_BASE_URL = "https://tidesandcurrents.noaa.gov/";

@Provides
@Singleton
NoaaApi provideNoaaApi(Retrofit retrofit) {
return retrofit.create(NoaaApi.class);
}

@Provides
@Singleton
Retrofit provideRetrofit(OkHttpClient httpClient) {
return new Retrofit.Builder()
.baseUrl(NOAA_API_BASE_URL)
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(JacksonConverterFactory.create())
.client(httpClient)
.build();
}

@Provides
@Singleton
OkHttpClient provideHttpClient() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
return new OkHttpClient.Builder().addInterceptor(interceptor).build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.harshitbangar.conductormvp;

import android.app.Application;
import android.content.Context;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

public class DemoApplication extends Application {

private AppComponent appComponent;
private RefWatcher refWatcher;

public static DemoApplication app(Context context) {
return (DemoApplication) context.getApplicationContext();
}

@Override public void onCreate() {
super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
refWatcher = LeakCanary.install(this);
appComponent = DaggerAppComponent.builder().appModule(new AppModule()).build();
}

public AppComponent injector() {
return appComponent;
}

public RefWatcher refWatcher() {
return refWatcher;
}
}
32 changes: 32 additions & 0 deletions app/src/main/java/com/harshitbangar/conductormvp/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.harshitbangar.conductormvp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ViewGroup;
import com.bluelinelabs.conductor.Conductor;
import com.bluelinelabs.conductor.Router;
import com.bluelinelabs.conductor.RouterTransaction;
import com.harshitbangar.conductormvp.locations.TideLocationsController;

public class MainActivity extends AppCompatActivity {

private Router router;

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewGroup container = (ViewGroup)findViewById(R.id.controller_container);

router = Conductor.attachRouter(this, container, savedInstanceState);
if (!router.hasRootController()) {
router.setRoot(RouterTransaction.with(new TideLocationsController()));
}
}

@Override
public void onBackPressed() {
if (!router.handleBack()) {
super.onBackPressed();
}
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/com/harshitbangar/conductormvp/NoaaApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.harshitbangar.conductormvp;

import com.harshitbangar.conductormvp.model.TideInfo;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;

public interface NoaaApi {

@GET("/api/datagetter?format=json&application=wealthfront&product=water_level&date=today&datum=mllw&time_zone=GMT&units=english")
Observable<TideInfo> getTideInfo(@Query("station") int stationId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.harshitbangar.conductormvp.base;

import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.harshitbangar.rx2mvpconductor.BuildConfig;
import com.harshitbangar.rx2mvpconductor.RXBaseController;
import com.harshitbangar.rx2mvpconductor.RXBaseView;

import static com.harshitbangar.conductormvp.DemoApplication.app;

public abstract class RefWatcherController<T extends RXBaseView> extends RXBaseController<T> {

public RefWatcherController() {
this(null);
}

public RefWatcherController(Bundle args) {
super(args);
}

@Override protected abstract T createView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container);

@Override @CallSuper protected void onDestroy() {
super.onDestroy();
if (BuildConfig.DEBUG) {
app(getApplicationContext()).refWatcher().watch(this);
}
}
}
Loading

0 comments on commit 01f8711

Please sign in to comment.