Search in sources :

Example 1 with RegistrationResponse

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

the class Applozic method loginUser.

/**
 * @deprecated Use {@link Applozic#connectUser(Context, User)}.
 */
@Deprecated
public static void loginUser(Context context, User user, AlLoginHandler loginHandler) {
    if (MobiComUserPreference.getInstance(context).isLoggedIn()) {
        RegistrationResponse registrationResponse = new RegistrationResponse();
        registrationResponse.setMessage("User already Logged in");
        loginHandler.onSuccess(registrationResponse, context);
    } else {
        AlTask.execute(new UserLoginTask(user, loginHandler, context));
    }
}
Also used : UserLoginTask(com.applozic.mobicomkit.api.account.user.UserLoginTask) RegistrationResponse(com.applozic.mobicomkit.api.account.register.RegistrationResponse)

Example 2 with RegistrationResponse

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

the class ApplozicBridge method startChatActivity.

/**
 * Starts the chat activity if user is not loggedIn then it will login to applozic server and launch the chat-list
 * else if user is loggedIn then directly opens chat-list
 *
 * @param context
 * @param user    :User object
 */
private static void startChatActivity(Context context, User user) {
    if (!MobiComUserPreference.getInstance(context).isLoggedIn()) {
        TaskListener listener = new TaskListener() {

            @Override
            public void onSuccess(RegistrationResponse registrationResponse, Context context) {
                // Todo: get pushnotification id.
                String pushNotificationId = "";
                gcmRegister(context, pushNotificationId);
                launchChat(context);
            }

            @Override
            public void onFailure(RegistrationResponse registrationResponse, Exception exception) {
            }
        };
        user = user != null ? user : getLoggedInUserInformation();
        AlTask.execute(new UserLoginTask(user, listener, context));
    } else {
        launchChat(context);
    }
}
Also used : Context(android.content.Context) UserLoginTask(com.applozic.mobicomkit.api.account.user.UserLoginTask) TaskListener(com.applozic.mobicomkit.api.account.user.UserLoginTask.TaskListener) RegistrationResponse(com.applozic.mobicomkit.api.account.register.RegistrationResponse)

Example 3 with RegistrationResponse

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

the class FcmListenerService method onNewToken.

@Override
public void onNewToken(@NonNull String registrationId) {
    super.onNewToken(registrationId);
    Log.i(TAG, "Found Registration Id:" + registrationId);
    Applozic.Store.setDeviceRegistrationId(this, registrationId);
    if (MobiComUserPreference.getInstance(this).isRegistered()) {
        try {
            RegistrationResponse registrationResponse = new RegisterUserClientService(this).updatePushNotificationId(registrationId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : RegistrationResponse(com.applozic.mobicomkit.api.account.register.RegistrationResponse) RegisterUserClientService(com.applozic.mobicomkit.api.account.register.RegisterUserClientService)

Example 4 with RegistrationResponse

use of com.applozic.mobicomkit.api.account.register.RegistrationResponse 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
        User user = new User();
        user.setUserId(userId);
        user.setEmail(email);
        user.setPassword(password);
        user.setDisplayName(displayName);
        user.setContactNumber(phoneNumber);
        user.setAuthenticationTypeId(authenticationType.getValue());
        Applozic.connectUser(this, user, new AlLoginHandler() {

            @Override
            public void onSuccess(@NonNull RegistrationResponse registrationResponse, final Context context) {
                // After successful registration with Applozic server the callback will come here
                mAuthTask = null;
                showProgress(false);
                // Basic setting for context based chat enable...
                ApplozicClient.getInstance(context).setContextBasedChat(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);
                buildContactData();
                // Start FCM registration....
                AlTask.execute(new PushNotificationTask(context, Applozic.Store.getDeviceRegistrationId(context), new AlPushNotificationHandler() {

                    @Override
                    public void onSuccess(RegistrationResponse registrationResponse) {
                    }

                    @Override
                    public void onFailure(RegistrationResponse registrationResponse, Exception exception) {
                    }
                }));
                // 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) {
                // If any failure in registration the callback  will come here
                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 == null ? registrationResponse.getMessage() : exception.getMessage());
                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();
                }
            }
        });
        mEmailSignInButton.setVisibility(View.INVISIBLE);
        mSpinnerView.setVisibility(View.INVISIBLE);
    }
}
Also used : Context(android.content.Context) ConversationActivity(com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity) AlertDialog(android.app.AlertDialog) User(com.applozic.mobicomkit.api.account.user.User) PushNotificationTask(com.applozic.mobicomkit.api.account.user.PushNotificationTask) DialogInterface(android.content.DialogInterface) ApplozicSetting(com.applozic.mobicomkit.uiwidgets.ApplozicSetting) Intent(android.content.Intent) AlLoginHandler(com.applozic.mobicomkit.listners.AlLoginHandler) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) OnClickListener(android.view.View.OnClickListener) RegistrationResponse(com.applozic.mobicomkit.api.account.register.RegistrationResponse) Map(java.util.Map) HashMap(java.util.HashMap) AlPushNotificationHandler(com.applozic.mobicomkit.listners.AlPushNotificationHandler)

Example 5 with RegistrationResponse

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

the class FcmInstanceIDListenerService method onTokenRefresh.

@Override
public void onTokenRefresh() {
    super.onTokenRefresh();
    String registrationId = FirebaseInstanceId.getInstance().getToken();
    Log.i(TAG, "Found Registration Id:" + registrationId);
    Applozic.getInstance(this).setDeviceRegistrationId(registrationId);
    if (MobiComUserPreference.getInstance(this).isRegistered()) {
        try {
            RegistrationResponse registrationResponse = new RegisterUserClientService(this).updatePushNotificationId(registrationId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : RegistrationResponse(com.applozic.mobicomkit.api.account.register.RegistrationResponse) RegisterUserClientService(com.applozic.mobicomkit.api.account.register.RegisterUserClientService)

Aggregations

RegistrationResponse (com.applozic.mobicomkit.api.account.register.RegistrationResponse)8 UserLoginTask (com.applozic.mobicomkit.api.account.user.UserLoginTask)4 Context (android.content.Context)2 RegisterUserClientService (com.applozic.mobicomkit.api.account.register.RegisterUserClientService)2 PushNotificationTask (com.applozic.mobicomkit.api.account.user.PushNotificationTask)2 TaskListener (com.applozic.mobicomkit.api.account.user.UserLoginTask.TaskListener)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)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 ContactDatabase (com.applozic.mobicomkit.contact.database.ContactDatabase)1 AlLoginHandler (com.applozic.mobicomkit.listners.AlLoginHandler)1 AlPushNotificationHandler (com.applozic.mobicomkit.listners.AlPushNotificationHandler)1 ApplozicSetting (com.applozic.mobicomkit.uiwidgets.ApplozicSetting)1