Skip to content

Instantly share code, notes, and snippets.

View larkintuckerllc's full-sized avatar

John Tucker larkintuckerllc

View GitHub Profile
@larkintuckerllc
larkintuckerllc / MainActivity.java
Created November 29, 2017 00:51
How-to Dagger 2 with Android: Part 2 - 1
...
((MyApplication) getApplication())
.getMyComponent()
.inject(MainActivity.this);
...
@larkintuckerllc
larkintuckerllc / MyApplication.java
Created November 29, 2017 00:55
How-to Dagger 2 with Android: Part 2 - 2
...
public class MyApplication extends Application {
private MyComponent mMyComponent;
@Override
public void onCreate() {
super.onCreate();
mMyComponent = createMyComponent();
}
@larkintuckerllc
larkintuckerllc / MyApplication.java
Created November 29, 2017 01:00
How-to Dagger 2 with Android: Part 2 -3
void setMyComponent(MyComponent myComponent) {
mMyComponent = myComponent;
}
@larkintuckerllc
larkintuckerllc / MyComponentMock.java
Created November 29, 2017 01:07
How-to Dagger 2 with Android: Part 2 - 4
package com.larkintuckerllc.dagger.mocks;
import com.larkintuckerllc.dagger.MyComponent;
import javax.inject.Singleton;
import dagger.Component;
@Singleton
@Component(modules = MyModuleMock.class)
public interface MyComponentMock extends MyComponent {
}
@larkintuckerllc
larkintuckerllc / MyModuleMock.java
Created November 29, 2017 01:08
How-to Dagger 2 with Android: Part 2 - 5
package com.larkintuckerllc.dagger.mocks;
import com.larkintuckerllc.dagger.MyExample;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
@Module
public class MyModuleMock {
@larkintuckerllc
larkintuckerllc / MyExampleImplMock.java
Created November 29, 2017 01:09
How-to Dagger 2 with Android: Part 2 - 6
package com.larkintuckerllc.dagger.mocks;
import com.larkintuckerllc.dagger.MyExample;
import java.util.Date;
public class MyExampleImplMock implements MyExample {
public long getDate() {
return 0;
@larkintuckerllc
larkintuckerllc / MainActivityTest.java
Created November 29, 2017 01:12
How-to Dagger 2 with Android: Part 2 - 6
...
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityTest {
@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<MainActivity>(MainActivity.class) {
@Override
protected void beforeActivityLaunched() {
@larkintuckerllc
larkintuckerllc / MyModule.java
Created December 1, 2017 13:11
How-to Dagger 2 with Android: Part 3 - 1
...
@Module
class MyModule {
@Provides
@Singleton
static MyExample provideMyExample() {
return new MyExampleImpl();
}
@larkintuckerllc
larkintuckerllc / MyComponent.java
Created December 1, 2017 13:18
How-to Dagger 2 with Android: Part 3 - 2
...
@Singleton
@Component(modules = MyModule.class)
interface MyComponent {
void inject(MainActivity mainActivity);
}
@larkintuckerllc
larkintuckerllc / MyApplication.java
Created December 1, 2017 14:43
How-to Dagger 2 with Android: Part 3 - 3
...
public class MyApplication extends Application {
static private AppComponent sAppComponent;
static private AuthComponent sAuthComponent;
@Override
public void onCreate() {
super.onCreate();
sAppComponent = DaggerAppComponent.create();