Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksanderMielczarek committed Oct 30, 2016
0 parents commit fc1cbdf
Show file tree
Hide file tree
Showing 42 changed files with 1,488 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.iml
.idea
.gradle
local.properties
build

65 changes: 65 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'me.tatarka.retrolambda'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.github.aleksandermielczarek.observablecacheexample"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

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

//test
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'

//support
compile 'com.android.support:appcompat-v7:25.0.0'

//dagger
compile 'com.google.dagger:dagger:2.7'
apt 'com.google.dagger:dagger-compiler:2.7'
compile 'com.github.AleksanderMielczarek:Napkin:0.3.0'

//rx
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.2.1'
compile project(':observablecache')

//utils
apt 'org.androidannotations:androidannotations:4.1.0'
compile 'org.androidannotations:androidannotations-api:4.1.0'
compile 'org.parceler:parceler-api:1.1.6'
apt 'org.parceler:parceler:1.1.6'
}

apt {
arguments {
androidManifestFile variant.outputs[0]?.processResources?.manifestFile
resourcePackageName android.defaultConfig.applicationId
}
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
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 C:\Users\Aleksander\AppData\Local\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 *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.aleksandermielczarek.observablecacheexample;

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.github.aleksandermielczarek.observablecacheexample", appContext.getPackageName());
}
}
20 changes: 20 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.aleksandermielczarek.observablecacheexample">

<application
android:name=".ObservableCacheApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".ui.MainActivity_">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.aleksandermielczarek.observablecacheexample;

import android.app.Application;

import com.github.aleksandermielczarek.napkin.ComponentProvider;
import com.github.aleksandermielczarek.observablecacheexample.component.AppComponent;
import com.github.aleksandermielczarek.observablecacheexample.component.DaggerAppComponent;

/**
* Created by Aleksander Mielczarek on 30.10.2016.
*/

public class ObservableCacheApplication extends Application implements ComponentProvider<AppComponent> {

private AppComponent appComponent;

@Override
public void onCreate() {
super.onCreate();
appComponent = DaggerAppComponent.create();
}

@Override
public AppComponent provideComponent() {
return appComponent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.aleksandermielczarek.observablecacheexample.component;

import com.github.aleksandermielczarek.napkin.scope.AppScope;
import com.github.aleksandermielczarek.observablecacheexample.module.AppModule;
import com.github.aleksandermielczarek.observablecacheexample.ui.MainActivity;

import dagger.Component;

/**
* Created by Aleksander Mielczarek on 30.10.2016.
*/
@Component(modules = AppModule.class)
@AppScope
public interface AppComponent {

void inject(MainActivity mainActivity);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.aleksandermielczarek.observablecacheexample.module;

import com.github.aleksandermielczarek.napkin.scope.AppScope;
import com.github.aleksandermielczarek.observablecache.LruObservableCache;
import com.github.aleksandermielczarek.observablecache.MapObservableCache;
import com.github.aleksandermielczarek.observablecache.ObservableCache;
import com.github.aleksandermielczarek.observablecacheexample.service.ObservableService;

import dagger.Module;
import dagger.Provides;

/**
* Created by Aleksander Mielczarek on 30.10.2016.
*/
@Module
@AppScope
public class AppModule {

@Provides
@AppScope
ObservableCache provideObservableCache() {
return LruObservableCache.newInstance();
}

@Provides
@AppScope
ObservableService provideObservableService() {
return new ObservableService();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.github.aleksandermielczarek.observablecacheexample.service;

import java.util.concurrent.TimeUnit;

import rx.Completable;
import rx.Observable;
import rx.Single;

/**
* Created by Aleksander Mielczarek on 30.10.2016.
*/

public class ObservableService {

public static final int DELAY = 4;
public static final TimeUnit TIME_UNIT = TimeUnit.SECONDS;

public Observable<String> observable() {
return Observable.fromCallable(() -> "observable")
.delay(15, TIME_UNIT);
}

public Single<String> single() {
return Single.fromCallable(() -> "single")
.delay(DELAY, TIME_UNIT);
}

public Completable completable() {
return Completable.fromCallable(() -> null)
.delay(DELAY, TIME_UNIT);
}

public Observable<String> observableError() {
return observable().doOnNext(observable -> {
throw new IllegalArgumentException("observableError");
});
}

public Single<String> singleError() {
return single().doOnSuccess(single -> {
throw new IllegalArgumentException("singleError");
});
}

public Completable completableError() {
return completable().doOnEach(completable -> {
throw new IllegalArgumentException("completableError");
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.github.aleksandermielczarek.observablecacheexample.ui;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.github.aleksandermielczarek.napkin.Napkin;
import com.github.aleksandermielczarek.observablecacheexample.R;
import com.github.aleksandermielczarek.observablecacheexample.component.AppComponent;
import com.github.aleksandermielczarek.observablecacheexample.databinding.ActivityMainBinding;

import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.InstanceState;

import javax.inject.Inject;

/**
* Created by Aleksander Mielczarek on 30.10.2016.
*/
@EActivity
public class MainActivity extends AppCompatActivity {

@InstanceState
protected MainViewModel.State state;

@Inject
protected MainViewModel mainViewModel;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Napkin.provideComponent(this, AppComponent.class).inject(this);
mainViewModel.restoreState(state);
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
binding.setViewModel(mainViewModel);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
state = mainViewModel.saveState();
}

@Override
protected void onStart() {
super.onStart();
mainViewModel.restoreObservables();
}

@Override
protected void onStop() {
super.onStop();
mainViewModel.unsubscribe();
}
}
Loading

0 comments on commit fc1cbdf

Please sign in to comment.