Fix various UI bugs for chat folders.

This commit is contained in:
Michelle Tang
2024-11-01 16:28:45 -04:00
committed by GitHub
parent 90ff3d1e32
commit d115835606
5 changed files with 56 additions and 65 deletions

View File

@@ -62,7 +62,7 @@ class ChatsSettingsFragment : DSLSettingsFragment(R.string.preferences_chats__ch
sectionHeaderPref(R.string.ChatsSettingsFragment__chat_folders)
if (state.folderCount == 0) {
if (state.folderCount == 1) {
clickPref(
title = DSLSettingsText.from(R.string.ChatsSettingsFragment__add_chat_folder),
onClick = {

View File

@@ -327,8 +327,7 @@ class ChatFoldersViewModel : ViewModel() {
val originalFolder = state.value.originalFolder
return if (currentFolder.id == -1L) {
currentFolder.name.isNotEmpty() &&
(currentFolder.includedRecipients.isNotEmpty() || currentFolder.showIndividualChats || currentFolder.showGroupChats)
currentFolder.includedRecipients.isNotEmpty() || currentFolder.showIndividualChats || currentFolder.showGroupChats
} else {
originalFolder != currentFolder ||
originalFolder.includedRecipients != currentFolder.includedRecipients ||

View File

@@ -364,42 +364,35 @@ fun CreateFolderScreen(
}
}
if (hasChanges && isNewFolder) {
Buttons.MediumTonal(
onClick = { onCreateConfirmed() },
modifier = modifier
.align(Alignment.BottomEnd)
.padding(end = 16.dp, bottom = 16.dp)
) {
Text(text = stringResource(R.string.CreateFoldersFragment__create))
}
} else if (!isNewFolder) {
Buttons.MediumTonal(
colors = ButtonDefaults.filledTonalButtonColors(
contentColor = if (state.currentFolder.name.isEmpty()) {
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
} else {
MaterialTheme.colorScheme.onSurface
},
containerColor = if (state.currentFolder.name.isEmpty()) {
MaterialTheme.colorScheme.surfaceVariant
} else {
MaterialTheme.colorScheme.primaryContainer
},
disabledContainerColor = MaterialTheme.colorScheme.surfaceVariant
),
enabled = hasChanges,
onClick = {
if (state.currentFolder.name.isEmpty()) {
onShowToast()
} else {
onCreateConfirmed()
}
Buttons.MediumTonal(
colors = ButtonDefaults.filledTonalButtonColors(
contentColor = if (state.currentFolder.name.isEmpty()) {
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
} else {
MaterialTheme.colorScheme.onSurface
},
modifier = modifier
.align(Alignment.BottomEnd)
.padding(end = 16.dp, bottom = 16.dp)
) {
containerColor = if (state.currentFolder.name.isEmpty()) {
MaterialTheme.colorScheme.surfaceVariant
} else {
MaterialTheme.colorScheme.primaryContainer
},
disabledContainerColor = MaterialTheme.colorScheme.surfaceVariant
),
enabled = hasChanges,
onClick = {
if (state.currentFolder.name.isEmpty()) {
onShowToast()
} else {
onCreateConfirmed()
}
},
modifier = modifier
.align(Alignment.BottomEnd)
.padding(end = 16.dp, bottom = 16.dp)
) {
if (isNewFolder) {
Text(text = stringResource(R.string.CreateFoldersFragment__create))
} else {
Text(text = stringResource(R.string.CreateFoldersFragment__save))
}
}

View File

@@ -234,13 +234,12 @@ class ChatFolderTables(context: Context?, databaseHelper: SignalDatabase?) : Dat
}
/**
* Returns the number of user-made folders
* Returns the number of folders a user has, including the default 'All Chats'
*/
fun getFolderCount(): Int {
return readableDatabase
.count()
.from(ChatFolderTable.TABLE_NAME)
.where("${ChatFolderTable.FOLDER_TYPE} != ${ChatFolderRecord.FolderType.ALL.value}")
.run()
.readToSingleInt()
}