From 06a8076bde169b66a088b1dbf8e37bd59c7f1bea Mon Sep 17 00:00:00 2001 From: Qun Xin Lin Date: Sat, 17 Apr 2021 13:20:34 +0200 Subject: [PATCH 1/3] CATROID-1038 Fix NullPointerException in FormulaEditorHistory.java:55 --- .../catroid/formulaeditor/FormulaEditorHistory.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/catroid/src/main/java/org/catrobat/catroid/formulaeditor/FormulaEditorHistory.java b/catroid/src/main/java/org/catrobat/catroid/formulaeditor/FormulaEditorHistory.java index 92ba178a126..71d7f26e663 100644 --- a/catroid/src/main/java/org/catrobat/catroid/formulaeditor/FormulaEditorHistory.java +++ b/catroid/src/main/java/org/catrobat/catroid/formulaeditor/FormulaEditorHistory.java @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2018 The Catrobat Team + * Copyright (C) 2010-2021 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -51,9 +51,9 @@ public void push(UndoState state) { } if (current != null) { undoStack.push(current); - } - if (!initialStates.containsKey(current.formulaField)) { - initialStates.put(current.formulaField, current.internFormulaState); + if (!initialStates.containsKey(current.formulaField)) { + initialStates.put(current.formulaField, current.internFormulaState); + } } current = state; redoStack.clear(); From 7d38d24ac9688dd548a8282bb501a48aee504002 Mon Sep 17 00:00:00 2001 From: Wolfgang Slany <1747888+wslany@users.noreply.github.com> Date: Sun, 18 Apr 2021 15:31:37 +0200 Subject: [PATCH 2/3] HOTFIX version number increase HOTFIX is related to potentially severe loss of edits, see https://jira.catrob.at/browse/CATROID-1043 --- catroid/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/catroid/build.gradle b/catroid/build.gradle index 7a56db78dff..223c1efb0e5 100644 --- a/catroid/build.gradle +++ b/catroid/build.gradle @@ -105,8 +105,8 @@ jacocoAndroidUnitTestReport { xml.enabled true } -def defaultVersionCode = 83 -def defaultVersionName = "1.0.1" +def defaultVersionCode = 84 +def defaultVersionName = "1.0.2" android { compileSdkVersion 29 From bd4606aa62962933ab08ed1226620a6699ed8fc1 Mon Sep 17 00:00:00 2001 From: David Andrawes Date: Sun, 18 Apr 2021 19:44:16 +0200 Subject: [PATCH 3/3] CATROID-1043 Fix project renaming via project properties --- .../ui/fragment/ProjectOptionsTest.java | 96 ++++++++++++++++++- .../ui/fragment/ProjectOptionsFragment.java | 4 + 2 files changed, 97 insertions(+), 3 deletions(-) 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 d93db2d33e2..ca160cfda68 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 @@ -23,17 +23,26 @@ package org.catrobat.catroid.uiespresso.ui.fragment; +import android.app.Activity; +import android.app.Instrumentation; +import android.content.Intent; +import android.net.Uri; +import android.os.Environment; import android.widget.EditText; import org.catrobat.catroid.ProjectManager; import org.catrobat.catroid.R; +import org.catrobat.catroid.common.Constants; import org.catrobat.catroid.common.ScreenModes; import org.catrobat.catroid.content.Project; +import org.catrobat.catroid.io.ResourceImporter; import org.catrobat.catroid.io.StorageOperations; import org.catrobat.catroid.io.asynctask.ProjectSaveTask; import org.catrobat.catroid.ui.ProjectActivity; import org.catrobat.catroid.uiespresso.util.UiTestUtils; import org.catrobat.catroid.uiespresso.util.rules.FragmentActivityTestRule; +import org.hamcrest.Matcher; +import org.hamcrest.core.AllOf; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -49,13 +58,21 @@ import androidx.test.core.app.ApplicationProvider; import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.intent.Intents; import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; +import static org.catrobat.catroid.R.id.tab_layout; import static org.catrobat.catroid.common.Constants.CATROBAT_EXTENSION; -import static org.catrobat.catroid.common.FlavoredConstants.DEFAULT_ROOT_DIRECTORY; import static org.catrobat.catroid.common.Constants.EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY; +import static org.catrobat.catroid.common.FlavoredConstants.DEFAULT_ROOT_DIRECTORY; +import static org.catrobat.catroid.uiespresso.util.actions.TabActionsKt.selectTabAtPosition; +import static org.catrobat.catroid.uiespresso.util.matchers.BundleMatchers.bundleHasExtraIntent; +import static org.catrobat.catroid.uiespresso.util.matchers.BundleMatchers.bundleHasMatchingString; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.instanceOf; import static androidx.test.espresso.Espresso.closeSoftKeyboard; @@ -66,6 +83,13 @@ import static androidx.test.espresso.action.ViewActions.replaceText; import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist; import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.intent.Intents.intended; +import static androidx.test.espresso.intent.Intents.intending; +import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction; +import static androidx.test.espresso.intent.matcher.IntentMatchers.hasCategories; +import static androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent; +import static androidx.test.espresso.intent.matcher.IntentMatchers.hasExtras; +import static androidx.test.espresso.intent.matcher.IntentMatchers.hasType; import static androidx.test.espresso.matcher.RootMatchers.isDialog; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.isNotChecked; @@ -85,7 +109,7 @@ public class ProjectOptionsTest { @Rule public FragmentActivityTestRule baseActivityTestRule = new FragmentActivityTestRule<>(ProjectActivity.class, ProjectActivity.EXTRA_FRAGMENT_POSITION, - ProjectActivity.FRAGMENT_SPRITES); + ProjectActivity.FRAGMENT_SPRITES); @Before public void setUp() throws Exception { @@ -108,7 +132,7 @@ public void tearDown() { } @Test - public void changeProjectName() { + public void changeProjectName() throws IOException { onView(allOf(withText(PROJECT_NAME), isDisplayed(), instanceOf(EditText.class))) .perform(replaceText(EXISTING_PROJECT_NAME)); @@ -131,6 +155,72 @@ public void changeProjectName() { onView(withText(NEW_PROJECT_NAME)) .check(matches(isDisplayed())); Assert.assertEquals(NEW_PROJECT_NAME, project.getName()); + + onView(withText(R.string.default_project_background_name)) + .perform(click()); + + onView(withId(tab_layout)).perform(selectTabAtPosition(1)); + + onView(withId(R.id.button_add)) + .perform(click()); + + Matcher expectedPaintNewLookIntent = createLookFromPaintroid(); + + onView(withId(R.id.dialog_new_look_paintroid)) + .perform(click()); + + intended(expectedPaintNewLookIntent); + + onView(withText("Background (1)")) + .check(matches(isDisplayed())); + } + + private Matcher createLookFromPaintroid() throws IOException { + File tmpDir = new File( + Environment.getExternalStorageDirectory().getAbsolutePath(), "Pocket Code Test Temp"); + String lookFileName = "catroid_sunglasses.png"; + + Intents.init(); + + Matcher expectedGetContentIntent = AllOf.allOf( + hasAction("android.intent.action.GET_CONTENT"), + hasType("image/*")); + + String chooserTitle = UiTestUtils.getResourcesString(R.string.select_look_from_gallery); + Matcher expectedChooserIntent = AllOf.allOf( + hasAction("android.intent.action.CHOOSER"), + hasExtras(bundleHasMatchingString("android.intent.extra.TITLE", chooserTitle)), + hasExtras(bundleHasExtraIntent(expectedGetContentIntent))); + + if (!tmpDir.exists()) { + tmpDir.mkdirs(); + } + + File imageFile = ResourceImporter.createImageFileFromResourcesInDirectory( + InstrumentationRegistry.getInstrumentation().getContext().getResources(), + org.catrobat.catroid.test.R.drawable.catroid_banzai, + tmpDir, + lookFileName, + 1); + + Intent resultData = new Intent(); + resultData.setData(Uri.fromFile(imageFile)); + + Instrumentation.ActivityResult result = + new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData); + + intending(expectedChooserIntent).respondWith(result); + + Matcher expectedPaintNewLookIntent = AllOf.allOf( + hasComponent(Constants.POCKET_PAINT_INTENT_ACTIVITY_NAME), + hasAction("android.intent.action.MAIN"), + hasCategories(hasItem(equalTo("android.intent.category.LAUNCHER")))); + + Instrumentation.ActivityResult resultPaintroid = new Instrumentation.ActivityResult(Activity.RESULT_OK, null); + + intending(expectedPaintNewLookIntent).respondWith(resultPaintroid); + + return expectedPaintNewLookIntent; } @Test diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectOptionsFragment.java b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectOptionsFragment.java index bc7df9c721f..1641852734e 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectOptionsFragment.java +++ b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectOptionsFragment.java @@ -81,6 +81,7 @@ public class ProjectOptionsFragment extends Fragment implements private View view; private Project project; + private String sceneName; private TextInputLayout nameInputLayout; private TextInputLayout descriptionInputLayout; @@ -102,6 +103,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(R.string.project_options); project = ProjectManager.getInstance().getCurrentProject(); + sceneName = ProjectManager.getInstance().getCurrentlyEditedScene().getName(); nameInputLayout = view.findViewById(R.id.project_options_name_layout); nameInputLayout.getEditText().setText(project.getName()); @@ -233,9 +235,11 @@ private void setProjectName() { if (!project.getName().equals(name)) { try { + XstreamSerializer.getInstance().saveProject(project); File renamedDirectory = ProjectRenameTask.task(project.getDirectory(), name); ProjectLoadTask.task(renamedDirectory, getActivity().getApplicationContext()); project = ProjectManager.getInstance().getCurrentProject(); + ProjectManager.getInstance().setCurrentlyEditedScene(project.getSceneByName(sceneName)); } catch (IOException e) { Log.e(TAG, "Creating renamed directory failed!", e); }