Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAINTROID-420 Support more than four layers #1136

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Paintroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ dependencies {
implementation 'androidx.exifinterface:exifinterface:1.3.2'
implementation 'com.esotericsoftware:kryo:5.1.1'
implementation 'id.zelory:compressor:2.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

debugImplementation 'androidx.multidex:multidex:2.0.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,28 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.net.Uri
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition
import androidx.test.espresso.idling.CountingIdlingResource
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.ViewMatchers.isClickable
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isEnabled
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import androidx.test.rule.GrantPermissionRule
import junit.framework.AssertionFailedError
import org.catrobat.paintroid.MainActivity
import org.catrobat.paintroid.R
import org.catrobat.paintroid.common.MAX_LAYERS
import org.catrobat.paintroid.test.espresso.util.BitmapLocationProvider
import org.catrobat.paintroid.test.espresso.util.DrawingSurfaceLocationProvider
import org.catrobat.paintroid.test.espresso.util.EspressoUtils
Expand All @@ -67,6 +72,8 @@ import org.junit.Test
import org.junit.runner.RunWith
import java.io.File

private const val FOUR_LAYERS = 4

@RunWith(AndroidJUnit4::class)
class LayerIntegrationTest {
@get:Rule
Expand Down Expand Up @@ -109,13 +116,13 @@ class LayerIntegrationTest {
fun testShowLayerMenu() {
LayerMenuViewInteraction.onLayerMenuView()
.performOpen()
.check(ViewAssertions.matches(isDisplayed()))
.check(matches(isDisplayed()))
}

@Test
fun testInitialSetup() {
LayerMenuViewInteraction.onLayerMenuView()
.check(ViewAssertions.matches(Matchers.not(isDisplayed())))
.check(matches(Matchers.not(isDisplayed())))
assertIfLayerAddButtonIsEnabled()
assertIfLayerDeleteButtonIsDisabled()
}
Expand All @@ -129,19 +136,6 @@ class LayerIntegrationTest {
.checkLayerCount(2)
}

@Test
fun testTryAddMoreLayersThanLimit() {
LayerMenuViewInteraction.onLayerMenuView()
.checkLayerCount(1)
.performOpen()
.performAddLayer()
.performAddLayer()
.performAddLayer()
.checkLayerCount(4)
.performAddLayer()
.checkLayerCount(4)
}

@Test
fun testButtonsAddOneLayer() {
LayerMenuViewInteraction.onLayerMenuView()
Expand All @@ -152,26 +146,22 @@ class LayerIntegrationTest {
.check(
assertIfAddLayerButtonIsEnabled()
)
asserIfDeleteLayerButtonIsDisabled()
assertIfDeleteLayerButtonIsDisabled()
LayerMenuViewInteraction.onLayerMenuView()
.performAddLayer()
.performAddLayer()
.checkLayerCount(4)
assertIfLayerAddButtonIsDisabled()
asserIfDeleteLayerButtonIsDisabled()
LayerMenuViewInteraction.onLayerMenuView()
.performDeleteLayer()
.performDeleteLayer()
.performDeleteLayer()
.checkLayerCount(1)
assertIfLayerAddButtonIsEnabled()
assertIfLayerDeleteButtonIsDisabled()
}

private fun assertIfLayerAddButtonIsEnabled() {
LayerMenuViewInteraction.onLayerMenuView().onButtonAdd()
.check(
ViewAssertions.matches(
matches(
Matchers.allOf(
isEnabled(),
UiMatcher.withDrawable(R.drawable.ic_pocketpaint_layers_add)
Expand All @@ -189,8 +179,6 @@ class LayerIntegrationTest {
.performAddLayer()
.performClose()
.checkLayerCount(4)
assertIfLayerAddButtonIsDisabled()
asserIfDeleteLayerButtonIsDisabled()
TopBarViewInteraction.onTopBarView()
.performOpenMoreOptions()
onView(withText(R.string.menu_new_image))
Expand All @@ -206,10 +194,10 @@ class LayerIntegrationTest {
.checkLayerCount(1)
}

private fun asserIfDeleteLayerButtonIsDisabled() {
private fun assertIfDeleteLayerButtonIsDisabled() {
LayerMenuViewInteraction.onLayerMenuView().onButtonDelete()
.check(
ViewAssertions.matches(
matches(
Matchers.allOf(
isEnabled(),
UiMatcher.withDrawable(R.drawable.ic_pocketpaint_layers_delete)
Expand All @@ -221,7 +209,7 @@ class LayerIntegrationTest {
private fun assertIfLayerAddButtonIsDisabled() {
LayerMenuViewInteraction.onLayerMenuView().onButtonAdd()
.check(
ViewAssertions.matches(
matches(
Matchers.allOf(
Matchers.not(isEnabled()),
UiMatcher.withDrawable(R.drawable.ic_pocketpaint_layers_add_disabled)
Expand All @@ -233,7 +221,7 @@ class LayerIntegrationTest {
private fun assertIfLayerDeleteButtonIsDisabled() {
LayerMenuViewInteraction.onLayerMenuView().onButtonDelete()
.check(
ViewAssertions.matches(
matches(
Matchers.allOf(
Matchers.not(isEnabled()),
UiMatcher.withDrawable(R.drawable.ic_pocketpaint_layers_delete_disabled)
Expand All @@ -242,7 +230,7 @@ class LayerIntegrationTest {
)
}

private fun assertIfAddLayerButtonIsEnabled() = ViewAssertions.matches(
private fun assertIfAddLayerButtonIsEnabled() = matches(
Matchers.allOf(
isEnabled(),
UiMatcher.withDrawable(R.drawable.ic_pocketpaint_layers_add)
Expand Down Expand Up @@ -752,7 +740,57 @@ class LayerIntegrationTest {
.performAddLayer()
.performAddLayer()
.performAddLayer()
.checkLayerCount(MAX_LAYERS)
.checkLayerCount(FOUR_LAYERS)
}

@Test
fun testAddTenLayers() {
LayerMenuViewInteraction.onLayerMenuView()
.checkLayerCount(1)
.performOpen()
.performAddLayer()
.checkLayerCount(2)
.performAddLayer()
.checkLayerCount(3)
.performAddLayer()
.checkLayerCount(4)
.performAddLayer()
.checkLayerCount(5)
.performAddLayer()
.checkLayerCount(6)
.performAddLayer()
.checkLayerCount(7)
.performAddLayer()
.checkLayerCount(8)
.performAddLayer()
.checkLayerCount(9)
.performAddLayer()
.checkLayerCount(10)
}

@Test
fun testAddAsManyLayersAsPossibleAndScrollToEndOfList() {
LayerMenuViewInteraction.onLayerMenuView()
.checkLayerCount(1)
.performOpen()
.performAddLayer()
.checkLayerCount(2)
var layerCount = 3
while (true) {
try {
LayerMenuViewInteraction.onLayerMenuView()
.performAddLayer()
.checkLayerCount(layerCount)
onView(withId(R.id.pocketpaint_layer_side_nav_button_add)).check(matches(isClickable()))
layerCount++
} catch (ignore: AssertionFailedError) {
break
}
}
assertIfLayerAddButtonIsDisabled()
LayerMenuViewInteraction.onLayerMenuView()
.checkLayerCount(--layerCount)
onView(withId(R.id.pocketpaint_layer_side_nav_list)).perform(scrollToPosition<RecyclerView.ViewHolder>(99))
}

private fun createTestImageFile(): Uri {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
package org.catrobat.paintroid.test.espresso.util;

import android.graphics.PointF;
import android.graphics.Rect;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SeekBar;

import org.hamcrest.Matcher;

import androidx.test.espresso.NoMatchingViewException;
import static org.catrobat.paintroid.test.espresso.util.CustomSwiper.ACCURATE;
import static org.hamcrest.Matchers.is;

import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.ViewAssertion;
Expand All @@ -47,9 +46,6 @@
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.viewpager.widget.ViewPager;

import static org.catrobat.paintroid.test.espresso.util.CustomSwiper.ACCURATE;
import static org.hamcrest.Matchers.is;

import static androidx.test.espresso.action.ViewActions.actionWithAssertions;
import static androidx.test.espresso.matcher.ViewMatchers.assertThat;
import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;
Expand Down Expand Up @@ -84,16 +80,15 @@ public void perform(UiController uiController, final View view) {
};
}

public static ViewAssertion assertListViewCount(final int expectedCount) {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
if (noViewFoundException != null) {
throw noViewFoundException;
}
public static ViewAssertion assertRecyclerViewCount(final int expectedCount) {
return (view, noViewFoundException) -> {
if (noViewFoundException != null) {
throw noViewFoundException;
}

ListAdapter adapter = ((ListView) view).getAdapter();
assertThat(adapter.getCount(), is(expectedCount));
org.catrobat.paintroid.ui.LayerAdapter adapter = (org.catrobat.paintroid.ui.LayerAdapter) ((androidx.recyclerview.widget.RecyclerView) view).getAdapter();
if (adapter != null) {
assertThat(adapter.getItemCount(), is(expectedCount));
}
};
}
Expand All @@ -120,23 +115,20 @@ public void perform(UiController uiController, View view) {

public static ViewAction clickOutside(final Direction direction) {
return actionWithAssertions(
new GeneralClickAction(Tap.SINGLE, new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
Rect r = new Rect();
view.getGlobalVisibleRect(r);
switch (direction) {
case ABOVE:
return new float[]{r.centerX(), r.top - 50};
case BELOW:
return new float[]{r.centerX(), r.bottom + 50};
case LEFT:
return new float[]{r.left - 50, r.centerY()};
case RIGHT:
return new float[]{r.right + 50, r.centerY()};
}
return null;
new GeneralClickAction(Tap.SINGLE, view -> {
android.graphics.Rect r = new android.graphics.Rect();
view.getGlobalVisibleRect(r);
switch (direction) {
case ABOVE:
return new float[]{r.centerX(), r.top - 50};
case BELOW:
return new float[]{r.centerX(), r.bottom + 50};
case LEFT:
return new float[]{r.left - 50, r.centerY()};
case RIGHT:
return new float[]{r.right + 50, r.centerY()};
}
return null;
}, Press.FINGER, 0, 1)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import org.catrobat.paintroid.R;
import org.catrobat.paintroid.tools.ToolType;

import androidx.test.espresso.ViewInteraction;

import static org.catrobat.paintroid.test.espresso.util.UiMatcher.withDrawable;
import static org.hamcrest.Matchers.allOf;

import androidx.test.espresso.ViewInteraction;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
Expand Down
Loading