Search in sources :

Example 16 with AppContactService

use of com.applozic.mobicomkit.contact.AppContactService in project Applozic-Android-SDK by AppLozic.

the class ProfileFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View view = inflater.inflate(R.layout.al_activity_profile, container, false);
    img_profile = (ImageView) view.findViewById(R.id.applozic_user_profile);
    statusEdit = (ImageView) view.findViewById(R.id.status_edit_btn);
    displayNameEdit = (ImageView) view.findViewById(R.id.displayName_edit_btn);
    contactEdit = (ImageView) view.findViewById(R.id.contact_edit_btn);
    selectImageProfileIcon = (ImageView) view.findViewById(R.id.applozic_user_profile_camera);
    logoutbtn = (Button) view.findViewById(R.id.applozic_profile_logout);
    displayNameText = (TextView) view.findViewById(R.id.applozic_profile_displayname);
    statusText = (TextView) view.findViewById(R.id.applozic_profile_status);
    contactNumberText = (TextView) view.findViewById(R.id.applozic_profile_contact);
    applozicProfileContactLayout = (RelativeLayout) view.findViewById(R.id.applozic_profile_contact_section_rl);
    setupDeviderView(view, R.id.applozic_profile_section_rl, R.id.applozic_profile_verticalline_rl);
    setupDeviderView(view, R.id.applozic_datausage_section_rl, R.id.applozic_datausage_verticalline_rl);
    setupDeviderView(view, R.id.applozic_notification_section_rl, R.id.applozic_notification_verticalline_rl);
    Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.my_toolbar);
    toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
    toolbarTitle.setText(R.string.applozic_user_profile_heading);
    ObjectAnimator animation = ObjectAnimator.ofFloat(toolbarTitle, "translationY", 0f);
    animation.setDuration(10);
    animation.start();
    toolbar.setClickable(false);
    // toolbar.setTitle(getString(R.string.applozic_user_profile_heading));
    // toolbar.setSubtitle("");
    setHasOptionsMenu(true);
    contactService = new AppContactService(getActivity());
    userContact = contactService.getContactById(MobiComUserPreference.getInstance(getActivity()).getUserId());
    if (!TextUtils.isEmpty(userContact.getDisplayName())) {
        displayNameText.setText(userContact.getDisplayName());
    }
    if (!TextUtils.isEmpty(userContact.getStatus())) {
        statusText.setText(userContact.getStatus());
    }
    if (!TextUtils.isEmpty(userContact.getContactNumber())) {
        contactNumberText.setText(userContact.getContactNumber());
    } else {
        applozicProfileContactLayout.setVisibility(View.GONE);
    }
    final Context context = getActivity().getApplicationContext();
    mImageLoader = new ImageLoader(context, img_profile.getHeight()) {

        @Override
        protected Bitmap processBitmap(Object data) {
            return contactService.downloadContactImage(context, (Contact) data);
        }
    };
    // For profile image
    selectImageProfileIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            processPhotoOption();
        }
    });
    logoutbtn.setVisibility(View.GONE);
    logoutbtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Applozic.logoutUser(getContext(), new AlLogoutHandler() {

                @Override
                public void onSuccess(Context context) {
                    try {
                        final String logoutActivity = ApplozicSetting.getInstance(getActivity()).getActivityCallback(ApplozicSetting.RequestCode.USER_LOOUT);
                        if (logoutActivity != null && getActivity() != null) {
                            Intent intent = new Intent(getActivity(), Class.forName(logoutActivity));
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                            startActivity(intent);
                            getActivity().finish();
                        }
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onFailure(Exception exception) {
                }
            });
        }
    });
    statusEdit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setTitle(R.string.status);
            final EditText input = new EditText(getContext());
            input.setInputType(InputType.TYPE_CLASS_TEXT);
            builder.setView(input);
            builder.setPositiveButton(R.string.ok_alert, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    changedStatusString = input.getText().toString();
                    Contact contact = new Contact();
                    contact.setStatus(changedStatusString);
                    AlTask.execute(new ProfilePictureUpload(contact, getActivity(), null, statusText, null));
                }
            });
            builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            builder.show();
        }
    });
    displayNameEdit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setTitle(getString(R.string.display_name));
            final EditText input = new EditText(getContext());
            input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
            builder.setView(input);
            builder.setPositiveButton(getString(R.string.ok_alert), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    displayName = input.getText().toString();
                    if (!displayName.trim().isEmpty() && !TextUtils.isEmpty(displayName)) {
                        Contact contact = new Contact();
                        contact.setFullName(displayName);
                        AlTask.execute(new ProfilePictureUpload(contact, getActivity(), displayNameText, null, null));
                    }
                }
            });
            builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            builder.show();
        }
    });
    contactEdit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setTitle(getString(R.string.profile_contact));
            final EditText input = new EditText(getContext());
            input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_PHONE);
            builder.setView(input);
            builder.setPositiveButton(getString(R.string.ok_alert), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    contactNumber = input.getText().toString();
                    if (!contactNumber.trim().isEmpty() && !TextUtils.isEmpty(contactNumber)) {
                        Contact contact = new Contact();
                        contact.setContactNumber(contactNumber);
                        AlTask.execute(new ProfilePictureUpload(contact, getActivity(), null, null, contactNumberText));
                    }
                }
            });
            builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            builder.show();
        }
    });
    mImageLoader.setImageFadeIn(false);
    mImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_180_holo_light);
    mImageLoader.loadImage(userContact, img_profile);
    return view;
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) EditText(android.widget.EditText) AppContactService(com.applozic.mobicomkit.contact.AppContactService) DialogInterface(android.content.DialogInterface) ObjectAnimator(android.animation.ObjectAnimator) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Contact(com.applozic.mobicommons.people.contact.Contact) Bitmap(android.graphics.Bitmap) AlLogoutHandler(com.applozic.mobicomkit.listners.AlLogoutHandler) ImageLoader(com.applozic.mobicommons.commons.image.ImageLoader) Toolbar(androidx.appcompat.widget.Toolbar)

Example 17 with AppContactService

use of com.applozic.mobicomkit.contact.AppContactService in project Applozic-Android-SDK by AppLozic.

the class MobiComQuickConversationFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String jsonString = FileUtils.loadSettingsJsonFile(ApplozicService.getContext(getContext()));
    if (!TextUtils.isEmpty(jsonString)) {
        alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
    } else {
        alCustomizationSettings = new AlCustomizationSettings();
    }
    syncCallService = SyncCallService.getInstance(getActivity());
    conversationUIService = new ConversationUIService(getActivity());
    baseContactService = new AppContactService(getActivity());
    messageDatabaseService = new MessageDatabaseService(getActivity());
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            MobiComUserPreference.getInstance(getActivity()).setDeviceTimeOffset(DateUtils.getTimeDiffFromUtc());
        }
    });
    thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    setHasOptionsMenu(true);
    BroadcastService.lastIndexForChats = 0;
}
Also used : AlCustomizationSettings(com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings) ConversationUIService(com.applozic.mobicomkit.uiwidgets.conversation.ConversationUIService) AppContactService(com.applozic.mobicomkit.contact.AppContactService) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)

Example 18 with AppContactService

use of com.applozic.mobicomkit.contact.AppContactService in project Applozic-Android-SDK by AppLozic.

the class ChannelFragment method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    inviteMessage = Utils.getMetaDataValue(getActivity().getApplicationContext(), SHARE_TEXT);
    baseContactService = new AppContactService(getActivity());
    mAdapter = new ChannelAdapter(getActivity().getApplicationContext());
    if (savedInstanceState != null) {
        mSearchTerm = savedInstanceState.getString(SearchManager.QUERY);
    }
    final Context context = getActivity().getApplicationContext();
    mChannelImageLoader = new ImageLoader(context, getListPreferredItemHeight()) {

        @Override
        protected Bitmap processBitmap(Object data) {
            return baseContactService.downloadGroupImage(context, (Channel) data);
        }
    };
    // Set a placeholder loading image for the image loader
    mChannelImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
    // Add a cache to the image loader
    mChannelImageLoader.addImageCache(getActivity().getSupportFragmentManager(), 0.1f);
    mChannelImageLoader.setImageFadeIn(false);
}
Also used : Context(android.content.Context) Bitmap(android.graphics.Bitmap) AppContactService(com.applozic.mobicomkit.contact.AppContactService) Channel(com.applozic.mobicommons.people.channel.Channel) ImageLoader(com.applozic.mobicommons.commons.image.ImageLoader)

Example 19 with AppContactService

use of com.applozic.mobicomkit.contact.AppContactService in project Applozic-Android-SDK by AppLozic.

the class AlTypingIndicator method createView.

/**
 * This method is always called whenever the typing status change is received from the subscribed userId or Group
 * Be careful to instantiate your views here.
 */
public void createView() {
    Contact contact = new AppContactService(getContext()).getContactById(typerUserId);
    removeAllViews();
    if (typingText == null) {
        typingText = new TextView(getContext());
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        typingText.setLayoutParams(params);
        typingText.setTextSize(14);
        typingText.setTextColor(getContext().getResources().getColor(R.color.apploizc_black_color));
    }
    addView(typingText);
    if (isTyping) {
        typingText.setText((contact != null ? contact.getDisplayName() : "") + " is Typing...");
    } else {
        typingText.setText((contact != null ? contact.getDisplayName() : "") + " is not Typing...");
    }
}
Also used : AppContactService(com.applozic.mobicomkit.contact.AppContactService) TextView(android.widget.TextView) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 20 with AppContactService

use of com.applozic.mobicomkit.contact.AppContactService in project Applozic-Android-SDK by AppLozic.

the class RegisterUserClientService method createAccount.

/**
 * This is an internal method. Use {@link Applozic#connectUser(Context, User, AlLoginHandler)}.
 *
 * <p>Registers(or logs in) a {@link User} to the Applozic servers. It also initializes the SDK for that user.</p>
 *
 * @param user the user object to register/authenticate
 * @return the {@link RegistrationResponse}, {@link RegistrationResponse#isRegistrationSuccess()} will be true in case of a successful login/register. otherwise {@link RegistrationResponse#getMessage()} will have the error message
 * @throws Exception in case of empty or invalid user-id (see {@link User#isValidUserId()}, and connection errors
 */
@NonNull
public RegistrationResponse createAccount(@NonNull User user) throws Exception {
    if (user.getDeviceType() == null) {
        user.setDeviceType(Short.valueOf("1"));
    }
    user.setPrefContactAPI(Short.valueOf("2"));
    user.setTimezone(TimeZone.getDefault().getID());
    user.setEnableEncryption(user.isEnableEncryption());
    if (!TextUtils.isEmpty(user.getAlBaseUrl())) {
        ALSpecificSettings.getInstance(context).setAlBaseUrl(user.getAlBaseUrl());
    }
    if (!TextUtils.isEmpty(user.getKmBaseUrl())) {
        ALSpecificSettings.getInstance(context).setKmBaseUrl(user.getKmBaseUrl());
    }
    if (TextUtils.isEmpty(user.getUserId())) {
        throw new ApplozicException("userId cannot be empty");
    }
    if (!user.isValidUserId()) {
        throw new ApplozicException("Invalid userId. Spacing and set of special characters ^!$%&*:(), are not accepted. \nOnly english language characters are accepted");
    }
    MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
    Gson gson = new Gson();
    user.setAppVersionCode(MOBICOMKIT_VERSION_CODE);
    user.setApplicationId(getApplicationKey(context));
    user.setRegistrationId(mobiComUserPreference.getDeviceRegistrationId());
    if (getAppModuleName(context) != null) {
        user.setAppModuleName(getAppModuleName(context));
    }
    Utils.printLog(context, TAG, "Net status" + Utils.isInternetAvailable(context.getApplicationContext()));
    if (!Utils.isInternetAvailable(context.getApplicationContext())) {
        throw new ConnectException("No Internet Connection");
    }
    HttpRequestUtils.isRefreshTokenInProgress = true;
    Utils.printLog(context, TAG, "Registration json " + gson.toJson(user));
    String response = httpRequestUtils.postJsonToServer(getCreateAccountUrl(), gson.toJson(user));
    Utils.printLog(context, TAG, "Registration response is: " + response);
    if (TextUtils.isEmpty(response) || response.contains("<html")) {
        throw new Exception("503 Service Unavailable");
    }
    final RegistrationResponse registrationResponse = gson.fromJson(response, RegistrationResponse.class);
    if (registrationResponse.isRegistrationSuccess()) {
        Utils.printLog(context, "Registration response ", "is " + registrationResponse);
        if (registrationResponse.getNotificationResponse() != null) {
            Utils.printLog(context, "Registration response ", "" + registrationResponse.getNotificationResponse());
        }
        JWT.parseToken(context, registrationResponse.getAuthToken());
        mobiComUserPreference.setEncryptionKey(registrationResponse.getEncryptionKey());
        mobiComUserPreference.enableEncryption(user.isEnableEncryption());
        mobiComUserPreference.setCountryCode(user.getCountryCode());
        mobiComUserPreference.setUserId(user.getUserId());
        mobiComUserPreference.setContactNumber(user.getContactNumber());
        mobiComUserPreference.setEmailVerified(user.isEmailVerified());
        mobiComUserPreference.setDisplayName(user.getDisplayName());
        mobiComUserPreference.setMqttBrokerUrl(registrationResponse.getBrokerUrl());
        mobiComUserPreference.setDeviceKeyString(registrationResponse.getDeviceKey());
        mobiComUserPreference.setEmailIdValue(user.getEmail());
        mobiComUserPreference.setImageLink(user.getImageLink());
        mobiComUserPreference.setSuUserKeyString(registrationResponse.getUserKey());
        mobiComUserPreference.setLastSyncTimeForMetadataUpdate(String.valueOf(registrationResponse.getCurrentTimeStamp()));
        mobiComUserPreference.setLastSyncTime(String.valueOf(registrationResponse.getCurrentTimeStamp()));
        mobiComUserPreference.setLastSeenAtSyncTime(String.valueOf(registrationResponse.getCurrentTimeStamp()));
        mobiComUserPreference.setChannelSyncTime(String.valueOf(registrationResponse.getCurrentTimeStamp()));
        mobiComUserPreference.setUserBlockSyncTime("10000");
        mobiComUserPreference.setUserDeactivated(registrationResponse.isDeactivate());
        if (registrationResponse.getNotificationAfter() != null) {
            ALSpecificSettings.getInstance(context).setNotificationAfterTime(registrationResponse.getNotificationAfter());
        }
        ApplozicClient.getInstance(context).skipDeletedGroups(user.isSkipDeletedGroups()).hideActionMessages(user.isHideActionMessages());
        if (!TextUtils.isEmpty(registrationResponse.getUserEncryptionKey())) {
            mobiComUserPreference.setUserEncryptionKey(registrationResponse.getUserEncryptionKey());
        }
        mobiComUserPreference.setPassword(user.getPassword());
        mobiComUserPreference.setPricingPackage(registrationResponse.getPricingPackage());
        mobiComUserPreference.setAuthenticationType(String.valueOf(user.getAuthenticationTypeId()));
        if (registrationResponse.getRoleType() != null) {
            mobiComUserPreference.setUserRoleType(registrationResponse.getRoleType());
        }
        if (user.getUserTypeId() != null) {
            mobiComUserPreference.setUserTypeId(String.valueOf(user.getUserTypeId()));
        }
        if (!TextUtils.isEmpty(user.getNotificationSoundFilePath())) {
            Applozic.getInstance(context).setCustomNotificationSound(user.getNotificationSoundFilePath());
        }
        Contact contact = new Contact();
        contact.setUserId(user.getUserId());
        contact.setFullName(registrationResponse.getDisplayName());
        contact.setImageURL(registrationResponse.getImageLink());
        contact.setContactNumber(registrationResponse.getContactNumber());
        contact.setMetadata(registrationResponse.getMetadata());
        if (user.getUserTypeId() != null) {
            contact.setUserTypeId(user.getUserTypeId());
        }
        contact.setRoleType(user.getRoleType());
        contact.setStatus(registrationResponse.getStatusMessage());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            Applozic.Store.setNotificationChannelVersion(context, NotificationChannels.NOTIFICATION_CHANNEL_VERSION - 1);
            new NotificationChannels(context).prepareNotificationChannels();
        }
        ApplozicClient.getInstance(context).setChatDisabled(contact.isChatForUserDisabled());
        new AppContactService(context).upsert(contact);
        ConversationWorker.enqueueWorkSync(context);
        ConversationWorker.enqueueWorkMutedUserListSync(context);
        ApplozicMqttWorker.enqueueWorkConnectPublish(context);
    }
    return registrationResponse;
}
Also used : NotificationChannels(com.applozic.mobicomkit.api.notification.NotificationChannels) AppContactService(com.applozic.mobicomkit.contact.AppContactService) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Gson(com.google.gson.Gson) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) ConnectException(java.net.ConnectException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) ConnectException(java.net.ConnectException) Contact(com.applozic.mobicommons.people.contact.Contact) NonNull(androidx.annotation.NonNull)

Aggregations

AppContactService (com.applozic.mobicomkit.contact.AppContactService)24 Contact (com.applozic.mobicommons.people.contact.Contact)17 Context (android.content.Context)7 Bitmap (android.graphics.Bitmap)7 ImageLoader (com.applozic.mobicommons.commons.image.ImageLoader)7 AlCustomizationSettings (com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings)5 SpannableString (android.text.SpannableString)4 MessageDatabaseService (com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)4 Channel (com.applozic.mobicommons.people.channel.Channel)4 ArrayList (java.util.ArrayList)4 Intent (android.content.Intent)3 TextView (android.widget.TextView)3 NonNull (androidx.annotation.NonNull)3 Toolbar (androidx.appcompat.widget.Toolbar)3 Message (com.applozic.mobicomkit.api.conversation.Message)3 ChannelDatabaseService (com.applozic.mobicomkit.channel.database.ChannelDatabaseService)3 ProgressDialog (android.app.ProgressDialog)2 IntentFilter (android.content.IntentFilter)2 View (android.view.View)2 ImageView (android.widget.ImageView)2