Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:0.13.3'
classpath 'com.jakewharton.hugo:hugo-plugin:1.1.0'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}

Expand All @@ -18,23 +19,27 @@ def versionBuild = 0 // bump for dogfood builds, public betas, etc.
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
apply plugin: 'hugo'
apply plugin: 'com.neenbedankt.android-apt'

repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
mavenLocal()
}

dependencies {
compile 'com.android.support:support-v4:21.0.0'

compile 'com.squareup.dagger:dagger:1.2.1'
provided 'com.squareup.dagger:dagger-compiler:1.2.1'
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
provided 'org.glassfish:javax.annotation:10.0-b28'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this requirement documented anywhere on the Dagger project?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add it. It's only for Java 6 users which Android falls under :(
On Nov 11, 2014 2:18 AM, "Prateek Srivastava" notifications@github.com
wrote:

In build.gradle:

}

dependencies {
compile 'com.android.support:support-v4:21.0.0'

  • compile 'com.squareup.dagger:dagger:1.2.1'
  • provided 'com.squareup.dagger:dagger-compiler:1.2.1'
  • compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
  • apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
  • provided 'org.glassfish:javax.annotation:10.0-b28'

Is this requirement documented anywhere on the Dagger project?


Reply to this email directly or view it on GitHub
https://github.com/JakeWharton/u2020/pull/42/files#r20126702.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we also should add gradle instructions in general, and android
specific instructions, but that should go in an issue on the dagger project.

On Tue Nov 11 2014 at 8:45:54 AM Jake Wharton notifications@github.com
wrote:

In build.gradle:

}

dependencies {
compile 'com.android.support:support-v4:21.0.0'

  • compile 'com.squareup.dagger:dagger:1.2.1'
  • provided 'com.squareup.dagger:dagger-compiler:1.2.1'
  • compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
  • apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
  • provided 'org.glassfish:javax.annotation:10.0-b28'

We can add it. It's only for Java 6 users which Android falls under :(
… <#msg-f:1484580130404185026_msg-f:1484460606908654908_>
On Nov 11, 2014 2:18 AM, "Prateek Srivastava" notifications@github.com
wrote: In build.gradle: > } > > dependencies { > compile
'com.android.support:support-v4:21.0.0' > > - compile
'com.squareup.dagger:dagger:1.2.1' > - provided
'com.squareup.dagger:dagger-compiler:1.2.1' > + compile
'com.google.dagger:dagger:2.0-SNAPSHOT' > + apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'


Reply to this email directly or view it on GitHub
https://github.com/JakeWharton/u2020/pull/42/files#r20135730.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better/cleaner/more elegant to use 'javax.annotation:javax.annotation-api:1.2'? The org.glassfish group and the weird version number don't feel good, but maybe it's just me.


compile 'com.squareup.okhttp:okhttp:1.3.0'
compile 'com.squareup.picasso:picasso:2.2.0'
compile 'com.squareup.retrofit:retrofit:1.4.1'
debugCompile 'com.squareup.retrofit:retrofit-mock:1.4.1'

compile 'com.jakewharton:butterknife:4.0.1'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.jakewharton.timber:timber:2.2.2'
debugCompile 'com.jakewharton.madge:madge:1.1.1'
debugCompile 'com.jakewharton.scalpel:scalpel:1.1.1'
Expand Down
16 changes: 0 additions & 16 deletions src/debug/java/com/jakewharton/u2020/DebugU2020Module.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/debug/java/com/jakewharton/u2020/Modules.java

This file was deleted.

26 changes: 26 additions & 0 deletions src/debug/java/com/jakewharton/u2020/U2020Component.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.jakewharton.u2020;

import com.jakewharton.u2020.data.DebugDataModule;
import com.jakewharton.u2020.ui.DebugUiModule;

import dagger.Component;
import javax.inject.Singleton;

/**
* The core debug component for u2020 applications
*/
@Singleton
@Component(modules = { U2020AppModule.class, DebugUiModule.class, DebugDataModule.class })
public interface U2020Component extends U2020Graph {
/**
* An initializer that creates the graph from an application.
*/
final static class Initializer {
static U2020Graph init(U2020App app) {
return Dagger_U2020Component.builder()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be updated with the new naming convention DaggerU2020Component

.u2020AppModule(new U2020AppModule(app))
.build();
}
private Initializer() {} // No instances.
}
}
10 changes: 3 additions & 7 deletions src/debug/java/com/jakewharton/u2020/data/DebugDataModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
import javax.net.ssl.X509TrustManager;
import retrofit.MockRestAdapter;

@Module(
includes = DebugApiModule.class,
complete = false,
library = true,
overrides = true
)
@Module(includes = { DataModule.class, DebugApiModule.class })
public final class DebugDataModule {
private static final int DEFAULT_ANIMATION_SPEED = 1; // 1x (normal) speed.
private static final boolean DEFAULT_PICASSO_DEBUGGING = false; // Debug indicators displayed
Expand Down Expand Up @@ -93,7 +88,8 @@ BooleanPreference provideScalpelWireframeEnabled(SharedPreferences preferences)
DEFAULT_SCALPEL_WIREFRAME_ENABLED);
}

@Provides @Singleton Picasso providePicasso(OkHttpClient client, MockRestAdapter mockRestAdapter,
@Provides @Singleton Picasso providePicasso(
OkHttpClient client, MockRestAdapter mockRestAdapter,
@IsMockMode boolean isMockMode, Application app) {
Picasso.Builder builder = new Picasso.Builder(app);
if (isMockMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
import retrofit.RestAdapter;
import retrofit.android.AndroidMockValuePersistence;

@Module(
complete = false,
library = true,
overrides = true
)
@Module(includes = ApiModule.class)
public final class DebugApiModule {

@Provides @Singleton
Expand Down
7 changes: 1 addition & 6 deletions src/debug/java/com/jakewharton/u2020/ui/DebugUiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
import dagger.Provides;
import javax.inject.Singleton;

@Module(
injects = DebugAppContainer.class,
complete = false,
library = true,
overrides = true
)
@Module
public class DebugUiModule {
@Provides @Singleton AppContainer provideAppContainer(DebugAppContainer debugAppContainer) {
return debugAppContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public class DebugAppContainer implements AppContainer {
}

@InjectView(R.id.debug_drawer_layout) DrawerLayout drawerLayout;
@InjectView(R.id.debug_content) ViewGroup content;

@InjectView(R.id.madge_container) MadgeFrameLayout madgeFrameLayout;
@InjectView(R.id.debug_content) ScalpelFrameLayout scalpelFrameLayout;
Expand Down Expand Up @@ -188,7 +187,8 @@ public class DebugAppContainer implements AppContainer {
// Set up the contextual actions to watch views coming in and out of the content area.
Set<ContextualDebugActions.DebugAction<?>> debugActions = Collections.emptySet();
ContextualDebugActions contextualActions = new ContextualDebugActions(this, debugActions);
content.setOnHierarchyChangeListener(HierarchyTreeChangeListener.wrap(contextualActions));
scalpelFrameLayout.setOnHierarchyChangeListener(
HierarchyTreeChangeListener.wrap(contextualActions));

drawerLayout.setDrawerShadow(R.drawable.debug_drawer_shadow, Gravity.END);
drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
Expand All @@ -214,7 +214,7 @@ public class DebugAppContainer implements AppContainer {
setupDeviceSection();
setupPicassoSection();

return content;
return scalpelFrameLayout;
}

private void setupNetworkSection() {
Expand Down Expand Up @@ -390,7 +390,7 @@ public void onItemSelected(AdapterView<?> adapterView, View view, int position,
}
});
// Ensure the animation speed value is always applied across app restarts.
content.post(new Runnable() {
scalpelFrameLayout.post(new Runnable() {
@Override public void run() {
applyAnimationSpeed(animationSpeedValue);
}
Expand Down Expand Up @@ -624,6 +624,6 @@ private void setEndpointAndRelaunch(String endpoint) {
Intent newApp = new Intent(app, MainActivity.class);
newApp.setFlags(FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_NEW_TASK);
app.startActivity(newApp);
U2020App.get(app).buildObjectGraphAndInject();
U2020App.get(app).buildComponentAndInject();
}
}
17 changes: 8 additions & 9 deletions src/main/java/com/jakewharton/u2020/U2020App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import android.app.Application;
import android.content.Context;
import com.jakewharton.u2020.ui.ActivityHierarchyServer;
import dagger.ObjectGraph;
import hugo.weaving.DebugLog;
import javax.inject.Inject;
import timber.log.Timber;

import static timber.log.Timber.DebugTree;

public class U2020App extends Application {
private ObjectGraph objectGraph;
private U2020Graph component;

@Inject ActivityHierarchyServer activityHierarchyServer;

Expand All @@ -25,19 +24,19 @@ public class U2020App extends Application {
// TODO Timber.plant(new CrashlyticsTree());
}

buildObjectGraphAndInject();
buildComponentAndInject();

registerActivityLifecycleCallbacks(activityHierarchyServer);
}

@DebugLog
public void buildObjectGraphAndInject() {
objectGraph = ObjectGraph.create(Modules.list(this));
objectGraph.inject(this);
@DebugLog // Extracted for debugging.
public void buildComponentAndInject() {
component = U2020Component.Initializer.init(this);
component.inject(this);
}

public void inject(Object o) {
objectGraph.inject(o);
public U2020Graph component() {
return component;
}

public static U2020App get(Context context) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/jakewharton/u2020/U2020AppModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.jakewharton.u2020;

import android.app.Application;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;

@Module
public final class U2020AppModule {
private final U2020App app;

public U2020AppModule(U2020App app) {
this.app = app;
}

@Provides @Singleton Application provideApplication() {
return app;
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/jakewharton/u2020/U2020Graph.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.jakewharton.u2020;

import com.jakewharton.u2020.ui.MainActivity;
import com.jakewharton.u2020.ui.gallery.GalleryView;
import dagger.Component;
import javax.inject.Singleton;

/**
* A common interface implemented by both the Release and Debug flavored components.
*/
public interface U2020Graph {
void inject(U2020App app);
void inject(MainActivity activity);
void inject(GalleryView view);
}
29 changes: 0 additions & 29 deletions src/main/java/com/jakewharton/u2020/U2020Module.java

This file was deleted.

22 changes: 2 additions & 20 deletions src/main/java/com/jakewharton/u2020/data/DataModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,14 @@

import static android.content.Context.MODE_PRIVATE;

@Module(
includes = ApiModule.class,
complete = false,
library = true
)
@Module(includes = ApiModule.class)
public final class DataModule {
static final int DISK_CACHE_SIZE = 50 * 1024 * 1024; // 50MB

@Provides @Singleton SharedPreferences provideSharedPreferences(Application app) {
return app.getSharedPreferences("u2020", MODE_PRIVATE);
}

@Provides @Singleton OkHttpClient provideOkHttpClient(Application app) {
return createOkHttpClient(app);
}

@Provides @Singleton Picasso providePicasso(Application app, OkHttpClient client) {
return new Picasso.Builder(app)
.downloader(new OkHttpDownloader(client))
.listener(new Picasso.Listener() {
@Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
Timber.e(e, "Failed to load image: %s", uri);
}
})
.build();
}

static OkHttpClient createOkHttpClient(Application app) {
OkHttpClient client = new OkHttpClient();

Expand All @@ -58,4 +39,5 @@ static OkHttpClient createOkHttpClient(Application app) {

return client;
}

}
14 changes: 2 additions & 12 deletions src/main/java/com/jakewharton/u2020/data/api/ApiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@
import retrofit.client.Client;
import retrofit.client.OkClient;

@Module(
complete = false,
library = true
)
@Module
public final class ApiModule {
public static final String PRODUCTION_API_URL = "https://api.imgur.com/3/";

private static final String CLIENT_ID = "3436c108ccc17d3";

@Provides @Singleton @ClientId String provideClientId() {
return CLIENT_ID;
}

@Provides @Singleton Endpoint provideEndpoint() {
return Endpoints.newFixedEndpoint(PRODUCTION_API_URL);
}

@Provides @Singleton Client provideClient(OkHttpClient client) {
return new OkClient(client);
}
Expand All @@ -38,8 +32,4 @@ RestAdapter provideRestAdapter(Endpoint endpoint, Client client, ApiHeaders head
.setRequestInterceptor(headers) //
.build();
}

@Provides @Singleton GalleryService provideGalleryService(RestAdapter restAdapter) {
return restAdapter.create(GalleryService.class);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/jakewharton/u2020/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MainActivity extends Activity {
super.onCreate(savedInstanceState);

U2020App app = U2020App.get(this);
app.inject(this);
app.component().inject(this);

container = appContainer.get(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class GalleryView extends BetterViewAnimator {

public GalleryView(Context context, AttributeSet attrs) {
super(context, attrs);
U2020App.get(context).inject(this);
U2020App.get(context).component().inject(this);

adapter = new GalleryAdapter(context, picasso);
}
Expand Down
Loading