diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/test/io/asynctask/ProjectExportTaskTest.java b/catroid/src/androidTest/java/org/catrobat/catroid/test/io/asynctask/ProjectExportTaskTest.java index fb1d2c39863..6d98910d340 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/test/io/asynctask/ProjectExportTaskTest.java +++ b/catroid/src/androidTest/java/org/catrobat/catroid/test/io/asynctask/ProjectExportTaskTest.java @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2021 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -56,7 +56,7 @@ import static org.catrobat.catroid.common.Constants.CATROBAT_EXTENSION; import static org.catrobat.catroid.common.Constants.CODE_XML_FILE_NAME; -import static org.catrobat.catroid.common.Constants.EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY; +import static org.catrobat.catroid.common.Constants.DOWNLOAD_DIRECTORY; import static org.catrobat.catroid.common.Constants.UNDO_CODE_XML_FILE_NAME; import static org.catrobat.catroid.io.asynctask.ProjectSaverKt.saveProjectSerial; import static org.junit.Assert.assertTrue; @@ -101,7 +101,7 @@ public void exportProjectTest() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { projectZip = new File(Constants.CACHE_DIR, fileName); } else { - projectZip = new File(EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY, fileName); + projectZip = new File(DOWNLOAD_DIRECTORY, fileName); } Uri projectUri = Uri.fromFile(projectZip); NotificationData notificationData = notificationManager @@ -156,8 +156,8 @@ public void tearDown() throws Exception { } projectZip.delete(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q - && EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY.exists()) { - StorageOperations.deleteDir(EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY); + && DOWNLOAD_DIRECTORY.exists()) { + StorageOperations.deleteDir(DOWNLOAD_DIRECTORY); } } } diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/fragment/ProjectOptionsTest.java b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/fragment/ProjectOptionsTest.java index 11e26d5aaea..13dd4bea01e 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/fragment/ProjectOptionsTest.java +++ b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/fragment/ProjectOptionsTest.java @@ -65,7 +65,7 @@ import static org.catrobat.catroid.R.id.tab_layout; import static org.catrobat.catroid.common.Constants.CATROBAT_EXTENSION; -import static org.catrobat.catroid.common.Constants.EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY; +import static org.catrobat.catroid.common.Constants.DOWNLOAD_DIRECTORY; import static org.catrobat.catroid.common.FlavoredConstants.DEFAULT_ROOT_DIRECTORY; import static org.catrobat.catroid.uiespresso.ui.fragment.rvutils.RecyclerViewInteractionWrapper.onRecyclerView; import static org.catrobat.catroid.uiespresso.util.UiTestUtils.onToast; @@ -314,27 +314,24 @@ public void uploadProject() { public void saveExternal() throws IOException { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { - String doneToastText = - context.getString( - R.string.notification_save_project_to_external_storage_open, - EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY - ) + "/" + PROJECT_NAME + CATROBAT_EXTENSION; - - if (EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY.exists()) { - StorageOperations.deleteDir(EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY); + String pendingToastText = + context.getString(R.string.notification_save_project_to_external_storage_pending); + File externalProjectZip = new File(DOWNLOAD_DIRECTORY, + project.getDirectory().getName() + CATROBAT_EXTENSION); + if (externalProjectZip.exists()) { + StorageOperations.deleteFile(externalProjectZip); } + assertFalse(externalProjectZip.exists()); onView(withId(R.id.project_options_save_external)) .perform(ViewActions.scrollTo()) .perform(click()); - onToast(withText(doneToastText)) + onToast(withText(pendingToastText)) .check(matches(isDisplayed())); onView(isRoot()).perform(CustomActions .wait(DURATION_WAIT_FOR_ZIP_FILE_IN_MILLISECONDS)); - File externalProjectZip = new File(EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY, - project.getDirectory().getName() + CATROBAT_EXTENSION); assertTrue(externalProjectZip.exists()); } } diff --git a/catroid/src/main/java/org/catrobat/catroid/common/Constants.java b/catroid/src/main/java/org/catrobat/catroid/common/Constants.java index 886b0775359..8d21fb0c386 100644 --- a/catroid/src/main/java/org/catrobat/catroid/common/Constants.java +++ b/catroid/src/main/java/org/catrobat/catroid/common/Constants.java @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2021 The Catrobat Team + * Copyright (C) 2010-2022 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -62,7 +62,8 @@ public final class Constants { public static final String POCKET_CODE_EXTERNAL_EXPORT_STORAGE_FOLDER_NAME = "Catrobat"; public static final File EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY = new File( Environment.getExternalStorageDirectory(), POCKET_CODE_EXTERNAL_EXPORT_STORAGE_FOLDER_NAME); - + public static final File DOWNLOAD_DIRECTORY = + new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), ""); public static final String CATROBAT_EXTENSION = ".catrobat"; public static final String ZIP_EXTENSION = ".zip"; public static final String DEFAULT_IMAGE_EXTENSION = ".png"; diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectOptionsFragment.kt b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectOptionsFragment.kt index 1f8b70cea25..ab8e85ea7ba 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectOptionsFragment.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectOptionsFragment.kt @@ -334,9 +334,9 @@ class ProjectOptionsFragment : Fragment() { ) { override fun task() { val fileName = project?.name + Constants.CATROBAT_EXTENSION - val projectZip = File(Constants.EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY, fileName) - Constants.EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY.mkdirs() - if (!Constants.EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY.isDirectory) { + val projectZip = File(Constants.DOWNLOAD_DIRECTORY, fileName) + Constants.DOWNLOAD_DIRECTORY.mkdirs() + if (!Constants.DOWNLOAD_DIRECTORY.isDirectory) { return } if (projectZip.exists()) {