diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DirectoryNavigator.java b/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DirectoryNavigator.java index 7b779a07..6130abc6 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DirectoryNavigator.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DirectoryNavigator.java @@ -82,6 +82,28 @@ public class DirectoryNavigator //return itemsToShow; return currentItems; } + + /** + * Travel inside a subdirectory. + * @param directoryPosition The position of the subdirectory where we will travel. + * @return Return a list of items that are inside the subdirectory. + * @throws InvalidPath When the directory don't exist. + */ + public ArrayList goToSubDirectory(int directoryPosition) throws InvalidPath + { + String subDirectory = currentItems.get(directoryPosition).getName(); + + //We increase the path. + path.add(subDirectory); + + Node node = goToDirectory(); + + //ArrayList itemsToShow; + //itemsToShow = new ArrayList(getItems(node)); + currentItems= new ArrayList(getItems(node)); + //return itemsToShow; + return currentItems; + } /** * Travel to the parent directory. @@ -353,8 +375,7 @@ public class DirectoryNavigator /** *Searches for a node in the current directory with the given name *@param name Name of the node located on the current directory. - *@returns -1 in case it does not exists any node with the given name - * directoryItem with the given name + *@returns null in case it does not exists any node with the given name * */ public DirectoryItem getDirectoryItem(String name){ DirectoryItem node = null; @@ -374,6 +395,20 @@ public class DirectoryNavigator return node; } + /** + *Searches for a node in the current directory with the given position + *@param position position where the node is located + *@returns null in case it does not exists any node located at the given position + * */ + public DirectoryItem getDirectoryItem(int position){ + DirectoryItem node = null; + if(position >=0 && position < currentItems.size()){ + node = currentItems.get(position); + } + return node; + } + + /** * Identifies the node with name @a name and gets its file code in case the node is a file. In case the node is a directory returns -1 * @param name Name of the node located on the current directory. diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DownloadsManager.java b/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DownloadsManager.java index e7915486..236d6328 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DownloadsManager.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/DownloadsManager.java @@ -159,12 +159,15 @@ public class DownloadsManager extends MenuActivity { grid.setOnItemClickListener((new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { - TextView text = (TextView) v.findViewById(R.id.icon_text); - chosenNodeName = text.getText().toString(); - DirectoryItem node = navigator.getDirectoryItem(chosenNodeName); + //TextView text = (TextView) v.findViewById(R.id.icon_text); + //chosenNodeName = text.getText().toString(); + //DirectoryItem node = navigator.getDirectoryItem(chosenNodeName); + DirectoryItem node = navigator.getDirectoryItem(position); if(node.getFileCode() == -1) //it is a directory therefore navigates into it - updateView(navigator.goToSubDirectory(chosenNodeName)); + updateView(navigator.goToSubDirectory(position)); + //updateView(navigator.goToSubDirectory(chosenNodeName)); else{ //it is a files therefore gets its information through web service GETFILE + chosenNodeName = node.getName(); AlertDialog fileInfoDialog = createFileInfoDialog(node.getName(),node.getSize(),node.getTime(),node.getPublisher(),node.getFileCode()); fileInfoDialog.show(); } @@ -419,7 +422,7 @@ public class DownloadsManager extends MenuActivity { * @param fileSize - file size of the file. It is used to show the download progress in the notification * */ private void downloadFile(String directory, String url,long fileSize){ - new FileDownloaderAsyncTask(getApplicationContext(),true,fileSize).execute(directory,url); + new FileDownloaderAsyncTask(getApplicationContext(),this.chosenNodeName,true,fileSize).execute(directory,url); } private void openFileDefaultApp(String absolutePath){ File file = new File(absolutePath); diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/FileDownloaderAsyncTask.java b/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/FileDownloaderAsyncTask.java index 0b2d6d10..87554851 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/FileDownloaderAsyncTask.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/downloads/FileDownloaderAsyncTask.java @@ -56,7 +56,8 @@ public class FileDownloaderAsyncTask extends AsyncTask { this.fileName = text; this.progressBar = progressBar; }*/ - public FileDownloaderAsyncTask(Context context, boolean notification, long fileSize){ + public FileDownloaderAsyncTask(Context context,String fileName, boolean notification, long fileSize){ + this.fileName = fileName; mNotification = new DownloadNotification(context); this.notification = notification; this.fileSize = fileSize; @@ -120,12 +121,11 @@ public class FileDownloaderAsyncTask extends AsyncTask { /* The downloaded file will be saved to a temporary file, whose prefix * will be the basename of the file and the suffix its extension */ - String filename = FileDownloader.getFilenameFromURL(url.getPath()); - //if(filename == null) + //if(FileDownloader.getFilenameFromURL(url.getPath() == null) // throw new FileNotFoundException("URL does not point to a file"); - int lastSlashIndex = filename.lastIndexOf("/"); - int lastDotIndex = filename.lastIndexOf("."); + int lastSlashIndex = this.fileName.lastIndexOf("/"); + int lastDotIndex = this.fileName.lastIndexOf("."); /* Avoid StringIndexOutOfBoundsException from being thrown if the * file has no extension (such as "http://www.domain.com/README" */ @@ -133,26 +133,25 @@ public class FileDownloaderAsyncTask extends AsyncTask { String extension = ""; if(lastDotIndex == -1) - basename = filename.substring(lastSlashIndex + 1); + basename = this.fileName.substring(lastSlashIndex + 1); else { - basename = filename.substring(lastSlashIndex + 1, lastDotIndex); - extension = filename.substring(lastDotIndex); + basename = this.fileName.substring(lastSlashIndex + 1, lastDotIndex); + extension = this.fileName.substring(lastDotIndex); } /* The prefix must be at least three characters long */ // if(basename.length() < 3) // basename = "tmp"; - File output = new File(this.getDownloadDir(),filename) ; + File output = new File(this.getDownloadDir(),this.fileName) ; if(output.exists()){ int i = 1; do{ output = new File(this.getDownloadDir(),basename+"-"+String.valueOf(i)+extension); ++i; }while(output.exists()); - filename = basename+"-"+String.valueOf(i-1)+extension; + this.fileName = basename+"-"+String.valueOf(i-1)+extension; } - this.fileName = filename; mNotification.createNotification(this.fileName);