ConnectyCube / android-messenger-app

Chat and voice / video calling app using ConnectyCube
https://connectycube.com
Apache License 2.0
51 stars 23 forks source link

Empty screen ChatMessageActivity when open by new way #61

Closed nguyenbahung94 closed 4 years ago

nguyenbahung94 commented 4 years ago

Hi, I want to login by these steps and base on your example.

  1. I replace method login in LoginActivity by this:

    var user1 = ConnectycubeUser() user1.login = "hung1" user1.password = "password1"

    ConnectycubeUsers.signIn(user1).performAsync(object : EntityCallback<ConnectycubeUser> {
        override fun onSuccess(p0: ConnectycubeUser?, p1: Bundle?) {
            p0!!.password = user1.password
            Toast.makeText(this@LoginActivity, "user 1 login success", Toast.LENGTH_SHORT)
                .show()
            SharedPreferencesManager.getInstance(this@LoginActivity).saveCurrentUser(p0!!)
            createChatPrivate(1479875)
        }
    
        override fun onError(p0: ResponseException?) {
            Toast.makeText(this@LoginActivity, p0?.message.toString(), Toast.LENGTH_SHORT)
                .show()
        }
    
    })

////////////////////// private fun createChatPrivate(id: Int) { val occupantIds = ArrayList() occupantIds.add(id)

    val dialog = ConnectycubeChatDialog().apply {
        type = ConnectycubeDialogType.PRIVATE
        setOccupantsIds(occupantIds)
    }

    ConnectycubeRestChatService.createChatDialog(dialog)
        .performAsync(object : EntityCallback<ConnectycubeChatDialog> {
            override fun onSuccess(createdDialog: ConnectycubeChatDialog, params: Bundle) {
                startChatActivity(createdDialog)
            }

            override fun onError(exception: ResponseException) {

            }
        })
}

////////// private fun startChatActivity(chat: ConnectycubeChatDialog) { val intent = Intent(this@LoginActivity, ChatMessageActivity::class.java) intent.putExtra(EXTRA_CHAT, chat) startActivity(intent) }

  1. after login success I will create a private chat and then open ChatMessageActivity . then I get issue empty screen with a message "Something went wrong, try again later"

You should uninstall the app before test this. I got an issue for a few days and I hope you can help me fix this. Thanks,

TatankaConCube commented 4 years ago

Please provide full log from logcat and add more information on which step you get this error (login to the chat or load messages or another ways).

nguyenbahung94 commented 4 years ago

Please provide full log from logcat and add more information on which step you get this error (login to the chat or load messages or another ways).

Sorry about that 1.I have an issue at screen load messages. in class ChatMessageListViewModel. it always return null .

fun getChatDialog(dialogId: String = this.dialogId): LiveData<Resource> { val result = MediatorLiveData<Resource>() result.value = Resource.loading(null)

    val source = chatRepository.getChat(dialogId)
    result.addSource(source) { chatDialog ->

        if (chatDialog == null) {
            result.value = Resource.error(
                getApplication<Application>().getString(R.string.something_went_wrong_try_again_later),
                null
            )
        } else {
            result.value = Resource.success(chatDialog)
        }
        result.removeSource(source)
    }
    return result
}

2.If in screen ChatMessageActivity I type some characters and press send the app will be crash.

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.connectycube.messenger, PID: 19486 java.lang.IllegalStateException: Could not execute method for android:onClick at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:402) at android.view.View.performClick(View.java:7161) at android.view.View.performClickInternal(View.java:7138) at android.view.View.access$3500(View.java:811) at android.view.View$PerformClick.run(View.java:27419) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:224) at android.app.ActivityThread.main(ActivityThread.java:7520) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397) at android.view.View.performClick(View.java:7161)  at android.view.View.performClickInternal(View.java:7138)  at android.view.View.access$3500(View.java:811)  at android.view.View$PerformClick.run(View.java:27419)  at android.os.Handler.handleCallback(Handler.java:883)  at android.os.Handler.dispatchMessage(Handler.java:100)  at android.os.Looper.loop(Looper.java:224)  at android.app.ActivityThread.main(ActivityThread.java:7520)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)  Caused by: kotlin.UninitializedPropertyAccessException: lateinit property modelMessageSender has not been initialized at com.connectycube.messenger.ChatMessageActivity.sendChatMessage(ChatMessageActivity.kt:480) at com.connectycube.messenger.ChatMessageActivity.onSendChatClick(ChatMessageActivity.kt:450) at java.lang.reflect.Method.invoke(Native Method)  at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)  at android.view.View.performClick(View.java:7161)  at android.view.View.performClickInternal(View.java:7138)  at android.view.View.access$3500(View.java:811)  at android.view.View$PerformClick.run(View.java:27419)  at android.os.Handler.handleCallback(Handler.java:883)  at android.os.Handler.dispatchMessage(Handler.java:100)  at android.os.Looper.loop(Looper.java:224)  at android.app.ActivityThread.main(ActivityThread.java:7520)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)  E/MQSEventManagerDelegate: failed to get MQSService.

You can test this case by these information :

private val applicationID = "2631"
private val authKey = "dSmHvdrdgZstryr"
private val authSecret = "jtnyXeZABwgRVR3"
private val accountKey = "wsSEhzAJEGkL66N4mBiF"

activity_login.txt LoginActivity.txt

TatankaConCube commented 4 years ago

in logs I found next line 'Caused by: kotlin.UninitializedPropertyAccessException: lateinit property modelMessageSender has not been initialized'. Please check if you initialise field modelMessageSender in your ChatMessageActivity class before send message.

nguyenbahung94 commented 4 years ago

in logs I found next line 'Caused by: kotlin.UninitializedPropertyAccessException: lateinit property modelMessageSender has not been initialized'. Please check if you initialise field modelMessageSender in your ChatMessageActivity class before send message.

1, I see, But I want to know why the input when start ChatMessageActivity is an instance of ConnectycubeChatDialog, then I pass that object but the code did not work well as your example.

  1. There are two ways to start ChatMessageActivity
    • The first case is I click on the item of screen ChatDialogActivity then open ChatMessageActivity. it's oke, the message synchronized.
    • The second case I create an instance of ConnectycubeChatDialog then pass it into ChatMessageActivity. it's not work well, the message not synchronizes. I still receive the message but it does not have two icons check blue at the bottom of the message.

How I can fix this? I want to use it to make a real app. I really need solution for these case, Could you answer me soon?

TatankaConCube commented 4 years ago

We need FULL log to investigate behavoir of your app logic. I asked this information in my previous comments, but you provided only stacktrace of error. From provided information we can't understand did you send message or not, did sender receive message status package or not, etc. I think this issue related with your new logic, but without asked information we can't help you.

nguyenbahung94 commented 4 years ago

We need FULL log to investigate behavoir of your app logic. I asked this information in my previous comments, but you provided only stacktrace of error. From provided information we can't understand did you send message or not, did sender receive message status package or not, etc. I think this issue related with your new logic, but without asked information we can't help you.

Can you check out this link: https://drive.google.com/file/d/1LdRHn5XIglWWiCncCi9bYMQSa-V8MUBS/view?usp=sharing Please download the project and run, When you login with different user (I already set two user in the project) and chat you will understand. Thank you for your response to me soon.

TatankaConCube commented 4 years ago

today I built your app and tested. After first start of app behavior looks like normal, but when I clicked back button I receive behavoir like you described before. After fast review your code I found next part

        ConnectycubeRestChatService.createChatDialog(dialog)
            .performAsync(object : EntityCallback<ConnectycubeChatDialog> {
                override fun onSuccess(createdDialog: ConnectycubeChatDialog, params: Bundle) {
                    // startChatActivity(createdDialog)
                    chatDialogListViewModel.createNewChatDialog(createdDialog)

why you call chatDialogListViewModel.createNewChatDialog in success block of request ConnectycubeRestChatService.createChatDialog? As result you call same request again, because method chatDialogListViewModel.createNewChatDialog calls ConnectycubeRestChatService.createChatDialog inside.

If you see logs, you will found new request for dialog creation with next parameters:

        name=null
        occupants_ids=1479801,1479875
        type=3

As result you get new dialog with name 'null'. Then you asked messages for this dialog and receive empty list, it is expected behavior, because you don't have any messages in new dialog.

Please review your code and fix not clear behavior of your app .

nguyenbahung94 commented 4 years ago

today I built your app and tested. After first start of app behavior looks like normal, but when I clicked back button I receive behavoir like you described before. After fast review your code I found next part

        ConnectycubeRestChatService.createChatDialog(dialog)
            .performAsync(object : EntityCallback<ConnectycubeChatDialog> {
                override fun onSuccess(createdDialog: ConnectycubeChatDialog, params: Bundle) {
                    // startChatActivity(createdDialog)
                    chatDialogListViewModel.createNewChatDialog(createdDialog)

why you call chatDialogListViewModel.createNewChatDialog in success block of request ConnectycubeRestChatService.createChatDialog? As result you call same request again, because method chatDialogListViewModel.createNewChatDialog calls ConnectycubeRestChatService.createChatDialog inside.

If you see logs, you will found new request for dialog creation with next parameters:

        name=null
        occupants_ids=1479801,1479875
        type=3

As result you get new dialog with name 'null'. Then you asked messages for this dialog and receive empty list, it is expected behavior, because you don't have any messages in new dialog.

Please review your code and fix not clear behavior of your app .

I was my bad I'm so sorry about that. I was check and write new code to make it more clear about my issue. Please help me check out this link : https://drive.google.com/file/d/1z8MIiRLtEZKgXOhGop3o_tDvM10VjHGS/view?usp=sharing

When you run a project you will get a message "Error while loading users" But don't pay attention to that. The issue I was mentioned here is the message I sent it not synchronized. When I reinstall and log in again the message synchronized, like the first message in the picture below.

isssue 1 issue 2

TatankaConCube commented 4 years ago

now I can't reproduce issue from yesterday, what help you need now?

nguyenbahung94 commented 4 years ago

now I can't reproduce issue from yesterday, what help you need now?

Like I said before the I still receive the message but it does not have two icons check blue at the bottom of the message. When I'm chatting, Could you try function chat on two devices, you will more understanding. I run the app on two devices at the same time and chat but the message still not have two blue sticks at the bottom of the message. Like the picture below issue 2

TatankaConCube commented 4 years ago

As you can see in our sample ChatMessagesStatusListener initialises in ChatDialogActivity, but in your code you don't use this activity, it is because you don't get statuses of messages. You can move needed logic from ChatDialogActivity to ChatMessageActivity but pay attention what and how you do in your code.

nguyenbahung94 commented 4 years ago

As you can see in our sample ChatMessagesStatusListener initialises in ChatDialogActivity, but in your code you don't use this activity, it is because you don't get statuses of messages. You can move needed logic from ChatDialogActivity to ChatMessageActivity but pay attention what and how you do in your code.

Finally, I'm done with this issue, Thank you for spending time to support me. Thank you so much and Have a nice day,