Skip to content

Commit 73f02bf

Browse files
committed
- AccountControllerSpacesViewController: account for several instances, each using a different list / grid view (fixing finding (1) in #1529)
1 parent e3f703f commit 73f02bf

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

ownCloudAppShared/Client/Account/Controller/AccountControllerSpacesViewController.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class AccountControllerSpacesViewController: CollectionViewController, ViewContr
4141
context.viewControllerPusher = owner as? ViewControllerPusher
4242
}
4343

44-
spacesSection = CollectionViewSection(identifier: "spaces", dataSource: spacesDataSource, cellStyle: Self.cellStyle(for: .current), cellLayout: Self.cellLayout(for: .current))
44+
spacesSection = CollectionViewSection(identifier: "spaces", dataSource: spacesDataSource, cellStyle: Self.cellStyle(for: .current, listView: Self.listView), cellLayout: Self.cellLayout(for: .current, listView: Self.listView))
45+
_actualListView = Self.listView
4546

4647
super.init(context: gridContext, sections: [ spacesSection ], useStackViewRoot: true, hierarchic: false)
4748

@@ -104,8 +105,8 @@ class AccountControllerSpacesViewController: CollectionViewController, ViewContr
104105
// List/Grid
105106
if let self {
106107
completion([
107-
UIAction(title: Self.listView ? OCLocalizedString("Grid",nil) : OCLocalizedString("List", nil),
108-
image: OCSymbol.icon(forSymbolName: Self.listView ? "square.grid.2x2" : "list.bullet"),
108+
UIAction(title: self.listView ? OCLocalizedString("Grid",nil) : OCLocalizedString("List", nil),
109+
image: OCSymbol.icon(forSymbolName: self.listView ? "square.grid.2x2" : "list.bullet"),
109110
handler: { _ in
110111
self.listView = !self.listView
111112
})
@@ -165,28 +166,30 @@ class AccountControllerSpacesViewController: CollectionViewController, ViewContr
165166
}
166167
}
167168

169+
private var _actualListView: Bool
168170
var listView: Bool {
169171
get {
170-
return Self.listView
172+
return _actualListView
171173
}
172174

173175
set {
176+
_actualListView = newValue
174177
Self.listView = newValue
175178
OnMainThread {
176-
self.spacesSection.cellStyle = Self.cellStyle(for: .current)
177-
self.spacesSection.cellLayout = Self.cellLayout(for: .current)
179+
self.spacesSection.cellStyle = Self.cellStyle(for: .current, listView:newValue)
180+
self.spacesSection.cellLayout = Self.cellLayout(for: .current, listView:newValue)
178181
}
179182
}
180183
}
181184

182-
static func cellStyle(for traitCollection: UITraitCollection) -> CollectionViewCellStyle {
185+
static func cellStyle(for traitCollection: UITraitCollection, listView: Bool) -> CollectionViewCellStyle {
183186
if listView {
184187
return .init(with: .tableCell)
185188
}
186189
return .init(with: .gridCell)
187190
}
188191

189-
static func cellLayout(for traitCollection: UITraitCollection) -> CollectionViewSection.CellLayout {
192+
static func cellLayout(for traitCollection: UITraitCollection, listView: Bool) -> CollectionViewSection.CellLayout {
190193
if listView {
191194
return .list(appearance: .plain, contentInsets: NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
192195
}
@@ -200,7 +203,7 @@ class AccountControllerSpacesViewController: CollectionViewController, ViewContr
200203
super.traitCollectionDidChange(previousTraitCollection)
201204

202205
OnMainThread {
203-
self.spacesSection.cellLayout = Self.cellLayout(for: self.traitCollection)
206+
self.spacesSection.cellLayout = Self.cellLayout(for: self.traitCollection, listView: self.listView)
204207
}
205208
}
206209

0 commit comments

Comments
 (0)