Skip to content

Commit

Permalink
CATROID-1394 Export projects to Downloads-directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Walcho1125 committed May 11, 2022
1 parent 722b1ac commit 5ab9a10
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 5ab9a10

Please sign in to comment.