Shipr-Hub / Shipr-Community-Android

Shipr Social is the Multi Platform Chat Project for Developers
https://play.google.com/store/apps/details?id=tech.shipr.social
GNU General Public License v3.0
21 stars 17 forks source link

Chat message of sender should be on right #94

Closed yhdesai closed 5 years ago

yhdesai commented 5 years ago

It should use the item_message_right.xml if the message is sent by the same user as in the device

PatilShreyas commented 5 years ago

Hi @yhdesai, I tried to solve this issue. But I observed that some DeveloperMessage object having uid null. I tested them on Log and saw they are having null uid.

2019-04-18 15:25:48.646 5553-5553/tech.shipr.socialdev I/System.out: MSG-UID---xxxxxxxxxxxxxxxxx
2019-04-18 15:25:48.662 5553-5553/tech.shipr.socialdev I/System.out: MSG-UID---null
2019-04-18 15:25:48.677 5553-5553/tech.shipr.socialdev I/System.out: MSG-UID---null
2019-04-18 15:25:57.016 5553-5553/tech.shipr.socialdev I/System.out: MSG-UID---xxxxxxxxxxxxxxxxx
2019-04-18 15:25:57.027 5553-5553/tech.shipr.socialdev I/System.out: MSG-UID---xxxxxxxxxxxxxxxxx
2019-04-18 15:25:57.038 5553-5553/tech.shipr.socialdev I/System.out: MSG-UID---xxxxxxxxxxxxxxxxx
2019-04-18 15:25:57.048 5553-5553/tech.shipr.socialdev I/System.out: MSG-UID---xxxxxxxxxxxxxxxxx
2019-04-18 15:25:57.057 5553-5553/tech.shipr.socialdev I/System.out: MSG-UID---null
2019-04-18 15:25:57.066 5553-5553/tech.shipr.socialdev I/System.out: MSG-UID---null
2019-04-18 15:25:57.211 5553-5553/tech.shipr.socialdev I/System.out: MSG-UID---xxxxxxxxxxxxxxxxx
2019-04-18 15:25:57.213 5553-5553/tech.shipr.socialdev I/System.out: MSG-UID---xxxxxxxxxxxxxxxxx
2019-04-18 15:25:57.217 5553-5553/tech.shipr.socialdev I/System.out: MSG-UID---xxxxxxxxxxxxxxxxx
.......and so on

That's why app was crashing earlier. Then I updated the code as below...

        if (convertView == null) {
            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            assert user != null;
            String uid = user.getUid();
            if (message.getUid() != null) {
                if (message.getUid().equals(uid)) {
                    convertView = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.item_message_right, parent, false);
                } else {
                    convertView = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.item_message, parent, false);
                }
            } else {
                convertView = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.item_message, parent, false);

            }
        }

After doing this, finally, I run the app and see...

This was just a temporary adjustment to avoid NullPointerException. But later, you will have to clean up the Database.

Another Change: Here, I have replaced ImageView with CircleImageView (created new class) to display a profile image in Circle Shape

PatilShreyas commented 5 years ago

I think this issue is solved now!