diff --git a/app/src/main/java/com/connectycube/messenger/ChatDialogActivity.kt b/app/src/main/java/com/connectycube/messenger/ChatDialogActivity.kt index 8d3fe2a..4341087 100644 --- a/app/src/main/java/com/connectycube/messenger/ChatDialogActivity.kt +++ b/app/src/main/java/com/connectycube/messenger/ChatDialogActivity.kt @@ -27,6 +27,7 @@ import com.connectycube.messenger.helpers.RTCSessionManager import com.connectycube.messenger.utilities.InjectorUtils import com.connectycube.messenger.utilities.SharedPreferencesManager import com.connectycube.messenger.utilities.loadUserAvatar +import com.connectycube.messenger.utilities.setSingleOnClickListener import com.connectycube.messenger.viewmodels.ChatDialogListViewModel import com.connectycube.messenger.vo.Status import com.connectycube.users.model.ConnectycubeUser @@ -68,7 +69,7 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt } private fun initActionbar() { - action_bar_view.setOnClickListener { startSettingsActivity() } + action_bar_view.setSingleOnClickListener { startSettingsActivity() } setCurrentUser() } diff --git a/app/src/main/java/com/connectycube/messenger/ChatDialogDetailsActivity.kt b/app/src/main/java/com/connectycube/messenger/ChatDialogDetailsActivity.kt index 5eeb173..f32f0f8 100644 --- a/app/src/main/java/com/connectycube/messenger/ChatDialogDetailsActivity.kt +++ b/app/src/main/java/com/connectycube/messenger/ChatDialogDetailsActivity.kt @@ -49,11 +49,11 @@ class ChatDialogDetailsActivity : BaseChatActivity(), private fun initToolbar() { setSupportActionBar(toolbar) back_btn.setOnClickListener { onBackPressed() } - edit_group_name_btn.setOnClickListener { editGroupName() } - edit_grop_description_btn.setOnClickListener { editGroupDescription() } - edit_avatar_btn.setOnClickListener { editGroupPhoto() } - add_occupants_img.setOnClickListener { addOccupants() } - remove_occupants_img.setOnClickListener { removeOccupants() } + edit_group_name_btn.setSingleOnClickListener { editGroupName() } + edit_grop_description_btn.setSingleOnClickListener { editGroupDescription() } + edit_avatar_btn.setSingleOnClickListener { editGroupPhoto() } + add_occupants_img.setSingleOnClickListener { addOccupants() } + remove_occupants_img.setSingleOnClickListener { removeOccupants() } } private fun editGroupPhoto() { diff --git a/app/src/main/java/com/connectycube/messenger/ChatMessageActivity.kt b/app/src/main/java/com/connectycube/messenger/ChatMessageActivity.kt index b63d8a2..d7688ca 100644 --- a/app/src/main/java/com/connectycube/messenger/ChatMessageActivity.kt +++ b/app/src/main/java/com/connectycube/messenger/ChatMessageActivity.kt @@ -264,7 +264,7 @@ class ChatMessageActivity : BaseChatActivity() { private fun initToolbar() { back_btn.setOnClickListener { onBackPressed() } - toolbar_layout.setOnClickListener { startChatDetailsActivity() } + toolbar_layout.setSingleOnClickListener { startChatDetailsActivity() } loadChatDialogPhoto(this, chatDialog.isPrivate, chatDialog.photo, avatar_img) chat_message_name.text = chatDialog.name } diff --git a/app/src/main/java/com/connectycube/messenger/CreateChatDialogDetailActivity.kt b/app/src/main/java/com/connectycube/messenger/CreateChatDialogDetailActivity.kt index 9467108..a76482a 100644 --- a/app/src/main/java/com/connectycube/messenger/CreateChatDialogDetailActivity.kt +++ b/app/src/main/java/com/connectycube/messenger/CreateChatDialogDetailActivity.kt @@ -32,7 +32,7 @@ class CreateChatDialogDetailActivity : BaseChatActivity() { setContentView(R.layout.activity_create_chat_details) initToolbar() subscribeUi() - edit_avatar_btn.setOnClickListener { editAvatar() } + edit_avatar_btn.setSingleOnClickListener { editAvatar() } } private fun initToolbar() { diff --git a/app/src/main/java/com/connectycube/messenger/SettingsActivity.kt b/app/src/main/java/com/connectycube/messenger/SettingsActivity.kt index 8f49f01..5414dad 100644 --- a/app/src/main/java/com/connectycube/messenger/SettingsActivity.kt +++ b/app/src/main/java/com/connectycube/messenger/SettingsActivity.kt @@ -45,8 +45,8 @@ class SettingsActivity : BaseChatActivity() { } private fun initViews() { - edit_name_fb.setOnClickListener { editName() } - avatar_img.setOnClickListener { editAvatar() } + edit_name_fb.setSingleOnClickListener { editName() } + avatar_img.setSingleOnClickListener { editAvatar() } } private fun initData() { diff --git a/app/src/main/java/com/connectycube/messenger/adapters/ChatDialogAdapter.kt b/app/src/main/java/com/connectycube/messenger/adapters/ChatDialogAdapter.kt index 29a0a05..87f87be 100644 --- a/app/src/main/java/com/connectycube/messenger/adapters/ChatDialogAdapter.kt +++ b/app/src/main/java/com/connectycube/messenger/adapters/ChatDialogAdapter.kt @@ -14,6 +14,7 @@ import com.connectycube.chat.model.ConnectycubeDialogType import com.connectycube.messenger.R import com.connectycube.messenger.utilities.getPrettyDate import com.connectycube.messenger.utilities.loadChatDialogPhoto +import com.connectycube.messenger.utilities.setSingleOnClickListener const val MENU_ITEM_DELETE: Int = 1 @@ -96,7 +97,7 @@ internal class ChatDialogAdapter(private val context: Context) : setTextColor(activityContext, txtLastMessageDate, R.color.dark_grey) } - itemView.setOnClickListener { notifyItemSelected() } + itemView.setSingleOnClickListener { notifyItemSelected() } itemView.setOnCreateContextMenuListener(this) } diff --git a/app/src/main/java/com/connectycube/messenger/adapters/ChatMessageAdapter.kt b/app/src/main/java/com/connectycube/messenger/adapters/ChatMessageAdapter.kt index 6625a6c..85c3d5f 100644 --- a/app/src/main/java/com/connectycube/messenger/adapters/ChatMessageAdapter.kt +++ b/app/src/main/java/com/connectycube/messenger/adapters/ChatMessageAdapter.kt @@ -160,7 +160,7 @@ class ChatMessageAdapter( with(holder) { bindTo(it) message.let { - itemView.setOnClickListener { + itemView.setSingleOnClickListener { attachmentClickListener(message.attachments.first(), holder.attachmentView) } } @@ -173,7 +173,7 @@ class ChatMessageAdapter( message?.let { with(holder) { bindTo(it, showAvatar(position, message), showName(position, message)) - itemView.setOnClickListener { + itemView.setSingleOnClickListener { attachmentClickListener(message.attachments.first(), holder.attachmentView) } } diff --git a/app/src/main/java/com/connectycube/messenger/utilities/SingleClickListener.kt b/app/src/main/java/com/connectycube/messenger/utilities/SingleClickListener.kt new file mode 100644 index 0000000..9b35f4a --- /dev/null +++ b/app/src/main/java/com/connectycube/messenger/utilities/SingleClickListener.kt @@ -0,0 +1,30 @@ +package com.connectycube.messenger.utilities + +import android.os.SystemClock +import android.view.View + + +/** + * The class preventing multiple times clicking in a row with predefined interval. + */ +class SingleClickListener( + private var defaultInterval: Int = 1000, + private val onSingleClick: (View) -> Unit +) : View.OnClickListener { + private var lastTimeClicked: Long = 0 + override fun onClick(v: View) { + if (SystemClock.elapsedRealtime() - lastTimeClicked < defaultInterval) { + return + } + lastTimeClicked = SystemClock.elapsedRealtime() + onSingleClick(v) + } +} + +fun View.setSingleOnClickListener(onSingleClick: (View) -> Unit): Boolean { + val singleTimeClickListener = SingleClickListener { + onSingleClick(it) + } + setOnClickListener(singleTimeClickListener) + return true +} \ No newline at end of file