Skip to content

Commit

Permalink
Upgraded butterknife to 8.8.1 (#524)
Browse files Browse the repository at this point in the history
Refactored MusicListFragment and PVRListFragment to use AbstractTabsFragment
Fixed scrolling in a nested scroll view using espresso
Fixed issue with setting and checking Kodi major version
  • Loading branch information
poisdeux authored and SyncedSynapse committed Apr 5, 2018
1 parent 2f2791a commit 2ed9684
Show file tree
Hide file tree
Showing 39 changed files with 563 additions and 342 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ dependencies {
compile "com.android.support:design:${supportLibVersion}"

compile 'com.fasterxml.jackson.core:jackson-databind:2.5.2'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'de.greenrobot:eventbus:2.4.0'
Expand Down
4 changes: 2 additions & 2 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

# Butterknife
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}
-keep class **$$ViewBinder { *; }
-keepnames class * { @butterknife.BindView *;}

# Jackson
-dontskipnonpubliclibraryclassmembers
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2018 Martijn Brekhof. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.xbmc.kore.testhelpers.action;

import android.graphics.Rect;
import android.support.test.espresso.PerformException;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.espresso.util.HumanReadables;
import android.support.v4.widget.NestedScrollView;
import android.view.View;

import org.hamcrest.Matcher;
import org.xbmc.kore.utils.LogUtils;

import static android.support.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.anyOf;

/**
* Modified version of {@link android.support.test.espresso.action.ScrollToAction} to support
* NestedScrollView.
* TODO Check future versions of {@link android.support.test.espresso.action.ScrollToAction} to see if support for NestedScrollView has been added
*/
public class NestedScrollTo implements ViewAction {
private final static String TAG = LogUtils.makeLogTag(NestedScrollTo.class);

@Override
public Matcher<View> getConstraints() {
return allOf(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), isDescendantOfA(anyOf(
isAssignableFrom(NestedScrollView.class))));
}

@Override
public String getDescription() {
return "nested scroll to";
}

@Override
public void perform(UiController uiController, View view) {
if (isDisplayingAtLeast(90).matches(view)) {
LogUtils.LOGI(TAG, "View is already displayed. Returning.");
return;
}
Rect rect = new Rect();
view.getDrawingRect(rect);
if (!view.requestRectangleOnScreen(rect, true /* immediate */)) {
LogUtils.LOGW(TAG, "Scrolling to view was requested, but none of the parents scrolled.");
}
uiController.loopMainThreadUntilIdle();
if (!isDisplayingAtLeast(90).matches(view)) {
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new RuntimeException(
"Scrolling to view was attempted, but the view is not displayed"))
.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.MotionEvents;
import android.support.test.espresso.action.Press;
import android.support.test.espresso.action.ScrollToAction;
import android.support.test.espresso.util.HumanReadables;
import android.support.test.espresso.util.TreeIterables;
import android.view.View;
Expand Down Expand Up @@ -50,6 +51,19 @@ public static ViewAction clearFocus() {
return actionWithAssertions(new ClearFocus());
}

/**
* Returns an action that scrolls to the view in a nested scroll view.<br>
* <br>
* View preconditions:
* <ul>
* <li>must be a descendant of NestedScrollView
* <li>must have visibility set to View.VISIBLE
* <ul></ul>
*/
public static ViewAction nestedScrollTo() {
return actionWithAssertions(new NestedScrollTo());
}

public interface CheckStatus {
boolean check(View v);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ abstract public class AbstractTestClass<T extends AppCompatActivity> {
private static PlayerHandler playerHandler;
private static ApplicationHandler applicationHandler;
private static InputHandler inputHandler;

private int kodiMajorVersion = HostInfo.DEFAULT_KODI_VERSION_MAJOR;
private HostInfo hostInfo;

@BeforeClass
Expand Down Expand Up @@ -120,7 +120,7 @@ public void setUp() throws Throwable {

hostInfo = Database.addHost(context, server.getHostName(),
HostConnection.PROTOCOL_TCP, HostInfo.DEFAULT_HTTP_PORT,
server.getPort(), useEventServer);
server.getPort(), useEventServer, kodiMajorVersion);
//Allow each test to change the host info
configureHostInfo(hostInfo);

Expand Down Expand Up @@ -164,6 +164,17 @@ protected T getActivity() {
return null;
}

/**
* Use this to set the major version of Kodi.
* <br/>
* NOTE: be sure to call this before {@link #setUp()} is called to have the version correctly
* set in the database.
* @param kodiMajorVersion
*/
protected void setKodiMajorVersion(int kodiMajorVersion) {
this.kodiMajorVersion = kodiMajorVersion;
}

public static PlayerHandler getPlayerHandler() {
return playerHandler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.app.Activity;
import android.content.Context;
import android.os.SystemClock;
import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
Expand Down Expand Up @@ -180,6 +181,7 @@ public void searchSwitchTabRotateTest() {
clickAlbumsTab();
EspressoTestUtils.rotateDevice(activity);
EspressoTestUtils.clickMenuItem(activity, activity.getString(R.string.action_search), R.id.action_search);
Espresso.closeSoftKeyboard();

EspressoTestUtils.checkTextInSearchQuery("");
EspressoTestUtils.checkListMatchesSearchQuery("", ALBUM_COMPLETE_LIST_SIZE, R.id.list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected void setSharedPreferences(Context context) {

@Override
protected void configureHostInfo(HostInfo hostInfo) {
hostInfo.setKodiVersionMajor(17);

}

@BeforeClass
Expand All @@ -74,6 +74,12 @@ public static void setupEventServer() throws Throwable {
mockEventServer.start();
}

@Override
public void setUp() throws Throwable {
setKodiMajorVersion(HostInfo.KODI_V17_KRYPTON);
super.setUp();
}

@After
public void resetState() {
mockEventServer.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public static void setupEventServer() throws Throwable {
mockEventServer.start();
}

@Override
public void setUp() throws Throwable {
setKodiMajorVersion(HostInfo.KODI_V16_JARVIS);
super.setUp();
}

@After
public void resetState() {
mockEventServer.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ protected void configureHostInfo(HostInfo hostInfo) {
hostInfo.setKodiVersionMajor(17);
}

@Override
public void setUp() throws Throwable {
setKodiMajorVersion(HostInfo.KODI_V17_KRYPTON);
super.setUp();
}

@Test
public void leftControlPadButtonTest() throws InterruptedException {
onView(withId(R.id.left)).perform(click());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ protected void configureHostInfo(HostInfo hostInfo) {
hostInfo.setKodiVersionMajor(16);
}

@Override
public void setUp() throws Throwable {
setKodiMajorVersion(HostInfo.KODI_V16_JARVIS);
super.setUp();
}

@Test
public void infoControlPadButtonLongClickTest() throws InterruptedException {
onView(withId(R.id.info)).perform(longClick());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.scrollTo;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
import static org.xbmc.kore.testhelpers.action.ViewActions.nestedScrollTo;

public class TVShowsActivityTests extends BaseMediaActivityTests<TVShowsActivity> {

Expand Down Expand Up @@ -79,7 +79,7 @@ public void setActionBarTitle() {
@Test
public void setActionBarTitleOnNextEpisode() {
EspressoTestUtils.clickAdapterViewItem(1, R.id.list);
onView( withId(R.id.next_episode_list)).perform( scrollTo(), click());
onView( withId(R.id.next_episode_list)).perform( nestedScrollTo(), click());

onView(allOf(instanceOf(TextView.class), withParent(withId(R.id.default_toolbar))))
.check(matches(withText("3")));
Expand All @@ -96,7 +96,7 @@ public void setActionBarTitleOnNextEpisode() {
@Test
public void setActionBarTitleOnSeasonList() {
EspressoTestUtils.clickAdapterViewItem(0, R.id.list);
onView( withId(R.id.seasons_list)).perform( scrollTo(), click());
onView( withId(R.id.seasons_list)).perform( nestedScrollTo(), click());

onView(allOf(instanceOf(TextView.class), withParent(withId(R.id.default_toolbar))))
.check(matches(withText("Season 01")));
Expand All @@ -114,7 +114,7 @@ public void setActionBarTitleOnSeasonList() {
@Test
public void setActionBarTitleOnSeasonListEpisode() {
EspressoTestUtils.clickAdapterViewItem(0, R.id.list);
onView( withId(R.id.seasons_list)).perform( scrollTo(), click());
onView( withId(R.id.seasons_list)).perform( nestedScrollTo(), click());
EspressoTestUtils.selectListItemAndCheckActionbarTitle(0, R.id.list, "11.22.63");
}

Expand Down Expand Up @@ -145,7 +145,7 @@ public void restoreActionBarTitleOnConfigurationStateChanged() {
@Test
public void restoreActionBarTitleSeasonListOnConfigurationStateChanged() {
EspressoTestUtils.clickAdapterViewItem(0, R.id.list);
onView( withId(R.id.seasons_list)).perform( scrollTo(), click());
onView( withId(R.id.seasons_list)).perform( nestedScrollTo(), click());
EspressoTestUtils.rotateDevice(mActivityRule.getActivity());

onView(allOf(instanceOf(TextView.class), withParent(withId(R.id.default_toolbar))))
Expand All @@ -165,7 +165,7 @@ public void restoreActionBarTitleSeasonListOnConfigurationStateChanged() {
@Test
public void restoreActionBarTitleSeasonListEpisodeOnConfigurationStateChanged() {
EspressoTestUtils.clickAdapterViewItem(0, R.id.list);
onView( withId(R.id.seasons_list)).perform( scrollTo(), click());
onView( withId(R.id.seasons_list)).perform( nestedScrollTo(), click());
EspressoTestUtils.selectListItemRotateDeviceAndCheckActionbarTitle(0, R.id.list,
"11.22.63",
mActivityRule.getActivity());
Expand All @@ -183,7 +183,7 @@ public void restoreActionBarTitleSeasonListEpisodeOnConfigurationStateChanged()
@Test
public void restoreActionBarTitleNextEpisodeOnConfigurationStateChanged() {
EspressoTestUtils.clickAdapterViewItem(1, R.id.list);
onView( withId(R.id.next_episode_list)).perform( scrollTo() );
onView( withId(R.id.next_episode_list)).perform( nestedScrollTo() );
onView( withText("You'll See the Sparkle")).perform( click() );
EspressoTestUtils.rotateDevice(mActivityRule.getActivity());

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/xbmc/kore/host/HostInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ public void setKodiVersionTag(String kodiVersionTag) {
}

public boolean isGothamOrLater() {
return kodiVersionMajor > KODI_V13_GOTHAM;
return kodiVersionMajor >= KODI_V13_GOTHAM;
}

public boolean isKryptonOrLater() {
return kodiVersionMajor > KODI_V17_KRYPTON;
return kodiVersionMajor >= KODI_V17_KRYPTON;
}

/**
Expand Down
Loading

0 comments on commit 2ed9684

Please sign in to comment.