From 4b4f14382da9679c572608982ba2dbef5720da14 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Thu, 16 Mar 2023 11:19:19 +0100 Subject: [PATCH] open works now for android 10 --- src/app/model/actions/open-file.ts | 2 +- src/app/model/sorting.ts | 30 +++++++++++++++---- .../show-folder/show-folder.component.html | 5 ++-- src/app/trash/trash.page.html | 2 +- src/app/trash/trash.page.ts | 11 +++++-- 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/app/model/actions/open-file.ts b/src/app/model/actions/open-file.ts index fb70f6c..5dfed9e 100644 --- a/src/app/model/actions/open-file.ts +++ b/src/app/model/actions/open-file.ts @@ -42,7 +42,7 @@ export class OpenFile { const fileWrited = await Filesystem.writeFile({ path: this.item.getTitle(), data: base64, - directory: Directory.Documents + directory: Directory.Data }); const mimeType = this.item.item.content?.mimeType; diff --git a/src/app/model/sorting.ts b/src/app/model/sorting.ts index fd9b0e8..19005c9 100644 --- a/src/app/model/sorting.ts +++ b/src/app/model/sorting.ts @@ -3,6 +3,7 @@ import { WSItem } from "./ws-item"; export enum SortName { Name = "Name", LastModificationTime = "Last Modified", + Size = "Size", FolderFirst = "Folders First" } @@ -14,19 +15,33 @@ export enum SortType { export class Sorting { private static sortByNameASC = (item1: WSItem, item2: WSItem) => item1.getTitle().toLowerCase() > item2.getTitle().toLowerCase() ? -1 : 1; - private static sortByNameDESC = (item1: WSItem, item2: WSItem) => item1.getTitle().toLowerCase() > item2.getTitle().toLowerCase() ? 1 : -1; + private static sortByNameDESC = (item1: WSItem, item2: WSItem) => this.sortByNameASC(item1, item2) * (-1); - private static sortByLastModificationASC = (item1: WSItem, item2: WSItem) => item1.item.lastModificationTime > item2.item.lastModificationTime ? 1 : -1; - private static sortByLastModificationDESC = (item1: WSItem, item2: WSItem) => item1.item.lastModificationTime > item2.item.lastModificationTime ? -1 : 1; + private static sortByLastModificationASC = (item1: WSItem, item2: WSItem) => item1.item.lastModificationTime > item2.item.lastModificationTime ? -1 : 1; + private static sortByLastModificationDESC = (item1: WSItem, item2: WSItem) => this.sortByLastModificationASC(item1, item2) * (-1); private static folderFirst(item1: WSItem, item2: WSItem) { if (item1.isFolder() && !item2.isFolder()) return -1; if (!item1.isFolder() && item2.isFolder()) return 1; - if (item1.item.title > item2.item.title) return 1; - if (item1.item.title < item2.item.title) return -1; + if (item1.getTitle().toLocaleLowerCase() > item2.getTitle().toLocaleLowerCase()) return -1; + if (item1.getTitle().toLocaleLowerCase() < item2.getTitle().toLocaleLowerCase()) return 1; return 0; } + private static sortBySizeASC(item1: WSItem, item2: WSItem) { + if (item1.isFolder() && item2.isFile()) return 1; + if (item1.isFile() && item2.isFolder()) return -1; + if (item1.isFile() && item2.isFile()) { + const sizeFile1 = item1.item.content ? item1.item.content.size : 0; + const sizeFile2 = item2.item.content ? item2.item.content.size : 0; + return sizeFile2 - sizeFile1; + } + return 0; + } + + private static sortBySizeDESC = (item1: WSItem, item2: WSItem) => this.sortBySizeASC(item1, item2) * (-1); + + static getSortFunction(name: SortName, type: SortType): (a: WSItem, b: WSItem) => number { switch (name) { case SortName.Name: @@ -39,6 +54,11 @@ export class Sorting { case SortType.Asc: return this.sortByLastModificationASC; case SortType.Desc: return this.sortByLastModificationDESC; } + case SortName.Size: + switch (type) { + case SortType.Asc: return this.sortBySizeASC; + case SortType.Desc: return this.sortBySizeDESC; + } case SortName.FolderFirst: return this.folderFirst; } diff --git a/src/app/show-folder/show-folder.component.html b/src/app/show-folder/show-folder.component.html index bfdca38..ff52574 100644 --- a/src/app/show-folder/show-folder.component.html +++ b/src/app/show-folder/show-folder.component.html @@ -1,5 +1,5 @@ - + All @@ -7,7 +7,7 @@ Folders - Shared Folders + Shared Files @@ -32,6 +32,7 @@ Name Last Modified + Size {{ currentSortType }} diff --git a/src/app/trash/trash.page.html b/src/app/trash/trash.page.html index 797fdac..ce7f7c0 100644 --- a/src/app/trash/trash.page.html +++ b/src/app/trash/trash.page.html @@ -1,4 +1,4 @@ - + diff --git a/src/app/trash/trash.page.ts b/src/app/trash/trash.page.ts index 707a0a8..358fd41 100644 --- a/src/app/trash/trash.page.ts +++ b/src/app/trash/trash.page.ts @@ -16,7 +16,9 @@ import { presentConnectionAlert } from '../_helper/utils'; export class TrashPage implements OnInit { - values: WSItem[] = []; + values: WSItem[] | undefined; + + currentItem : WSItem | undefined ; constructor(private storagehub: StoragehubService, private alertCtrl: AlertController) { } @@ -30,6 +32,7 @@ export class TrashPage implements OnInit { } private onSuccess(res: Item) { + this.currentItem = new WSItem(res); this.storagehub.getChildren(res.id, false).then((obs) => obs.subscribe({ next: (res) => { const tmpItems$: WSItem[] = [] @@ -41,7 +44,11 @@ export class TrashPage implements OnInit { )) } - public getValues(): WSItem[] { + public getValues(): WSItem[] | undefined{ return this.values; } + + public getCurrentItem(){ + return this.currentItem; + } }