mirror of
https://github.com/ChronosX88/Influence.git
synced 2024-12-28 00:51:47 +00:00
Avatars now shown in ChatActivity toolbar
This commit is contained in:
parent
8a062745d9
commit
99f0934a64
@ -36,6 +36,7 @@ import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import io.github.chronosx88.influence.R;
|
||||
import io.github.chronosx88.influence.contracts.CoreContracts;
|
||||
@ -51,6 +52,7 @@ import java8.util.stream.StreamSupport;
|
||||
import java9.util.concurrent.CompletableFuture;
|
||||
|
||||
public class DialogListPresenter implements CoreContracts.IDialogListPresenterContract {
|
||||
private ConcurrentHashMap<String, byte[]> avatarsMap = new ConcurrentHashMap<>();
|
||||
private CoreContracts.IChatListViewContract view;
|
||||
private CoreContracts.IDialogListLogicContract logic;
|
||||
private DialogsListAdapter<GenericDialog> dialogListAdapter = new DialogsListAdapter<>((imageView, url, payload) -> {
|
||||
@ -75,6 +77,7 @@ public class DialogListPresenter implements CoreContracts.IDialogListPresenterCo
|
||||
if(avatarBytes != null) {
|
||||
Bitmap avatar = BitmapFactory.decodeByteArray(avatarBytes, 0, avatarBytes.length);
|
||||
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.putExtra("chatID", chatID);
|
||||
intent.putExtra("chatName", LocalDBWrapper.getChatByChatID(chatID).chatName);
|
||||
intent.putExtra("chatAvatar", avatarsMap.get(chatID));
|
||||
view.startActivity(intent);
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,16 @@
|
||||
package io.github.chronosx88.influence.views
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
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.messages.MessageInput
|
||||
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.roomEntities.MessageEntity
|
||||
import io.github.chronosx88.influence.presenters.ChatPresenter
|
||||
import kotlinx.android.synthetic.main.activity_chat.view.*
|
||||
|
||||
class ChatActivity : AppCompatActivity(), CoreContracts.IChatViewContract {
|
||||
private var messageList: MessagesList? = null
|
||||
private var messageInput: MessageInput? = null
|
||||
private var chatNameTextView: TextView? = null
|
||||
private var chatAvatar: ImageView? = null
|
||||
private var presenter: ChatPresenter? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -37,12 +44,14 @@ class ChatActivity : AppCompatActivity(), CoreContracts.IChatViewContract {
|
||||
messageList = findViewById(R.id.messages_list)
|
||||
messageList!!.layoutManager = LinearLayoutManager(this)
|
||||
chatNameTextView = findViewById(R.id.appbar_username)
|
||||
chatAvatar = findViewById(R.id.profile_image_chat_activity)
|
||||
messageInput = findViewById(R.id.message_input)
|
||||
messageInput!!.setInputListener {
|
||||
presenter!!.sendMessage(it.toString())
|
||||
}
|
||||
chatNameTextView!!.text = intent.getStringExtra("chatName")
|
||||
presenter = ChatPresenter(this, intent.getStringExtra("chatID"))
|
||||
loadAvatarFromIntent(intent)
|
||||
presenter!!.loadLocalMessages()
|
||||
}
|
||||
|
||||
@ -64,4 +73,20 @@ class ChatActivity : AppCompatActivity(), CoreContracts.IChatViewContract {
|
||||
override fun setAdapter(adapter: MessagesListAdapter<GenericMessage>) {
|
||||
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]))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,6 @@ import io.github.chronosx88.influence.R;
|
||||
import io.github.chronosx88.influence.XMPPConnectionService;
|
||||
import io.github.chronosx88.influence.contracts.CoreContracts;
|
||||
import io.github.chronosx88.influence.helpers.AppHelper;
|
||||
import io.github.chronosx88.influence.helpers.HashUtils;
|
||||
import io.github.chronosx88.influence.models.appEvents.AuthenticationStatusEvent;
|
||||
|
||||
public class LoginActivity extends AppCompatActivity implements CoreContracts.ILoginViewContract {
|
||||
|
@ -21,7 +21,6 @@
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:src="@mipmap/ic_launcher"
|
||||
android:id="@+id/profile_image_chat_activity"/>
|
||||
|
||||
<TextView
|
||||
|
Loading…
Reference in New Issue
Block a user