public interface LoginView extends MvpView {
void showLoginLoading();
void loginSucceeded();
void loginFailed();
}
public class LoginPresenter implements MvpPresenter<LoginView> {
public void cancel() {}
public void forgotPassword() {}
public void login(String username, String password) {}
}
In software engineering, dependency injection
is a software design pattern that implements
inversion of control for resolving dependencies.
Dependency injection means giving an object
its instance variables. Really. That's it.
~ Wikipedia
DataManager mDataManager;
Analytics mAnalytics;
Session mSessionl
KioskService mKioskService;
public KioskPresenter(DataManager dataManager,
Analytics analytics, Session session,
KioskService kioskService) {
mDataManager = dataManager;
mAnalytics = analytics;
mSession = session;
mKioskService = kioskService;
}
@Inject DataManager mDataManager;
@Inject Analytics mAnalytics;
@Inject Session mSession;
@Inject KioskService mKioskService;
public KioskPresenter(Context context) {
MyApp.get(context).getSessionComponent().inject(this);
}
@Module
public class SessionModule {
@Provides
public OkHttpClient provideHttpClient() {
return new OkHttpClient();
}
@Provides
public DataManager provideDataManager(client) {
return new DataManager(client);
}
DataManager mDataManager;
Analytics mAnalytics;
Session mSessionl
KioskService mKioskService;
public KioskPresenter(Context context) {
mDataManager = DataManager.getInstance();
mAnalytics = new Analytics(context);
mSession = Session.retrieveSession();
mKioskService = new KioskService(context);
}