Search in sources :

Example 6 with Item

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

the class ThreadPreviewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Item item = getIntent().getParcelableExtra(EXTRA_ITEM);
    if (item == null) {
        finish();
        return;
    }
    supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_thread_preview);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    //noinspection ConstantConditions
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new SnappyLinearLayoutManager(this, false));
    recyclerView.addItemDecoration(new CommentItemDecoration(this));
    recyclerView.setAdapter(new ThreadPreviewRecyclerViewAdapter(mItemManager, item));
    mKeyDelegate.setScrollable(new KeyDelegate.RecyclerViewHelper(recyclerView, KeyDelegate.RecyclerViewHelper.SCROLL_ITEM), null);
}
Also used : Item(io.github.hidroh.materialistic.data.Item) MenuItem(android.view.MenuItem) SnappyLinearLayoutManager(io.github.hidroh.materialistic.widget.SnappyLinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) CommentItemDecoration(io.github.hidroh.materialistic.widget.CommentItemDecoration) ThreadPreviewRecyclerViewAdapter(io.github.hidroh.materialistic.widget.ThreadPreviewRecyclerViewAdapter)

Example 7 with Item

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

the class ItemRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final VH holder, int position) {
    final Item item = getItem(position);
    if (item == null) {
        return;
    }
    clear(holder);
    if (item.getLocalRevision() < 0) {
        load(holder.getAdapterPosition(), item);
    } else if (item.getLocalRevision() > 0) {
        bind(holder, item);
    }
}
Also used : Item(io.github.hidroh.materialistic.data.Item)

Example 8 with Item

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

the class SinglePageItemRecyclerViewAdapter method getNextPosition.

@Override
public void getNextPosition(int position, int direction, PositionCallback callback) {
    if (position < 0) {
        return;
    }
    Item item = getItem(position);
    if (item == null) {
        return;
    }
    long id = item.getNeighbour(direction);
    switch(direction) {
        case Navigable.DIRECTION_UP:
            if (id == 0) {
                // no more previous sibling, try previous list item
                setSelectedPosition(position - 1, callback);
            } else {
                setSelectedPosition(mState.indexOf(id), callback);
            }
            break;
        case Navigable.DIRECTION_DOWN:
            if (id == 0) {
                // no more next sibling, try next list item
                setSelectedPosition(position + 1, callback);
            } else {
                setSelectedPosition(mState.indexOf(id), callback);
            }
            break;
        case Navigable.DIRECTION_LEFT:
            if (id != 0) {
                setSelectedPosition(mState.indexOf(id), callback);
            }
            break;
        case Navigable.DIRECTION_RIGHT:
            if (id == 0) {
                // no kids, try next list item
                setSelectedPosition(position + 1, callback);
            } else if (mState.isExpanded(item)) {
                setSelectedPosition(mState.indexOf(id), callback);
            } else {
                expand(item, callback);
            }
            break;
    }
}
Also used : Item(io.github.hidroh.materialistic.data.Item)

Example 9 with Item

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

the class ItemFragmentMultiPageTest method testBindLocalKidData.

@Test
public void testBindLocalKidData() {
    Item story = new TestHnItem(0L);
    story.populate(new TestItem() {

        @Override
        public int getDescendants() {
            return 1;
        }

        @Override
        public long[] getKids() {
            return new long[] { 1L };
        }
    });
    story.getKidItems()[0].populate(new TestItem() {

        @Override
        public String getText() {
            return "text";
        }

        @Override
        public long[] getKids() {
            return new long[] { 2L };
        }

        @Override
        public int getDescendants() {
            return 1;
        }
    });
    Bundle args = new Bundle();
    args.putParcelable(ItemFragment.EXTRA_ITEM, story);
    Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application, ItemFragment.class.getName(), args);
    makeVisible(fragment);
    assertThat(fragment.getView().findViewById(R.id.empty)).isNotVisible();
    RecyclerView recyclerView = (RecyclerView) fragment.getView().findViewById(R.id.recycler_view);
    RecyclerView.ViewHolder viewHolder = CustomShadows.customShadowOf(recyclerView.getAdapter()).getViewHolder(0);
    assertThat((TextView) viewHolder.itemView.findViewById(R.id.text)).hasTextString("text");
    assertThat(viewHolder.itemView.findViewById(R.id.comment)).isVisible();
    viewHolder.itemView.findViewById(R.id.comment).performClick();
    Intent actual = shadowOf(fragment.getActivity()).getNextStartedActivity();
    assertEquals(ItemActivity.class.getName(), actual.getComponent().getClassName());
    assertThat(actual).hasExtra(ItemActivity.EXTRA_OPEN_COMMENTS, true);
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) Fragment(android.support.v4.app.Fragment) TestItem(io.github.hidroh.materialistic.test.TestItem) WebItem(io.github.hidroh.materialistic.data.WebItem) Item(io.github.hidroh.materialistic.data.Item) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) TestItem(io.github.hidroh.materialistic.test.TestItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 10 with Item

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

the class ItemFragmentSinglePageTest method testDefaultCollapsed.

@Test
public void testDefaultCollapsed() {
    PreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application).edit().putString(RuntimeEnvironment.application.getString(R.string.pref_comment_display), RuntimeEnvironment.application.getString(R.string.pref_comment_display_value_collapsed)).apply();
    final TestItem item0 = new // level 0
    TestItem() {

        @Override
        public String getId() {
            return "1";
        }

        @Override
        public int getKidCount() {
            return 1;
        }

        @Override
        public Item[] getKidItems() {
            return new Item[] { new TestItem() {

                @Override
                public String getId() {
                    return "2";
                }
            } };
        }
    };
    Bundle args = new Bundle();
    args.putParcelable(ItemFragment.EXTRA_ITEM, new TestItem() {

        @Override
        public Item[] getKidItems() {
            return new Item[] { item0 };
        }

        @Override
        public int getKidCount() {
            return 1;
        }
    });
    Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application, ItemFragment.class.getName(), args);
    SupportFragmentTestUtil.startVisibleFragment(fragment, ItemFragmentMultiPageTest.TestItemActivity.class, R.id.content_frame);
    recyclerView = (RecyclerView) fragment.getView().findViewById(R.id.recycler_view);
    adapter = (SinglePageItemRecyclerViewAdapter) recyclerView.getAdapter();
    // item + footer
    assertEquals(2, adapter.getItemCount());
    // should not add kid to adapter
    assertEquals(2, adapter.getItemCount());
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) Item(io.github.hidroh.materialistic.data.Item) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Bundle(android.os.Bundle) Fragment(android.support.v4.app.Fragment) TestItem(io.github.hidroh.materialistic.test.TestItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Aggregations

Item (io.github.hidroh.materialistic.data.Item)16 WebItem (io.github.hidroh.materialistic.data.WebItem)6 Bundle (android.os.Bundle)4 Fragment (android.support.v4.app.Fragment)4 RecyclerView (android.support.v7.widget.RecyclerView)4 Intent (android.content.Intent)3 MenuItem (android.view.MenuItem)3 Context (android.content.Context)2 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)2 Synthetic (io.github.hidroh.materialistic.annotation.Synthetic)2 TestHnItem (io.github.hidroh.materialistic.data.TestHnItem)2 TestItem (io.github.hidroh.materialistic.test.TestItem)2 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)2 Test (org.junit.Test)2 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ContentResolver (android.content.ContentResolver)1 IntentFilter (android.content.IntentFilter)1