From 1e1c3018135e443cee4b9702c3347d19695ab6e4 Mon Sep 17 00:00:00 2001 From: 0000248716-lijiaxiao Date: Mon, 26 Jul 2021 10:16:22 +0800 Subject: [PATCH] 1.0.0 --- Readme.md | 2 +- .../file/slice/MainAbilitySlice.java | 7 ++- .../developer/filepicker/utils/Utility.java | 7 ++- .../filepicker/view/FilePickerDialog.java | 60 ++++++++++++------- 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/Readme.md b/Readme.md index d34e276..34881cc 100644 --- a/Readme.md +++ b/Readme.md @@ -67,7 +67,7 @@ dialog.setDialogSelectionListener((files) -> { File file = new File(path); ListItem item = new ListItem(); item.setName(file.getName()); - item.setPath(file.getAbsolutePath()); + item.setPath(file.getCanonicalPath()); listItem.add(item); } mFileListAdapter.notifyDataSetItemRangeInserted(0, listItem.size()); diff --git a/entry/src/main/java/com/developer/filepicker/file/slice/MainAbilitySlice.java b/entry/src/main/java/com/developer/filepicker/file/slice/MainAbilitySlice.java index bdbfca7..be93a8a 100644 --- a/entry/src/main/java/com/developer/filepicker/file/slice/MainAbilitySlice.java +++ b/entry/src/main/java/com/developer/filepicker/file/slice/MainAbilitySlice.java @@ -19,6 +19,7 @@ import ohos.agp.window.dialog.ToastDialog; import ohos.agp.window.service.WindowManager; import ohos.app.Context; import ohos.app.Environment; +import ohos.data.resultset.ResultSet; import ohos.global.resource.RawFileEntry; import ohos.global.resource.Resource; import ohos.global.resource.ResourceManager; @@ -196,7 +197,11 @@ public class MainAbilitySlice extends AbilitySlice { File file = new File(path); ListItem item = new ListItem(); item.setName(file.getName()); - item.setPath(file.getAbsolutePath()); + try { + item.setPath(file.getCanonicalPath()); + } catch (IOException e) { + e.printStackTrace(); + } listItem.add(item); } mFileListAdapter.notifyDataSetItemRangeInserted(0, listItem.size()); diff --git a/library/src/main/java/com/developer/filepicker/utils/Utility.java b/library/src/main/java/com/developer/filepicker/utils/Utility.java index 607445c..4ebea67 100644 --- a/library/src/main/java/com/developer/filepicker/utils/Utility.java +++ b/library/src/main/java/com/developer/filepicker/utils/Utility.java @@ -5,6 +5,7 @@ import ohos.app.Context; import ohos.bundle.IBundleManager; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Objects; @@ -36,7 +37,11 @@ public class Utility { FileListItem item = new FileListItem(); item.setFilename(name.getName()); item.setDirectory(name.isDirectory()); - item.setLocation(name.getAbsolutePath()); + try { + item.setLocation(name.getCanonicalPath()); + } catch (IOException e) { + e.printStackTrace(); + } item.setTime(name.lastModified()); internalList.add(item); } diff --git a/library/src/main/java/com/developer/filepicker/view/FilePickerDialog.java b/library/src/main/java/com/developer/filepicker/view/FilePickerDialog.java index 19e05e3..ebdde0f 100644 --- a/library/src/main/java/com/developer/filepicker/view/FilePickerDialog.java +++ b/library/src/main/java/com/developer/filepicker/view/FilePickerDialog.java @@ -182,7 +182,7 @@ public class FilePickerDialog extends CommonDialog implements ListContainer.Item } } - public void onStart() { + public void onStart() throws IOException { positiveBtnNameStr = ( positiveBtnNameStr == null ? "Select" : @@ -193,21 +193,21 @@ public class FilePickerDialog extends CommonDialog implements ListContainer.Item File currLoc; internalList.clear(); if (properties.offset.isDirectory() && validateOffsetPath()) { - currLoc = new File(properties.offset.getAbsolutePath()); + currLoc = new File(properties.offset.getCanonicalPath()); FileListItem parent = new FileListItem(); parent.setFilename(".."); parent.setDirectory(true); parent.setLocation(Objects.requireNonNull(currLoc.getParentFile()) - .getAbsolutePath()); + .getCanonicalPath()); parent.setTime(currLoc.lastModified()); internalList.add(parent); } else if (properties.root.exists() && properties.root.isDirectory()) { - currLoc = new File(properties.root.getAbsolutePath()); + currLoc = new File(properties.root.getCanonicalPath()); } else { - currLoc = new File(properties.error_dir.getAbsolutePath()); + currLoc = new File(properties.error_dir.getCanonicalPath()); } dname.setText(currLoc.getName()); - dir_path.setText(currLoc.getAbsolutePath()); + dir_path.setText(currLoc.getCanonicalPath()); setTitle(); internalList = Utility.prepareFileListEntries(internalList, currLoc, filter, @@ -218,9 +218,9 @@ public class FilePickerDialog extends CommonDialog implements ListContainer.Item } } - private boolean validateOffsetPath() { - String offset_path = properties.offset.getAbsolutePath(); - String root_path = properties.root.getAbsolutePath(); + private boolean validateOffsetPath() throws IOException { + String offset_path = properties.offset.getCanonicalPath(); + String root_path = properties.root.getCanonicalPath(); return !offset_path.equals(root_path) && offset_path.contains(root_path); } @@ -233,14 +233,22 @@ public class FilePickerDialog extends CommonDialog implements ListContainer.Item File currLoc = new File(fitem.getLocation()); dname.setText(currLoc.getName()); setTitle(); - dir_path.setText(currLoc.getAbsolutePath()); + try { + dir_path.setText(currLoc.getCanonicalPath()); + } catch (IOException e) { + e.printStackTrace(); + } internalList.clear(); if (!currLoc.getName().equals(properties.root.getName())) { FileListItem parent = new FileListItem(); parent.setFilename(".."); parent.setDirectory(true); - parent.setLocation(Objects.requireNonNull(currLoc - .getParentFile()).getAbsolutePath()); + try { + parent.setLocation(Objects.requireNonNull(currLoc + .getParentFile()).getCanonicalPath()); + } catch (IOException e) { + e.printStackTrace(); + } parent.setTime(currLoc.lastModified()); internalList.add(parent); } @@ -286,7 +294,7 @@ public class FilePickerDialog extends CommonDialog implements ListContainer.Item } } - public void markFiles(List paths) { + public void markFiles(List paths) throws IOException { if (paths != null && paths.size() > 0) { if (properties.selection_mode == DialogConfigs.SINGLE_MODE) { File temp = new File(paths.get(0)); @@ -298,7 +306,7 @@ public class FilePickerDialog extends CommonDialog implements ListContainer.Item item.setDirectory(temp.isDirectory()); item.setMarked(true); item.setTime(temp.lastModified()); - item.setLocation(temp.getAbsolutePath()); + item.setLocation(temp.getCanonicalPath()); MarkedItemList.addSelectedItem(item); } break; @@ -310,7 +318,7 @@ public class FilePickerDialog extends CommonDialog implements ListContainer.Item item.setDirectory(temp.isDirectory()); item.setMarked(true); item.setTime(temp.lastModified()); - item.setLocation(temp.getAbsolutePath()); + item.setLocation(temp.getCanonicalPath()); MarkedItemList.addSelectedItem(item); } break; @@ -322,7 +330,7 @@ public class FilePickerDialog extends CommonDialog implements ListContainer.Item item.setDirectory(temp.isDirectory()); item.setMarked(true); item.setTime(temp.lastModified()); - item.setLocation(temp.getAbsolutePath()); + item.setLocation(temp.getCanonicalPath()); MarkedItemList.addSelectedItem(item); } break; @@ -338,7 +346,7 @@ public class FilePickerDialog extends CommonDialog implements ListContainer.Item item.setDirectory(temp.isDirectory()); item.setMarked(true); item.setTime(temp.lastModified()); - item.setLocation(temp.getAbsolutePath()); + item.setLocation(temp.getCanonicalPath()); MarkedItemList.addSelectedItem(item); } break; @@ -350,7 +358,7 @@ public class FilePickerDialog extends CommonDialog implements ListContainer.Item item.setDirectory(temp.isDirectory()); item.setMarked(true); item.setTime(temp.lastModified()); - item.setLocation(temp.getAbsolutePath()); + item.setLocation(temp.getCanonicalPath()); MarkedItemList.addSelectedItem(item); } break; @@ -363,7 +371,7 @@ public class FilePickerDialog extends CommonDialog implements ListContainer.Item item.setDirectory(temp.isDirectory()); item.setMarked(true); item.setTime(temp.lastModified()); - item.setLocation(temp.getAbsolutePath()); + item.setLocation(temp.getCanonicalPath()); MarkedItemList.addSelectedItem(item); } break; @@ -420,14 +428,22 @@ public class FilePickerDialog extends CommonDialog implements ListContainer.Item } else { dname.setText(currLoc.getName()); - dir_path.setText(currLoc.getAbsolutePath()); + try { + dir_path.setText(currLoc.getCanonicalPath()); + } catch (IOException e) { + e.printStackTrace(); + } internalList.clear(); if (!currLoc.getName().equals(properties.root.getName())) { FileListItem parent = new FileListItem(); parent.setFilename(".."); parent.setDirectory(true); - parent.setLocation(Objects.requireNonNull(currLoc.getParentFile()) - .getAbsolutePath()); + try { + parent.setLocation(Objects.requireNonNull(currLoc.getParentFile()) + .getCanonicalPath()); + } catch (IOException e) { + e.printStackTrace(); + } parent.setTime(currLoc.lastModified()); internalList.add(parent); } -- Gitee