Search in sources :

Example 1 with AlLogoutHandler

use of com.applozic.mobicomkit.listners.AlLogoutHandler in project Applozic-Android-SDK by AppLozic.

the class MainActivity method onNavigationDrawerItemSelected.

@Override
public void onNavigationDrawerItemSelected(int position) {
    if (position == 1) {
        Intent intent = new Intent(this, ConversationActivity.class);
        if (ApplozicClient.getInstance(this).isContextBasedChat()) {
            intent.putExtra(ConversationUIService.CONTEXT_BASED_CHAT, true);
        }
        startActivity(intent);
        return;
    }
    /*
        if (position == 1) {
            ConversationFragment conversationFragment = new ConversationFragment();
            Contact contact = new Contact(this, "mobicomkit");
            mTitle = getString(R.string.user_id);
            addFragment(this, conversationFragment, "conversationFragment");
            conversationFragment.loadConversation(contact);
            return;

        }*/
    if (position == 0) {
        mTitle = getString(R.string.ecommerce);
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.container, EcommerceFragment.newInstance("", "")).commit();
        return;
    }
    if (position == 2) {
        Applozic.logoutUser(this, new AlLogoutHandler() {

            @Override
            public void onSuccess(Context context) {
                Toast.makeText(getBaseContext(), getBaseContext().getString(R.string.log_out_successful), Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(context, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(intent);
                finish();
            }

            @Override
            public void onFailure(Exception exception) {
                AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.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();
                }
            }
        });
    }
    if (position == 3) {
        Map<String, String> messageMetaData = new HashMap<>();
        messageMetaData.put(Message.MetaDataType.KEY.getValue(), Message.MetaDataType.HIDDEN.getValue());
        Message message = new Message();
        MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(MainActivity.this);
        message.setContactIds("android");
        message.setTo("android");
        message.setContentType(Message.ContentType.CUSTOM.getValue());
        message.setMessage("this is meta data hidden");
        message.setMetadata(messageMetaData);
        message.setStoreOnDevice(Boolean.TRUE);
        message.setRead(Boolean.TRUE);
        message.setCreatedAtTime(System.currentTimeMillis() + userPreferences.getDeviceTimeOffset());
        message.setSendToDevice(Boolean.FALSE);
        message.setType(Message.MessageType.MT_OUTBOX.getValue());
        message.setDeviceKeyString(userPreferences.getDeviceKeyString());
        message.setSource(Message.Source.MT_MOBILE_APP.getValue());
        new MobiComConversationService(MainActivity.this).sendMessage(message);
    }
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.container, PlaceholderFragment.newInstance(position + 1)).commit();
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) Message(com.applozic.mobicomkit.api.conversation.Message) DialogInterface(android.content.DialogInterface) HashMap(java.util.HashMap) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Intent(android.content.Intent) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) FragmentManager(androidx.fragment.app.FragmentManager) AlLogoutHandler(com.applozic.mobicomkit.listners.AlLogoutHandler)

Example 2 with AlLogoutHandler

use of com.applozic.mobicomkit.listners.AlLogoutHandler 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 3 with AlLogoutHandler

use of com.applozic.mobicomkit.listners.AlLogoutHandler in project Applozic-Android-SDK by AppLozic.

the class ConversationActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    // noinspection SimplifiableIfStatement
    if (id == R.id.start_new) {
        if (!TextUtils.isEmpty(contactsGroupId)) {
            if (Utils.isInternetAvailable(this)) {
                conversationUIService.startContactActivityForResult();
            } else {
                Intent intent = new Intent(this, MobiComKitPeopleActivity.class);
                ChannelDatabaseService channelDatabaseService = ChannelDatabaseService.getInstance(this);
                String[] userIdArray = channelDatabaseService.getChannelMemberByName(contactsGroupId, null);
                if (userIdArray != null) {
                    conversationUIService.startContactActivityForResult(intent, null, null, userIdArray);
                }
            }
        } else {
            conversationUIService.startContactActivityForResult();
        }
    } else if (id == R.id.conversations) {
        Intent intent = new Intent(this, ChannelCreateActivity.class);
        intent.putExtra(ChannelCreateActivity.GROUP_TYPE, Channel.GroupType.PUBLIC.getValue().intValue());
        startActivity(intent);
    } else if (id == R.id.broadcast) {
        Intent intent = new Intent(this, ContactSelectionActivity.class);
        intent.putExtra(ContactSelectionActivity.GROUP_TYPE, Channel.GroupType.BROADCAST.getValue().intValue());
        startActivity(intent);
    } else if (id == R.id.refresh) {
        Toast.makeText(this, getString(R.string.info_message_sync), Toast.LENGTH_LONG).show();
        AlTask.execute(new SyncMessagesAsyncTask(this));
    } else if (id == R.id.shareOptions) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setAction(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, inviteMessage);
        startActivity(Intent.createChooser(intent, "Share Via"));
        return super.onOptionsItemSelected(item);
    } else if (id == R.id.applozicUserProfile) {
        profilefragment.setApplozicPermissions(applozicPermission);
        addFragment(this, profilefragment, ProfileFragment.ProfileFragmentTag);
    } else if (id == R.id.logout) {
        if (!TextUtils.isEmpty(alCustomizationSettings.getLogoutPackage())) {
            Applozic.logoutUser(ConversationActivity.this, new AlLogoutHandler() {

                @Override
                public void onSuccess(Context context) {
                    try {
                        Class loginActivity = Class.forName(alCustomizationSettings.getLogoutPackage().trim());
                        if (loginActivity != null) {
                            Toast.makeText(getBaseContext(), getString(R.string.user_logout_info), Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(ConversationActivity.this, loginActivity);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                            startActivity(intent);
                            finish();
                        }
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onFailure(Exception exception) {
                }
            });
        }
    } else if (id == R.id.sendTextLogs) {
        try {
            Intent emailIntent = new Intent(Intent.ACTION_SEND);
            emailIntent.setType("vnd.android.cursor.dir/email");
            String[] receivers = { ALSpecificSettings.getInstance(this).getSupportEmailId() };
            emailIntent.putExtra(Intent.EXTRA_EMAIL, receivers);
            emailIntent.putExtra(Intent.EXTRA_STREAM, Utils.getTextLogFileUri(this));
            emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name) + " " + getString(R.string.log_email_subject));
            startActivity(Intent.createChooser(emailIntent, getString(R.string.select_email_app_chooser_title)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return false;
}
Also used : Context(android.content.Context) Intent(android.content.Intent) ChannelDatabaseService(com.applozic.mobicomkit.channel.database.ChannelDatabaseService) SuppressLint(android.annotation.SuppressLint) AlLogoutHandler(com.applozic.mobicomkit.listners.AlLogoutHandler)

Aggregations

Context (android.content.Context)3 Intent (android.content.Intent)3 AlLogoutHandler (com.applozic.mobicomkit.listners.AlLogoutHandler)3 DialogInterface (android.content.DialogInterface)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 ObjectAnimator (android.animation.ObjectAnimator)1 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 View (android.view.View)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Toolbar (androidx.appcompat.widget.Toolbar)1 FragmentManager (androidx.fragment.app.FragmentManager)1 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)1 Message (com.applozic.mobicomkit.api.conversation.Message)1 MobiComConversationService (com.applozic.mobicomkit.api.conversation.MobiComConversationService)1 ChannelDatabaseService (com.applozic.mobicomkit.channel.database.ChannelDatabaseService)1 AppContactService (com.applozic.mobicomkit.contact.AppContactService)1 ImageLoader (com.applozic.mobicommons.commons.image.ImageLoader)1