use of org.eyeseetea.malariacare.data.authentication.AuthenticationManager in project pictureapp by EyeSeeTea.
the class ProgressActivity method initializeDependencies.
private void initializeDependencies() {
AuthenticationManager authenticationManager = new AuthenticationManager(this);
IPullController pullController = new PullController(this);
IAsyncExecutor asyncExecutor = new AsyncExecutor();
IMainExecutor mainExecutor = new UIThreadExecutor();
mLogoutUseCase = new LogoutUseCase(authenticationManager);
mPullUseCase = new PullUseCase(pullController, asyncExecutor, mainExecutor);
}
use of org.eyeseetea.malariacare.data.authentication.AuthenticationManager in project pictureapp by EyeSeeTea.
the class PushServiceStrategy method push.
@Override
public void push() {
IAuthenticationManager authenticationManager = new AuthenticationManager(PreferencesState.getInstance().getContext());
IMainExecutor mainExecutor = new UIThreadExecutor();
IAsyncExecutor asyncExecutor = new AsyncExecutor();
ICredentialsRepository credentialsLocalDataSoruce = new CredentialsLocalDataSource();
IOrganisationUnitRepository organisationDataSource = new OrganisationUnitRepository();
IInvalidLoginAttemptsRepository iInvalidLoginAttemptsRepository = new InvalidLoginAttemptsRepositoryLocalDataSource();
LoginUseCase loginUseCase = new LoginUseCase(authenticationManager, mainExecutor, asyncExecutor, organisationDataSource, credentialsLocalDataSoruce, iInvalidLoginAttemptsRepository);
final Credentials oldCredentials = credentialsLocalDataSoruce.getOrganisationCredentials();
loginUseCase.execute(oldCredentials, new ALoginUseCase.Callback() {
@Override
public void onLoginSuccess() {
PushServiceStrategy.this.onCorrectCredentials();
}
@Override
public void onServerURLNotValid() {
Log.e(TAG, "Error getting user credentials: URL not valid ");
}
@Override
public void onInvalidCredentials() {
logout();
}
@Override
public void onNetworkError() {
Log.e(TAG, "Error getting user credentials: NetworkError");
}
@Override
public void onConfigJsonInvalid() {
Log.e(TAG, "Error getting user credentials: JsonInvalid");
}
@Override
public void onUnexpectedError() {
Log.e(TAG, "Error getting user credentials: unexpectedError ");
}
@Override
public void onMaxLoginAttemptsReachedError() {
}
});
}
use of org.eyeseetea.malariacare.data.authentication.AuthenticationManager in project pictureapp by EyeSeeTea.
the class PushServiceStrategy method logout.
public void logout() {
IAuthenticationManager authenticationManager;
LogoutUseCase logoutUseCase;
authenticationManager = new AuthenticationManager(mPushService);
logoutUseCase = new LogoutUseCase(authenticationManager);
AlarmPushReceiver.cancelPushAlarm(mPushService);
logoutUseCase.execute(new LogoutUseCase.Callback() {
@Override
public void onLogoutSuccess() {
if (!EyeSeeTeaApplication.getInstance().isAppWentToBg()) {
Intent loginIntent = new Intent(mPushService, LoginActivity.class);
loginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mPushService.startActivity(loginIntent);
}
}
@Override
public void onLogoutError(String message) {
Log.d(TAG, message);
}
});
}
use of org.eyeseetea.malariacare.data.authentication.AuthenticationManager in project pictureapp by EyeSeeTea.
the class SettingsActivityStrategy method onCreate.
@Override
public void onCreate() {
mAuthenticationManager = new AuthenticationManager(settingsActivity);
mLogoutUseCase = new LogoutUseCase(mAuthenticationManager);
IntentFilter screenStateFilter = new IntentFilter();
screenStateFilter.addAction(Intent.ACTION_SCREEN_ON);
screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
settingsActivity.registerReceiver(mScreenOffReceiver, screenStateFilter);
}
use of org.eyeseetea.malariacare.data.authentication.AuthenticationManager in project pictureapp by EyeSeeTea.
the class LogoutAndLoginRequiredOnPreferenceClickListener method logout.
private void logout() {
Log.d(TAG, "Logging out...");
AuthenticationManager authenticationManager = new AuthenticationManager(settingsActivity);
LogoutUseCase logoutUseCase = new LogoutUseCase(authenticationManager);
logoutUseCase.execute(new LogoutUseCase.Callback() {
@Override
public void onLogoutSuccess() {
Intent loginIntent = new Intent(settingsActivity, LoginActivity.class);
settingsActivity.finish();
settingsActivity.startActivity(loginIntent);
}
@Override
public void onLogoutError(String message) {
Log.e(TAG, message);
}
});
}
Aggregations