Fehler in der Indexierung beim Sortieren behoben
This commit is contained in:
parent
0194f0c860
commit
c59667881b
@ -42,7 +42,7 @@ struct ContentView: View {
|
||||
.focusable()
|
||||
.onMoveCommand { (direction) in
|
||||
var newIndex = Shared.shared.currentFile.index
|
||||
|
||||
print("\(direction)")
|
||||
switch direction {
|
||||
case MoveCommandDirection.down:
|
||||
let max = self.fileList.count
|
||||
|
||||
@ -53,7 +53,7 @@ class FinderHelper {
|
||||
|
||||
var index = 0
|
||||
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)
|
||||
index += 1
|
||||
}
|
||||
@ -61,7 +61,28 @@ class FinderHelper {
|
||||
// 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 {
|
||||
|
||||
@ -18,7 +18,7 @@ class MiscHelper {
|
||||
dateFormatterGet.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
||||
|
||||
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)) {
|
||||
return dateFormatterPrint.string(from: date)
|
||||
|
||||
@ -10,8 +10,9 @@ import Foundation
|
||||
|
||||
struct YapsFile: Identifiable, Hashable {
|
||||
let id = UUID()
|
||||
let index: Int
|
||||
let name: String
|
||||
let file: URL
|
||||
|
||||
var index: Int
|
||||
var name: String
|
||||
var file: URL
|
||||
var current: Bool
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user