Skip to content

Commit

Permalink
adding a sample without dagger.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejchm committed Jul 10, 2016
1 parent 43abffa commit 608cea0
Show file tree
Hide file tree
Showing 58 changed files with 1,639 additions and 132 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ This library makes it easy to use it with dependency injection frameworks like [

##Sample Project
A small android app which uses Dependency Injection along with **DroidMVP** can be found
[**here**](/sample)
[**here**](/sample-dagger), and one without dagger can be found [**here**](/sample).

86 changes: 86 additions & 0 deletions sample-dagger/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (C) 2016 Appflate.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

buildscript {
repositories {
mavenCentral()
jcenter()
}

dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply from: '../quality_tools/findbugs.gradle'

android {
compileSdkVersion 24
buildToolsVersion "24"

defaultConfig {
applicationId "io.appflate.droidmvp.androidsample"
minSdkVersion 10
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner 'io.appflate.droidmvp.androidsample.CustomTestRunner'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

lintOptions {
warningsAsErrors true
abortOnError true
disable 'InvalidPackage'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.google.dagger:dagger:2.2'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.code.findbugs:annotations:2.0.3'
provided 'javax.annotation:jsr250-api:1.0'
apt 'com.google.dagger:dagger-compiler:2.2'

//the most important: DroidMVP :)
compile project(':library')

//Test dependencies

testCompile 'com.android.support:appcompat-v7:24.0.0'
testCompile 'com.android.support:design:24.0.0'
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.0"
testCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
testCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}
}
17 changes: 17 additions & 0 deletions sample-dagger/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/andrzejchm/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http:https://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
43 changes: 43 additions & 0 deletions sample-dagger/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2016 Appflate.io
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http:https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:tools="http:https://schemas.android.com/tools"
package="io.appflate.droidvmp.androidsample">

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

<application
android:name="io.appflate.droidvmp.androidsample.SampleApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name="io.appflate.droidvmp.androidsample.ui.activities.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name="io.appflate.droidvmp.androidsample.ui.activities.RepositoriesActivity">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2016 Appflate.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appflate.droidvmp.androidsample;

import android.app.Application;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.appflate.droidvmp.androidsample.di.AppComponent;
import io.appflate.droidvmp.androidsample.di.AppModule;
import io.appflate.droidvmp.androidsample.di.DaggerAppComponent;

/**
* Created by andrzejchm on 22/04/16.
*/
public class SampleApplication extends Application {
private static final String BASE_URL = "https://api.github.com/";
static AppComponent appComponent;

@Override public void onCreate() {
super.onCreate();
setupGraph();
}

@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") protected void setupGraph() {
appComponent = DaggerAppComponent.builder().appModule(new AppModule(BASE_URL)).build();
}

public static AppComponent getComponent() {
return appComponent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@

package io.appflate.droidvmp.androidsample.di;

import io.appflate.droidvmp.androidsample.ui.fragments.RepositoriesFragment;
import javax.inject.Singleton;

import dagger.Component;
import io.appflate.droidvmp.androidsample.domain.GithubApi;
import io.appflate.droidvmp.androidsample.ui.activities.MainActivity;
import io.appflate.droidvmp.androidsample.ui.activities.RepositoriesActivity;
import io.appflate.droidvmp.androidsample.domain.GithubApi;
import io.appflate.droidvmp.androidsample.ui.fragments.RepositoriesFragment;
import javax.inject.Singleton;

/**
* Created by andrzejchm on 23/04/16.
*/
@Singleton
@Component(modules = { AppModule.class})
public interface AppComponent {
@Singleton @Component(modules = { AppModule.class }) public interface AppComponent {
GithubApi getRestService();

void inject(MainActivity mainActivity);

void inject(RepositoriesActivity repositoriesActivity);

void inject(RepositoriesFragment repositoriesFragment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@
/**
* Created by andrzejchm on 23/04/16.
*/
@Module
public class AppModule {
@Module public class AppModule {

private String baseUrl;

public AppModule(String baseUrl) {
this.baseUrl = baseUrl;
}

@Provides
GithubApi provideRestService() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
@Provides GithubApi provideRestService() {
Retrofit retrofit = new Retrofit.Builder().baseUrl(baseUrl)
.addConverterFactory(
GsonConverterFactory.create())
.build();

GithubApi githubApi = retrofit.create(GithubApi.class);
return githubApi;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2016 Appflate.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appflate.droidvmp.androidsample.domain;

import io.appflate.droidvmp.androidsample.model.Repository;
import io.appflate.droidvmp.androidsample.model.User;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;

/**
* Created by andrzejchm on 22/04/16.
*/
public interface GithubApi {

@GET("users/{username}") Call<User> getUserProfile(@Path("username") String username);

@GET("users/{username}/repos") Call<List<Repository>> getUserRepositories(
@Path("username") String username);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2016 Appflate.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appflate.droidvmp.androidsample.model;

import com.google.gson.annotations.SerializedName;
import java.io.Serializable;

/**
* Created by andrzejchm on 23/04/16.
*/
public class Owner implements Serializable {
@SerializedName("login") public String login;
@SerializedName("id") public int id;
@SerializedName("avatar_url") public String avatarUrl;
@SerializedName("gravatar_id") public String gravatarId;
@SerializedName("url") public String url;
@SerializedName("html_url") public String htmlUrl;
@SerializedName("followers_url") public String followersUrl;
@SerializedName("following_url") public String followingUrl;
@SerializedName("gists_url") public String gistsUrl;
@SerializedName("starred_url") public String starredUrl;
@SerializedName("subscriptions_url") public String subscriptionsUrl;
@SerializedName("organizations_url") public String organizationsUrl;
@SerializedName("repos_url") public String reposUrl;
@SerializedName("events_url") public String eventsUrl;
@SerializedName("received_events_url") public String receivedEventsUrl;
@SerializedName("type") public String type;
@SerializedName("site_admin") public boolean siteAdmin;
}
Loading

0 comments on commit 608cea0

Please sign in to comment.