Skip to content

Commit

Permalink
修改客户端底部表情列表显示方式。
Browse files Browse the repository at this point in the history
  • Loading branch information
lilongweidev committed Aug 29, 2022
1 parent b1c37fe commit 4d0ae41
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 177 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.SocketDemo"
tools:targetApi="31">
<activity
android:name=".ui.TestActivity"
android:exported="true">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->

<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
<activity
android:name=".ui.ClientActivity"
android:exported="false"
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/llw/socket/SocketApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import android.app.Application
import android.util.Log
import androidx.annotation.Nullable
import androidx.emoji2.bundled.BundledEmojiCompatConfig
import androidx.emoji2.text.DefaultEmojiCompatConfig
import androidx.emoji2.text.EmojiCompat
import androidx.emoji2.text.EmojiCompat.InitCallback
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
import kotlin.properties.Delegates

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/llw/socket/adapter/MsgAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import androidx.recyclerview.widget.RecyclerView
import com.llw.socket.bean.Message
import com.llw.socket.databinding.ItemRvMsgBinding

/**
* 消息适配器
*/
class MsgAdapter(private val messages: ArrayList<Message>) :
RecyclerView.Adapter<MsgAdapter.ViewHolder>() {

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/llw/socket/ui/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.llw.socket.ui
import android.content.Context
import android.content.Intent
import android.net.wifi.WifiManager
import android.os.Looper
import android.view.LayoutInflater
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -29,7 +30,8 @@ open class BaseActivity: AppCompatActivity() {
/**
* 显示Toast
*/
protected fun showMsg(msg: CharSequence?) = Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
protected fun showMsg(msg: CharSequence?) =
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()

/**
* 跳转页面
Expand Down
64 changes: 54 additions & 10 deletions app/src/main/java/com/llw/socket/ui/ClientActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.llw.socket.ui

import android.os.Bundle
import android.os.Looper
import android.util.Log
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.llw.socket.R
import com.llw.socket.SocketApp
import com.llw.socket.adapter.EmojiAdapter
import com.llw.socket.adapter.MsgAdapter
import com.llw.socket.bean.Message
import com.llw.socket.client.ClientCallback
Expand All @@ -31,6 +38,11 @@ class ClientActivity : BaseActivity(), ClientCallback, EmojiCallback {
//消息适配器
private lateinit var msgAdapter: MsgAdapter

//是否显示表情
private var isShowEmoji = false

private var bottomSheetBehavior: BottomSheetBehavior<LinearLayout>? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityClientBinding.inflate(layoutInflater)
Expand All @@ -42,11 +54,8 @@ class ClientActivity : BaseActivity(), ClientCallback, EmojiCallback {
private fun initView() {
binding.toolbar.setNavigationOnClickListener { onBackPressed() }

//显示emoji
binding.ivEmoji.setOnClickListener {
//显示底部弹窗
showEmojiDialog(this, this)
}
//初始化BottomSheet
initBottomSheet()

//连接服务/断开连接 客户端处理
binding.tvConnectService.setOnClickListener {
Expand All @@ -60,8 +69,8 @@ class ClientActivity : BaseActivity(), ClientCallback, EmojiCallback {
binding.tvConnectService.text = if (connectSocket) "关闭连接" else "连接服务"
}
//发送消息给服务端
binding.btnSendMsg.setOnClickListener {
val msg = binding.etMsg.text.toString().trim()
binding.layBottomSheetEdit.btnSendMsg.setOnClickListener {
val msg = binding.layBottomSheetEdit.etMsg.text.toString().trim()
if (msg.isEmpty()) {
showMsg("请输入要发送的信息");return@setOnClickListener
}
Expand All @@ -71,7 +80,7 @@ class ClientActivity : BaseActivity(), ClientCallback, EmojiCallback {
showMsg("当前未开启服务或连接服务");return@setOnClickListener
}
SocketClient.sendToServer(msg)
binding.etMsg.setText("")
binding.layBottomSheetEdit.etMsg.setText("")
updateList(2, msg)
}
//初始化列表
Expand All @@ -82,6 +91,39 @@ class ClientActivity : BaseActivity(), ClientCallback, EmojiCallback {
}
}

private fun initBottomSheet() {
//Emoji布局
bottomSheetBehavior =
BottomSheetBehavior.from(binding.layBottomSheetEdit.bottomSheet).apply {
state = BottomSheetBehavior.STATE_HIDDEN
isHideable = false
isDraggable = false
}
binding.layBottomSheetEdit.rvEmoji.apply {
layoutManager = GridLayoutManager(context, 6)
adapter = EmojiAdapter(SocketApp.instance().emojiList).apply {
setOnItemClickListener(object : EmojiAdapter.OnClickListener {
override fun onItemClick(position: Int) {
val charSequence = SocketApp.instance().emojiList[position]
checkedEmoji(charSequence)
}
})
}
}
//显示emoji
binding.layBottomSheetEdit.ivEmoji.setOnClickListener {
if (isShowEmoji) {
isShowEmoji = false
bottomSheetBehavior!!.state = BottomSheetBehavior.STATE_COLLAPSED
binding.layBottomSheetEdit.ivEmoji.setImageDrawable(ContextCompat.getDrawable(this,R.drawable.ic_emoji))
} else {
isShowEmoji = true
bottomSheetBehavior!!.state = BottomSheetBehavior.STATE_EXPANDED
binding.layBottomSheetEdit.ivEmoji.setImageDrawable(ContextCompat.getDrawable(this,R.drawable.ic_emoji_checked))
}
}
}

private fun showEditDialog() {
val dialogBinding =
DialogEditIpBinding.inflate(LayoutInflater.from(this@ClientActivity), null, false)
Expand Down Expand Up @@ -109,7 +151,9 @@ class ClientActivity : BaseActivity(), ClientCallback, EmojiCallback {
*/
override fun receiveServerMsg(msg: String) = updateList(1, msg)

override fun otherMsg(msg: String) = showMsg(msg)
override fun otherMsg(msg: String) {
Log.d(TAG, "otherMsg: $msg")
}

/**
* 更新列表
Expand All @@ -125,7 +169,7 @@ class ClientActivity : BaseActivity(), ClientCallback, EmojiCallback {
}

override fun checkedEmoji(charSequence: CharSequence) {
binding.etMsg.apply {
binding.layBottomSheetEdit.etMsg.apply {
setText(text.toString() + charSequence)
setSelection(text.toString().length)//光标置于最后
}
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/llw/socket/ui/SelectTypeActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.llw.socket.ui

import android.os.Bundle
import android.util.Log
import android.widget.Button
import com.llw.socket.R

Expand Down
57 changes: 43 additions & 14 deletions app/src/main/java/com/llw/socket/ui/ServerActivity.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.llw.socket.ui

import android.os.Bundle
import android.os.Looper
import android.util.Log
import android.view.MenuItem
import android.view.View
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.GridLayoutManager
Expand Down Expand Up @@ -38,7 +40,6 @@ class ServerActivity : BaseActivity(), ServerCallback, EmojiCallback {
//是否显示表情
private var isShowEmoji = false

//
private var bottomSheetBehavior: BottomSheetBehavior<LinearLayout>? = null

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -56,18 +57,6 @@ class ServerActivity : BaseActivity(), ServerCallback, EmojiCallback {
}
//初始化BottomSheet
initBottomSheet()
//显示emoji
binding.layBottomSheetEdit.ivEmoji.setOnClickListener {
if (isShowEmoji) {
isShowEmoji = false
bottomSheetBehavior!!.state = BottomSheetBehavior.STATE_COLLAPSED
binding.layBottomSheetEdit.ivEmoji.setImageDrawable(ContextCompat.getDrawable(this,R.drawable.ic_emoji))
} else {
isShowEmoji = true
bottomSheetBehavior!!.state = BottomSheetBehavior.STATE_EXPANDED
binding.layBottomSheetEdit.ivEmoji.setImageDrawable(ContextCompat.getDrawable(this,R.drawable.ic_emoji_checked))
}
}

//开启服务/关闭服务 服务端处理
binding.tvStartService.setOnClickListener {
Expand Down Expand Up @@ -111,6 +100,7 @@ class ServerActivity : BaseActivity(), ServerCallback, EmojiCallback {
isHideable = false
isDraggable = false
}
//表情列表适配器
binding.layBottomSheetEdit.rvEmoji.apply {
layoutManager = GridLayoutManager(context, 6)
adapter = EmojiAdapter(SocketApp.instance().emojiList).apply {
Expand All @@ -122,6 +112,43 @@ class ServerActivity : BaseActivity(), ServerCallback, EmojiCallback {
})
}
}
//显示emoji
binding.layBottomSheetEdit.ivEmoji.setOnClickListener {
bottomSheetBehavior!!.state =
if (isShowEmoji) BottomSheetBehavior.STATE_COLLAPSED else BottomSheetBehavior.STATE_EXPANDED
}
//BottomSheet显示隐藏的相关处理
bottomSheetBehavior!!.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
when (newState) {
BottomSheetBehavior.STATE_EXPANDED -> {//显示
isShowEmoji = true
binding.layBottomSheetEdit.ivEmoji.setImageDrawable(
ContextCompat.getDrawable(
this@ServerActivity,
R.drawable.ic_emoji_checked
)
)
}
BottomSheetBehavior.STATE_COLLAPSED -> {//隐藏
isShowEmoji = false
binding.layBottomSheetEdit.ivEmoji.setImageDrawable(
ContextCompat.getDrawable(
this@ServerActivity,
R.drawable.ic_emoji
)
)
}
else -> isShowEmoji = false
}
Log.e(TAG, "onStateChanged: $newState")
}

override fun onSlide(bottomSheet: View, slideOffset: Float) {

}

})
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
Expand All @@ -136,7 +163,9 @@ class ServerActivity : BaseActivity(), ServerCallback, EmojiCallback {
*/
override fun receiveClientMsg(success: Boolean, msg: String) = updateList(2, msg)

override fun otherMsg(msg: String) = showMsg(msg)
override fun otherMsg(msg: String) {
Log.d(TAG, "otherMsg: $msg")
}

/**
* 更新列表
Expand Down
56 changes: 0 additions & 56 deletions app/src/main/java/com/llw/socket/ui/TestActivity.kt

This file was deleted.

9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_delete_emoji.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="128dp"
android:height="128dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:fillColor="#EEE"
android:pathData="M921.5,170.7L288,170.7a53.2,53.2 0,0 0,-44.4 23.7l-192,288a53.2,53.2 0,0 0,0 59.2l192,288A53.2,53.2 0,0 0,288 853.3h633.5a53.4,53.4 0,0 0,53.3 -53.3L974.9,224a53.4,53.4 0,0 0,-53.3 -53.3zM719.1,603.6a21.3,21.3 0,0 1,-30.2 30.2L597.3,542.2 505.8,633.8a21.3,21.3 0,0 1,-30.2 -30.2L567.2,512 475.6,420.4a21.3,21.3 0,0 1,30.2 -30.2L597.3,481.8l91.6,-91.6a21.3,21.3 0,1 1,30.2 30.2L627.5,512z" />
</vector>
Loading

0 comments on commit 4d0ae41

Please sign in to comment.