Skip to content

Commit

Permalink
fix MAJOR move folders bug and better import/move UX
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Martin committed Jan 16, 2015
1 parent defa8c0 commit 30344d7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "me.writeily.pro"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.01"
}
buildTypes {
release {
Expand Down
33 changes: 18 additions & 15 deletions app/src/main/java/me/writeily/pro/dialog/FilesystemDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,27 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
isMovingFile = getArguments().getString(Constants.FILESYSTEM_ACTIVITY_ACCESS_TYPE_KEY).equals(Constants.FILESYSTEM_FOLDER_ACCESS_TYPE);

final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
dialogBuilder.setView(dialogView);

if (isMovingFile) {
dialogBuilder.setTitle(getResources().getString(R.string.select_folder_move));

dialogBuilder.setPositiveButton("Move here", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
sendBroadcast(selectedPath);
}
});
} else {
dialogBuilder.setTitle(getResources().getString(R.string.import_from_device));
}

dialogBuilder.setView(dialogView);
dialogBuilder.setPositiveButton("Select", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
sendBroadcast(selectedPath);
}
});
dialogBuilder.setPositiveButton("Select", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
sendBroadcast(selectedPath);
}
});
}

dialogBuilder.setNegativeButton("Cancel", new
DialogInterface.OnClickListener() {
Expand Down Expand Up @@ -191,13 +198,9 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

// Refresh list if directory, else import
if (file.isDirectory()) {
if (!isMovingFile || (selectedPath != null && selectedPath.equalsIgnoreCase(file.getAbsolutePath()))) {
currentDir = file;
selectedPath = null;
listFilesInDirectory(file);
} else {
selectedPath = file.getAbsolutePath();
}
currentDir = file;
selectedPath = file.getAbsolutePath();
listFilesInDirectory(file);
} else {
selectedPath = file.getAbsolutePath();
}
Expand Down
37 changes: 34 additions & 3 deletions app/src/main/java/me/writeily/pro/model/WriteilySingleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ public void setNotesLastDirectory(File notesLastDirectory) {
WriteilySingleton.notesLastDirectory = notesLastDirectory;
}

public String copyDirectory(File dir, String destinationDir) {
String dirName = dir.getName();
File outputFile = new File(destinationDir + File.separator + dirName + File.separator);

if (!outputFile.exists()) {
outputFile.mkdir();
}

return outputFile.getAbsolutePath();
}

public void copyFile(File file, String destinationDir) {
try {
String filename = file.getName();
Expand Down Expand Up @@ -75,10 +86,30 @@ public void copyFile(File file, String destinationDir) {
}

public void moveFile(File file, String destinationDir) {
copyFile(file, destinationDir);
/* Rules:
* 1. Don't move a file to the same location, no point
* 2. Don't move a folder to itself
* 3. Don't move a folder into its children
*/

if (destinationDir != null &&
!destinationDir.equalsIgnoreCase(file.getParentFile().getAbsolutePath()) &&
!destinationDir.startsWith(file.getAbsolutePath())) {

if (file.isDirectory()) {
String newDestinationDir = copyDirectory(file, destinationDir);

for (File dirFile : file.listFiles()) {
moveFile(dirFile, newDestinationDir);
}
} else {
copyFile(file, destinationDir);
}

// Delete the old file after copying it over
deleteFile(file);
// Delete the old file after copying it over
deleteFile(file);

}
}

public boolean deleteFile(File file) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<string name="email_header">Feedback about Writeily</string>

<string name="about_string">
Writeily Pro 1.0\n\n
Writeily Pro 1.01\n\n
Developed by Jeff Martin (http://jeffreymartin.ca)\n
</string>

Expand Down

0 comments on commit 30344d7

Please sign in to comment.