/*
* Copyright (C) 2016 Payworks GmbH (http://www.payworks.com)
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.mpos.ui.acquirer.view;
import android.os.Bundle;
import io.mpos.ui.R;
import io.mpos.ui.shared.MposUi;
import io.mpos.ui.shared.util.UiHelper;
import io.mpos.ui.shared.util.UiState;
import io.mpos.ui.shared.view.AbstractBaseActivity;
public class LoginActivity extends AbstractBaseActivity implements LoginFragment.Interaction {
public static final String TAG = "LoginActivity";
public final static String BUNDLE_EXTRA_ACQUIRER_APPLICATION_ID = "io.mpos.ui.acquirer.LoginActivity.BUNDLE_EXTRA_ACQUIRER_APPLICATION_ID";
LoginFragment mLoginFragment;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mpu_activity_login);
UiHelper.setActionbarWithCustomColors(this, (android.support.v7.widget.Toolbar) findViewById(R.id.mpu_toolbar));
setTitle(R.string.MPULogin);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
if (savedInstanceState == null) {
String applicationIdentifier = getIntent().getStringExtra(BUNDLE_EXTRA_ACQUIRER_APPLICATION_ID);
showLoginFragment(applicationIdentifier);
}
}
private void showLoginFragment(String applicationIdentifier) {
LoginFragment fragment = LoginFragment.newInstance(applicationIdentifier);
showFragment(fragment, LoginFragment.TAG, UiState.LOGIN_DISPLAYING, true);
}
@Override
public void onLoginCompleted() {
finishWithResult(true);
}
@Override
public void onLoginModeChanged(boolean loginMode) {
if (loginMode) {
setUiState(UiState.LOGIN_DISPLAYING);
} else {
setUiState(UiState.FORGOT_PASSWORD_DISPLAYING);
}
}
@Override
public void onBackPressed() {
navigateBack();
}
@Override
public void navigateBack() {
if (getUiState() == UiState.FORGOT_PASSWORD_DISPLAYING) {
LoginFragment loginFragment = (LoginFragment) getFragmentManager().findFragmentByTag(LoginFragment.TAG);
if (loginFragment != null) {
loginFragment.setLoginMode(true);
}
} else {
finishWithResult(false);
}
}
private void finishWithResult(boolean success) {
int resultCode = success ? MposUi.RESULT_CODE_LOGIN_SUCCESS : MposUi.RESULT_CODE_LOGIN_FAILED;
setResult(resultCode);
finish();
}
}