Added intent handling on item click

Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
rapterjet2004 2025-02-05 11:52:22 -06:00 committed by Marcel Hibbe
parent 93fa89fb81
commit b707cebf6f
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
7 changed files with 50 additions and 13 deletions

View File

@ -66,6 +66,9 @@
<option name="composableFile" value="true" /> <option name="composableFile" value="true" />
<option name="previewFile" value="true" /> <option name="previewFile" value="true" />
</inspection_tool> </inspection_tool>
<inspection_tool class="PreviewParameterProviderOnFirstParameter" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true"> <inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" /> <option name="composableFile" value="true" />
<option name="previewFile" value="true" /> <option name="previewFile" value="true" />

View File

@ -194,6 +194,7 @@ class ContactItem(
} }
companion object { companion object {
const val VIEW_TYPE = FlexibleItemViewType.CONTACT_ITEM
private const val FULLY_OPAQUE: Float = 1.0f private const val FULLY_OPAQUE: Float = 1.0f
private const val SEMI_TRANSPARENT: Float = 0.38f private const val SEMI_TRANSPARENT: Float = 0.38f
} }

View File

@ -6,14 +6,13 @@
*/ */
package com.nextcloud.talk.adapters.items package com.nextcloud.talk.adapters.items
class FlexibleItemViewType { object FlexibleItemViewType {
companion object { const val CONVERSATION_ITEM: Int = 1120391230
const val CONVERSATION_ITEM: Int = 1120391230 const val LOAD_MORE_RESULTS_ITEM: Int = 1120391231
const val LOAD_MORE_RESULTS_ITEM: Int = 1120391231 const val MESSAGE_RESULT_ITEM: Int = 1120391232
const val MESSAGE_RESULT_ITEM: Int = 1120391232 const val MESSAGES_TEXT_HEADER_ITEM: Int = 1120391233
const val MESSAGES_TEXT_HEADER_ITEM: Int = 1120391233 const val POLL_RESULT_HEADER_ITEM: Int = 1120391234
const val POLL_RESULT_HEADER_ITEM: Int = 1120391234 const val POLL_RESULT_VOTER_ITEM: Int = 1120391235
const val POLL_RESULT_VOTER_ITEM: Int = 1120391235 const val POLL_RESULT_VOTERS_OVERVIEW_ITEM: Int = 1120391236
const val POLL_RESULT_VOTERS_OVERVIEW_ITEM: Int = 1120391236 const val CONTACT_ITEM: Int = 2131558687
}
} }

View File

@ -12,6 +12,11 @@ import com.nextcloud.talk.models.json.conversations.RoomOverall
interface ContactsRepository { interface ContactsRepository {
suspend fun getContacts(searchQuery: String?, shareTypes: List<String>): AutocompleteOverall 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 fun getImageUri(avatarId: String, requestBigSize: Boolean): String
} }

View File

@ -45,7 +45,7 @@ class ContactsRepositoryImpl(
override suspend fun createRoom( override suspend fun createRoom(
roomType: String, roomType: String,
sourceType: String, sourceType: String?,
userId: String, userId: String,
conversationName: String? conversationName: String?
): RoomOverall { ): RoomOverall {

View File

@ -87,7 +87,7 @@ class ContactsViewModel @Inject constructor(
} }
@Suppress("Detekt.TooGenericExceptionCaught") @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 { viewModelScope.launch {
try { try {
val room = repository.createRoom( val room = repository.createRoom(

View File

@ -83,6 +83,7 @@ import com.nextcloud.talk.chat.ChatActivity
import com.nextcloud.talk.contacts.ContactsActivityCompose import com.nextcloud.talk.contacts.ContactsActivityCompose
import com.nextcloud.talk.contacts.ContactsUiState import com.nextcloud.talk.contacts.ContactsUiState
import com.nextcloud.talk.contacts.ContactsViewModel import com.nextcloud.talk.contacts.ContactsViewModel
import com.nextcloud.talk.contacts.RoomUiState
import com.nextcloud.talk.conversationlist.viewmodels.ConversationsListViewModel import com.nextcloud.talk.conversationlist.viewmodels.ConversationsListViewModel
import com.nextcloud.talk.data.network.NetworkMonitor import com.nextcloud.talk.data.network.NetworkMonitor
import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.data.user.model.User
@ -398,6 +399,24 @@ class ConversationsListActivity :
}.collect() }.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 { lifecycleScope.launch {
contactsViewModel.contactsViewState.onEach { state -> contactsViewModel.contactsViewState.onEach { state ->
when (state) { when (state) {
@ -1304,6 +1323,16 @@ class ConversationsListActivity :
ConversationItem.VIEW_TYPE -> { ConversationItem.VIEW_TYPE -> {
handleConversation((Objects.requireNonNull(item) as ConversationItem).model) 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 return true