Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ final class TranslationPickerSettingsViewController: UIViewController,
}

dataSource.reorderingHandlers.canReorderItem = { [weak self] item in
guard let self, state.isEditing else { return false }
guard let self, state.isTranslationsEnabled else { return false }
if case .language = item { return true }
return false
}
Expand All @@ -249,11 +249,19 @@ final class TranslationPickerSettingsViewController: UIViewController,
if case .language(let details) = item { return details }
return nil
}
store.dispatch(TranslationSettingsViewAction(
pendingLanguages: reorderedLanguages,
windowUUID: windowUUID,
actionType: TranslationSettingsViewActionType.reorderLanguages
))
if state.isEditing {
store.dispatch(TranslationSettingsViewAction(
pendingLanguages: reorderedLanguages,
windowUUID: windowUUID,
actionType: TranslationSettingsViewActionType.reorderLanguages
))
} else {
store.dispatch(TranslationSettingsViewAction(
languages: reorderedLanguages.map { $0.code },
windowUUID: windowUUID,
actionType: TranslationSettingsViewActionType.saveLanguages
))
}
}

return dataSource
Expand All @@ -265,7 +273,7 @@ final class TranslationPickerSettingsViewController: UIViewController,
guard let self, case let .language(details) = item else { return }
cell.configure(with: details, theme: themeManager.getCurrentTheme(for: windowUUID))
if details.isDeviceLanguage {
cell.accessories = [.reorder(displayed: .whenEditing)]
cell.accessories = [.reorder(displayed: .always)]
} else {
let deleteActionHandler = { [weak self] in
guard let self else { return }
Expand All @@ -277,7 +285,7 @@ final class TranslationPickerSettingsViewController: UIViewController,
}
cell.accessories = [
.delete(displayed: .whenEditing, actionHandler: deleteActionHandler),
.reorder(displayed: .whenEditing)
.reorder(displayed: .always)
]
cell.accessibilityCustomActions = [
UIAccessibilityCustomAction(
Expand Down Expand Up @@ -367,6 +375,18 @@ final class TranslationPickerSettingsViewController: UIViewController,

// MARK: - UICollectionViewDelegate

func collectionView(
_ collectionView: UICollectionView,
targetIndexPathForMoveFromItemAt originalIndexPath: IndexPath,
toProposedIndexPath proposedIndexPath: IndexPath
) -> IndexPath {
guard proposedIndexPath.section == originalIndexPath.section,
dataSource.itemIdentifier(for: proposedIndexPath) != .addLanguage else {
return originalIndexPath
}
return proposedIndexPath
}

func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
return dataSource.itemIdentifier(for: indexPath) == .addLanguage
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,24 @@ final class TranslationSettingsDiffableDataSource:
currentState = state

var snapshot = NSDiffableDataSourceSnapshot<TranslationSettingsSection, TranslationSettingsItem>()
snapshot.appendSections([.enableToggle])
snapshot.appendItems([.enableToggle], toSection: .enableToggle)

if state.isTranslationsEnabled {
if state.isEditing {
snapshot.appendSections([.preferredLanguages])
let displayLanguages = state.pendingLanguages ?? state.preferredLanguages
let langItems = displayLanguages.map { TranslationSettingsItem.language($0) }
snapshot.appendItems(langItems + [.addLanguage], toSection: .preferredLanguages)
snapshot.appendSections([.autoTranslate])
snapshot.appendItems([.autoTranslate], toSection: .autoTranslate)
snapshot.appendItems(langItems, toSection: .preferredLanguages)
} else {
snapshot.appendSections([.enableToggle])
snapshot.appendItems([.enableToggle], toSection: .enableToggle)

if state.isTranslationsEnabled {
snapshot.appendSections([.preferredLanguages])
let displayLanguages = state.pendingLanguages ?? state.preferredLanguages
let langItems = displayLanguages.map { TranslationSettingsItem.language($0) }
snapshot.appendItems(langItems + [.addLanguage], toSection: .preferredLanguages)
snapshot.appendSections([.autoTranslate])
snapshot.appendItems([.autoTranslate], toSection: .autoTranslate)
}
}

if let previousState {
Expand Down
Loading