-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/issue 95/change track slide (#96)
Issue-95 - added swipe to change track functionality, added a mechanism to kill notifications when the app is not in use, started to work on end to end test compatibility
- Loading branch information
Showing
68 changed files
with
1,839 additions
and
540 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/src/androidTest/java/com/example/mike/mp3player/RecyclerViewMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.example.mike.mp3player; | ||
|
||
|
||
import android.content.res.Resources; | ||
import android.view.View; | ||
|
||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.TypeSafeMatcher; | ||
|
||
/** | ||
* Created by dannyroa on 5/10/15. | ||
*/ | ||
public class RecyclerViewMatcher { | ||
private final int recyclerViewId; | ||
|
||
public RecyclerViewMatcher(int recyclerViewId) { | ||
this.recyclerViewId = recyclerViewId; | ||
} | ||
|
||
public Matcher<View> atPosition(final int position) { | ||
return atPositionOnView(position, -1); | ||
} | ||
|
||
public Matcher<View> atPositionOnView(final int position, final int targetViewId) { | ||
|
||
return new TypeSafeMatcher<View>() { | ||
Resources resources = null; | ||
View childView; | ||
|
||
public void describeTo(Description description) { | ||
String idDescription = Integer.toString(recyclerViewId); | ||
if (this.resources != null) { | ||
try { | ||
idDescription = this.resources.getResourceName(recyclerViewId); | ||
} catch (Resources.NotFoundException var4) { | ||
idDescription = String.format("%s (resource name not found)", | ||
new Object[] { Integer.valueOf | ||
(recyclerViewId) }); | ||
} | ||
} | ||
|
||
description.appendText("with id: " + idDescription); | ||
} | ||
|
||
public boolean matchesSafely(View view) { | ||
|
||
this.resources = view.getResources(); | ||
|
||
if (childView == null) { | ||
RecyclerView recyclerView = | ||
(RecyclerView) view.getRootView().findViewById(recyclerViewId); | ||
if (recyclerView != null && recyclerView.getId() == recyclerViewId) { | ||
childView = recyclerView.findViewHolderForAdapterPosition(position).itemView; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
if (targetViewId == -1) { | ||
return view == childView; | ||
} else { | ||
View targetView = childView.findViewById(targetViewId); | ||
return view == targetView; | ||
} | ||
|
||
} | ||
}; | ||
} | ||
} |
118 changes: 117 additions & 1 deletion
118
app/src/androidTest/java/com/example/mike/mp3player/TestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,125 @@ | ||
package com.example.mike.mp3player; | ||
|
||
import android.view.View; | ||
|
||
import androidx.annotation.IdRes; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
import androidx.test.espresso.PerformException; | ||
import androidx.test.espresso.UiController; | ||
import androidx.test.espresso.ViewAction; | ||
import androidx.test.espresso.matcher.ViewMatchers; | ||
import androidx.test.espresso.util.HumanReadables; | ||
|
||
import com.google.android.material.tabs.TabLayout; | ||
|
||
import org.hamcrest.Matcher; | ||
import org.hamcrest.Matchers; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* This class will be used for utility methods in the automation framework. | ||
*/ | ||
public final class TestUtils { | ||
public class TestUtils { | ||
|
||
public static void assertTabName(TabLayout tabLayout, int position, String expectedTabTitle) { | ||
TabLayout.Tab tab = tabLayout.getTabAt(position); | ||
final String actualNameFirstTab = tab.getText().toString(); | ||
assertEquals(expectedTabTitle, actualNameFirstTab); | ||
} | ||
|
||
|
||
|
||
|
||
// RECYCLER VIEW | ||
public static <VH extends RecyclerView.ViewHolder> ViewAction actionOnItemViewAtPosition(int position, | ||
@IdRes | ||
int viewId, | ||
ViewAction viewAction) { | ||
return new ActionOnItemViewAtPositionViewAction(position, viewId, viewAction); | ||
} | ||
|
||
private static final class ActionOnItemViewAtPositionViewAction<VH extends RecyclerView | ||
.ViewHolder> | ||
implements | ||
|
||
ViewAction { | ||
private final int position; | ||
private final ViewAction viewAction; | ||
private final int viewId; | ||
|
||
private ActionOnItemViewAtPositionViewAction(int position, | ||
@IdRes int viewId, | ||
ViewAction viewAction) { | ||
this.position = position; | ||
this.viewAction = viewAction; | ||
this.viewId = viewId; | ||
} | ||
|
||
public Matcher<View> getConstraints() { | ||
return Matchers.allOf(new Matcher[] { | ||
ViewMatchers.isAssignableFrom(RecyclerView.class), ViewMatchers.isDisplayed() | ||
}); | ||
} | ||
|
||
public String getDescription() { | ||
return "actionOnItemAtPosition performing ViewAction: " | ||
+ this.viewAction.getDescription() | ||
+ " on item at position: " | ||
+ this.position; | ||
} | ||
|
||
public void perform(UiController uiController, View view) { | ||
RecyclerView recyclerView = (RecyclerView) view; | ||
(new ScrollToPositionViewAction(this.position)).perform(uiController, view); | ||
uiController.loopMainThreadUntilIdle(); | ||
|
||
View targetView = recyclerView.getChildAt(this.position).findViewById(this.viewId); | ||
|
||
if (targetView == null) { | ||
throw (new PerformException.Builder()).withActionDescription(this.toString()) | ||
.withViewDescription( | ||
|
||
HumanReadables.describe(view)) | ||
.withCause(new IllegalStateException( | ||
"No view with id " | ||
+ this.viewId | ||
+ " found at position: " | ||
+ this.position)) | ||
.build(); | ||
} else { | ||
this.viewAction.perform(uiController, targetView); | ||
} | ||
} | ||
} | ||
|
||
private static final class ScrollToPositionViewAction implements ViewAction { | ||
private final int position; | ||
|
||
private ScrollToPositionViewAction(int position) { | ||
this.position = position; | ||
} | ||
|
||
public Matcher<View> getConstraints() { | ||
return Matchers.allOf(new Matcher[] { | ||
ViewMatchers.isAssignableFrom(RecyclerView.class), ViewMatchers.isDisplayed() | ||
}); | ||
} | ||
|
||
public String getDescription() { | ||
return "scroll RecyclerView to position: " + this.position; | ||
} | ||
|
||
public void perform(UiController uiController, View view) { | ||
RecyclerView recyclerView = (RecyclerView) view; | ||
recyclerView.scrollToPosition(this.position); | ||
} | ||
} | ||
|
||
|
||
public static RecyclerViewMatcher withRecyclerView(final int recyclerViewId) { | ||
|
||
return new RecyclerViewMatcher(recyclerViewId); | ||
} | ||
|
||
} |
Oops, something went wrong.