Update chat folder settings display.

This commit is contained in:
Michelle Tang
2024-10-22 12:36:28 -07:00
committed by Greyson Parrelli
parent c291d84738
commit 9e955e94d9
7 changed files with 116 additions and 23 deletions

View File

@@ -63,12 +63,22 @@ class ChatsSettingsFragment : DSLSettingsFragment(R.string.preferences_chats__ch
if (RemoteConfig.showChatFolders) {
sectionHeaderPref(R.string.ChatsSettingsFragment__chat_folders)
clickPref(
title = DSLSettingsText.from(R.string.ChatsSettingsFragment__add_chat_folder),
onClick = {
Navigation.findNavController(requireView()).safeNavigate(R.id.action_chatsSettingsFragment_to_chatFoldersFragment)
}
)
if (state.folderCount == 0) {
clickPref(
title = DSLSettingsText.from(R.string.ChatsSettingsFragment__add_chat_folder),
onClick = {
Navigation.findNavController(requireView()).safeNavigate(R.id.action_chatsSettingsFragment_to_chatFoldersFragment)
}
)
} else {
clickPref(
title = DSLSettingsText.from(R.string.ChatsSettingsFragment__add_edit_chat_folder),
summary = DSLSettingsText.from(resources.getQuantityString(R.plurals.ChatsSettingsFragment__d_folder, state.folderCount, state.folderCount)),
onClick = {
Navigation.findNavController(requireView()).safeNavigate(R.id.action_chatsSettingsFragment_to_chatFoldersFragment)
}
)
}
dividerPref()
}

View File

@@ -6,5 +6,6 @@ data class ChatsSettingsState(
val keepMutedChatsArchived: Boolean,
val useSystemEmoji: Boolean,
val enterKeySends: Boolean,
val localBackupsEnabled: Boolean
val localBackupsEnabled: Boolean,
val folderCount: Int
)

View File

@@ -2,6 +2,10 @@ package org.thoughtcrime.securesms.components.settings.app.chats
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.thoughtcrime.securesms.components.settings.app.chats.folders.ChatFoldersRepository
import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.util.BackupUtil
@@ -22,7 +26,8 @@ class ChatsSettingsViewModel @JvmOverloads constructor(
keepMutedChatsArchived = SignalStore.settings.shouldKeepMutedChatsArchived(),
useSystemEmoji = SignalStore.settings.isPreferSystemEmoji,
enterKeySends = SignalStore.settings.isEnterKeySends,
localBackupsEnabled = SignalStore.settings.isBackupEnabled && BackupUtil.canUserAccessBackupDirectory(AppDependencies.application)
localBackupsEnabled = SignalStore.settings.isBackupEnabled && BackupUtil.canUserAccessBackupDirectory(AppDependencies.application),
folderCount = 0
)
)
@@ -58,11 +63,24 @@ class ChatsSettingsViewModel @JvmOverloads constructor(
}
fun refresh() {
val backupsEnabled = SignalStore.settings.isBackupEnabled && BackupUtil.canUserAccessBackupDirectory(AppDependencies.application)
viewModelScope.launch(Dispatchers.IO) {
val count = ChatFoldersRepository.getFolderCount()
val backupsEnabled = SignalStore.settings.isBackupEnabled && BackupUtil.canUserAccessBackupDirectory(AppDependencies.application)
if (store.state.localBackupsEnabled != backupsEnabled
) {
store.update { it.copy(localBackupsEnabled = backupsEnabled) }
if (store.state.localBackupsEnabled != backupsEnabled) {
store.update {
it.copy(
folderCount = count,
localBackupsEnabled = backupsEnabled
)
}
} else {
store.update {
it.copy(
folderCount = count
)
}
}
}
}
}

View File

@@ -44,4 +44,8 @@ object ChatFoldersRepository {
fun getFolder(id: Long): ChatFolderRecord {
return SignalDatabase.chatFolders.getChatFolder(id)
}
fun getFolderCount(): Int {
return SignalDatabase.chatFolders.getFolderCount()
}
}

View File

@@ -33,6 +33,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
@@ -58,6 +59,8 @@ import org.thoughtcrime.securesms.compose.ComposeFragment
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.util.navigation.safeNavigate
private const val MAX_CHAT_COUNT = 5
/**
* Fragment that allows user to create, edit, or delete an individual folder
*/
@@ -175,6 +178,9 @@ fun CreateFolderScreen(
onCreateConfirmed: (Boolean) -> Unit = {},
onCreateDismissed: (Boolean) -> Unit = {}
) {
var expandIncluded by remember { mutableStateOf(false) }
var expandExcluded by remember { mutableStateOf(false) }
if (state.showDeleteDialog) {
Dialogs.SimpleAlertDialog(
title = "",
@@ -250,11 +256,27 @@ fun CreateFolderScreen(
}
}
items(state.currentFolder.includedRecipients.toList()) { recipient ->
ChatRow(
recipient = recipient,
onClick = onAddChat
)
if (!expandIncluded && state.currentFolder.includedRecipients.size > MAX_CHAT_COUNT) {
items(state.currentFolder.includedRecipients.toList().subList(0, MAX_CHAT_COUNT)) { recipient ->
ChatRow(
recipient = recipient,
onClick = onAddChat
)
}
item {
FolderRow(
icon = R.drawable.symbol_chevron_down_24,
title = stringResource(R.string.CreateFoldersFragment__see_all),
onClick = { expandIncluded = true }
)
}
} else {
items(state.currentFolder.includedRecipients.toList()) { recipient ->
ChatRow(
recipient = recipient,
onClick = onAddChat
)
}
}
item {
@@ -279,11 +301,27 @@ fun CreateFolderScreen(
)
}
items(state.currentFolder.excludedRecipients.toList()) { recipient ->
ChatRow(
recipient = recipient,
onClick = onRemoveChat
)
if (!expandExcluded && state.currentFolder.excludedRecipients.size > MAX_CHAT_COUNT) {
items(state.currentFolder.excludedRecipients.toList().subList(0, MAX_CHAT_COUNT)) { recipient ->
ChatRow(
recipient = recipient,
onClick = onAddChat
)
}
item {
FolderRow(
icon = R.drawable.symbol_chevron_down_24,
title = stringResource(R.string.CreateFoldersFragment__see_all),
onClick = { expandExcluded = true }
)
}
} else {
items(state.currentFolder.excludedRecipients.toList()) { recipient ->
ChatRow(
recipient = recipient,
onClick = onRemoveChat
)
}
}
item {

View File

@@ -4,6 +4,7 @@ import android.content.ContentValues
import android.content.Context
import androidx.core.content.contentValuesOf
import org.signal.core.util.SqlUtil
import org.signal.core.util.count
import org.signal.core.util.delete
import org.signal.core.util.groupBy
import org.signal.core.util.insertInto
@@ -232,6 +233,18 @@ class ChatFolderTables(context: Context?, databaseHelper: SignalDatabase?) : Dat
}
}
/**
* Returns the number of user-made folders
*/
fun getFolderCount(): Int {
return readableDatabase
.count()
.from(ChatFolderTable.TABLE_NAME)
.where("${ChatFolderTable.FOLDER_TYPE} != ${ChatFolderRecord.FolderType.ALL.value}")
.run()
.readToSingleInt()
}
/**
* Adds a chat folder and its corresponding included/excluded chats
*/

View File

@@ -5069,8 +5069,15 @@
<string name="ChatsSettingsFragment__send_with_enter">Send with enter</string>
<!-- Heading within chats settings for chat folders -->
<string name="ChatsSettingsFragment__chat_folders">Chat folders</string>
<!-- Option within settings to add a new chat folder -->
<!-- Option within settings to add a new chat folder if you have never created a folder before -->
<string name="ChatsSettingsFragment__add_chat_folder">Add a chat folder</string>
<!-- Option within settings to add or edit chat folders that is shown when you have already created folders -->
<string name="ChatsSettingsFragment__add_edit_chat_folder">Add or edit folders</string>
<!-- Text describing the number of folders you have -->
<plurals name="ChatsSettingsFragment__d_folder">
<item quantity="one">%1$d folder</item>
<item quantity="other">%1$d folders</item>
</plurals>
<!-- ChatFoldersFragment -->
<!-- Description of what chat folders are -->
@@ -5172,6 +5179,8 @@
<string name="CreateFoldersFragment__delete_folder">Delete folder</string>
<!-- Alert dialog title to delete the current folder -->
<string name="CreateFoldersFragment__delete_this_chat_folder">Delete this chat folder?</string>
<!-- Option to see all of the chats if the chat list was too long and had been truncated -->
<string name="CreateFoldersFragment__see_all">See all</string>
<!-- ChooseChatsFragment -->
<!-- Section title representing chat types that can be added to the folder -->