This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface BookRepository { | |
public List<Book> getAllBooks(); | |
public List<Book> getAllBooksFromUser(int userId); | |
public List<Book> getAllBooksByCategory(BookCategory category); | |
public Book getBook(int bookId); | |
public Book getBookByName(String bookName); | |
public void removeBook(int bookId); | |
public void markAsCompleted(int bookId); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void BookController { | |
private static BookController instance = null; | |
private BookRepository bookRepository = new PersistentBookRepository(); | |
protected BookController() {} | |
public static BookController getInstance() { | |
if(instance == null) { | |
instance = new BookController(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApplicationClass extends Application { | |
private ObjectGraph objectGraph; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
objectGraph = ObjectGraph.create(getModules().toArray()); | |
objectGraph.inject(this); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module( | |
injects = { | |
ApplicationClass.class, | |
AbstractFontFactory.class, | |
RobotoFontFactory.class, | |
DataController.class, | |
LocationController.class, | |
RestAnimalProvider.class, | |
MainActivity.class, | |
TutorialActivity.class, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A module for more generic or external dependencies wich doesnt require a {@link android.content.Context} or | |
* {@link android.app.Application} to create. | |
*/ | |
@Module( | |
library = true | |
) | |
public class AppModule { | |
@Provides |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A module for dependencies which require a {@link android.content.Context} or | |
* {@link android.app.Application} to create. | |
*/ | |
@Module( | |
library = true | |
) | |
public class ContextModule { | |
private Context appContext; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocationController implements LocationListener { | |
private static final int TWO_MINUTES = 1000 * 60 * 2; | |
private Context context; | |
private LocationManager locationManager; | |
private String provider; | |
private Location bestLocationUntilNow; | |
@Inject |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by jorge on 3/17/14. | |
*/ | |
public class MainActivity extends InjectedActivity { | |
@Inject | |
GoogleApiClient mGoogleApiClient; | |
@Inject | |
LocationController mLocationController; | |
@Inject |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by jorge on 5/3/14. | |
*/ | |
public class InjectedActivity extends FragmentActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
((ApplicationClass) getApplicationContext()).inject(this); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GridingCoffeeMaker { | |
@Inject Lazy<Grinder> lazyGrinder; | |
public void brew() { | |
while (needsGrinding()) { | |
// Grinder created once on first call to .get() and cached. | |
lazyGrinder.get().grind(); | |
} | |
} | |
} |
OlderNewer