Skip to content

Refactor project structure to one single module #103

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
File renamed without changes.
27 changes: 22 additions & 5 deletions presentation/build.gradle → app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
}
}

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.fernandocejas.frodo'
apply plugin: 'me.tatarka.retrolambda'

frodo {
enabled = true
Expand All @@ -24,8 +34,8 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

packagingOptions {
Expand Down Expand Up @@ -65,17 +75,19 @@ android {
dependencies {
def presentationDependencies = rootProject.ext.presentationDependencies
def presentationTestDependencies = rootProject.ext.presentationTestDependencies
def dataDependencies = rootProject.ext.dataDependencies
def testDependencies = rootProject.ext.dataTestDependencies
def developmentDependencies = rootProject.ext.developmentDependencies

compile project(':domain')
compile project(':data')

apt presentationDependencies.daggerCompiler
compile presentationDependencies.dagger
compile dataDependencies.okHttp
compile dataDependencies.gson
compile presentationDependencies.butterKnife
compile presentationDependencies.recyclerView
compile presentationDependencies.rxJava
compile presentationDependencies.rxAndroid
compile dataDependencies.androidAnnotations
provided presentationDependencies.javaxAnnotation

androidTestCompile presentationTestDependencies.mockito
Expand All @@ -84,6 +96,11 @@ dependencies {
androidTestCompile presentationTestDependencies.espresso
androidTestCompile presentationTestDependencies.testingSupportLib

testCompile testDependencies.junit
testCompile testDependencies.assertj
testCompile testDependencies.mockito
testCompile testDependencies.robolectric

//Development
compile developmentDependencies.leakCanary
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.test.view.activity;
package com.fernandocejas.android10.sample.test.users;

import android.app.Fragment;
import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2;
import com.fernandocejas.android10.sample.presentation.R;
import com.fernandocejas.android10.sample.presentation.view.activity.UserDetailsActivity;
import com.fernandocejas.android10.sample.app.R;
import com.fernandocejas.android10.sample.app.users.UserDetailsActivity;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.test.view.activity;
package com.fernandocejas.android10.sample.test.users;

import android.app.Fragment;
import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2;
import com.fernandocejas.android10.sample.presentation.R;
import com.fernandocejas.android10.sample.presentation.view.activity.UserListActivity;
import com.fernandocejas.android10.sample.app.R;
import com.fernandocejas.android10.sample.app.users.UserListActivity;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fernandocejas.android10.sample.presentation">
package="com.fernandocejas.android10.sample.app">

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

<application
android:allowBackup="true"
android:name=".AndroidApplication"
android:name="com.fernandocejas.android10.sample.app.AndroidApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
Expand All @@ -22,12 +22,12 @@
</activity>

<activity
android:name=".view.activity.UserListActivity"
android:name=".users.UserListActivity"
android:label="@string/activity_title_user_list">
</activity>

<activity
android:name=".view.activity.UserDetailsActivity"
android:name=".users.UserDetailsActivity"
android:label="@string/activity_title_user_details">
</activity>
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.presentation;
package com.fernandocejas.android10.sample.app;

import android.app.Application;
import com.fernandocejas.android10.sample.presentation.internal.di.components.ApplicationComponent;
import com.fernandocejas.android10.sample.presentation.internal.di.components.DaggerApplicationComponent;
import com.fernandocejas.android10.sample.presentation.internal.di.modules.ApplicationModule;
import com.fernandocejas.android10.sample.app.core.di.components.ApplicationComponent;
import com.fernandocejas.android10.sample.app.core.di.components.DaggerApplicationComponent;
import com.fernandocejas.android10.sample.app.core.di.modules.ApplicationModule;
import com.squareup.leakcanary.LeakCanary;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.presentation.internal.di;
package com.fernandocejas.android10.sample.app.core.di;

/**
* Interface representing a contract for clients that contains a component for dependency injection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.presentation.internal.di;
package com.fernandocejas.android10.sample.app.core.di;

import java.lang.annotation.Retention;
import javax.inject.Scope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.presentation.internal.di.components;
package com.fernandocejas.android10.sample.app.core.di.components;

import android.app.Activity;
import com.fernandocejas.android10.sample.presentation.internal.di.PerActivity;
import com.fernandocejas.android10.sample.presentation.internal.di.modules.ActivityModule;
import com.fernandocejas.android10.sample.app.core.di.PerActivity;
import com.fernandocejas.android10.sample.app.core.di.modules.ActivityModule;
import dagger.Component;

/**
* A base component upon which fragment's components may depend.
* Activity-level components should extend this component.
*
* Subtypes of ActivityComponent should be decorated with annotation:
* {@link com.fernandocejas.android10.sample.presentation.internal.di.PerActivity}
* {@link PerActivity}
*/
@PerActivity
@Component(dependencies = ApplicationComponent.class, modules = ActivityModule.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.presentation.internal.di.components;
package com.fernandocejas.android10.sample.app.core.di.components;

import android.content.Context;
import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread;
import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor;
import com.fernandocejas.android10.sample.domain.repository.UserRepository;
import com.fernandocejas.android10.sample.presentation.internal.di.modules.ApplicationModule;
import com.fernandocejas.android10.sample.presentation.view.activity.BaseActivity;
import com.fernandocejas.android10.sample.app.core.executor.PostExecutionThread;
import com.fernandocejas.android10.sample.app.core.executor.ThreadExecutor;
import com.fernandocejas.android10.sample.app.users.UserRepository;
import com.fernandocejas.android10.sample.app.core.di.modules.ApplicationModule;
import com.fernandocejas.android10.sample.app.view.activity.BaseActivity;
import dagger.Component;
import javax.inject.Singleton;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.presentation.internal.di.modules;
package com.fernandocejas.android10.sample.app.core.di.modules;

import android.app.Activity;
import com.fernandocejas.android10.sample.presentation.internal.di.PerActivity;
import com.fernandocejas.android10.sample.app.core.di.PerActivity;
import dagger.Module;
import dagger.Provides;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.presentation.internal.di.modules;
package com.fernandocejas.android10.sample.app.core.di.modules;

import android.content.Context;
import com.fernandocejas.android10.sample.data.cache.UserCache;
import com.fernandocejas.android10.sample.data.cache.UserCacheImpl;
import com.fernandocejas.android10.sample.data.executor.JobExecutor;
import com.fernandocejas.android10.sample.data.repository.UserDataRepository;
import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread;
import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor;
import com.fernandocejas.android10.sample.domain.repository.UserRepository;
import com.fernandocejas.android10.sample.presentation.AndroidApplication;
import com.fernandocejas.android10.sample.presentation.UIThread;
import com.fernandocejas.android10.sample.presentation.navigation.Navigator;
import com.fernandocejas.android10.sample.app.users.cache.UserCache;
import com.fernandocejas.android10.sample.app.users.cache.UserCacheImpl;
import com.fernandocejas.android10.sample.app.core.executor.JobExecutor;
import com.fernandocejas.android10.sample.app.users.UserDataRepository;
import com.fernandocejas.android10.sample.app.core.executor.PostExecutionThread;
import com.fernandocejas.android10.sample.app.core.executor.ThreadExecutor;
import com.fernandocejas.android10.sample.app.users.UserRepository;
import com.fernandocejas.android10.sample.app.AndroidApplication;
import com.fernandocejas.android10.sample.app.core.executor.UIThread;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (C) 2015 Fernando Cejas Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.app.core.executor;

import android.support.annotation.NonNull;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Singleton;

/**
* Decorated {@link java.util.concurrent.ThreadPoolExecutor}
*/
@Singleton
public class JobExecutor implements ThreadExecutor {
private final ThreadPoolExecutor threadPoolExecutor;

@Inject
JobExecutor() {
this.threadPoolExecutor = new ThreadPoolExecutor(3, 5, 10, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(), new JobThreadFactory());
}

@Override public void execute(@NonNull Runnable runnable) {
this.threadPoolExecutor.execute(runnable);
}

private static class JobThreadFactory implements ThreadFactory {
private int counter = 0;

@Override public Thread newThread(@NonNull Runnable runnable) {
return new Thread(runnable, "android_" + counter++);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.domain.executor;
package com.fernandocejas.android10.sample.app.core.executor;

import rx.Scheduler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.domain.executor;
package com.fernandocejas.android10.sample.app.core.executor;

import java.util.concurrent.Executor;

/**
* Executor implementation can be based on different frameworks or techniques of asynchronous
* execution, but every implementation will execute the
* {@link com.fernandocejas.android10.sample.domain.interactor.UseCase} out of the UI thread.
* execution, but every implementation will execute UseCases out of the UI thread.
*/
public interface ThreadExecutor extends Executor {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.presentation;
package com.fernandocejas.android10.sample.app.core.executor;

import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread;
import javax.inject.Inject;
import javax.inject.Singleton;
import rx.Scheduler;
Expand All @@ -29,7 +28,7 @@
public class UIThread implements PostExecutionThread {

@Inject
public UIThread() {}
UIThread() {}

@Override public Scheduler getScheduler() {
return AndroidSchedulers.mainThread();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fernandocejas.android10.sample.data.net;
package com.fernandocejas.android10.sample.app.data;

import android.support.annotation.Nullable;
import com.squareup.okhttp.OkHttpClient;
Expand All @@ -29,7 +29,7 @@
* Implements {@link java.util.concurrent.Callable} so when executed asynchronously can
* return a value.
*/
public class ApiConnection implements Callable<String> {
class ApiConnection implements Callable<String> {

private static final String CONTENT_TYPE_LABEL = "Content-Type";
private static final String CONTENT_TYPE_VALUE_JSON = "application/json; charset=utf-8";
Expand All @@ -41,7 +41,7 @@ private ApiConnection(String url) throws MalformedURLException {
this.url = new URL(url);
}

public static ApiConnection createGET(String url) throws MalformedURLException {
static ApiConnection createGET(String url) throws MalformedURLException {
return new ApiConnection(url);
}

Expand All @@ -52,7 +52,7 @@ public static ApiConnection createGET(String url) throws MalformedURLException {
* @return A string response
*/
@Nullable
public String requestSyncCall() {
String requestSyncCall() {
connectToApi();
return response;
}
Expand Down
Loading