Search in sources :

Example 1 with PushNotificationTask

use of com.applozic.mobicomkit.api.account.user.PushNotificationTask in project Applozic-Android-SDK by AppLozic.

the class LoginActivity method attemptLogin.

/**
 * Attempts to sign in or register the account specified by the login form.
 * If there are form errors (invalid email, missing fields, etc.), the
 * errors are presented and no actual login attempt is made.
 */
public void attemptLogin(User.AuthenticationType authenticationType) {
    if (mAuthTask != null) {
        return;
    }
    // Reset errors.
    mUserIdView.setError(null);
    mEmailView.setError(null);
    mPasswordView.setError(null);
    mDisplayName.setError(null);
    // Store values at the time of the login attempt.
    String email = mEmailView.getText().toString();
    String phoneNumber = mPhoneNumberView.getText().toString();
    String userId = mUserIdView.getText().toString().trim();
    String password = mPasswordView.getText().toString();
    String displayName = mDisplayName.getText().toString();
    boolean cancel = false;
    View focusView = null;
    if (TextUtils.isEmpty(mUserIdView.getText().toString()) || mUserIdView.getText().toString().trim().length() == 0) {
        mUserIdView.setError(getString(R.string.error_field_required));
        focusView = mUserIdView;
        cancel = true;
    }
    // Check for a valid email address.
    if (TextUtils.isEmpty(email)) {
    /*mEmailView.setError(getString(R.string.error_field_required));
            focusView = mEmailView;
            cancel = true;*/
    } else if (!isEmailValid(email)) {
        mEmailView.setError(getString(R.string.error_invalid_email));
        focusView = mEmailView;
        cancel = true;
    }
    if (cancel) {
        // There was an error; don't attempt login and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        // Show a progress spinner, and kick off a background task to
        // perform the user login attempt.
        showProgress(true);
        // callback for login process
        final Activity activity = LoginActivity.this;
        UserLoginTask.TaskListener listener = new UserLoginTask.TaskListener() {

            @Override
            public void onSuccess(RegistrationResponse registrationResponse, final Context context) {
                mAuthTask = null;
                showProgress(false);
                // Basic settings...
                ApplozicClient.getInstance(context).setContextBasedChat(true).setHandleDial(true);
                Map<ApplozicSetting.RequestCode, String> activityCallbacks = new HashMap<ApplozicSetting.RequestCode, String>();
                activityCallbacks.put(ApplozicSetting.RequestCode.USER_LOOUT, LoginActivity.class.getName());
                ApplozicSetting.getInstance(context).setActivityCallbacks(activityCallbacks);
                // Set activity callbacks
                /*Map<ApplozicSetting.RequestCode, String> activityCallbacks = new HashMap<ApplozicSetting.RequestCode, String>();
                    activityCallbacks.put(ApplozicSetting.RequestCode.MESSAGE_TAP, MainActivity.class.getName());
                    ApplozicSetting.getInstance(context).setActivityCallbacks(activityCallbacks);*/
                // Start GCM registration....
                PushNotificationTask.TaskListener pushNotificationTaskListener = new PushNotificationTask.TaskListener() {

                    @Override
                    public void onSuccess(RegistrationResponse registrationResponse) {
                    }

                    @Override
                    public void onFailure(RegistrationResponse registrationResponse, Exception exception) {
                    }
                };
                PushNotificationTask pushNotificationTask = new PushNotificationTask(Applozic.getInstance(context).getDeviceRegistrationId(), pushNotificationTaskListener, context);
                pushNotificationTask.execute((Void) null);
                buildContactData();
                // starting main MainActivity
                Intent mainActvity = new Intent(context, MainActivity.class);
                startActivity(mainActvity);
                Intent intent = new Intent(context, ConversationActivity.class);
                if (ApplozicClient.getInstance(LoginActivity.this).isContextBasedChat()) {
                    intent.putExtra(ConversationUIService.CONTEXT_BASED_CHAT, true);
                }
                startActivity(intent);
                finish();
            }

            @Override
            public void onFailure(RegistrationResponse registrationResponse, Exception exception) {
                mAuthTask = null;
                showProgress(false);
                mEmailSignInButton.setVisibility(View.VISIBLE);
                AlertDialog alertDialog = new AlertDialog.Builder(LoginActivity.this).create();
                alertDialog.setTitle(getString(R.string.text_alert));
                alertDialog.setMessage(exception.toString());
                alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.ok_alert), new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                if (!isFinishing()) {
                    alertDialog.show();
                }
            }
        };
        User user = new User();
        user.setUserId(userId);
        user.setEmail(email);
        user.setPassword(password);
        user.setDisplayName(displayName);
        user.setContactNumber(phoneNumber);
        user.setAuthenticationTypeId(authenticationType.getValue());
        mAuthTask = new UserLoginTask(user, listener, this);
        mEmailSignInButton.setVisibility(View.INVISIBLE);
        mSpinnerView.setVisibility(View.INVISIBLE);
        mAuthTask.execute((Void) null);
    }
}
Also used : Context(android.content.Context) AlertDialog(android.app.AlertDialog) User(com.applozic.mobicomkit.api.account.user.User) PushNotificationTask(com.applozic.mobicomkit.api.account.user.PushNotificationTask) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) ConversationActivity(com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity) Activity(android.app.Activity) ApplozicSetting(com.applozic.mobicomkit.uiwidgets.ApplozicSetting) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) UserLoginTask(com.applozic.mobicomkit.api.account.user.UserLoginTask) RegistrationResponse(com.applozic.mobicomkit.api.account.register.RegistrationResponse)

Example 2 with PushNotificationTask

use of com.applozic.mobicomkit.api.account.user.PushNotificationTask in project Applozic-Android-SDK by AppLozic.

the class ApplozicBridge method gcmRegister.

public static void gcmRegister(Context context, String pushnotificationId) {
    if (!MobiComUserPreference.getInstance(context).isRegistered()) {
        Log.i("ApplozicBridge", "user is not Registered");
        MobiComUserPreference pref = MobiComUserPreference.getInstance(context);
        if (!TextUtils.isEmpty(pushnotificationId)) {
            pref.setDeviceRegistrationId(pushnotificationId);
        }
        return;
    }
    PushNotificationTask pushNotificationTask = null;
    PushNotificationTask.TaskListener listener = new PushNotificationTask.TaskListener() {

        @Override
        public void onSuccess(RegistrationResponse registrationResponse) {
        }

        @Override
        public void onFailure(RegistrationResponse registrationResponse, Exception exception) {
        }
    };
    pushNotificationTask = new PushNotificationTask(pushnotificationId, listener, context);
    pushNotificationTask.execute((Void) null);
}
Also used : PushNotificationTask(com.applozic.mobicomkit.api.account.user.PushNotificationTask) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) TaskListener(com.applozic.mobicomkit.api.account.user.UserLoginTask.TaskListener) RegistrationResponse(com.applozic.mobicomkit.api.account.register.RegistrationResponse)

Aggregations

RegistrationResponse (com.applozic.mobicomkit.api.account.register.RegistrationResponse)2 PushNotificationTask (com.applozic.mobicomkit.api.account.user.PushNotificationTask)2 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 TextView (android.widget.TextView)1 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)1 User (com.applozic.mobicomkit.api.account.user.User)1 UserLoginTask (com.applozic.mobicomkit.api.account.user.UserLoginTask)1 TaskListener (com.applozic.mobicomkit.api.account.user.UserLoginTask.TaskListener)1 ApplozicSetting (com.applozic.mobicomkit.uiwidgets.ApplozicSetting)1 ConversationActivity (com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity)1 HashMap (java.util.HashMap)1