Commit 528c1d60 authored by Donald's avatar Donald Committed by GitHub

Merge pull request #329 from HoraApps/314-bug

fixed copy on the same folder
parents 884f1bb9 d7b4059e
......@@ -97,12 +97,21 @@ public class ContentHelper {
return success;
}
private static File getTargetFile(File source, File targetDir) {
File file = new File(targetDir, source.getName());
if (!source.getParentFile().equals(targetDir) && !file.exists())
return file;
return new File(targetDir, StringUtils.incrementFileNameSuffix(source.getName()));
}
public static boolean copyFile(Context context, @NonNull final File source, @NonNull final File targetDir) {
InputStream inStream = null;
OutputStream outStream = null;
boolean success = false;
File target = new File(targetDir, source.getName());
File target = getTargetFile(source, targetDir);
try {
inStream = new FileInputStream(source);
......
package org.horaapps.leafpic.util;
import android.content.Context;
import android.media.ExifInterface;
import android.webkit.MimeTypeMap;
import android.widget.Toast;
import java.io.IOException;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by dnld on 1/3/16.
......@@ -36,6 +37,22 @@ public class StringUtils {
return c;
}
static String incrementFileNameSuffix(String name) {
StringBuilder builder = new StringBuilder();
int dot = name.lastIndexOf('.');
String baseName = dot != -1 ? name.subSequence(0, dot).toString() : name;
String nameWoSuffix = baseName;
Matcher matcher = Pattern.compile("_\\d").matcher(baseName);
if(matcher.find()) {
int i = baseName.lastIndexOf("_");
if (i != -1) nameWoSuffix = baseName.subSequence(0, i).toString();
}
builder.append(nameWoSuffix).append("_").append(new Date().getTime());
builder.append(name.substring(dot));
return builder.toString();
}
public static String getPhotoPathRenamedAlbumChange(String olderPath, String albumNewName) {
String c = "", b[] = olderPath.split("/");
for (int x = 0; x < b.length - 2; x++) c += b[x] + "/";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment