Skip to content

Commit

Permalink
Merge pull request #363 from you-apps/scrollbar
Browse files Browse the repository at this point in the history
feat: use fast scrollbar for contacts list
  • Loading branch information
Bnyro authored Jan 11, 2024
2 parents 48425ad + e0a2076 commit 81031da
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 259 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ dependencies {
implementation("androidx.compose.ui:ui-tooling-preview:$compose_version")
implementation("androidx.compose.material3:material3:1.2.0-alpha02")
implementation("androidx.compose.material:material-icons-extended:1.4.3")
implementation("com.github.nanihadesuka:LazyColumnScrollbar:1.9.0")

// VCard
implementation("com.googlecode.ez-vcard:ez-vcard:0.11.3")
Expand Down
77 changes: 42 additions & 35 deletions app/src/main/java/com/bnyro/contacts/ui/components/ContactsList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
Expand All @@ -15,7 +16,7 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.unit.dp
import com.bnyro.contacts.obj.ContactData
import com.bnyro.contacts.obj.FilterOptions
import com.bnyro.contacts.ui.components.modifier.scrollbar
import my.nanihadesuka.compose.LazyColumnScrollbar

@OptIn(ExperimentalFoundationApi::class)
@Composable
Expand Down Expand Up @@ -43,46 +44,52 @@ fun ContactsList(
it.getNameBySortOrder(filterOptions.sortOder)?.firstOrNull()?.uppercase()
}
}
LazyColumn(
state = state,
modifier = Modifier
.padding(end = 5.dp)
.scrollbar(state, false)
.let { modifier ->
scrollConnection?.let { modifier.nestedScroll(it) } ?: modifier
}
LazyColumnScrollbar(
listState = state,
thumbColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.5f),
thumbSelectedColor = MaterialTheme.colorScheme.primary,
thickness = 8.dp
) {
contactGroups.forEach { (firstLetter, groupedContacts) ->
stickyHeader {
CharacterHeader(firstLetter.orEmpty())
}
items(groupedContacts) {
ContactItem(
modifier = Modifier.padding(horizontal = 10.dp),
contact = it,
sortOrder = filterOptions.sortOder,
selected = selectedContacts.contains(it),
onSinglePress = {
if (selectedContacts.isEmpty()) {
false
} else {
if (selectedContacts.contains(it)) {
selectedContacts.remove(it)
LazyColumn(
state = state,
modifier = Modifier
.padding(end = 5.dp)
.let { modifier ->
scrollConnection?.let { modifier.nestedScroll(it) } ?: modifier
}
) {
contactGroups.forEach { (firstLetter, groupedContacts) ->
stickyHeader {
CharacterHeader(firstLetter.orEmpty())
}
items(groupedContacts) {
ContactItem(
modifier = Modifier.padding(horizontal = 10.dp),
contact = it,
sortOrder = filterOptions.sortOder,
selected = selectedContacts.contains(it),
onSinglePress = {
if (selectedContacts.isEmpty()) {
false
} else {
selectedContacts.add(it)
if (selectedContacts.contains(it)) {
selectedContacts.remove(it)
} else {
selectedContacts.add(it)
}
true
}
true
},
onLongPress = {
if (!selectedContacts.contains(it)) selectedContacts.add(it)
}
},
onLongPress = {
if (!selectedContacts.contains(it)) selectedContacts.add(it)
}
)
)
}
}
}

item {
Spacer(modifier = Modifier.height(10.dp))
item {
Spacer(modifier = Modifier.height(10.dp))
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bnyro.contacts.ui.components
package com.bnyro.contacts.ui.screens

import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
Expand Down Expand Up @@ -50,17 +50,16 @@ import com.bnyro.contacts.R
import com.bnyro.contacts.enums.ContactsSource
import com.bnyro.contacts.obj.ContactData
import com.bnyro.contacts.obj.FilterOptions
import com.bnyro.contacts.ui.components.ContactSearchScreen
import com.bnyro.contacts.ui.components.ContactsList
import com.bnyro.contacts.ui.components.NothingHere
import com.bnyro.contacts.ui.components.base.ClickableIcon
import com.bnyro.contacts.ui.components.base.OptionMenu
import com.bnyro.contacts.ui.components.dialogs.ConfirmationDialog
import com.bnyro.contacts.ui.components.dialogs.FilterDialog
import com.bnyro.contacts.ui.components.dialogs.SimImportDialog
import com.bnyro.contacts.ui.models.ContactsModel
import com.bnyro.contacts.ui.models.state.ContactListState
import com.bnyro.contacts.ui.screens.AboutScreen
import com.bnyro.contacts.ui.screens.EditorScreen
import com.bnyro.contacts.ui.screens.SettingsScreen
import com.bnyro.contacts.ui.screens.SingleContactScreen
import com.bnyro.contacts.util.BackupHelper
import com.bnyro.contacts.util.Preferences

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.bnyro.contacts.R
import com.bnyro.contacts.obj.NavBarItem
import com.bnyro.contacts.ui.components.ContactsPage
import com.bnyro.contacts.ui.models.ContactsModel
import com.bnyro.contacts.ui.models.SmsModel
import com.bnyro.contacts.ui.models.ThemeModel
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven("https://jitpack.io")
}
}
rootProject.name = "Connect You"
Expand Down

0 comments on commit 81031da

Please sign in to comment.