├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ └── layout
│ │ │ │ ├── list_item_normal.xml
│ │ │ │ ├── activity_repositories_list.xml
│ │ │ │ ├── list_item_big.xml
│ │ │ │ ├── list_item_featured.xml
│ │ │ │ ├── activity_splash.xml
│ │ │ │ └── activity_repository_details.xml
│ │ ├── java
│ │ │ └── frogermcs
│ │ │ │ └── io
│ │ │ │ └── githubclient
│ │ │ │ ├── ui
│ │ │ │ ├── activity
│ │ │ │ │ ├── ActivityScope.java
│ │ │ │ │ ├── BaseActivity.java
│ │ │ │ │ ├── component
│ │ │ │ │ │ ├── RepositoryDetailsActivityComponent.java
│ │ │ │ │ │ ├── SplashActivityComponent.java
│ │ │ │ │ │ └── RepositoriesListActivityComponent.java
│ │ │ │ │ ├── presenter
│ │ │ │ │ │ ├── RepositoryDetailsActivityPresenter.java
│ │ │ │ │ │ ├── RepositoriesListActivityPresenter.java
│ │ │ │ │ │ └── SplashActivityPresenter.java
│ │ │ │ │ ├── module
│ │ │ │ │ │ ├── RepositoryDetailsActivityModule.java
│ │ │ │ │ │ ├── SplashActivityModule.java
│ │ │ │ │ │ └── RepositoriesListActivityModule.java
│ │ │ │ │ ├── RepositoryDetailsActivity.java
│ │ │ │ │ ├── RepositoriesListActivity.java
│ │ │ │ │ └── SplashActivity.java
│ │ │ │ └── adapter
│ │ │ │ │ ├── viewholder
│ │ │ │ │ ├── RepositoriesListViewHolderFactory.java
│ │ │ │ │ ├── RepositoryViewHolder.java
│ │ │ │ │ ├── RepositoryViewHolderNormal.java
│ │ │ │ │ ├── RepositoryViewHolderBig.java
│ │ │ │ │ └── RepositoryViewHolderFeatured.java
│ │ │ │ │ └── RepositoriesListAdapter.java
│ │ │ │ ├── data
│ │ │ │ ├── UserScope.java
│ │ │ │ ├── api
│ │ │ │ │ ├── GithubApiService.java
│ │ │ │ │ ├── UserModule.java
│ │ │ │ │ ├── response
│ │ │ │ │ │ ├── UserResponse.java
│ │ │ │ │ │ └── RepositoryResponse.java
│ │ │ │ │ ├── UserManager.java
│ │ │ │ │ ├── GithubApiModule.java
│ │ │ │ │ └── RepositoriesManager.java
│ │ │ │ ├── UserComponent.java
│ │ │ │ └── model
│ │ │ │ │ ├── User.java
│ │ │ │ │ └── Repository.java
│ │ │ │ ├── utils
│ │ │ │ ├── Validator.java
│ │ │ │ ├── SimpleObserver.java
│ │ │ │ └── AnalyticsManager.java
│ │ │ │ ├── ExecutorModule.java
│ │ │ │ ├── HeavyExternalLibrary.java
│ │ │ │ ├── AppComponent.java
│ │ │ │ ├── AppModule.java
│ │ │ │ ├── GithubClientApplication.java
│ │ │ │ └── HeavyLibraryWrapper.java
│ │ └── AndroidManifest.xml
│ ├── androidTest
│ │ └── java
│ │ │ └── frogermcs
│ │ │ └── io
│ │ │ └── githubclient
│ │ │ ├── tests
│ │ │ ├── ApplicationTest.java
│ │ │ └── SplashActivityUITests.java
│ │ │ ├── MyTestRunner.java
│ │ │ └── inject
│ │ │ ├── GithubApiModuleMock.java
│ │ │ └── ApplicationMock.java
│ └── test
│ │ └── java
│ │ └── frogermcs
│ │ └── io
│ │ └── githubclient
│ │ ├── MockAppModule.java
│ │ ├── ui
│ │ └── activity
│ │ │ ├── module
│ │ │ └── MockSplashActivityModule.java
│ │ │ └── SplashActivityTests.java
│ │ └── TestGithubClientApplication.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/GithubClient/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/frogermcs/GithubClient/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 | *.iml
9 | .idea
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GithubClient
3 | https://api.github.com
4 |
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip
6 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/ActivityScope.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity;
2 |
3 | import javax.inject.Scope;
4 |
5 | /**
6 | * Created by Miroslaw Stanek on 22.04.15.
7 | */
8 | @Scope
9 | public @interface ActivityScope {
10 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/data/UserScope.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.data;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 |
6 | import javax.inject.Scope;
7 |
8 | /**
9 | * Created by Miroslaw Stanek on 22.04.15.
10 | */
11 | @Scope
12 | @Retention(RetentionPolicy.RUNTIME)
13 | public @interface UserScope {
14 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/adapter/viewholder/RepositoriesListViewHolderFactory.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.adapter.viewholder;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.ViewGroup;
5 |
6 | /**
7 | * Created by Miroslaw Stanek on 11.06.2016.
8 | */
9 |
10 | public interface RepositoriesListViewHolderFactory {
11 | RecyclerView.ViewHolder createViewHolder(ViewGroup parent);
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/frogermcs/io/githubclient/tests/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.tests;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/utils/Validator.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.utils;
2 |
3 | import android.text.TextUtils;
4 |
5 | import javax.inject.Inject;
6 | import javax.inject.Singleton;
7 |
8 | /**
9 | * Created by Miroslaw Stanek on 23.04.15.
10 | */
11 | public class Validator {
12 |
13 | public Validator() {
14 | }
15 |
16 | public boolean validUsername(String username) {
17 | return !TextUtils.isEmpty(username);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/utils/SimpleObserver.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.utils;
2 |
3 | import rx.Observer;
4 |
5 | /**
6 | * Created by Miroslaw Stanek on 23.04.15.
7 | */
8 | public class SimpleObserver implements Observer {
9 | @Override
10 | public void onCompleted() {
11 |
12 | }
13 |
14 | @Override
15 | public void onError(Throwable e) {
16 |
17 | }
18 |
19 | @Override
20 | public void onNext(T t) {
21 |
22 | }
23 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ExecutorModule.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient;
2 |
3 | import java.util.concurrent.Executor;
4 | import java.util.concurrent.Executors;
5 |
6 | import dagger.Module;
7 | import dagger.Provides;
8 | import dagger.producers.Production;
9 |
10 | /**
11 | * Created by froger_mcs on 12/02/2018.
12 | */
13 |
14 | @Module
15 | final class ExecutorModule {
16 | @Provides
17 | @Production
18 | static Executor executor() {
19 | return Executors.newSingleThreadExecutor();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/adapter/viewholder/RepositoryViewHolder.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.adapter.viewholder;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 |
6 | import frogermcs.io.githubclient.data.model.Repository;
7 |
8 | /**
9 | * Created by Miroslaw Stanek on 11.06.2016.
10 | */
11 |
12 | public abstract class RepositoryViewHolder extends RecyclerView.ViewHolder {
13 | public RepositoryViewHolder(View itemView) {
14 | super(itemView);
15 | }
16 |
17 | public abstract void bind(Repository repository);
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/HeavyExternalLibrary.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient;
2 |
3 | /**
4 | * Created by Miroslaw Stanek on 28.09.15.
5 | */
6 | public class HeavyExternalLibrary {
7 |
8 | private boolean initialized = false;
9 |
10 | public HeavyExternalLibrary() {
11 | }
12 |
13 | public void init() {
14 | try {
15 | Thread.sleep(500);
16 | } catch (InterruptedException e) {
17 | e.printStackTrace();
18 | }
19 | initialized = true;
20 | }
21 |
22 | public void callMethod() {
23 | if (!initialized) throw new RuntimeException("Call init() before you use this library");
24 | }
25 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | import frogermcs.io.githubclient.AppComponent;
7 | import frogermcs.io.githubclient.GithubClientApplication;
8 |
9 | /**
10 | * Created by Miroslaw Stanek on 23.04.15.
11 | */
12 | public abstract class BaseActivity extends AppCompatActivity {
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setupActivityComponent();
18 | }
19 |
20 | protected abstract void setupActivityComponent();
21 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/froger_mcs/dev/android_sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/frogermcs/io/githubclient/MyTestRunner.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import android.support.test.runner.AndroidJUnitRunner;
6 |
7 | import frogermcs.io.githubclient.inject.ApplicationMock;
8 |
9 | /**
10 | * Created by Miroslaw Stanek on 24.09.15.
11 | */
12 | public class MyTestRunner extends AndroidJUnitRunner {
13 |
14 | @Override
15 | public Application newApplication(ClassLoader cl, String className, Context context)
16 | throws InstantiationException, IllegalAccessException, ClassNotFoundException {
17 | return super.newApplication(cl, ApplicationMock.class.getName(), context);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/test/java/frogermcs/io/githubclient/MockAppModule.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient;
2 |
3 | import android.app.Application;
4 |
5 | import org.mockito.Mock;
6 | import org.mockito.MockitoAnnotations;
7 |
8 | import frogermcs.io.githubclient.utils.AnalyticsManager;
9 |
10 | /**
11 | * Created by Miroslaw Stanek on 20.09.15.
12 | */
13 | public class MockAppModule extends AppModule {
14 | @Mock
15 | AnalyticsManager analyticsManagerMock;
16 |
17 | public MockAppModule(Application application) {
18 | super(application);
19 | MockitoAnnotations.initMocks(this);
20 | }
21 |
22 | @Override
23 | AnalyticsManager provideAnalyticsManager() {
24 | return analyticsManagerMock;
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/component/RepositoryDetailsActivityComponent.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity.component;
2 |
3 | import dagger.Subcomponent;
4 | import frogermcs.io.githubclient.ui.activity.ActivityScope;
5 | import frogermcs.io.githubclient.ui.activity.RepositoryDetailsActivity;
6 | import frogermcs.io.githubclient.ui.activity.module.RepositoryDetailsActivityModule;
7 |
8 | /**
9 | * Created by Miroslaw Stanek on 23.04.15.
10 | */
11 | @ActivityScope
12 | @Subcomponent(
13 | modules = RepositoryDetailsActivityModule.class
14 | )
15 | public interface RepositoryDetailsActivityComponent {
16 |
17 | RepositoryDetailsActivity inject(RepositoryDetailsActivity repositoryDetailsActivity);
18 |
19 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/component/SplashActivityComponent.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity.component;
2 |
3 | import dagger.Subcomponent;
4 | import frogermcs.io.githubclient.ui.activity.ActivityScope;
5 | import frogermcs.io.githubclient.ui.activity.SplashActivity;
6 | import frogermcs.io.githubclient.ui.activity.module.SplashActivityModule;
7 | import frogermcs.io.githubclient.ui.activity.presenter.SplashActivityPresenter;
8 |
9 | /**
10 | * Created by Miroslaw Stanek on 23.04.15.
11 | */
12 | @ActivityScope
13 | @Subcomponent(
14 | modules = SplashActivityModule.class
15 | )
16 | public interface SplashActivityComponent {
17 |
18 | SplashActivity inject(SplashActivity splashActivity);
19 |
20 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/utils/AnalyticsManager.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.utils;
2 |
3 | import android.app.Application;
4 |
5 | import javax.inject.Inject;
6 | import javax.inject.Singleton;
7 |
8 | import frogermcs.io.githubclient.data.UserScope;
9 | import frogermcs.io.githubclient.ui.activity.ActivityScope;
10 | import timber.log.Timber;
11 |
12 | /**
13 | * Created by Miroslaw Stanek on 23.04.15.
14 | */
15 | public class AnalyticsManager {
16 |
17 | private Application app;
18 |
19 | public AnalyticsManager(Application app) {
20 | this.app = app;
21 | }
22 |
23 | public void logScreenView(String screenName) {
24 | Timber.d("Logged screen name: " + screenName);
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/frogermcs/io/githubclient/inject/GithubApiModuleMock.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.inject;
2 |
3 | import frogermcs.io.githubclient.data.api.GithubApiModule;
4 | import frogermcs.io.githubclient.data.api.GithubApiService;
5 | import frogermcs.io.githubclient.data.api.UserManager;
6 |
7 | /**
8 | * Created by Miroslaw Stanek on 23.09.15.
9 | */
10 | public class GithubApiModuleMock extends GithubApiModule {
11 |
12 | private UserManager userManagerMock;
13 |
14 | public GithubApiModuleMock(UserManager userManagerMock) {
15 | this.userManagerMock = userManagerMock;
16 | }
17 |
18 | @Override
19 | public UserManager provideUserManager(GithubApiService githubApiService) {
20 | return userManagerMock;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/data/api/GithubApiService.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.data.api;
2 |
3 | import java.util.List;
4 |
5 | import frogermcs.io.githubclient.data.api.response.RepositoryResponse;
6 | import frogermcs.io.githubclient.data.api.response.UserResponse;
7 | import retrofit2.http.GET;
8 | import retrofit2.http.Path;
9 | import rx.Observable;
10 |
11 | /**
12 | * Created by Miroslaw Stanek on 22.04.15.
13 | */
14 | public interface GithubApiService {
15 |
16 | @GET("/users/{username}")
17 | Observable getUser(
18 | @Path("username") String username
19 | );
20 |
21 | @GET("/users/{username}/repos")
22 | Observable> getUsersRepositories(
23 | @Path("username") String username
24 | );
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_repositories_list.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
14 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/data/api/UserModule.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.data.api;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import frogermcs.io.githubclient.data.UserScope;
6 | import frogermcs.io.githubclient.data.model.User;
7 |
8 | /**
9 | * Created by Miroslaw Stanek on 23.06.15.
10 | */
11 | @Module
12 | public class UserModule {
13 |
14 | private User user;
15 |
16 | public UserModule(User user) {
17 | this.user = user;
18 | }
19 |
20 | @Provides
21 | @UserScope
22 | User provideUser() {
23 | return user;
24 | }
25 |
26 | @Provides
27 | @UserScope
28 | RepositoriesManager provideRepositoriesManager(User user, GithubApiService githubApiService) {
29 | return new RepositoriesManager(user, githubApiService);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/component/RepositoriesListActivityComponent.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity.component;
2 |
3 | import dagger.Subcomponent;
4 | import frogermcs.io.githubclient.ui.activity.ActivityScope;
5 | import frogermcs.io.githubclient.ui.activity.RepositoriesListActivity;
6 | import frogermcs.io.githubclient.ui.activity.module.RepositoriesListActivityModule;
7 | import frogermcs.io.githubclient.ui.activity.presenter.RepositoriesListActivityPresenter;
8 |
9 | /**
10 | * Created by Miroslaw Stanek on 23.04.15.
11 | */
12 | @ActivityScope
13 | @Subcomponent(
14 | modules = RepositoriesListActivityModule.class
15 | )
16 | public interface RepositoriesListActivityComponent {
17 |
18 | RepositoriesListActivity inject(RepositoriesListActivity repositoriesListActivity);
19 |
20 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/presenter/RepositoryDetailsActivityPresenter.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity.presenter;
2 |
3 | import frogermcs.io.githubclient.data.model.User;
4 | import frogermcs.io.githubclient.ui.activity.RepositoryDetailsActivity;
5 |
6 | /**
7 | * Created by Miroslaw Stanek on 23.04.15.
8 | */
9 | public class RepositoryDetailsActivityPresenter {
10 | private RepositoryDetailsActivity repositoryDetailsActivity;
11 | private User user;
12 |
13 | public RepositoryDetailsActivityPresenter(RepositoryDetailsActivity repositoryDetailsActivity, User user) {
14 | this.repositoryDetailsActivity = repositoryDetailsActivity;
15 | this.user = user;
16 | }
17 |
18 | public void init() {
19 | repositoryDetailsActivity.setupUserName(user.login);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/AppComponent.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient;
2 |
3 | import javax.inject.Singleton;
4 |
5 | import dagger.Component;
6 | import frogermcs.io.githubclient.data.api.GithubApiModule;
7 | import frogermcs.io.githubclient.data.UserComponent;
8 | import frogermcs.io.githubclient.data.api.UserModule;
9 | import frogermcs.io.githubclient.ui.activity.component.SplashActivityComponent;
10 | import frogermcs.io.githubclient.ui.activity.module.SplashActivityModule;
11 |
12 | /**
13 | * Created by Miroslaw Stanek on 22.04.15.
14 | */
15 | @Singleton
16 | @Component(
17 | modules = {
18 | AppModule.class,
19 | GithubApiModule.class
20 | }
21 | )
22 | public interface AppComponent {
23 |
24 | SplashActivityComponent plus(SplashActivityModule module);
25 |
26 | UserComponent plus(UserModule userModule);
27 |
28 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/test/java/frogermcs/io/githubclient/ui/activity/module/MockSplashActivityModule.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity.module;
2 |
3 | import dagger.Provides;
4 | import frogermcs.io.githubclient.data.api.UserManager;
5 | import frogermcs.io.githubclient.ui.activity.ActivityScope;
6 | import frogermcs.io.githubclient.ui.activity.SplashActivity;
7 | import frogermcs.io.githubclient.ui.activity.presenter.SplashActivityPresenter;
8 | import frogermcs.io.githubclient.utils.Validator;
9 |
10 | import static org.mockito.Mockito.mock;
11 |
12 | /**
13 | * Created by Miroslaw Stanek on 20.09.15.
14 | */
15 | public class MockSplashActivityModule extends SplashActivityModule {
16 |
17 | public MockSplashActivityModule(SplashActivity splashActivity) {
18 | super(splashActivity);
19 | }
20 |
21 | @Provides
22 | @ActivityScope
23 | SplashActivityPresenter provideSplashActivityPresenter(Validator validator, UserManager userManager) {
24 | return mock(SplashActivityPresenter.class);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GithubClient
2 | Example of Github API client implemented on top of Dagger 2 DI framework.
3 |
4 | This code was created as an example for Dependency Injection with Dagger 2 series on my dev-blog:
5 |
6 | - [Introdution to Dependency Injection](http://frogermcs.github.io/dependency-injection-with-dagger-2-introdution-to-di/)
7 | - [Dagger 2 API](http://frogermcs.github.io/dependency-injection-with-dagger-2-the-api/)
8 | - [Dagger 2 - custom scopes](http://frogermcs.github.io/dependency-injection-with-dagger-2-custom-scopes/)
9 | - [Dagger 2 - graph creation performance](http://frogermcs.github.io/dagger-graph-creation-performance/)
10 | - [Dependency injection with Dagger 2 - Producers](http://frogermcs.github.io/dependency-injection-with-dagger-2-producers/)
11 | - [Inject everything - ViewHolder and Dagger 2 (with Multibinding and AutoFactory example)](http://frogermcs.github.io/inject-everything-viewholder-and-dagger-2-example/)
12 |
13 | This code was originally prepared for my presentation at Google I/O Extended 2015 in Tech Space Cracow. http://www.meetup.com/GDG-Krakow/events/221822600/
14 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/data/api/response/UserResponse.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.data.api.response;
2 |
3 | import java.util.Date;
4 |
5 | /**
6 | * Created by Miroslaw Stanek on 22.04.15.
7 | */
8 | public class UserResponse {
9 | public String login;
10 | public long id;
11 | public String avatar_url;
12 | public String gravatar_id;
13 | public String url;
14 | public String html_url;
15 | public String followers_url;
16 | public String following_url;
17 | public String gists_url;
18 | public String starred_url;
19 | public String subscriptions_url;
20 | public String organizations_url;
21 | public String repos_url;
22 | public String events_url;
23 | public String received_events_url;
24 | public String type;
25 | public String name;
26 | public String blog;
27 | public String location;
28 | public String email;
29 | public int public_repos;
30 | public int public_gists;
31 | public int followers;
32 | public int following;
33 | public Date created_at;
34 | public Date updated_at;
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item_big.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/data/UserComponent.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.data;
2 |
3 | import dagger.Subcomponent;
4 | import frogermcs.io.githubclient.data.api.UserModule;
5 | import frogermcs.io.githubclient.ui.activity.component.RepositoriesListActivityComponent;
6 | import frogermcs.io.githubclient.ui.activity.component.RepositoryDetailsActivityComponent;
7 | import frogermcs.io.githubclient.ui.activity.component.SplashActivityComponent;
8 | import frogermcs.io.githubclient.ui.activity.module.RepositoriesListActivityModule;
9 | import frogermcs.io.githubclient.ui.activity.module.RepositoryDetailsActivityModule;
10 | import frogermcs.io.githubclient.ui.activity.module.SplashActivityModule;
11 |
12 | /**
13 | * Created by Miroslaw Stanek on 23.06.15.
14 | */
15 | @UserScope
16 | @Subcomponent(
17 | modules = {
18 | UserModule.class
19 | }
20 | )
21 | public interface UserComponent {
22 |
23 | RepositoriesListActivityComponent plus(RepositoriesListActivityModule module);
24 |
25 | RepositoryDetailsActivityComponent plus(RepositoryDetailsActivityModule module);
26 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/adapter/viewholder/RepositoryViewHolderNormal.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.adapter.viewholder;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.ViewGroup;
5 | import android.widget.TextView;
6 |
7 | import com.google.auto.factory.AutoFactory;
8 |
9 | import butterknife.BindView;
10 | import butterknife.ButterKnife;
11 | import frogermcs.io.githubclient.R;
12 | import frogermcs.io.githubclient.data.model.Repository;
13 |
14 | /**
15 | * Created by Miroslaw Stanek on 11.06.2016.
16 | */
17 | @AutoFactory(implementing = RepositoriesListViewHolderFactory.class)
18 | public class RepositoryViewHolderNormal extends RepositoryViewHolder {
19 |
20 | @BindView(R.id.tvName)
21 | TextView tvName;
22 |
23 | public RepositoryViewHolderNormal(ViewGroup parent) {
24 | super(LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_normal, parent, false));
25 | ButterKnife.bind(this, itemView);
26 | }
27 |
28 | @Override
29 | public void bind(Repository repository) {
30 | tvName.setText(repository.name);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/data/api/response/RepositoryResponse.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.data.api.response;
2 |
3 | import java.util.Date;
4 |
5 | /**
6 | * Created by Miroslaw Stanek on 22.04.15.
7 | */
8 | public class RepositoryResponse {
9 | public long id;
10 | public String name;
11 | public String full_name;
12 | public UserResponse owner;
13 | public String html_url;
14 | public String description;
15 | public String url;
16 | public Date created_at;
17 | public Date updated_at;
18 | public Date pushed_at;
19 | public String git_url;
20 | public String ssh_url;
21 | public String clone_url;
22 | public String svn_url;
23 | public String homepage;
24 | public int stargazers_count;
25 | public int watchers_count;
26 | public String language;
27 | public boolean has_issues;
28 | public boolean has_downloads;
29 | public boolean has_wiki;
30 | public boolean has_pages;
31 | public int forks_count;
32 | public int open_issues_count;
33 | public int forks;
34 | public int open_issues;
35 | public int watchers;
36 | public String default_branch;
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/test/java/frogermcs/io/githubclient/TestGithubClientApplication.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient;
2 |
3 | import frogermcs.io.githubclient.ui.activity.component.SplashActivityComponent;
4 | import frogermcs.io.githubclient.ui.activity.module.SplashActivityModule;
5 |
6 | import static org.mockito.Matchers.any;
7 | import static org.mockito.Mockito.mock;
8 | import static org.mockito.Mockito.when;
9 |
10 | /**
11 | * Created by Miroslaw Stanek on 19.09.15.
12 | */
13 | public class TestGithubClientApplication
14 | extends GithubClientApplication {
15 |
16 | private AppComponent appComponent;
17 | private SplashActivityComponent splashActivityComponent;
18 |
19 | @Override
20 | public AppComponent getAppComponent() {
21 | if (appComponent == null) {
22 | appComponent = mock(AppComponent.class);
23 | when(appComponent.plus(any(SplashActivityModule.class)))
24 | .thenReturn(splashActivityComponent);
25 | }
26 |
27 | return appComponent;
28 | }
29 |
30 | public void setSplashActivityComponent(SplashActivityComponent component) {
31 | this.splashActivityComponent = component;
32 | }
33 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/frogermcs/io/githubclient/inject/ApplicationMock.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.inject;
2 |
3 | import frogermcs.io.githubclient.AppComponent;
4 | import frogermcs.io.githubclient.AppModule;
5 | import frogermcs.io.githubclient.DaggerAppComponent;
6 | import frogermcs.io.githubclient.GithubClientApplication;
7 | import frogermcs.io.githubclient.data.api.GithubApiModule;
8 |
9 | /**
10 | * Created by Miroslaw Stanek on 24.09.15.
11 | */
12 | public class ApplicationMock extends GithubClientApplication {
13 |
14 | private AppComponent appComponent;
15 | private GithubApiModule githubApiModuleMock;
16 |
17 | public void setGithubApiModuleMock(GithubApiModule githubApiModuleMock) {
18 | this.githubApiModuleMock = githubApiModuleMock;
19 | setupMockAppComponent();
20 | }
21 |
22 | public void setupMockAppComponent() {
23 | appComponent = DaggerAppComponent.builder()
24 | .appModule(new AppModule(this))
25 | .githubApiModule(githubApiModuleMock)
26 | .build();
27 | }
28 |
29 | @Override
30 | public AppComponent getAppComponent() {
31 | return appComponent == null ? super.getAppComponent() : appComponent;
32 | }
33 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item_featured.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
26 |
27 |
34 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/module/RepositoryDetailsActivityModule.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity.module;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import frogermcs.io.githubclient.data.model.User;
6 | import frogermcs.io.githubclient.ui.activity.ActivityScope;
7 | import frogermcs.io.githubclient.ui.activity.RepositoryDetailsActivity;
8 | import frogermcs.io.githubclient.ui.activity.presenter.RepositoryDetailsActivityPresenter;
9 |
10 | /**
11 | * Created by Miroslaw Stanek on 23.04.15.
12 | */
13 | @Module
14 | public class RepositoryDetailsActivityModule {
15 | private RepositoryDetailsActivity repositoryDetailsActivity;
16 |
17 | public RepositoryDetailsActivityModule(RepositoryDetailsActivity repositoryDetailsActivity) {
18 | this.repositoryDetailsActivity = repositoryDetailsActivity;
19 | }
20 |
21 | @Provides
22 | @ActivityScope
23 | RepositoryDetailsActivity provideRepositoryDetailsActivity() {
24 | return repositoryDetailsActivity;
25 | }
26 |
27 | @Provides
28 | @ActivityScope
29 | RepositoryDetailsActivityPresenter provideRepositoryDetailsActivityPresenter(User user) {
30 | return new RepositoryDetailsActivityPresenter(repositoryDetailsActivity, user);
31 | }
32 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/data/model/User.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.data.model;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * Created by Miroslaw Stanek on 22.04.15.
8 | */
9 | public class User implements Parcelable {
10 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
11 | public User createFromParcel(Parcel source) {
12 | return new User(source);
13 | }
14 |
15 | public User[] newArray(int size) {
16 | return new User[size];
17 | }
18 | };
19 | public String login;
20 | public long id;
21 | public String url;
22 | public String email;
23 |
24 | public User() {
25 | }
26 |
27 | protected User(Parcel in) {
28 | this.login = in.readString();
29 | this.id = in.readLong();
30 | this.url = in.readString();
31 | this.email = in.readString();
32 | }
33 |
34 | @Override
35 | public int describeContents() {
36 | return 0;
37 | }
38 |
39 | @Override
40 | public void writeToParcel(Parcel dest, int flags) {
41 | dest.writeString(this.login);
42 | dest.writeLong(this.id);
43 | dest.writeString(this.url);
44 | dest.writeString(this.email);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/adapter/viewholder/RepositoryViewHolderBig.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.adapter.viewholder;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.ViewGroup;
5 | import android.widget.TextView;
6 |
7 | import com.google.auto.factory.AutoFactory;
8 |
9 | import butterknife.BindView;
10 | import butterknife.ButterKnife;
11 | import frogermcs.io.githubclient.R;
12 | import frogermcs.io.githubclient.data.model.Repository;
13 |
14 | /**
15 | * Created by Miroslaw Stanek on 11.06.2016.
16 | */
17 | @AutoFactory(implementing = RepositoriesListViewHolderFactory.class)
18 | public class RepositoryViewHolderBig extends RepositoryViewHolder {
19 |
20 | @BindView(R.id.tvName)
21 | TextView tvName;
22 | @BindView(R.id.tvStars)
23 | TextView tvStars;
24 | @BindView(R.id.tvForks)
25 | TextView tvForks;
26 |
27 | public RepositoryViewHolderBig(ViewGroup parent) {
28 | super(LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_big, parent, false));
29 | ButterKnife.bind(this, itemView);
30 | }
31 |
32 | @Override
33 | public void bind(Repository repository) {
34 | tvName.setText(repository.name);
35 | tvStars.setText("Stars: " + repository.stargazers_count);
36 | tvForks.setText("Forks: " + repository.forks_count);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/adapter/viewholder/RepositoryViewHolderFeatured.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.adapter.viewholder;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.ViewGroup;
5 | import android.widget.TextView;
6 |
7 | import com.google.auto.factory.AutoFactory;
8 |
9 | import butterknife.BindView;
10 | import butterknife.ButterKnife;
11 | import frogermcs.io.githubclient.R;
12 | import frogermcs.io.githubclient.data.model.Repository;
13 |
14 | /**
15 | * Created by Miroslaw Stanek on 11.06.2016.
16 | */
17 | @AutoFactory(implementing = RepositoriesListViewHolderFactory.class)
18 | public class RepositoryViewHolderFeatured extends RepositoryViewHolder {
19 |
20 | @BindView(R.id.tvName)
21 | TextView tvName;
22 | @BindView(R.id.tvStars)
23 | TextView tvStars;
24 | @BindView(R.id.tvForks)
25 | TextView tvForks;
26 |
27 | public RepositoryViewHolderFeatured(ViewGroup parent) {
28 | super(LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_featured, parent, false));
29 | ButterKnife.bind(this, itemView);
30 | }
31 |
32 | @Override
33 | public void bind(Repository repository) {
34 | tvName.setText(repository.name);
35 | tvStars.setText("Stars: " + repository.stargazers_count);
36 | tvForks.setText("Forks: " + repository.forks_count);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/module/SplashActivityModule.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity.module;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import frogermcs.io.githubclient.HeavyExternalLibrary;
6 | import frogermcs.io.githubclient.HeavyLibraryWrapper;
7 | import frogermcs.io.githubclient.data.api.UserManager;
8 | import frogermcs.io.githubclient.ui.activity.ActivityScope;
9 | import frogermcs.io.githubclient.ui.activity.SplashActivity;
10 | import frogermcs.io.githubclient.ui.activity.presenter.SplashActivityPresenter;
11 | import frogermcs.io.githubclient.utils.Validator;
12 |
13 | /**
14 | * Created by Miroslaw Stanek on 23.04.15.
15 | */
16 | @Module
17 | public class SplashActivityModule {
18 | private SplashActivity splashActivity;
19 |
20 | public SplashActivityModule(SplashActivity splashActivity) {
21 | this.splashActivity = splashActivity;
22 | }
23 |
24 | @Provides
25 | @ActivityScope
26 | SplashActivity provideSplashActivity() {
27 | return splashActivity;
28 | }
29 |
30 | @Provides
31 | @ActivityScope
32 | SplashActivityPresenter
33 | provideSplashActivityPresenter(Validator validator, UserManager userManager, HeavyLibraryWrapper heavyLibraryWrapper) {
34 | return new SplashActivityPresenter(splashActivity, validator, userManager, heavyLibraryWrapper);
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_splash.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
14 |
15 |
20 |
21 |
28 |
29 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/data/api/UserManager.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.data.api;
2 |
3 | import frogermcs.io.githubclient.data.api.response.UserResponse;
4 | import frogermcs.io.githubclient.data.model.User;
5 | import rx.Observable;
6 | import rx.android.schedulers.AndroidSchedulers;
7 | import rx.functions.Func1;
8 | import rx.schedulers.Schedulers;
9 |
10 | /**
11 | * Created by Miroslaw Stanek on 22.04.15.
12 | */
13 | public class UserManager {
14 |
15 | private GithubApiService githubApiService;
16 |
17 | public UserManager(GithubApiService githubApiService) {
18 | this.githubApiService = githubApiService;
19 | }
20 |
21 | public Observable getUser(String username) {
22 | return githubApiService.getUser(username)
23 | .map(new Func1() {
24 | @Override
25 | public User call(UserResponse userResponse) {
26 | User user = new User();
27 | user.login = userResponse.login;
28 | user.id = userResponse.id;
29 | user.url = userResponse.url;
30 | user.email = userResponse.email;
31 | return user;
32 | }
33 | })
34 | .subscribeOn(Schedulers.io())
35 | .observeOn(AndroidSchedulers.mainThread());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/AppModule.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient;
2 |
3 | import android.app.Application;
4 |
5 | import javax.inject.Singleton;
6 |
7 | import dagger.Module;
8 | import dagger.Provides;
9 | import frogermcs.io.githubclient.utils.AnalyticsManager;
10 | import frogermcs.io.githubclient.utils.Validator;
11 |
12 | /**
13 | * Created by Miroslaw Stanek on 22.04.15.
14 | */
15 | @Module
16 | public class AppModule {
17 | private Application application;
18 |
19 | public AppModule(Application application) {
20 | this.application = application;
21 | }
22 |
23 | @Provides
24 | @Singleton
25 | public Application provideApplication() {
26 | return application;
27 | }
28 |
29 | @Provides
30 | @Singleton
31 | AnalyticsManager provideAnalyticsManager() {
32 | return new AnalyticsManager(application);
33 | }
34 |
35 | @Provides
36 | @Singleton
37 | Validator provideValidator() {
38 | return new Validator();
39 | }
40 |
41 | @Provides
42 | @Singleton
43 | HeavyExternalLibrary provideHeavyExternalLibrary() {
44 | HeavyExternalLibrary heavyExternalLibrary = new HeavyExternalLibrary();
45 | heavyExternalLibrary.init();
46 | return heavyExternalLibrary;
47 | }
48 |
49 | @Provides
50 | @Singleton
51 | HeavyLibraryWrapper provideLibraryWrapper() {
52 | return new HeavyLibraryWrapper();
53 | }
54 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/data/model/Repository.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.data.model;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * Created by Miroslaw Stanek on 22.04.15.
8 | */
9 | public class Repository implements Parcelable {
10 | public static final int TYPE_NORMAL = 0;
11 | public static final int TYPE_BIG = 1;
12 | public static final int TYPE_FEATURED = 2;
13 |
14 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
15 | public Repository createFromParcel(Parcel source) {
16 | return new Repository(source);
17 | }
18 |
19 | public Repository[] newArray(int size) {
20 | return new Repository[size];
21 | }
22 | };
23 | public long id;
24 | public String name;
25 | public String url;
26 | public int stargazers_count;
27 | public int forks_count;
28 |
29 | public Repository() {
30 | }
31 |
32 | private Repository(Parcel in) {
33 | this.id = in.readLong();
34 | this.name = in.readString();
35 | this.url = in.readString();
36 | this.stargazers_count = in.readInt();
37 | this.forks_count = in.readInt();
38 | }
39 |
40 | @Override
41 | public int describeContents() {
42 | return 0;
43 | }
44 |
45 | @Override
46 | public void writeToParcel(Parcel dest, int flags) {
47 | dest.writeLong(this.id);
48 | dest.writeString(this.name);
49 | dest.writeString(this.url);
50 | dest.writeInt(this.stargazers_count);
51 | dest.writeInt(this.forks_count);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_repository_details.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
12 |
13 |
19 |
20 |
26 |
27 |
28 |
33 |
34 |
38 |
39 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/presenter/RepositoriesListActivityPresenter.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity.presenter;
2 |
3 | import com.google.common.collect.ImmutableList;
4 |
5 | import frogermcs.io.githubclient.data.api.RepositoriesManager;
6 | import frogermcs.io.githubclient.data.model.Repository;
7 | import frogermcs.io.githubclient.ui.activity.RepositoriesListActivity;
8 | import frogermcs.io.githubclient.utils.SimpleObserver;
9 |
10 | /**
11 | * Created by Miroslaw Stanek on 23.04.15.
12 | */
13 | public class RepositoriesListActivityPresenter {
14 | private RepositoriesListActivity repositoriesListActivity;
15 | private RepositoriesManager repositoriesManager;
16 |
17 | public RepositoriesListActivityPresenter(RepositoriesListActivity repositoriesListActivity,
18 | RepositoriesManager repositoriesManager) {
19 | this.repositoriesListActivity = repositoriesListActivity;
20 | this.repositoriesManager = repositoriesManager;
21 | }
22 |
23 | public void loadRepositories() {
24 | repositoriesListActivity.showLoading(true);
25 | repositoriesManager.getUsersRepositories().subscribe(new SimpleObserver>() {
26 | @Override
27 | public void onNext(ImmutableList repositories) {
28 | repositoriesListActivity.showLoading(false);
29 | repositoriesListActivity.setRepositories(repositories);
30 | }
31 |
32 | @Override
33 | public void onError(Throwable e) {
34 | repositoriesListActivity.showLoading(false);
35 | }
36 | });
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/GithubClientApplication.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | import com.frogermcs.androiddevmetrics.AndroidDevMetrics;
7 |
8 | import frogermcs.io.githubclient.data.UserComponent;
9 | import frogermcs.io.githubclient.data.api.UserModule;
10 | import frogermcs.io.githubclient.data.model.User;
11 | import timber.log.Timber;
12 |
13 | /**
14 | * Created by Miroslaw Stanek on 22.04.15.
15 | */
16 | public class GithubClientApplication extends Application {
17 |
18 | private AppComponent appComponent;
19 | private UserComponent userComponent;
20 |
21 | public static GithubClientApplication get(Context context) {
22 | return (GithubClientApplication) context.getApplicationContext();
23 | }
24 |
25 | @Override
26 | public void onCreate() {
27 | super.onCreate();
28 | if (BuildConfig.DEBUG) {
29 | Timber.plant(new Timber.DebugTree());
30 | AndroidDevMetrics.initWith(this);
31 | }
32 |
33 | initAppComponent();
34 | }
35 |
36 | private void initAppComponent() {
37 | appComponent = DaggerAppComponent.builder()
38 | .appModule(new AppModule(this))
39 | .build();
40 | }
41 |
42 | public UserComponent createUserComponent(User user) {
43 | userComponent = appComponent.plus(new UserModule(user));
44 | return userComponent;
45 | }
46 |
47 | public void releaseUserComponent() {
48 | userComponent = null;
49 | }
50 |
51 | public AppComponent getAppComponent() {
52 | return appComponent;
53 | }
54 |
55 | public UserComponent getUserComponent() {
56 | return userComponent;
57 | }
58 |
59 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/HeavyLibraryWrapper.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient;
2 |
3 | import frogermcs.io.githubclient.utils.SimpleObserver;
4 | import rx.Observable;
5 | import rx.Subscriber;
6 | import rx.android.schedulers.AndroidSchedulers;
7 | import rx.observables.ConnectableObservable;
8 | import rx.schedulers.Schedulers;
9 |
10 | /**
11 | * Created by Miroslaw Stanek on 28.09.15.
12 | */
13 | public class HeavyLibraryWrapper {
14 |
15 | private HeavyExternalLibrary heavyExternalLibrary;
16 |
17 | private boolean isInitialized = false;
18 |
19 | ConnectableObservable initObservable;
20 |
21 | public HeavyLibraryWrapper() {
22 | initObservable = Observable.create(new Observable.OnSubscribe() {
23 | @Override
24 | public void call(Subscriber super HeavyExternalLibrary> subscriber) {
25 | HeavyLibraryWrapper.this.heavyExternalLibrary = new HeavyExternalLibrary();
26 | HeavyLibraryWrapper.this.heavyExternalLibrary.init();
27 | subscriber.onNext(heavyExternalLibrary);
28 | subscriber.onCompleted();
29 | }
30 | }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).publish();
31 |
32 | initObservable.subscribe(new SimpleObserver() {
33 | @Override
34 | public void onNext(HeavyExternalLibrary heavyExternalLibrary) {
35 | isInitialized = true;
36 | }
37 | });
38 |
39 | initObservable.connect();
40 | }
41 |
42 | public void callMethod() {
43 | if (isInitialized) {
44 | heavyExternalLibrary.callMethod();
45 | } else {
46 | initObservable.subscribe(new SimpleObserver() {
47 | @Override
48 | public void onNext(HeavyExternalLibrary heavyExternalLibrary) {
49 | heavyExternalLibrary.callMethod();
50 | }
51 | });
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/data/api/GithubApiModule.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.data.api;
2 |
3 | import android.app.Application;
4 |
5 | import java.util.concurrent.TimeUnit;
6 |
7 | import javax.inject.Singleton;
8 |
9 | import dagger.Module;
10 | import dagger.Provides;
11 | import frogermcs.io.githubclient.BuildConfig;
12 | import frogermcs.io.githubclient.R;
13 | import okhttp3.OkHttpClient;
14 | import okhttp3.logging.HttpLoggingInterceptor;
15 | import retrofit2.Retrofit;
16 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
17 | import retrofit2.converter.gson.GsonConverterFactory;
18 |
19 | /**
20 | * Created by Miroslaw Stanek on 22.04.15.
21 | */
22 | @Module
23 | public class GithubApiModule {
24 |
25 | @Provides
26 | @Singleton
27 | public OkHttpClient provideOkHttpClient() {
28 | final OkHttpClient.Builder builder = new OkHttpClient.Builder();
29 |
30 | if (BuildConfig.DEBUG) {
31 | HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
32 | logging.setLevel(HttpLoggingInterceptor.Level.BODY);
33 | builder.addInterceptor(logging);
34 | }
35 |
36 | builder.connectTimeout(60 * 1000, TimeUnit.MILLISECONDS)
37 | .readTimeout(60 * 1000, TimeUnit.MILLISECONDS);
38 |
39 | return builder.build();
40 | }
41 |
42 | @Provides
43 | @Singleton
44 | public Retrofit provideRestAdapter(Application application, OkHttpClient okHttpClient) {
45 | Retrofit.Builder builder = new Retrofit.Builder();
46 | builder.client(okHttpClient)
47 | .baseUrl(application.getString(R.string.endpoint))
48 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
49 | .addConverterFactory(GsonConverterFactory.create());
50 | return builder.build();
51 | }
52 |
53 | @Provides
54 | @Singleton
55 | public GithubApiService provideGithubApiService(Retrofit restAdapter) {
56 | return restAdapter.create(GithubApiService.class);
57 | }
58 |
59 | @Provides
60 | @Singleton
61 | public UserManager provideUserManager(GithubApiService githubApiService) {
62 | return new UserManager(githubApiService);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/data/api/RepositoriesManager.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.data.api;
2 |
3 | import com.google.common.collect.ImmutableList;
4 |
5 | import java.util.List;
6 |
7 | import frogermcs.io.githubclient.data.api.response.RepositoryResponse;
8 | import frogermcs.io.githubclient.data.model.Repository;
9 | import frogermcs.io.githubclient.data.model.User;
10 | import rx.Observable;
11 | import rx.android.schedulers.AndroidSchedulers;
12 | import rx.functions.Func1;
13 | import rx.schedulers.Schedulers;
14 |
15 | /**
16 | * Created by Miroslaw Stanek on 22.04.15.
17 | */
18 | public class RepositoriesManager {
19 | private User user;
20 | private GithubApiService githubApiService;
21 |
22 | public RepositoriesManager(User user, GithubApiService githubApiService) {
23 | this.user = user;
24 | this.githubApiService = githubApiService;
25 | }
26 |
27 | public Observable> getUsersRepositories() {
28 | return githubApiService.getUsersRepositories(user.login)
29 | .map(new Func1, ImmutableList>() {
30 | @Override
31 | public ImmutableList call(List repositoriesListResponse) {
32 | final ImmutableList.Builder listBuilder = ImmutableList.builder();
33 | for (RepositoryResponse repositoryResponse : repositoriesListResponse) {
34 | Repository repository = new Repository();
35 | repository.id = repositoryResponse.id;
36 | repository.name = repositoryResponse.name;
37 | repository.url = repositoryResponse.url;
38 | repository.stargazers_count = repositoryResponse.stargazers_count;
39 | repository.forks_count = repositoryResponse.forks_count;
40 | listBuilder.add(repository);
41 | }
42 | return listBuilder.build();
43 | }
44 | })
45 | .subscribeOn(Schedulers.io())
46 | .observeOn(AndroidSchedulers.mainThread());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/presenter/SplashActivityPresenter.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity.presenter;
2 |
3 | import frogermcs.io.githubclient.HeavyLibraryWrapper;
4 | import frogermcs.io.githubclient.data.api.UserManager;
5 | import frogermcs.io.githubclient.data.model.User;
6 | import frogermcs.io.githubclient.ui.activity.SplashActivity;
7 | import frogermcs.io.githubclient.utils.SimpleObserver;
8 | import frogermcs.io.githubclient.utils.Validator;
9 |
10 | /**
11 | * Created by Miroslaw Stanek on 23.04.15.
12 | */
13 | public class SplashActivityPresenter {
14 | public String username;
15 |
16 | private SplashActivity splashActivity;
17 | private Validator validator;
18 | private UserManager userManager;
19 | private HeavyLibraryWrapper heavyLibraryWrapper;
20 |
21 | public SplashActivityPresenter(SplashActivity splashActivity, Validator validator,
22 | UserManager userManager, HeavyLibraryWrapper heavyLibraryWrapper) {
23 | this.splashActivity = splashActivity;
24 | this.validator = validator;
25 | this.userManager = userManager;
26 | this.heavyLibraryWrapper = heavyLibraryWrapper;
27 |
28 | //This calls should be delivered to ExternalLibrary right after it will be initialized
29 | this.heavyLibraryWrapper.callMethod();
30 | this.heavyLibraryWrapper.callMethod();
31 | this.heavyLibraryWrapper.callMethod();
32 | this.heavyLibraryWrapper.callMethod();
33 | }
34 |
35 | public void onShowRepositoriesClick() {
36 | if (validator.validUsername(username)) {
37 | splashActivity.showLoading(true);
38 | userManager.getUser(username).subscribe(new SimpleObserver() {
39 | @Override
40 | public void onNext(User user) {
41 | splashActivity.showLoading(false);
42 | splashActivity.showRepositoriesListForUser(user);
43 | }
44 |
45 | @Override
46 | public void onError(Throwable e) {
47 | splashActivity.showLoading(false);
48 | splashActivity.showValidationError();
49 | }
50 | });
51 | } else {
52 | splashActivity.showValidationError();
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/test/java/frogermcs/io/githubclient/ui/activity/SplashActivityTests.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.mockito.Mock;
7 | import org.mockito.MockitoAnnotations;
8 | import org.mockito.invocation.InvocationOnMock;
9 | import org.mockito.stubbing.Answer;
10 | import org.robolectric.Robolectric;
11 | import org.robolectric.RobolectricTestRunner;
12 | import org.robolectric.RuntimeEnvironment;
13 | import org.robolectric.annotation.Config;
14 |
15 | import frogermcs.io.githubclient.BuildConfig;
16 | import frogermcs.io.githubclient.TestGithubClientApplication;
17 | import frogermcs.io.githubclient.ui.activity.component.SplashActivityComponent;
18 | import frogermcs.io.githubclient.utils.AnalyticsManager;
19 |
20 | import static org.mockito.Matchers.any;
21 | import static org.mockito.Matchers.anyString;
22 | import static org.mockito.Mockito.doAnswer;
23 | import static org.mockito.Mockito.verify;
24 |
25 | /**
26 | * Created by Miroslaw Stanek on 19.09.15.
27 | */
28 | @RunWith(RobolectricTestRunner.class)
29 | @Config(
30 | sdk = 18,
31 | constants = BuildConfig.class,
32 | application = TestGithubClientApplication.class
33 | )
34 | public class SplashActivityTests {
35 |
36 | @Mock
37 | SplashActivityComponent splashActivityComponentMock;
38 | @Mock
39 | AnalyticsManager analyticsManagerMock;
40 |
41 | @Before
42 | public void setup() {
43 | MockitoAnnotations.initMocks(this);
44 |
45 | doAnswer(new Answer() {
46 | @Override
47 | public Object answer(InvocationOnMock invocation) {
48 | SplashActivity activity = (SplashActivity) invocation.getArguments()[0];
49 | activity.analyticsManager = analyticsManagerMock;
50 | return null;
51 | }
52 | }).when(splashActivityComponentMock).inject(any(SplashActivity.class));
53 |
54 | TestGithubClientApplication app = (TestGithubClientApplication) RuntimeEnvironment.application;
55 | app.setSplashActivityComponent(splashActivityComponentMock);
56 | }
57 |
58 | @Test
59 | public void testName() throws Exception {
60 | SplashActivity activity = Robolectric.setupActivity(SplashActivity.class);
61 | verify(activity.analyticsManager).logScreenView(anyString());
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/RepositoryDetailsActivity.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.widget.TextView;
7 |
8 | import javax.inject.Inject;
9 |
10 | import butterknife.BindView;
11 | import butterknife.ButterKnife;
12 | import frogermcs.io.githubclient.GithubClientApplication;
13 | import frogermcs.io.githubclient.R;
14 | import frogermcs.io.githubclient.data.model.Repository;
15 | import frogermcs.io.githubclient.ui.activity.module.RepositoryDetailsActivityModule;
16 | import frogermcs.io.githubclient.ui.activity.presenter.RepositoryDetailsActivityPresenter;
17 | import frogermcs.io.githubclient.utils.AnalyticsManager;
18 |
19 |
20 | public class RepositoryDetailsActivity extends BaseActivity {
21 | private static final String ARG_REPOSITORY = "arg_repository";
22 |
23 | @BindView(R.id.tvRepoName)
24 | TextView tvRepoName;
25 | @BindView(R.id.tvRepoDetails)
26 | TextView tvRepoDetails;
27 | @BindView(R.id.tvUserName)
28 | TextView tvUserName;
29 |
30 | @Inject
31 | AnalyticsManager analyticsManager;
32 | @Inject
33 | RepositoryDetailsActivityPresenter presenter;
34 |
35 | private Repository repository;
36 |
37 | public static void startWithRepository(Repository repository, Activity startingActivity) {
38 | Intent intent = new Intent(startingActivity, RepositoryDetailsActivity.class);
39 | intent.putExtra(ARG_REPOSITORY, repository);
40 | startingActivity.startActivity(intent);
41 | }
42 |
43 | @Override
44 | protected void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | setContentView(R.layout.activity_repository_details);
47 | ButterKnife.bind(this);
48 | analyticsManager.logScreenView(getClass().getName());
49 |
50 | repository = getIntent().getParcelableExtra(ARG_REPOSITORY);
51 | tvRepoName.setText(repository.name);
52 | tvRepoDetails.setText(repository.url);
53 |
54 | presenter.init();
55 | }
56 |
57 | @Override
58 | protected void setupActivityComponent() {
59 | GithubClientApplication.get(this).getUserComponent()
60 | .plus(new RepositoryDetailsActivityModule(this))
61 | .inject(this);
62 |
63 | }
64 |
65 | public void setupUserName(String userName) {
66 | tvUserName.setText(userName);
67 | }
68 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/RepositoriesListActivity.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.View;
7 | import android.widget.ProgressBar;
8 |
9 | import com.google.common.collect.ImmutableList;
10 |
11 | import javax.inject.Inject;
12 |
13 | import butterknife.BindView;
14 | import butterknife.ButterKnife;
15 | import frogermcs.io.githubclient.GithubClientApplication;
16 | import frogermcs.io.githubclient.R;
17 | import frogermcs.io.githubclient.data.model.Repository;
18 | import frogermcs.io.githubclient.ui.activity.module.RepositoriesListActivityModule;
19 | import frogermcs.io.githubclient.ui.activity.presenter.RepositoriesListActivityPresenter;
20 | import frogermcs.io.githubclient.ui.adapter.RepositoriesListAdapter;
21 |
22 |
23 | public class RepositoriesListActivity extends BaseActivity {
24 | @BindView(R.id.rvRepositories)
25 | RecyclerView rvRepositories;
26 | @BindView(R.id.pbLoading)
27 | ProgressBar pbLoading;
28 |
29 | @Inject
30 | RepositoriesListActivityPresenter presenter;
31 | @Inject
32 | RepositoriesListAdapter repositoriesListAdapter;
33 | @Inject
34 | LinearLayoutManager linearLayoutManager;
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.activity_repositories_list);
40 | ButterKnife.bind(this);
41 | setupRepositoriesListView();
42 | presenter.loadRepositories();
43 | }
44 |
45 | private void setupRepositoriesListView() {
46 | rvRepositories.setAdapter(repositoriesListAdapter);
47 | rvRepositories.setLayoutManager(linearLayoutManager);
48 | }
49 |
50 | @Override
51 | protected void setupActivityComponent() {
52 | GithubClientApplication.get(this).getUserComponent()
53 | .plus(new RepositoriesListActivityModule(this))
54 | .inject(this);
55 | }
56 |
57 | public void showLoading(boolean loading) {
58 | rvRepositories.setVisibility(loading ? View.GONE : View.VISIBLE);
59 | pbLoading.setVisibility(loading ? View.VISIBLE : View.GONE);
60 | }
61 |
62 | public void setRepositories(ImmutableList repositories) {
63 | repositoriesListAdapter.updateRepositoriesList(repositories);
64 | }
65 |
66 | public void onRepositoryClick(Repository repository) {
67 | RepositoryDetailsActivity.startWithRepository(repository, this);
68 | }
69 |
70 | @Override
71 | public void finish() {
72 | super.finish();
73 | GithubClientApplication.get(this).releaseUserComponent();
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/adapter/RepositoriesListAdapter.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.adapter;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | import frogermcs.io.githubclient.data.model.Repository;
12 | import frogermcs.io.githubclient.ui.activity.RepositoriesListActivity;
13 | import frogermcs.io.githubclient.ui.adapter.viewholder.RepositoriesListViewHolderFactory;
14 | import frogermcs.io.githubclient.ui.adapter.viewholder.RepositoryViewHolder;
15 |
16 | /**
17 | * Created by Miroslaw Stanek on 24.04.15.
18 | */
19 | public class RepositoriesListAdapter extends RecyclerView.Adapter {
20 |
21 | private RepositoriesListActivity repositoriesListActivity;
22 | private Map viewHolderFactories;
23 |
24 | private final List repositories = new ArrayList<>();
25 |
26 | public RepositoriesListAdapter(RepositoriesListActivity repositoriesListActivity,
27 | Map viewHolderFactories) {
28 | this.repositoriesListActivity = repositoriesListActivity;
29 | this.viewHolderFactories = viewHolderFactories;
30 | }
31 |
32 | @Override
33 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
34 | final RecyclerView.ViewHolder viewHolder = viewHolderFactories.get(viewType).createViewHolder(parent);
35 | viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View v) {
38 | onRepositoryItemClicked(viewHolder.getAdapterPosition());
39 | }
40 | });
41 | return viewHolder;
42 | }
43 |
44 | private void onRepositoryItemClicked(int adapterPosition) {
45 | repositoriesListActivity.onRepositoryClick(repositories.get(adapterPosition));
46 | }
47 |
48 | @Override
49 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
50 | ((RepositoryViewHolder) holder).bind(repositories.get(position));
51 | }
52 |
53 | @Override
54 | public int getItemCount() {
55 | return repositories.size();
56 | }
57 |
58 | @Override
59 | public int getItemViewType(int position) {
60 | Repository repository = repositories.get(position);
61 | if (repository.stargazers_count > 500) {
62 | if (repository.forks_count > 100) {
63 | return Repository.TYPE_FEATURED;
64 | }
65 | return Repository.TYPE_BIG;
66 | }
67 | return Repository.TYPE_NORMAL;
68 | }
69 |
70 | public void updateRepositoriesList(List repositories) {
71 | this.repositories.clear();
72 | this.repositories.addAll(repositories);
73 | notifyDataSetChanged();
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.frogermcs.androiddevmetrics'
3 |
4 | android {
5 | compileSdkVersion 28
6 | useLibrary 'org.apache.http.legacy'
7 |
8 | defaultConfig {
9 | applicationId "frogermcs.io.githubclient"
10 | minSdkVersion 15
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner 'frogermcs.io.githubclient.MyTestRunner'
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | lintOptions {
24 | warning 'InvalidPackage'
25 | }
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 | implementation 'com.android.support:support-compat:28.0.0'
31 | implementation 'com.android.support:appcompat-v7:28.0.0'
32 | implementation 'com.android.support:recyclerview-v7:28.0.0'
33 |
34 | //Dagger 2
35 | implementation 'com.google.dagger:dagger:2.14.1'
36 | implementation 'com.google.dagger:dagger-producers:2.14.1'
37 | annotationProcessor 'com.google.dagger:dagger-compiler:2.14.1'
38 | provided 'org.glassfish:javax.annotation:10.0-b28'
39 | implementation 'com.google.auto.factory:auto-factory:1.0-beta3'
40 | annotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta3'
41 |
42 | implementation 'com.jakewharton:butterknife:8.8.1'
43 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
44 | implementation 'com.jakewharton.timber:timber:4.3.1'
45 | implementation 'io.reactivex:rxandroid:1.2.1'
46 | implementation 'io.reactivex:rxjava:1.2.1'
47 | implementation 'com.jakewharton.rxbinding:rxbinding:0.4.0'
48 | implementation 'com.squareup.retrofit2:retrofit:2.1.0'
49 | implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
50 | implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
51 | implementation 'com.squareup.okhttp3:okhttp:3.4.1'
52 | implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
53 | implementation 'com.google.guava:guava:23.4-android'
54 | implementation 'com.google.code.findbugs:jsr305:2.0.1'
55 |
56 | testImplementation "org.robolectric:robolectric:3.1.2"
57 | testImplementation "org.mockito:mockito-core:1.10.19"
58 | testImplementation 'junit:junit:4.12'
59 |
60 | androidTestImplementation 'com.android.support:support-annotations:25.0.0'
61 | androidTestImplementation 'com.squareup:javawriter:2.5.1'
62 |
63 | androidTestImplementation 'junit:junit:4.12'
64 | androidTestImplementation 'com.android.support.test:runner:0.5'
65 | androidTestImplementation 'com.android.support.test:rules:0.5'
66 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
67 | androidTestImplementation "org.mockito:mockito-core:1.10.19"
68 | androidTestImplementation "com.google.dexmaker:dexmaker:1.2"
69 | androidTestImplementation "com.google.dexmaker:dexmaker-mockito:1.2"
70 | testAnnotationProcessor "com.google.auto.factory:auto-factory:1.0-beta3"
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/module/RepositoriesListActivityModule.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity.module;
2 |
3 | import android.support.v7.widget.LinearLayoutManager;
4 |
5 | import java.util.Map;
6 |
7 | import dagger.Module;
8 | import dagger.Provides;
9 | import dagger.multibindings.IntKey;
10 | import dagger.multibindings.IntoMap;
11 | import frogermcs.io.githubclient.data.api.RepositoriesManager;
12 | import frogermcs.io.githubclient.data.model.Repository;
13 | import frogermcs.io.githubclient.ui.activity.ActivityScope;
14 | import frogermcs.io.githubclient.ui.activity.RepositoriesListActivity;
15 | import frogermcs.io.githubclient.ui.activity.presenter.RepositoriesListActivityPresenter;
16 | import frogermcs.io.githubclient.ui.adapter.RepositoriesListAdapter;
17 | import frogermcs.io.githubclient.ui.adapter.viewholder.RepositoriesListViewHolderFactory;
18 | import frogermcs.io.githubclient.ui.adapter.viewholder.RepositoryViewHolderBigFactory;
19 | import frogermcs.io.githubclient.ui.adapter.viewholder.RepositoryViewHolderFeaturedFactory;
20 | import frogermcs.io.githubclient.ui.adapter.viewholder.RepositoryViewHolderNormalFactory;
21 |
22 | /**
23 | * Created by Miroslaw Stanek on 23.04.15.
24 | */
25 | @Module
26 | public class RepositoriesListActivityModule {
27 | private RepositoriesListActivity repositoriesListActivity;
28 |
29 | public RepositoriesListActivityModule(RepositoriesListActivity repositoriesListActivity) {
30 | this.repositoriesListActivity = repositoriesListActivity;
31 | }
32 |
33 | @Provides
34 | @ActivityScope
35 | RepositoriesListActivity provideRepositoriesListActivity() {
36 | return repositoriesListActivity;
37 | }
38 |
39 | @Provides
40 | @ActivityScope
41 | RepositoriesListActivityPresenter provideRepositoriesListActivityPresenter(RepositoriesManager repositoriesManager) {
42 | return new RepositoriesListActivityPresenter(repositoriesListActivity, repositoriesManager);
43 | }
44 |
45 | @Provides
46 | @ActivityScope
47 | RepositoriesListAdapter provideRepositoriesListAdapter(RepositoriesListActivity repositoriesListActivity,
48 | Map viewHolderFactories) {
49 | return new RepositoriesListAdapter(repositoriesListActivity, viewHolderFactories);
50 | }
51 |
52 | @Provides
53 | @ActivityScope
54 | LinearLayoutManager provideLinearLayoutManager(RepositoriesListActivity repositoriesListActivity) {
55 | return new LinearLayoutManager(repositoriesListActivity);
56 | }
57 |
58 | @Provides
59 | @IntoMap
60 | @IntKey(Repository.TYPE_NORMAL)
61 | RepositoriesListViewHolderFactory provideViewHolderNormal() {
62 | return new RepositoryViewHolderNormalFactory();
63 | }
64 |
65 | @Provides
66 | @IntoMap
67 | @IntKey(Repository.TYPE_BIG)
68 | RepositoriesListViewHolderFactory provideViewHolderBig() {
69 | return new RepositoryViewHolderBigFactory();
70 | }
71 |
72 | @Provides
73 | @IntoMap
74 | @IntKey(Repository.TYPE_FEATURED)
75 | RepositoriesListViewHolderFactory provideViewHolderFeatured() {
76 | return new RepositoryViewHolderFeaturedFactory();
77 | }
78 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/frogermcs/io/githubclient/tests/SplashActivityUITests.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.tests;
2 |
3 | import android.content.Intent;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.espresso.matcher.ViewMatchers;
6 | import android.support.test.rule.ActivityTestRule;
7 | import android.support.test.runner.AndroidJUnit4;
8 |
9 | import org.junit.Before;
10 | import org.junit.Rule;
11 | import org.junit.Test;
12 | import org.junit.runner.RunWith;
13 | import org.mockito.Mock;
14 | import org.mockito.Mockito;
15 | import org.mockito.MockitoAnnotations;
16 |
17 | import frogermcs.io.githubclient.R;
18 | import frogermcs.io.githubclient.data.api.UserManager;
19 | import frogermcs.io.githubclient.data.model.User;
20 | import frogermcs.io.githubclient.inject.ApplicationMock;
21 | import frogermcs.io.githubclient.inject.GithubApiModuleMock;
22 | import frogermcs.io.githubclient.ui.activity.SplashActivity;
23 | import rx.Observable;
24 |
25 | import static android.support.test.espresso.Espresso.onView;
26 | import static android.support.test.espresso.action.ViewActions.click;
27 | import static android.support.test.espresso.action.ViewActions.typeText;
28 | import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
29 | import static android.support.test.espresso.assertion.ViewAssertions.matches;
30 | import static android.support.test.espresso.matcher.ViewMatchers.hasErrorText;
31 | import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
32 | import static android.support.test.espresso.matcher.ViewMatchers.withId;
33 | import static org.hamcrest.Matchers.not;
34 | import static org.mockito.Matchers.anyString;
35 |
36 | /**
37 | * Created by Miroslaw Stanek on 23.09.15.
38 | */
39 | @RunWith(AndroidJUnit4.class)
40 | public class SplashActivityUITests {
41 |
42 | @Mock
43 | UserManager userManagerMock;
44 |
45 | @Rule
46 | public ActivityTestRule activityRule = new ActivityTestRule<>(
47 | SplashActivity.class, true, false
48 | );
49 |
50 | @Before
51 | public void setUp() {
52 | MockitoAnnotations.initMocks(this);
53 | GithubApiModuleMock githubApiModuleMock = new GithubApiModuleMock(userManagerMock);
54 | ApplicationMock app = (ApplicationMock) InstrumentationRegistry.getTargetContext().getApplicationContext();
55 | app.setGithubApiModuleMock(githubApiModuleMock);
56 | activityRule.launchActivity(new Intent());
57 | }
58 |
59 | @Test
60 | public void checkLoadingError() {
61 | Mockito.when(userManagerMock.getUser(anyString()))
62 | .thenReturn(Observable.error(new RuntimeException("test")));
63 |
64 | onView(withId(R.id.etUsername)).perform(typeText("frogermcs"));
65 | onView(withId(R.id.btnShowRepositories)).perform(click());
66 |
67 | onView(withId(R.id.etUsername)).check(matches(hasErrorText("Validation error")));
68 | }
69 |
70 | @Test
71 | public void checkLoadingSuccess() {
72 | User user = new User();
73 | user.id = 1;
74 | user.email = "abc@gmail.com";
75 | user.login = "frogermcs";
76 | user.url = null;
77 |
78 | Mockito.when(userManagerMock.getUser(anyString())).thenReturn(Observable.just(user));
79 |
80 | onView(withId(R.id.pbLoading)).check(matches(not(isDisplayed())));
81 |
82 | onView(withId(R.id.etUsername)).perform(typeText("frogermcs"));
83 | onView(withId(R.id.btnShowRepositories)).perform(click());
84 |
85 | onView(withId(R.id.btnShowRepositories)).check(doesNotExist());
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/java/frogermcs/io/githubclient/ui/activity/SplashActivity.java:
--------------------------------------------------------------------------------
1 | package frogermcs.io.githubclient.ui.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.os.Debug;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.EditText;
9 | import android.widget.ProgressBar;
10 |
11 | import com.jakewharton.rxbinding.widget.RxTextView;
12 | import com.jakewharton.rxbinding.widget.TextViewTextChangeEvent;
13 |
14 | import javax.inject.Inject;
15 |
16 | import butterknife.BindView;
17 | import butterknife.ButterKnife;
18 | import butterknife.OnClick;
19 | import frogermcs.io.githubclient.GithubClientApplication;
20 | import frogermcs.io.githubclient.R;
21 | import frogermcs.io.githubclient.data.model.User;
22 | import frogermcs.io.githubclient.ui.activity.module.SplashActivityModule;
23 | import frogermcs.io.githubclient.ui.activity.presenter.SplashActivityPresenter;
24 | import frogermcs.io.githubclient.utils.AnalyticsManager;
25 | import rx.Subscription;
26 | import rx.functions.Action1;
27 |
28 |
29 | public class SplashActivity extends BaseActivity {
30 |
31 | @BindView(R.id.etUsername)
32 | EditText etUsername;
33 | @BindView(R.id.pbLoading)
34 | ProgressBar pbLoading;
35 | @BindView(R.id.btnShowRepositories)
36 | Button btnShowRepositories;
37 |
38 | //These references will be satisfied by 'SplashActivityComponent.inject(this)' method
39 | @Inject
40 | SplashActivityPresenter presenter;
41 | @Inject
42 | AnalyticsManager analyticsManager;
43 |
44 | private Subscription textChangeSubscription;
45 |
46 | @Override
47 | protected void onCreate(Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | setContentView(R.layout.activity_splash);
50 | ButterKnife.bind(this);
51 |
52 | analyticsManager.logScreenView(getClass().getName());
53 |
54 | textChangeSubscription = RxTextView.textChangeEvents(etUsername).subscribe(new Action1() {
55 | @Override
56 | public void call(TextViewTextChangeEvent textViewTextChangeEvent) {
57 | presenter.username = textViewTextChangeEvent.text().toString();
58 | etUsername.setError(null);
59 | }
60 | });
61 | }
62 |
63 | @Override
64 | protected void onDestroy() {
65 | super.onDestroy();
66 | textChangeSubscription.unsubscribe();
67 | }
68 |
69 | //Local dependencies graph is constructed here
70 | @Override
71 | protected void setupActivityComponent() {
72 | //Uncomment those lines do measure dependencies creation time
73 | //Debug.startMethodTracing("SplashTrace");
74 | GithubClientApplication.get(this)
75 | .getAppComponent()
76 | .plus(new SplashActivityModule(this))
77 | .inject(this);
78 | //Debug.stopMethodTracing();
79 | }
80 |
81 | @OnClick(R.id.btnShowRepositories)
82 | public void onShowRepositoriesClick() {
83 | presenter.onShowRepositoriesClick();
84 | }
85 |
86 | public void showRepositoriesListForUser(User user) {
87 | GithubClientApplication.get(this).createUserComponent(user);
88 | startActivity(new Intent(this, RepositoriesListActivity.class));
89 | }
90 |
91 | public void showValidationError() {
92 | etUsername.setError("Validation error");
93 | }
94 |
95 | public void showLoading(boolean loading) {
96 | btnShowRepositories.setVisibility(loading ? View.GONE : View.VISIBLE);
97 | pbLoading.setVisibility(loading ? View.VISIBLE : View.GONE);
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------