-
-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4746 from nextcloud/refactorContactsActivityCompose
ContactsScreen: extract Composables to files and simplify passed parameters
- Loading branch information
Showing
12 changed files
with
690 additions
and
478 deletions.
There are no files selected for viewing
377 changes: 7 additions & 370 deletions
377
app/src/main/java/com/nextcloud/talk/contacts/ContactsActivityCompose.kt
Large diffs are not rendered by default.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/nextcloud/talk/contacts/ContactsScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Nextcloud Talk - Android Client | ||
* | ||
* SPDX-FileCopyrightText: 2024 Sowjanya Kota <sowjanya.kch@gmail.com> | ||
* SPDX-FileCopyrightText: 2025 Marcel Hibbe <dev@mhibbe.de> | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
package com.nextcloud.talk.contacts | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import com.nextcloud.talk.R | ||
import com.nextcloud.talk.contacts.components.AppBar | ||
import com.nextcloud.talk.contacts.components.ContactsList | ||
import com.nextcloud.talk.contacts.components.ConversationCreationOptions | ||
|
||
@Composable | ||
fun ContactsScreen(contactsViewModel: ContactsViewModel, uiState: ContactsUiState) { | ||
val context = LocalContext.current | ||
|
||
val searchQuery by contactsViewModel.searchQuery.collectAsStateWithLifecycle() | ||
val isSearchActive by contactsViewModel.isSearchActive.collectAsStateWithLifecycle() | ||
val isAddParticipants by contactsViewModel.isAddParticipantsView.collectAsStateWithLifecycle() | ||
val autocompleteUsers by contactsViewModel.selectedParticipantsList.collectAsStateWithLifecycle() | ||
|
||
Scaffold( | ||
topBar = { | ||
AppBar( | ||
title = stringResource(R.string.nc_app_product_name), | ||
searchQuery = searchQuery, | ||
isSearchActive = isSearchActive, | ||
isAddParticipants = isAddParticipants, | ||
autocompleteUsers = autocompleteUsers, | ||
onEnableSearch = { | ||
contactsViewModel.setSearchActive(true) | ||
}, | ||
onDisableSearch = { | ||
contactsViewModel.setSearchActive(false) | ||
}, | ||
onUpdateSearchQuery = { | ||
contactsViewModel.updateSearchQuery(query = it) | ||
}, | ||
onUpdateAutocompleteUsers = { | ||
contactsViewModel.getContactsFromSearchParams() | ||
} | ||
) | ||
}, | ||
content = { | ||
Column( | ||
Modifier.padding(it) | ||
.background(colorResource(id = R.color.bg_default)) | ||
) { | ||
ConversationCreationOptions( | ||
context = context, | ||
contactsViewModel = contactsViewModel | ||
) | ||
ContactsList( | ||
contactsUiState = uiState, | ||
contactsViewModel = contactsViewModel, | ||
context = context | ||
) | ||
} | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 0 additions & 104 deletions
104
app/src/main/java/com/nextcloud/talk/contacts/SearchComponent.kt
This file was deleted.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
app/src/main/java/com/nextcloud/talk/contacts/components/AppBar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Nextcloud Talk - Android Client | ||
* | ||
* SPDX-FileCopyrightText: 2024 Sowjanya Kota <sowjanya.kch@gmail.com> | ||
* SPDX-FileCopyrightText: 2025 Marcel Hibbe <dev@mhibbe.de> | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
package com.nextcloud.talk.contacts.components | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Activity | ||
import android.content.Intent | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.automirrored.filled.ArrowBack | ||
import androidx.compose.material.icons.filled.Search | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import com.nextcloud.talk.R | ||
import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser | ||
|
||
@SuppressLint("UnrememberedMutableState") | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun AppBar( | ||
title: String, | ||
searchQuery: String, | ||
isSearchActive: Boolean, | ||
isAddParticipants: Boolean, | ||
autocompleteUsers: List<AutocompleteUser>, | ||
onEnableSearch: () -> Unit, | ||
onDisableSearch: () -> Unit, | ||
onUpdateSearchQuery: (String) -> Unit, | ||
onUpdateAutocompleteUsers: () -> Unit | ||
) { | ||
val context = LocalContext.current | ||
|
||
TopAppBar( | ||
title = { Text(text = title) }, | ||
navigationIcon = { | ||
IconButton(onClick = { | ||
(context as? Activity)?.finish() | ||
}) { | ||
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(R.string.back_button)) | ||
} | ||
}, | ||
actions = { | ||
IconButton(onClick = onEnableSearch) { | ||
Icon(Icons.Filled.Search, contentDescription = stringResource(R.string.search_icon)) | ||
} | ||
if (isAddParticipants) { | ||
Text( | ||
text = stringResource(id = R.string.nc_contacts_done), | ||
modifier = Modifier.clickable { | ||
val resultIntent = Intent().apply { | ||
putParcelableArrayListExtra( | ||
"selectedParticipants", | ||
ArrayList(autocompleteUsers) | ||
) | ||
} | ||
(context as? Activity)?.setResult(Activity.RESULT_OK, resultIntent) | ||
(context as? Activity)?.finish() | ||
} | ||
) | ||
} | ||
} | ||
) | ||
if (isSearchActive) { | ||
Row { | ||
SearchComponent( | ||
text = searchQuery, | ||
onTextChange = { searchQuery -> | ||
onUpdateSearchQuery(searchQuery) | ||
onUpdateAutocompleteUsers() | ||
}, | ||
onDisableSearch = onDisableSearch | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.