Avatars now shown in ChatActivity toolbar

This commit is contained in:
ChronosX88 2019-05-23 17:30:36 +04:00
parent 8a062745d9
commit 99f0934a64
4 changed files with 29 additions and 2 deletions

View File

@ -36,6 +36,7 @@ import org.jxmpp.stringprep.XmppStringprepException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import io.github.chronosx88.influence.R; import io.github.chronosx88.influence.R;
import io.github.chronosx88.influence.contracts.CoreContracts; import io.github.chronosx88.influence.contracts.CoreContracts;
@ -51,6 +52,7 @@ import java8.util.stream.StreamSupport;
import java9.util.concurrent.CompletableFuture; import java9.util.concurrent.CompletableFuture;
public class DialogListPresenter implements CoreContracts.IDialogListPresenterContract { public class DialogListPresenter implements CoreContracts.IDialogListPresenterContract {
private ConcurrentHashMap<String, byte[]> avatarsMap = new ConcurrentHashMap<>();
private CoreContracts.IChatListViewContract view; private CoreContracts.IChatListViewContract view;
private CoreContracts.IDialogListLogicContract logic; private CoreContracts.IDialogListLogicContract logic;
private DialogsListAdapter<GenericDialog> dialogListAdapter = new DialogsListAdapter<>((imageView, url, payload) -> { private DialogsListAdapter<GenericDialog> dialogListAdapter = new DialogsListAdapter<>((imageView, url, payload) -> {
@ -75,6 +77,7 @@ public class DialogListPresenter implements CoreContracts.IDialogListPresenterCo
if(avatarBytes != null) { if(avatarBytes != null) {
Bitmap avatar = BitmapFactory.decodeByteArray(avatarBytes, 0, avatarBytes.length); Bitmap avatar = BitmapFactory.decodeByteArray(avatarBytes, 0, avatarBytes.length);
imageView.setImageBitmap(avatar); imageView.setImageBitmap(avatar);
avatarsMap.put(url, avatarBytes);
} }
}); });
}); });
@ -120,6 +123,7 @@ public class DialogListPresenter implements CoreContracts.IDialogListPresenterCo
Intent intent = new Intent(AppHelper.getContext(), ChatActivity.class); Intent intent = new Intent(AppHelper.getContext(), ChatActivity.class);
intent.putExtra("chatID", chatID); intent.putExtra("chatID", chatID);
intent.putExtra("chatName", LocalDBWrapper.getChatByChatID(chatID).chatName); intent.putExtra("chatName", LocalDBWrapper.getChatByChatID(chatID).chatName);
intent.putExtra("chatAvatar", avatarsMap.get(chatID));
view.startActivity(intent); view.startActivity(intent);
} }

View File

@ -1,11 +1,16 @@
package io.github.chronosx88.influence.views package io.github.chronosx88.influence.views
import android.content.Intent
import android.graphics.BitmapFactory
import android.os.Bundle import android.os.Bundle
import android.view.MenuItem import android.view.MenuItem
import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.amulyakhare.textdrawable.TextDrawable
import com.amulyakhare.textdrawable.util.ColorGenerator
import com.stfalcon.chatkit.commons.ImageLoader import com.stfalcon.chatkit.commons.ImageLoader
import com.stfalcon.chatkit.messages.MessageInput import com.stfalcon.chatkit.messages.MessageInput
import com.stfalcon.chatkit.messages.MessagesList import com.stfalcon.chatkit.messages.MessagesList
@ -16,11 +21,13 @@ import io.github.chronosx88.influence.helpers.AppHelper
import io.github.chronosx88.influence.models.GenericMessage import io.github.chronosx88.influence.models.GenericMessage
import io.github.chronosx88.influence.models.roomEntities.MessageEntity import io.github.chronosx88.influence.models.roomEntities.MessageEntity
import io.github.chronosx88.influence.presenters.ChatPresenter import io.github.chronosx88.influence.presenters.ChatPresenter
import kotlinx.android.synthetic.main.activity_chat.view.*
class ChatActivity : AppCompatActivity(), CoreContracts.IChatViewContract { class ChatActivity : AppCompatActivity(), CoreContracts.IChatViewContract {
private var messageList: MessagesList? = null private var messageList: MessagesList? = null
private var messageInput: MessageInput? = null private var messageInput: MessageInput? = null
private var chatNameTextView: TextView? = null private var chatNameTextView: TextView? = null
private var chatAvatar: ImageView? = null
private var presenter: ChatPresenter? = null private var presenter: ChatPresenter? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -37,12 +44,14 @@ class ChatActivity : AppCompatActivity(), CoreContracts.IChatViewContract {
messageList = findViewById(R.id.messages_list) messageList = findViewById(R.id.messages_list)
messageList!!.layoutManager = LinearLayoutManager(this) messageList!!.layoutManager = LinearLayoutManager(this)
chatNameTextView = findViewById(R.id.appbar_username) chatNameTextView = findViewById(R.id.appbar_username)
chatAvatar = findViewById(R.id.profile_image_chat_activity)
messageInput = findViewById(R.id.message_input) messageInput = findViewById(R.id.message_input)
messageInput!!.setInputListener { messageInput!!.setInputListener {
presenter!!.sendMessage(it.toString()) presenter!!.sendMessage(it.toString())
} }
chatNameTextView!!.text = intent.getStringExtra("chatName") chatNameTextView!!.text = intent.getStringExtra("chatName")
presenter = ChatPresenter(this, intent.getStringExtra("chatID")) presenter = ChatPresenter(this, intent.getStringExtra("chatID"))
loadAvatarFromIntent(intent)
presenter!!.loadLocalMessages() presenter!!.loadLocalMessages()
} }
@ -64,4 +73,20 @@ class ChatActivity : AppCompatActivity(), CoreContracts.IChatViewContract {
override fun setAdapter(adapter: MessagesListAdapter<GenericMessage>) { override fun setAdapter(adapter: MessagesListAdapter<GenericMessage>) {
messageList!!.setAdapter(adapter) messageList!!.setAdapter(adapter)
} }
private fun loadAvatarFromIntent(intent: Intent) {
val avatarBytes: ByteArray? = intent.getByteArrayExtra("chatAvatar")
if(avatarBytes != null) {
val avatar = BitmapFactory.decodeByteArray(avatarBytes, 0, avatarBytes.size)
chatAvatar!!.setImageBitmap(avatar)
} else {
val chatName = intent.getStringExtra("chatName")
chatAvatar!!.setImageDrawable(TextDrawable.builder()
.beginConfig()
.width(32)
.height(32)
.endConfig()
.buildRound(Character.toString(chatName[0]), ColorGenerator.MATERIAL.getColor(Character.toString(chatName[0]))))
}
}
} }

View File

@ -41,7 +41,6 @@ import io.github.chronosx88.influence.R;
import io.github.chronosx88.influence.XMPPConnectionService; import io.github.chronosx88.influence.XMPPConnectionService;
import io.github.chronosx88.influence.contracts.CoreContracts; import io.github.chronosx88.influence.contracts.CoreContracts;
import io.github.chronosx88.influence.helpers.AppHelper; import io.github.chronosx88.influence.helpers.AppHelper;
import io.github.chronosx88.influence.helpers.HashUtils;
import io.github.chronosx88.influence.models.appEvents.AuthenticationStatusEvent; import io.github.chronosx88.influence.models.appEvents.AuthenticationStatusEvent;
public class LoginActivity extends AppCompatActivity implements CoreContracts.ILoginViewContract { public class LoginActivity extends AppCompatActivity implements CoreContracts.ILoginViewContract {

View File

@ -21,7 +21,6 @@
<de.hdodenhof.circleimageview.CircleImageView <de.hdodenhof.circleimageview.CircleImageView
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:src="@mipmap/ic_launcher"
android:id="@+id/profile_image_chat_activity"/> android:id="@+id/profile_image_chat_activity"/>
<TextView <TextView