Skip to content

Commit

Permalink
Merge pull request #41 from ConnectyCube/development
Browse files Browse the repository at this point in the history
Development -> Master
  • Loading branch information
DaveLomber authored Nov 28, 2019
2 parents 73ef2e3 + 15eba3f commit 4fcaadc
Show file tree
Hide file tree
Showing 61 changed files with 1,490 additions and 349 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static void androidXComponents(configuration) {
configuration.implementation "androidx.recyclerview:recyclerview:1.1.0-beta03"
configuration.implementation 'androidx.appcompat:appcompat:1.0.2'
configuration.implementation 'androidx.core:core-ktx:1.0.2'
configuration.implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
configuration.implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3'
}

private static void kotlinComponents(configuration, kotlin_version) {
Expand All @@ -101,10 +101,10 @@ private static void kotlinComponents(configuration, kotlin_version) {
}

private static void externalMediaComponents(configuration) {
configuration.implementation "com.zhihu.android:matisse:0.5.3-beta1"
configuration.implementation "com.zhihu.android:matisse:0.5.3-beta3"
configuration.implementation 'com.github.yalantis:ucrop:2.2.4'
configuration.implementation "com.github.bumptech.glide:glide:4.9.0"
configuration.implementation 'com.github.chrisbanes:PhotoView:2.1.4'
configuration.implementation 'com.github.chrisbanes:PhotoView:2.2.0'
}

//apply plugin: 'com.google.gms.google-services'
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
android:label="@string/attachment_preview_label"
android:theme="@style/AppTheme.DarkTitle" />

<activity
android:name=".ImagePreviewActivity"
android:label=""
android:theme="@style/AppTheme.DarkTitle" />

<activity
android:name=".OccupantPreviewActivity"
android:label="@string/occupant_preview_label" />
Expand Down
79 changes: 62 additions & 17 deletions app/src/main/java/com/connectycube/messenger/ChatDialogActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.observe
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.connectycube.chat.ConnectycubeChatService
import com.connectycube.chat.IncomingMessagesManager
import com.connectycube.chat.exception.ChatException
import com.connectycube.chat.listeners.ChatDialogMessageListener
import com.connectycube.chat.listeners.MessageStatusListener
import com.connectycube.chat.model.ConnectycubeChatDialog
import com.connectycube.chat.model.ConnectycubeChatMessage
import com.connectycube.messenger.adapters.ChatDialogAdapter
Expand All @@ -25,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
Expand All @@ -35,6 +38,8 @@ import kotlinx.coroutines.launch
import timber.log.Timber

const val REQUEST_SETTING_SCREEN = 50
const val REQUEST_CHAT_DIALOG_ID = 55
const val EXTRA_DIALOG_ID = "chat_dialog_id"

class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapterCallback {

Expand All @@ -44,14 +49,15 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt

private lateinit var chatDialogAdapter: ChatDialogAdapter
private var incomingMessagesManager: IncomingMessagesManager? = null
private val messageStatusListener: MessageStatusListener = ChatMessagesStatusListener()

private var currentDialogId: String? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Timber.d("onCreate")
setContentView(R.layout.activity_chatdialogs)
initToolbar()
initActionbar()
initDialogsAdapter()
initDialogsRecyclerView()
subscribeUi()
Expand All @@ -60,12 +66,10 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt
override fun onResume() {
super.onResume()
setCurrentUser()
currentDialogId?.let { chatDialogListViewModel.updateChat(currentDialogId!!) }
}

private fun initToolbar() {
setSupportActionBar(toolbar)
toolbar.setOnClickListener { startSettingsActivity() }
private fun initActionbar() {
action_bar_view.setSingleOnClickListener { startSettingsActivity() }
setCurrentUser()
}

Expand All @@ -79,14 +83,36 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt
chats_recycler_view.layoutManager = LinearLayoutManager(this)
chats_recycler_view.itemAnimator = DefaultItemAnimator()
chats_recycler_view.adapter = chatDialogAdapter

chatDialogAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
scrollUp()
}

override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
scrollUp()
}

override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
scrollUp()
}
})
}

private fun scrollUp() {
chats_recycler_view.scrollToPosition(0)
}

private fun subscribeUi() {
Timber.d("subscribeUi")
showProgress(progressbar)
LiveDataBus.subscribe(EVENT_CHAT_LOGIN, this, Observer<EventChatConnection> {
if (it.error != null){
Toast.makeText(this, getString(R.string.login_chat_error_format, it.error.message), Toast.LENGTH_LONG).show()
if (it.error != null) {
val errMsg =
if (it.error.message != null && !it.error.message!!.contains(getString(R.string.read_error))) {
it.error.message
} else getString(R.string.chat_connection_problem)
Toast.makeText(this, getString(R.string.login_chat_error_format, errMsg), Toast.LENGTH_LONG).show()
} else if (it.connected) {
initManagers()
}
Expand Down Expand Up @@ -115,16 +141,16 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt
chatDialogAdapter.callback = this
}

fun initManagers() {
private fun initManagers() {
ConnectycubeChatService.getInstance().messageStatusesManager?.addMessageStatusListener(messageStatusListener)
incomingMessagesManager = ConnectycubeChatService.getInstance().incomingMessagesManager
incomingMessagesManager?.addDialogMessageListener(AllMessageListener())
}

fun unregisterChatManagers() {
private fun unregisterChatManagers() {
ConnectycubeChatService.getInstance().messageStatusesManager?.removeMessageStatusListener(messageStatusListener)
incomingMessagesManager?.dialogMessageListeners?.forEach {
incomingMessagesManager?.removeDialogMessageListrener(
it
)
incomingMessagesManager?.removeDialogMessageListrener(it)
}
}

Expand All @@ -138,6 +164,10 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt
logout()
}
}
REQUEST_CHAT_DIALOG_ID -> {
val chatDialogIdForUpdate = data.getStringExtra(EXTRA_DIALOG_ID)
chatDialogIdForUpdate?.let { chatDialogListViewModel.updateChat(it) }
}
}
}

Expand All @@ -154,7 +184,7 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt

fun onCreateNewChatClick(view: View) {
val intent = Intent(this, CreateChatDialogActivity::class.java)
startActivity(intent)
startActivityForResult(intent, REQUEST_CHAT_DIALOG_ID)
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left)
}

Expand All @@ -168,7 +198,7 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt
}

override fun onChatDialogDelete(chatDialog: ConnectycubeChatDialog) {
Timber.d("Try delete dialog " + chatDialog.dialogId)
Timber.d("Try delete dialog= ${chatDialog.dialogId}")
chatDialogListViewModel.deleteChat(chatDialog).observe(this) { resource ->
when (resource.status) {
Status.SUCCESS -> hideProgress(progressbar)
Expand All @@ -186,7 +216,8 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt
val intent = Intent(this, ChatMessageActivity::class.java).apply {
putExtra(EXTRA_CHAT, chat)
}
startActivity(intent)
startActivityForResult(intent, REQUEST_CHAT_DIALOG_ID)
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left)
}

override fun onBackPressed() {
Expand All @@ -199,6 +230,7 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt

private fun logout() {
showProgress(progressbar)
currentDialogId = null
chatDialogListViewModel.chatLiveDataLazy.removeObservers(this)
LiveDataBus.unregister(EVENT_CHAT_LOGIN)
GlobalScope.launch(Dispatchers.Main) {
Expand Down Expand Up @@ -233,11 +265,24 @@ class ChatDialogActivity : BaseChatActivity(), ChatDialogAdapter.ChatDialogAdapt
chatMessage: ConnectycubeChatMessage,
senderId: Int?
) {
Timber.d("processMessage chatMessage= " + chatMessage.body + ", from senderId $senderId")
Timber.d("processMessage chatMessage= ${chatMessage.body}, from senderId $senderId")
if (senderId != ConnectycubeChatService.getInstance().user.id) {
Timber.d("processMessage chatDialogListViewModel.updateChat chatMessage= " + chatMessage.body)
Timber.d("processMessage chatDialogListViewModel.updateChat chatMessage= ${chatMessage.body}")
chatDialogListViewModel.updateChat(dialogId)
}
}
}

private inner class ChatMessagesStatusListener : MessageStatusListener {
override fun processMessageRead(messageID: String, dialogId: String, userId: Int) {
Timber.d("processMessageRead messageID= $messageID")
chatDialogListViewModel.updateMessageReadStatus(messageID, userId)
}

override fun processMessageDelivered(messageID: String, dialogId: String, userId: Int) {
Timber.d("processMessageDelivered messageID= $messageID")
chatDialogListViewModel.updateMessageDeliveredStatus(messageID, userId)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -319,9 +319,4 @@ class ChatDialogDetailsActivity : BaseChatActivity(),
super.onBackPressed()
setResult(REQUEST_CODE_DETAILS)
}

override fun finish() {
super.finish()
overridePendingTransition(0, R.anim.slide_out_bottom)
}
}
Loading

0 comments on commit 4fcaadc

Please sign in to comment.