Get temp dir refactoring
This commit is contained in:
parent
915dc9800b
commit
2581bcb4e5
4 changed files with 18 additions and 24 deletions
|
@ -205,10 +205,7 @@ public class FileUtils {
|
|||
if (!src.exists()) {
|
||||
return null;
|
||||
}
|
||||
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
}
|
||||
File tempDir = getTempDir(app);
|
||||
File dest = new File(tempDir, src.getName());
|
||||
try {
|
||||
Algorithms.fileCopy(src, dest);
|
||||
|
@ -218,6 +215,14 @@ public class FileUtils {
|
|||
return dest;
|
||||
}
|
||||
|
||||
public static File getTempDir(OsmandApplication app) {
|
||||
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
}
|
||||
return tempDir;
|
||||
}
|
||||
|
||||
public interface RenameCallback {
|
||||
void renamedTo(File file);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import com.google.gson.reflect.TypeToken;
|
|||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.FileUtils;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.GPXTrackAnalysis;
|
||||
|
@ -2350,11 +2351,8 @@ public class OsmandAidlApi {
|
|||
}
|
||||
|
||||
private int copyFileImpl(String fileName, byte[] filePartData, long startTime, boolean done, String destinationDir) {
|
||||
File file = app.getAppPath(IndexConstants.TEMP_DIR + fileName);
|
||||
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
}
|
||||
File tempDir = FileUtils.getTempDir(app);
|
||||
File file = new File(tempDir, fileName);
|
||||
File destFile = app.getAppPath(destinationDir + fileName);
|
||||
long currentTime = System.currentTimeMillis();
|
||||
try {
|
||||
|
|
|
@ -21,6 +21,7 @@ import androidx.fragment.app.FragmentManager;
|
|||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.FileUtils;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
|
@ -715,17 +716,14 @@ public class ImportHelper {
|
|||
|
||||
@Override
|
||||
protected String doInBackground(Void... voids) {
|
||||
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
}
|
||||
File tempDir = FileUtils.getTempDir(app);
|
||||
File dest = new File(tempDir, name);
|
||||
return copyFile(app, dest, uri, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String error) {
|
||||
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
|
||||
File tempDir = FileUtils.getTempDir(app);
|
||||
final File file = new File(tempDir, name);
|
||||
if (error == null && file.exists()) {
|
||||
app.getSettingsHelper().collectSettings(file, latestChanges, version, new SettingsCollectListener() {
|
||||
|
|
|
@ -21,6 +21,7 @@ import androidx.fragment.app.FragmentActivity;
|
|||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.FileUtils;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -329,7 +330,7 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
if (app != null) {
|
||||
exportingProfile = true;
|
||||
showExportProgressDialog();
|
||||
File tempDir = getTempDir();
|
||||
File tempDir = FileUtils.getTempDir(app);
|
||||
String fileName = profile.toHumanString();
|
||||
app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), prepareSettingsItemsForExport(), true);
|
||||
}
|
||||
|
@ -391,19 +392,11 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
}
|
||||
|
||||
private File getExportFile() {
|
||||
File tempDir = getTempDir();
|
||||
File tempDir = FileUtils.getTempDir(app);
|
||||
String fileName = profile.toHumanString();
|
||||
return new File(tempDir, fileName + IndexConstants.OSMAND_SETTINGS_FILE_EXT);
|
||||
}
|
||||
|
||||
private File getTempDir() {
|
||||
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
}
|
||||
return tempDir;
|
||||
}
|
||||
|
||||
private void shareProfile(@NonNull File file, @NonNull ApplicationMode profile) {
|
||||
try {
|
||||
final Intent sendIntent = new Intent();
|
||||
|
|
Loading…
Reference in a new issue