mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 20:48:43 +00:00
Update chat folder settings display.
This commit is contained in:
committed by
Greyson Parrelli
parent
c291d84738
commit
9e955e94d9
@@ -63,12 +63,22 @@ class ChatsSettingsFragment : DSLSettingsFragment(R.string.preferences_chats__ch
|
|||||||
if (RemoteConfig.showChatFolders) {
|
if (RemoteConfig.showChatFolders) {
|
||||||
sectionHeaderPref(R.string.ChatsSettingsFragment__chat_folders)
|
sectionHeaderPref(R.string.ChatsSettingsFragment__chat_folders)
|
||||||
|
|
||||||
|
if (state.folderCount == 0) {
|
||||||
clickPref(
|
clickPref(
|
||||||
title = DSLSettingsText.from(R.string.ChatsSettingsFragment__add_chat_folder),
|
title = DSLSettingsText.from(R.string.ChatsSettingsFragment__add_chat_folder),
|
||||||
onClick = {
|
onClick = {
|
||||||
Navigation.findNavController(requireView()).safeNavigate(R.id.action_chatsSettingsFragment_to_chatFoldersFragment)
|
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()
|
dividerPref()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,6 @@ data class ChatsSettingsState(
|
|||||||
val keepMutedChatsArchived: Boolean,
|
val keepMutedChatsArchived: Boolean,
|
||||||
val useSystemEmoji: Boolean,
|
val useSystemEmoji: Boolean,
|
||||||
val enterKeySends: Boolean,
|
val enterKeySends: Boolean,
|
||||||
val localBackupsEnabled: Boolean
|
val localBackupsEnabled: Boolean,
|
||||||
|
val folderCount: Int
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ package org.thoughtcrime.securesms.components.settings.app.chats
|
|||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.ViewModel
|
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.dependencies.AppDependencies
|
||||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||||
import org.thoughtcrime.securesms.util.BackupUtil
|
import org.thoughtcrime.securesms.util.BackupUtil
|
||||||
@@ -22,7 +26,8 @@ class ChatsSettingsViewModel @JvmOverloads constructor(
|
|||||||
keepMutedChatsArchived = SignalStore.settings.shouldKeepMutedChatsArchived(),
|
keepMutedChatsArchived = SignalStore.settings.shouldKeepMutedChatsArchived(),
|
||||||
useSystemEmoji = SignalStore.settings.isPreferSystemEmoji,
|
useSystemEmoji = SignalStore.settings.isPreferSystemEmoji,
|
||||||
enterKeySends = SignalStore.settings.isEnterKeySends,
|
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() {
|
fun refresh() {
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
val count = ChatFoldersRepository.getFolderCount()
|
||||||
val backupsEnabled = SignalStore.settings.isBackupEnabled && BackupUtil.canUserAccessBackupDirectory(AppDependencies.application)
|
val backupsEnabled = SignalStore.settings.isBackupEnabled && BackupUtil.canUserAccessBackupDirectory(AppDependencies.application)
|
||||||
|
|
||||||
if (store.state.localBackupsEnabled != backupsEnabled
|
if (store.state.localBackupsEnabled != backupsEnabled) {
|
||||||
) {
|
store.update {
|
||||||
store.update { it.copy(localBackupsEnabled = backupsEnabled) }
|
it.copy(
|
||||||
|
folderCount = count,
|
||||||
|
localBackupsEnabled = backupsEnabled
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
store.update {
|
||||||
|
it.copy(
|
||||||
|
folderCount = count
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,4 +44,8 @@ object ChatFoldersRepository {
|
|||||||
fun getFolder(id: Long): ChatFolderRecord {
|
fun getFolder(id: Long): ChatFolderRecord {
|
||||||
return SignalDatabase.chatFolders.getChatFolder(id)
|
return SignalDatabase.chatFolders.getChatFolder(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getFolderCount(): Int {
|
||||||
|
return SignalDatabase.chatFolders.getFolderCount()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import androidx.compose.runtime.collectAsState
|
|||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
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.recipients.Recipient
|
||||||
import org.thoughtcrime.securesms.util.navigation.safeNavigate
|
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
|
* Fragment that allows user to create, edit, or delete an individual folder
|
||||||
*/
|
*/
|
||||||
@@ -175,6 +178,9 @@ fun CreateFolderScreen(
|
|||||||
onCreateConfirmed: (Boolean) -> Unit = {},
|
onCreateConfirmed: (Boolean) -> Unit = {},
|
||||||
onCreateDismissed: (Boolean) -> Unit = {}
|
onCreateDismissed: (Boolean) -> Unit = {}
|
||||||
) {
|
) {
|
||||||
|
var expandIncluded by remember { mutableStateOf(false) }
|
||||||
|
var expandExcluded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
if (state.showDeleteDialog) {
|
if (state.showDeleteDialog) {
|
||||||
Dialogs.SimpleAlertDialog(
|
Dialogs.SimpleAlertDialog(
|
||||||
title = "",
|
title = "",
|
||||||
@@ -250,12 +256,28 @@ fun CreateFolderScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ->
|
items(state.currentFolder.includedRecipients.toList()) { recipient ->
|
||||||
ChatRow(
|
ChatRow(
|
||||||
recipient = recipient,
|
recipient = recipient,
|
||||||
onClick = onAddChat
|
onClick = onAddChat
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
item {
|
item {
|
||||||
Text(
|
Text(
|
||||||
@@ -279,12 +301,28 @@ fun CreateFolderScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ->
|
items(state.currentFolder.excludedRecipients.toList()) { recipient ->
|
||||||
ChatRow(
|
ChatRow(
|
||||||
recipient = recipient,
|
recipient = recipient,
|
||||||
onClick = onRemoveChat
|
onClick = onRemoveChat
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
item {
|
item {
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.ContentValues
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.core.content.contentValuesOf
|
import androidx.core.content.contentValuesOf
|
||||||
import org.signal.core.util.SqlUtil
|
import org.signal.core.util.SqlUtil
|
||||||
|
import org.signal.core.util.count
|
||||||
import org.signal.core.util.delete
|
import org.signal.core.util.delete
|
||||||
import org.signal.core.util.groupBy
|
import org.signal.core.util.groupBy
|
||||||
import org.signal.core.util.insertInto
|
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
|
* Adds a chat folder and its corresponding included/excluded chats
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5069,8 +5069,15 @@
|
|||||||
<string name="ChatsSettingsFragment__send_with_enter">Send with enter</string>
|
<string name="ChatsSettingsFragment__send_with_enter">Send with enter</string>
|
||||||
<!-- Heading within chats settings for chat folders -->
|
<!-- Heading within chats settings for chat folders -->
|
||||||
<string name="ChatsSettingsFragment__chat_folders">Chat folders</string>
|
<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>
|
<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 -->
|
<!-- ChatFoldersFragment -->
|
||||||
<!-- Description of what chat folders are -->
|
<!-- Description of what chat folders are -->
|
||||||
@@ -5172,6 +5179,8 @@
|
|||||||
<string name="CreateFoldersFragment__delete_folder">Delete folder</string>
|
<string name="CreateFoldersFragment__delete_folder">Delete folder</string>
|
||||||
<!-- Alert dialog title to delete the current folder -->
|
<!-- Alert dialog title to delete the current folder -->
|
||||||
<string name="CreateFoldersFragment__delete_this_chat_folder">Delete this chat folder?</string>
|
<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 -->
|
<!-- ChooseChatsFragment -->
|
||||||
<!-- Section title representing chat types that can be added to the folder -->
|
<!-- Section title representing chat types that can be added to the folder -->
|
||||||
|
|||||||
Reference in New Issue
Block a user