New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: passcode feature #728

Merged
merged 1 commit into from Aug 2, 2017
Jump to file or symbol
Failed to load files and symbols.
+38 −52
Diff settings

Always

Just for now

@@ -19,6 +19,7 @@
import com.mifos.mifosxdroid.injection.component.ApplicationComponent; import com.mifos.mifosxdroid.injection.component.ApplicationComponent;
import com.mifos.mifosxdroid.injection.component.DaggerApplicationComponent; import com.mifos.mifosxdroid.injection.component.DaggerApplicationComponent;
import com.mifos.mifosxdroid.injection.module.ApplicationModule; import com.mifos.mifosxdroid.injection.module.ApplicationModule;
import com.mifos.utils.ForegroundChecker;
import com.raizlabs.android.dbflow.config.FlowConfig; import com.raizlabs.android.dbflow.config.FlowConfig;
import com.raizlabs.android.dbflow.config.FlowManager; import com.raizlabs.android.dbflow.config.FlowManager;
@@ -65,6 +66,7 @@ public void onCreate() {
.detectFileUriExposure() .detectFileUriExposure()
.build(); .build();
StrictMode.setVmPolicy(policy); StrictMode.setVmPolicy(policy);
ForegroundChecker.init();
} }
public ApplicationComponent getComponent() { public ApplicationComponent getComponent() {
@@ -11,8 +11,7 @@
import com.mifos.api.BaseUrl; import com.mifos.api.BaseUrl;
import com.mifos.mifosxdroid.core.MifosBaseActivity; import com.mifos.mifosxdroid.core.MifosBaseActivity;
import com.mifos.mifosxdroid.login.LoginActivity; import com.mifos.mifosxdroid.login.LoginActivity;
import com.mifos.mifosxdroid.online.DashboardActivity; import com.mifos.mifosxdroid.passcode.PassCodeActivity;
import com.mifos.utils.ForegroundChecker;
import com.mifos.utils.PrefManager; import com.mifos.utils.PrefManager;
@@ -25,13 +24,12 @@
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash); setContentView(R.layout.activity_splash);
ForegroundChecker.init();
if (!PrefManager.isAuthenticated()) { if (!PrefManager.isAuthenticated()) {
PrefManager.setInstanceUrl(BaseUrl.PROTOCOL_HTTPS PrefManager.setInstanceUrl(BaseUrl.PROTOCOL_HTTPS
+ BaseUrl.API_ENDPOINT + BaseUrl.API_PATH); + BaseUrl.API_ENDPOINT + BaseUrl.API_PATH);
startActivity(new Intent(SplashScreenActivity.this, LoginActivity.class)); startActivity(new Intent(SplashScreenActivity.this, LoginActivity.class));
} else { } else {
startActivity(new Intent(SplashScreenActivity.this, DashboardActivity.class)); startActivity(new Intent(SplashScreenActivity.this, PassCodeActivity.class));
} }
finish(); finish();
} }
@@ -8,30 +8,27 @@
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.mifos.mifosxdroid.R; import com.mifos.mifosxdroid.R;
import com.mifos.mifosxdroid.SplashScreenActivity;
import com.mifos.mifosxdroid.core.MifosBaseActivity; import com.mifos.mifosxdroid.core.MifosBaseActivity;
import com.mifos.mifosxdroid.core.util.Toaster; import com.mifos.mifosxdroid.core.util.Toaster;
import com.mifos.mifosxdroid.login.LoginActivity;
import com.mifos.mifosxdroid.online.DashboardActivity; import com.mifos.mifosxdroid.online.DashboardActivity;
import com.mifos.utils.Constants; import com.mifos.utils.Constants;
import com.mifos.utils.EncryptionUtil; import com.mifos.utils.EncryptionUtil;
import com.mifos.utils.Network;
import com.mifos.utils.PassCodeView; import com.mifos.utils.PassCodeView;
import com.mifos.utils.PrefManager; import com.mifos.utils.PrefManager;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
public class PassCodeActivity extends MifosBaseActivity { public class PassCodeActivity extends MifosBaseActivity implements PassCodeView.PassCodeListener {
@BindView(R.id.cl_rootview) @BindView(R.id.cl_rootview)
NestedScrollView clRootview; NestedScrollView clRootview;
@BindView(R.id.btn_login)
AppCompatButton btnLogin;
@BindView(R.id.btn_forgot_passcode) @BindView(R.id.btn_forgot_passcode)
AppCompatButton btnForgotPasscode; AppCompatButton btnForgotPasscode;
@@ -66,8 +63,9 @@ protected void onCreate(Bundle savedInstanceState) {
btnSkip.setVisibility(View.GONE); btnSkip.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE); btnSave.setVisibility(View.GONE);
tvPasscodeIntro.setVisibility(View.GONE); tvPasscodeIntro.setVisibility(View.GONE);
btnLogin.setVisibility(View.VISIBLE);
btnForgotPasscode.setVisibility(View.VISIBLE); btnForgotPasscode.setVisibility(View.VISIBLE);
//enabling passCodeListener only when user has already setup PassCode
passCodeView.setPassCodeListener(this);
} }
} }
@@ -84,23 +82,20 @@ public void savePassCode() {
} }
} }
@OnClick(R.id.btn_login) @Override
public void loginUsingPassCode() { public void passCodeEntered(String passcode) {
String passwordEntered = EncryptionUtil.getHash(passCodeView.getPasscode());
if (!isInternetAvailable()) { boolean isPassCodeCorrect = PrefManager.getPassCode().equals(passwordEntered);
return; if (counter == 3 && !isPassCodeCorrect) {
} Toast.makeText(getApplicationContext(), R.string.incorrect_passcode_more_than_three,
Toast.LENGTH_SHORT).show();
if (counter == 3) {
Toaster.show(clRootview, R.string.incorrect_passcode_more_than_three);
PrefManager.clearPrefs(); PrefManager.clearPrefs();
startLoginActivity(); startSplashActivity();
return; return;
} }
if (isPassCodeLengthCorrect()) { if (isPassCodeLengthCorrect()) {
String passwordEntered = EncryptionUtil.getHash(passCodeView.getPasscode()); if (isPassCodeCorrect) {
if (PrefManager.getPassCode().equals(passwordEntered)) {
startDashBoardActivity(); startDashBoardActivity();
} else { } else {
counter++; counter++;
@@ -113,16 +108,7 @@ public void loginUsingPassCode() {
@OnClick(R.id.btn_forgot_passcode) @OnClick(R.id.btn_forgot_passcode)
public void forgotPassCode() { public void forgotPassCode() {
PrefManager.clearPrefs(); PrefManager.clearPrefs();
startLoginActivity(); startSplashActivity();
}
private boolean isInternetAvailable() {
if (Network.isOnline(this)) {
return true;
} else {
Toaster.show(clRootview, getString(R.string.error_not_connected_internet));
return false;
}
} }
@OnClick(R.id.btn_one) @OnClick(R.id.btn_one)
@@ -204,8 +190,8 @@ private void startDashBoardActivity() {
finish(); finish();
} }
private void startLoginActivity() { private void startSplashActivity() {
Intent i = new Intent(PassCodeActivity.this, LoginActivity.class); Intent i = new Intent(PassCodeActivity.this, SplashScreenActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i); startActivity(i);
finish(); finish();
@@ -8,7 +8,7 @@
public class ForegroundChecker { public class ForegroundChecker {
public static final long CHECK_DELAY = 500; public static final long CHECK_DELAY = 500;
public static final int MIN_BACKGROUND_THRESHOLD = 120; public static final int MIN_BACKGROUND_THRESHOLD = 60;
public static final String TAG = ForegroundChecker.class.getName(); public static final String TAG = ForegroundChecker.class.getName();
public interface Listener { public interface Listener {
@@ -31,9 +31,6 @@ public static ForegroundChecker init() {
} }
public static ForegroundChecker get() { public static ForegroundChecker get() {
if (instance == null) {
init();
}
return instance; return instance;
} }
@@ -64,10 +61,10 @@ public void onActivityResumed() {
if (wasBackground) { if (wasBackground) {
int secondsInBackground = (int) ((System.currentTimeMillis() - backgroundTimeStart) / int secondsInBackground = (int) ((System.currentTimeMillis() - backgroundTimeStart) /
1000) % 60; 1000);
if (backgroundTimeStart != -1 && secondsInBackground >= MIN_BACKGROUND_THRESHOLD && if (backgroundTimeStart != -1 && secondsInBackground >= MIN_BACKGROUND_THRESHOLD &&
listener != null) { listener != null && PrefManager.getPassCodeStatus()) {
listener.onBecameForeground(); listener.onBecameForeground();
} }
@@ -23,12 +23,17 @@
private final int PASSWORD_LENGTH = 4; private final int PASSWORD_LENGTH = 4;
private List<String> passwordList; private List<String> passwordList;
private boolean isPasscodeVisible; private boolean isPasscodeVisible;
private PassCodeListener passCodeListener;
public PassCodeView(Context context) { public PassCodeView(Context context) {
super(context); super(context);
init(); init();
} }
public void setPassCodeListener(PassCodeListener passCodeListener) {
this.passCodeListener = passCodeListener;
}
public PassCodeView(Context context, @Nullable AttributeSet attrs) { public PassCodeView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs); super(context, attrs);
init(); init();
@@ -82,6 +87,9 @@ public void enterCode(String character) {
passwordList.add(character); passwordList.add(character);
invalidate(); invalidate();
} }
if (passwordList.size() == PASSWORD_LENGTH && passCodeListener != null) {
passCodeListener.passCodeEntered(getPasscode());
}
} }
public String getPasscode() { public String getPasscode() {
@@ -112,4 +120,8 @@ public void revertPassCodeVisibility() {
public boolean passcodeVisible() { public boolean passcodeVisible() {
return isPasscodeVisible; return isPasscodeVisible;
} }
public interface PassCodeListener {
void passCodeEntered(String passcode);
}
} }
@@ -162,16 +162,6 @@
android:id="@+id/btn_save" android:id="@+id/btn_save"
app:backgroundTint="@color/primary" app:backgroundTint="@color/primary"
android:textColor="@color/white"/> android:textColor="@color/white"/>
<android.support.v7.widget.AppCompatButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/login"
android:id="@+id/btn_login"
android:visibility="gone"
android:layout_gravity="center"
android:layout_marginTop="@dimen/default_padding"
app:backgroundTint="@color/primary"
android:textColor="@color/white"/>
<android.support.v7.widget.AppCompatButton <android.support.v7.widget.AppCompatButton
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -180,6 +170,7 @@
android:id="@+id/btn_forgot_passcode" android:id="@+id/btn_forgot_passcode"
android:layout_gravity="center" android:layout_gravity="center"
android:visibility="gone" android:visibility="gone"
android:layout_marginTop="@dimen/default_padding"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
style="@style/Widget.AppCompat.Button.Borderless"/> style="@style/Widget.AppCompat.Button.Borderless"/>
</LinearLayout> </LinearLayout>
@@ -706,7 +706,7 @@
<string name="pass_code">Pass Code</string> <string name="pass_code">Pass Code</string>
<string name="forgot_passcode">Forgot passcode, login manually</string> <string name="forgot_passcode">Forgot passcode, login manually</string>
<string name="incorrect_passcode">Incorrect Passcode</string> <string name="incorrect_passcode">Incorrect Passcode</string>
<string name="incorrect_passcode_more_than_three">You have entered incorrect Passcode more than 3 times</string> <string name="incorrect_passcode_more_than_three">You have entered incorrect Passcode more than 3 times. Please login again.</string>
<string name="error_passcode">Passcode should be of 4 digit</string> <string name="error_passcode">Passcode should be of 4 digit</string>
ProTip! Use n and p to navigate between commits in a pull request.