livechat / chat-window-android

LiveChat mobile chat window for Android
https://developers.livechatinc.com/mobile/android/
MIT License
23 stars 28 forks source link

Cannot add attachment #42

Closed pateras01 closed 4 years ago

pateras01 commented 4 years ago

If i push button for sending attachment, dialog for select atachment is opened, but atachment is not sent after push button for sending. If we try push button several times and repaet his operation, dialog is not opened. I have to chat close and open once more.

Code in main activity: protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data);

    Object contentCurrent = App.screen.contentGetCurrent();
    if (contentCurrent instanceof HelpOnLineFragment) {
        HelpOnLineFragment fragment = (HelpOnLineFragment)contentCurrent;
        fragment.chatWindow.onActivityResult(requestCode, resultCode, data);
    }

}

Code in my fragment: public class HelpOnLineFragment extends AppFragment implements ChatWindowView.ChatWindowEventsListener {

public ChatWindowView chatWindow;
private ChatWindowConfiguration configuration;

@Override public void onCreateView() {
    chatWindow = findView(R.id.chatWindow);
    chatRun();
}

private void chatRun() {
    String licenceNumber = Const.ONLINE_HELP_LICENSE_ID;
    String groupId = "5"; 
    String visitorName = App.server.getClientName();
    String visitorEmail = App.data.clientInfo.email;

    configuration = new ChatWindowConfiguration(licenceNumber, groupId, visitorName, visitorEmail, null);

    chatWindow.setUpWindow(configuration);
    chatWindow.setUpListener(this);
    chatWindow.initialize();
    chatWindow.showChatWindow();
}

@Override public void onChatWindowVisibilityChanged(boolean visible) {
    if (!visible) {
        getActivity().onBackPressed();
    }
}

@Override public void onNewMessage(NewMessageModel message, boolean windowVisible) {
}

@Override public void onStartFilePickerActivity(Intent intent, int requestCode) {
    startActivityForResult(intent, requestCode);
}

@Override public boolean onError(ChatWindowErrorType errorType, int errorCode, String errorDescription) {
    return false;
}

@Override public boolean handleUri(Uri uri) {
    return false;
}

}

nomyzs commented 4 years ago

Hello there @pateras01

I've been trying to replicate your issue, but it's hard without knowing the details of your implementation.

I believe attachment should be uploaded straight to the conversation after you select it in another app. That leads me to believe chatwindow never receives the callback.

Here are some pointers on what I think is worth investigating:

  1. Have you considered overriding onActivityResult in your Fragment instead of listening for results in MainActivity? Is that possible to check with your current implementation?
  2. Are you sure the HelpOnLineFragment instance is the current one and has not been recreated when switching between the apps?
  3. Have you considered using ChatWindowActivity or ChatWindowFragment?

If any of the tips above will not bring you to a solution, I would need more details to be able to recreate your problem. Ideally a minimum reproducible code sample. If that is not possible, could you explain how App.screen.contentGetCurrent(); works and what Fragment AppFragment extends from?

pateras01 commented 4 years ago

Hi, I am implement ChatWindowView in own Fragment. Problem is resolved. Code in onActivityResult function must be in Fragment, it does not work in Activity.