Search in sources :

Example 1 with CommentItemDecoration

use of io.github.hidroh.materialistic.widget.CommentItemDecoration 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(androidx.recyclerview.widget.RecyclerView) CommentItemDecoration(io.github.hidroh.materialistic.widget.CommentItemDecoration) ThreadPreviewRecyclerViewAdapter(io.github.hidroh.materialistic.widget.ThreadPreviewRecyclerViewAdapter)

Example 2 with CommentItemDecoration

use of io.github.hidroh.materialistic.widget.CommentItemDecoration in project materialistic by hidroh.

the class UserActivity method onCreate.

@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mUsername = getIntent().getStringExtra(EXTRA_USERNAME);
    if (TextUtils.isEmpty(mUsername)) {
        mUsername = AppUtils.getDataUriId(getIntent(), PARAM_ID);
    }
    if (TextUtils.isEmpty(mUsername)) {
        finish();
        return;
    }
    setTaskTitle(mUsername);
    AppUtils.setStatusBarDim(getWindow(), true);
    setContentView(R.layout.activity_user);
    findViewById(R.id.touch_outside).setOnClickListener(v -> finish());
    mBottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottom_sheet));
    mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {

        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            switch(newState) {
                case BottomSheetBehavior.STATE_HIDDEN:
                    finish();
                    break;
                case BottomSheetBehavior.STATE_EXPANDED:
                    AppUtils.setStatusBarDim(getWindow(), false);
                    mRecyclerView.setLayoutFrozen(false);
                    break;
                case BottomSheetBehavior.STATE_COLLAPSED:
                case BottomSheetBehavior.STATE_DRAGGING:
                case BottomSheetBehavior.STATE_HALF_EXPANDED:
                case BottomSheetBehavior.STATE_SETTLING:
                default:
                    AppUtils.setStatusBarDim(getWindow(), true);
                    break;
            }
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        // no op
        }
    });
    mTitle = (TextView) findViewById(R.id.title);
    mTitle.setText(mUsername);
    mInfo = (TextView) findViewById(R.id.user_info);
    mAbout = (TextView) findViewById(R.id.about);
    mEmpty = findViewById(R.id.empty);
    mTabLayout = (TabLayout) findViewById(R.id.tab_layout);
    mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
        // no op
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        // no op
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            scrollToTop();
        }
    });
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new SnappyLinearLayoutManager(this, true));
    mRecyclerView.addItemDecoration(new CommentItemDecoration(this));
    mScrollableHelper = new KeyDelegate.RecyclerViewHelper(mRecyclerView, KeyDelegate.RecyclerViewHelper.SCROLL_ITEM);
    if (savedInstanceState != null) {
        mUser = savedInstanceState.getParcelable(STATE_USER);
    }
    if (mUser == null) {
        load();
    } else {
        bind();
    }
    if (!AppUtils.hasConnection(this)) {
        Snackbar.make(findViewById(R.id.content_frame), R.string.offline_notice, Snackbar.LENGTH_LONG).show();
    }
}
Also used : CommentItemDecoration(io.github.hidroh.materialistic.widget.CommentItemDecoration) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) TabLayout(com.google.android.material.tabs.TabLayout) SnappyLinearLayoutManager(io.github.hidroh.materialistic.widget.SnappyLinearLayoutManager)

Example 3 with CommentItemDecoration

use of io.github.hidroh.materialistic.widget.CommentItemDecoration in project materialistic by hidroh.

the class ItemFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState) {
    if (isNewInstance()) {
        mFragmentView = inflater.inflate(R.layout.fragment_item, container, false);
        mEmptyView = mFragmentView.findViewById(R.id.empty);
        mRecyclerView = (RecyclerView) mFragmentView.findViewById(R.id.recycler_view);
        mRecyclerView.setLayoutManager(new SnappyLinearLayoutManager(getActivity(), true));
        mItemDecoration = new CommentItemDecoration(getActivity());
        mRecyclerView.addItemDecoration(mItemDecoration);
        mSwipeRefreshLayout = (SwipeRefreshLayout) mFragmentView.findViewById(R.id.swipe_layout);
        mSwipeRefreshLayout.setColorSchemeResources(R.color.white);
        mSwipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.redA200);
        mSwipeRefreshLayout.setOnRefreshListener(() -> {
            if (TextUtils.isEmpty(mItemId)) {
                return;
            }
            mCacheMode = ItemManager.MODE_NETWORK;
            if (mAdapter != null) {
                mAdapter.setCacheMode(mCacheMode);
            }
            loadKidData();
        });
    }
    return mFragmentView;
}
Also used : SnappyLinearLayoutManager(io.github.hidroh.materialistic.widget.SnappyLinearLayoutManager) CommentItemDecoration(io.github.hidroh.materialistic.widget.CommentItemDecoration)

Aggregations

CommentItemDecoration (io.github.hidroh.materialistic.widget.CommentItemDecoration)3 SnappyLinearLayoutManager (io.github.hidroh.materialistic.widget.SnappyLinearLayoutManager)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 MenuItem (android.view.MenuItem)1 View (android.view.View)1 TextView (android.widget.TextView)1 BottomSheetBehavior (com.google.android.material.bottomsheet.BottomSheetBehavior)1 TabLayout (com.google.android.material.tabs.TabLayout)1 Item (io.github.hidroh.materialistic.data.Item)1 ThreadPreviewRecyclerViewAdapter (io.github.hidroh.materialistic.widget.ThreadPreviewRecyclerViewAdapter)1