Fehler in der Indexierung beim Sortieren behoben

This commit is contained in:
Gerrit Linnemann 2020-08-16 19:54:01 +02:00
parent 0194f0c860
commit c59667881b
4 changed files with 29 additions and 7 deletions

View File

@ -42,7 +42,7 @@ struct ContentView: View {
.focusable() .focusable()
.onMoveCommand { (direction) in .onMoveCommand { (direction) in
var newIndex = Shared.shared.currentFile.index var newIndex = Shared.shared.currentFile.index
print("\(direction)")
switch direction { switch direction {
case MoveCommandDirection.down: case MoveCommandDirection.down:
let max = self.fileList.count let max = self.fileList.count

View File

@ -53,7 +53,7 @@ class FinderHelper {
var index = 0 var index = 0
for item in items { for item in items {
let yapsFile: YapsFile = YapsFile(index: index, name: item.lastPathComponent, file: item, current: false) let yapsFile: YapsFile = YapsFile(index: -1, name: item.lastPathComponent, file: item, current: false)
fileList.append(yapsFile) fileList.append(yapsFile)
index += 1 index += 1
} }
@ -61,7 +61,28 @@ class FinderHelper {
// failed to read directory bad permissions, perhaps? // failed to read directory bad permissions, perhaps?
} }
return fileList return indexify(list: fileList.sorted {
let f01: YapsFile = $0
let f02: YapsFile = $1
let cd01 = FinderHelper.shared.getFileAttributes(yapsFile: f01)[FileAttributeKey.creationDate] as! Date
let cd02 = FinderHelper.shared.getFileAttributes(yapsFile: f02)[FileAttributeKey.creationDate] as! Date
return cd01 > cd02
})
}
func indexify(list: [YapsFile]) -> [YapsFile] {
var indexifiedFileList = [YapsFile]()
var index = 0
for item in list {
let yapsFile: YapsFile = YapsFile(index: index, name: item.file.lastPathComponent, file: item.file, current: false)
indexifiedFileList.append(yapsFile)
index += 1
}
return indexifiedFileList
} }
func getImageByFiletype(file: URL) -> Image { func getImageByFiletype(file: URL) -> Image {

View File

@ -18,7 +18,7 @@ class MiscHelper {
dateFormatterGet.dateFormat = "yyyy-MM-dd HH:mm:ss" dateFormatterGet.dateFormat = "yyyy-MM-dd HH:mm:ss"
let dateFormatterPrint = DateFormatter() let dateFormatterPrint = DateFormatter()
dateFormatterPrint.dateFormat = "yyyy.MM.dd" dateFormatterPrint.dateFormat = "yyyy.MM.dd HH:mm:ss"
if let date = dateFormatterGet.date(from: dateFormatterGet.string(from: inDate)) { if let date = dateFormatterGet.date(from: dateFormatterGet.string(from: inDate)) {
return dateFormatterPrint.string(from: date) return dateFormatterPrint.string(from: date)

View File

@ -10,8 +10,9 @@ import Foundation
struct YapsFile: Identifiable, Hashable { struct YapsFile: Identifiable, Hashable {
let id = UUID() let id = UUID()
let index: Int
let name: String var index: Int
let file: URL var name: String
var file: URL
var current: Bool var current: Bool
} }