Search in sources :

Example 1 with WebItem

use of io.github.hidroh.materialistic.data.WebItem in project materialistic by hidroh.

the class ItemFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    if (savedInstanceState != null) {
        mCacheMode = savedInstanceState.getInt(STATE_CACHE_MODE, ItemManager.MODE_DEFAULT);
        mItem = savedInstanceState.getParcelable(STATE_ITEM);
        mItemId = savedInstanceState.getString(STATE_ITEM_ID);
        mAdapterItems = savedInstanceState.getParcelable(STATE_ADAPTER_ITEMS);
    } else {
        mCacheMode = getArguments().getInt(EXTRA_CACHE_MODE, ItemManager.MODE_DEFAULT);
        WebItem item = getArguments().getParcelable(EXTRA_ITEM);
        if (item instanceof Item) {
            mItem = (Item) item;
        }
        mItemId = item != null ? item.getId() : null;
    }
}
Also used : MenuItem(android.view.MenuItem) WebItem(io.github.hidroh.materialistic.data.WebItem) Item(io.github.hidroh.materialistic.data.Item) WebItem(io.github.hidroh.materialistic.data.WebItem)

Example 2 with WebItem

use of io.github.hidroh.materialistic.data.WebItem in project materialistic by hidroh.

the class ItemFragmentMultiPageTest method testRefreshFailed.

@Test
public void testRefreshFailed() {
    WebItem webItem = mock(WebItem.class);
    when(webItem.getId()).thenReturn("1");
    Bundle args = new Bundle();
    args.putParcelable(ItemFragment.EXTRA_ITEM, webItem);
    Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application, ItemFragment.class.getName(), args);
    makeVisible(fragment);
    ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout) ShadowExtractor.extract(fragment.getView().findViewById(R.id.swipe_layout));
    shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
    verify(hackerNewsClient).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
    verify(hackerNewsClient).getItem(eq("1"), eq(ItemManager.MODE_NETWORK), listener.capture());
    listener.getAllValues().get(1).onError(null);
    assertThat((SwipeRefreshLayout) fragment.getView().findViewById(R.id.swipe_layout)).isNotRefreshing();
}
Also used : ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) Bundle(android.os.Bundle) WebItem(io.github.hidroh.materialistic.data.WebItem) Fragment(android.support.v4.app.Fragment) ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 3 with WebItem

use of io.github.hidroh.materialistic.data.WebItem in project materialistic by hidroh.

the class ItemActivityTest method testFullscreen.

@Config(shadows = { ShadowFloatingActionButton.class })
@Test
public void testFullscreen() {
    Intent intent = new Intent();
    WebItem webItem = new TestWebItem() {

        @Override
        public String getUrl() {
            return "http://example.com";
        }

        @Override
        public String getId() {
            return "1";
        }
    };
    intent.putExtra(ItemActivity.EXTRA_ITEM, webItem);
    controller.withIntent(intent).create().start().resume().visible();
    ShadowFloatingActionButton shadowFab = (ShadowFloatingActionButton) ShadowExtractor.extract(activity.findViewById(R.id.reply_button));
    assertTrue(shadowFab.isVisible());
    ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
    assertFalse(shadowFab.isVisible());
    ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, false));
    assertTrue(shadowFab.isVisible());
}
Also used : ShadowFloatingActionButton(io.github.hidroh.materialistic.test.shadow.ShadowFloatingActionButton) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) WebItem(io.github.hidroh.materialistic.data.WebItem) Intent(android.content.Intent) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 4 with WebItem

use of io.github.hidroh.materialistic.data.WebItem in project materialistic by hidroh.

the class ItemActivityTest method testFullscreenBackPressed.

@Test
public void testFullscreenBackPressed() {
    Intent intent = new Intent();
    WebItem webItem = new TestWebItem() {

        @Override
        public String getUrl() {
            return "http://example.com";
        }

        @Override
        public String getId() {
            return "1";
        }
    };
    intent.putExtra(ItemActivity.EXTRA_ITEM, webItem);
    controller.withIntent(intent).create().start().resume().visible();
    ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
    activity.onBackPressed();
    assertThat(activity).isNotFinishing();
    activity.onBackPressed();
    assertThat(activity).isFinishing();
}
Also used : TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) WebItem(io.github.hidroh.materialistic.data.WebItem) Intent(android.content.Intent) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 5 with WebItem

use of io.github.hidroh.materialistic.data.WebItem in project materialistic by hidroh.

the class ItemActivityTest method testBackPressed.

@Test
public void testBackPressed() {
    Intent intent = new Intent();
    WebItem webItem = new TestWebItem() {

        @Override
        public String getUrl() {
            return "http://example.com";
        }

        @Override
        public String getId() {
            return "1";
        }
    };
    intent.putExtra(ItemActivity.EXTRA_ITEM, webItem);
    controller.withIntent(intent).create().start().resume().visible();
    activity.onKeyDown(KeyEvent.KEYCODE_BACK, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
    verify(keyDelegate).setBackInterceptor(any());
    verify(keyDelegate).onKeyDown(anyInt(), any(KeyEvent.class));
}
Also used : KeyEvent(android.view.KeyEvent) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) WebItem(io.github.hidroh.materialistic.data.WebItem) Intent(android.content.Intent) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Aggregations

WebItem (io.github.hidroh.materialistic.data.WebItem)15 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)8 Test (org.junit.Test)8 Bundle (android.os.Bundle)7 TestWebItem (io.github.hidroh.materialistic.test.TestWebItem)6 Intent (android.content.Intent)5 Fragment (android.support.v4.app.Fragment)4 Item (io.github.hidroh.materialistic.data.Item)4 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)2 KeyEvent (android.view.KeyEvent)2 TestItem (io.github.hidroh.materialistic.test.TestItem)2 TestReadabilityActivity (io.github.hidroh.materialistic.test.TestReadabilityActivity)2 ShadowSwipeRefreshLayout (io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout)2 Before (org.junit.Before)2 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)2 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 ConnectivityManager (android.net.ConnectivityManager)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 AppBarLayout (android.support.design.widget.AppBarLayout)1