This file contains 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 ServiceLocator... | |
private static ServiceLocator sInstance; | |
public static void load(ServiceLocator arg) { | |
sInstance = arg; | |
} | |
private Map services = new HashMap(); | |
public static Object getService(String key){ | |
return sInstance.services.get(key); | |
} | |
public void loadService (String key, Object service) { |
This file contains 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 | |
public class BookFinderModule { | |
@Provides | |
BookFinder provideBookFinder() { | |
return new OxfordBookFinder(); | |
} | |
@Provides | |
@LocalFinder | |
BookFinder provideLocalBookFinder() { | |
return new LocalLibraryBookFinder(); |
This file contains 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 BookFinder { | |
List findAll(); | |
} | |
class Library… | |
private BookFinder finder; | |
public Library() { | |
finder = new(RemoteBookFinder("https://oxfordlibrary.com/books"); // Can be a local database implementation as well. | |
} | |
.... |
This file contains 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 Library… | |
public Book[] booksAuthoredBy(String arg) { | |
List allBooks = finder.findAll(); | |
for (Iterator it = allBooks.iterator(); it.hasNext();) { | |
Book book = (Book) it.next(); | |
if (!book.getAuthor().equals(arg)) it.remove(); | |
} | |
return (Book[]) allBooks.toArray(new Book[allBooks.size()]); | |
} |
This file contains 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
@Inject Map<MessageType, Provider<ViewHolder>> mViewHolders | |
//... | |
for (Message message : messages) { | |
mViewHolders.get(message.getType()).get().display(message); | |
} |
This file contains 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 | |
public abstract class ViewHolderModule { | |
@Binds | |
@IntoMap | |
@ViewHolderKey(MessageType.TEXT_MESSAGE_TYPE) | |
abstract ViewHolder bindUserViewModule(TextMessageViewHolder textMessageViewHolder); | |
@Binds | |
@IntoMap |
This file contains 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
@Target({ElementType.METHOD}) | |
@Retention(RetentionPolicy.RUNTIME) | |
@MapKey | |
@interface ViewHolderKey { | |
MessageType value(); | |
} |
This file contains 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 enum MessageType { | |
TEXT_MESSAGE_TYPE, | |
IMAGE_MESSAGE_TYPE, | |
INFO_MESSAGE_TYPE; | |
} |
This file contains 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 MainPresenterImpl implements MainContract.Presenter { | |
private final MainContract.View mView; | |
private final DataManager mDataManager; | |
// Constructor with view and datamanger parameters. | |
public MainPresenterImpl(MainContract.View view, DataManager dataManager) { | |
this.mView = view; | |
mDataManager = dataManager; | |
mView.setPresenter(this); // Set presenter to the mView. |
This file contains 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 MainActivity extends AppCompatActivity implements MainContract.View, View.OnClickListener { | |
// Contract Presenter | |
private MainContract.Presenter mPresenter; | |
...... | |
// Other fields | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); |
NewerOlder