Skip to content
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

firebase #351

Open
dprasetyo opened this issue Aug 31, 2018 · 0 comments
Open

firebase #351

dprasetyo opened this issue Aug 31, 2018 · 0 comments

Comments

@dprasetyo
Copy link

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzbth;

initFirebase();
ButterKnife.bind(this);
loggedIn = isLoggedIn();
if (loggedIn) {
// go to home
goToHome();
}
}

private void initFirebase() {
    firebaseAuth = FirebaseAuth.getInstance();
}

private void goToHome() {
    Intent intent = new Intent(this, home.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
}

@OnClick({R.id.button_login_activity_main, R.id.button_sign_up_activity_main})
public void onClick(Button button) {
    switch (button.getId()) {
        case R.id.button_login_activity_main:
            String username = editTextUsername.getText().toString().trim();
            String password = editTextPassword.getText().toString().trim();
            login(username, password);
            break;
        case R.id.button_sign_up_activity_main:
            //  go to form pendaftaran
            startActivity(new Intent(this, SignupActivity.class));
            break;
    }
}

private void login(final String username, final String password) {
    if (TextUtils.isEmpty(username)) {
        Snackbar.make(findViewById(android.R.id.content), R.string.error_message_username_empty, Snackbar.LENGTH_LONG)
                .show();
    } else if (TextUtils.isEmpty(password)) {
        Snackbar.make(findViewById(android.R.id.content), R.string.error_message_password_empty, Snackbar.LENGTH_LONG)
                .show();
    } else {
        //  do login
        showProgress();
        firebaseAuth.signInWithEmailAndPassword(username, password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        hideProgress();
                        if (task.isSuccessful()) {
                            //  login sucess
                            //  go to dashboard
                            goToHome();
                        } else {
                            //  login failed
                            showMessageBox("Login failed. Your username and password is not matched");
                        }
                    }
                });

    }
}

private void hideProgress() {
    relativeLayoutProgress.setVisibility(View.GONE);
    editTextUsername.setEnabled(true);
    editTextPassword.setEnabled(true);
}

private void showProgress() {
    relativeLayoutProgress.setVisibility(View.VISIBLE);
    editTextUsername.setEnabled(false);
    editTextPassword.setEnabled(false);
}

private void showMessageBox(String message) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle("Login");
    alertDialogBuilder.setMessage(message);
    alertDialogBuilder.setCancelable(false);
    alertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });
    alertDialogBuilder.show();
}

public boolean isLoggedIn() {
    if (firebaseAuth.getCurrentUser() != null) {
        //  user logged in
        return true;
    } else {
        return false;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant