Search in sources :

Example 6 with RegistrationResponse

use of com.applozic.mobicomkit.api.account.register.RegistrationResponse 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);
    AlTask.execute(pushNotificationTask);
}
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)

Example 7 with RegistrationResponse

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

the class Applozic method connectUser.

// old api >>>
/**
 * Use this method to log-in or register your {@link User}. This must be done before using any other SDK method.
 *
 * <p>Before calling this method, make sure that {@link User#isValidUserId()} returns <i>true</i>.</p>
 *
 * <p>If the user (<code>userId</code>) is not present in the servers, a new
 * one will be created and registered. Otherwise the existing user will be authenticated and logged in.</p>
 *
 * <p><i><b>Note:</b>Check if <code>registrationResponse</code> is non-null and {@link RegistrationResponse#isRegistrationSuccess()} is true to confirm a successful login.</i></p>
 *
 * <p>After a successful login, you'll be able to access:
 * <ul>
 *     <li>{@link MobiComUserPreference#getUserId() your user-id}.</li>
 *     <li>{@link com.applozic.mobicomkit.contact.AppContactService#getContactById(String) your contact object}.</li>
 *     <li>Your messages, contacts, channels and other freshly synced data to your local database for your user.</li>
 * </ul></p>
 *
 * <p>Other users will be able to see your status as "online".</p>
 *
 * <p>Next steps:</p>
 * <ol>
 *     <li>To set up push notifications - {@link #registerForPushNotification(Context, String)}. This is required for receiving messages.</li>
 *     <li>To send your first message - {@link com.applozic.mobicomkit.api.conversation.MessageBuilder}</li>
 * </ol>
 */
public static void connectUser(@NonNull Context context, @NonNull User user, @Nullable AlLoginHandler loginHandler) {
    if (isConnected(context)) {
        RegistrationResponse registrationResponse = new RegistrationResponse();
        registrationResponse.setMessage("User already Logged in");
        Contact contact = new ContactDatabase(context).getContactById(MobiComUserPreference.getInstance(context).getUserId());
        if (contact != null) {
            registrationResponse.setUserId(contact.getUserId());
            registrationResponse.setContactNumber(contact.getContactNumber());
            registrationResponse.setRoleType(contact.getRoleType());
            registrationResponse.setImageLink(contact.getImageURL());
            registrationResponse.setDisplayName(contact.getDisplayName());
            registrationResponse.setStatusMessage(contact.getStatus());
        }
        if (loginHandler != null) {
            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) ContactDatabase(com.applozic.mobicomkit.contact.database.ContactDatabase) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 8 with RegistrationResponse

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

the class Applozic method loginUser.

// deprecated code >>>
/**
 * @deprecated Use {@link Applozic#connectUser(Context, User)}.
 */
@Deprecated
public static void loginUser(Context context, User user, boolean withLoggedInCheck, AlLoginHandler loginHandler) {
    if (withLoggedInCheck && 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)

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