Skip to content

Commit

Permalink
Added intent handling on item click
Browse files Browse the repository at this point in the history
  • Loading branch information
rapterjet2004 committed Feb 5, 2025
1 parent b3d114d commit 2c1cab5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .idea/inspectionProfiles/ktlint.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class ContactItem(
}

companion object {
const val VIEW_TYPE = FlexibleItemViewType.CONTACT_ITEM
private const val FULLY_OPAQUE: Float = 1.0f
private const val SEMI_TRANSPARENT: Float = 0.38f
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
*/
package com.nextcloud.talk.adapters.items

class FlexibleItemViewType {
companion object {
const val CONVERSATION_ITEM: Int = 1120391230
const val LOAD_MORE_RESULTS_ITEM: Int = 1120391231
const val MESSAGE_RESULT_ITEM: Int = 1120391232
const val MESSAGES_TEXT_HEADER_ITEM: Int = 1120391233
const val POLL_RESULT_HEADER_ITEM: Int = 1120391234
const val POLL_RESULT_VOTER_ITEM: Int = 1120391235
const val POLL_RESULT_VOTERS_OVERVIEW_ITEM: Int = 1120391236
}
object FlexibleItemViewType {
const val CONVERSATION_ITEM: Int = 1120391230
const val LOAD_MORE_RESULTS_ITEM: Int = 1120391231
const val MESSAGE_RESULT_ITEM: Int = 1120391232
const val MESSAGES_TEXT_HEADER_ITEM: Int = 1120391233
const val POLL_RESULT_HEADER_ITEM: Int = 1120391234
const val POLL_RESULT_VOTER_ITEM: Int = 1120391235
const val POLL_RESULT_VOTERS_OVERVIEW_ITEM: Int = 1120391236
const val CONTACT_ITEM: Int = 2131558687
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import com.nextcloud.talk.models.json.conversations.RoomOverall

interface ContactsRepository {
suspend fun getContacts(searchQuery: String?, shareTypes: List<String>): AutocompleteOverall
suspend fun createRoom(roomType: String, sourceType: String, userId: String, conversationName: String?): RoomOverall
suspend fun createRoom(
roomType: String,
sourceType: String?,
userId: String,
conversationName: String?
): RoomOverall
fun getImageUri(avatarId: String, requestBigSize: Boolean): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ContactsRepositoryImpl(

override suspend fun createRoom(
roomType: String,
sourceType: String,
sourceType: String?,
userId: String,
conversationName: String?
): RoomOverall {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ContactsViewModel @Inject constructor(
}

@Suppress("Detekt.TooGenericExceptionCaught")
fun createRoom(roomType: String, sourceType: String, userId: String, conversationName: String?) {
fun createRoom(roomType: String, sourceType: String?, userId: String, conversationName: String?) {
viewModelScope.launch {
try {
val room = repository.createRoom(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import com.nextcloud.talk.chat.ChatActivity
import com.nextcloud.talk.contacts.ContactsActivityCompose
import com.nextcloud.talk.contacts.ContactsUiState
import com.nextcloud.talk.contacts.ContactsViewModel
import com.nextcloud.talk.contacts.RoomUiState
import com.nextcloud.talk.conversationlist.viewmodels.ConversationsListViewModel
import com.nextcloud.talk.data.network.NetworkMonitor
import com.nextcloud.talk.data.user.model.User
Expand Down Expand Up @@ -398,6 +399,24 @@ class ConversationsListActivity :
}.collect()
}

lifecycleScope.launch {
contactsViewModel.roomViewState.onEach { state ->
when (state) {
is RoomUiState.Success -> {
val conversation = state.conversation
val bundle = Bundle()
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation?.token)
val chatIntent = Intent(context, ChatActivity::class.java)
chatIntent.putExtras(bundle)
chatIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(chatIntent)
}

else -> {}
}
}.collect()
}

lifecycleScope.launch {
contactsViewModel.contactsViewState.onEach { state ->
when (state) {
Expand Down Expand Up @@ -1304,6 +1323,16 @@ class ConversationsListActivity :
ConversationItem.VIEW_TYPE -> {
handleConversation((Objects.requireNonNull(item) as ConversationItem).model)
}

ContactItem.VIEW_TYPE -> {
val contact = item as ContactItem
contactsViewModel.createRoom(
"1",
null,
contact.model.actorId!!,
null
)
}
}
}
return true
Expand Down

0 comments on commit 2c1cab5

Please sign in to comment.