Search in sources :

Example 6 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project UltimateRecyclerView by cymcsg.

the class SlidingTabLayout method populateTabStrip.

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();
    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;
        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }
        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }
        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }
        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }
        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }
        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}
Also used : TextView(android.widget.TextView) HorizontalScrollView(android.widget.HorizontalScrollView) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) LinearLayout(android.widget.LinearLayout)

Example 7 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project storymaker by StoryMaker.

the class SlidingTabLayout method populateTabStrip.

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();
    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;
        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }
        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }
        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
            tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector));
        }
        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }
        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }
        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}
Also used : TextView(android.widget.TextView) HorizontalScrollView(android.widget.HorizontalScrollView) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) LinearLayout(android.widget.LinearLayout)

Example 8 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project material-intro-screen by TangoAgency.

the class OverScrollViewPager method canOverScrollAtEnd.

private boolean canOverScrollAtEnd() {
    SwipeableViewPager viewPager = getOverScrollView();
    PagerAdapter adapter = viewPager.getAdapter();
    if (null != adapter && adapter.getCount() > 0) {
        if (viewPager.alphaExitTransitionEnabled() && viewPager.getCurrentItem() == adapter.getCount() - 1) {
            return true;
        }
        return false;
    }
    return false;
}
Also used : PagerAdapter(android.support.v4.view.PagerAdapter)

Example 9 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project Reader by TheKeeperOfPie.

the class FragmentNewPost method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_new_post, container, false);
    layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
    layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
    scrollText = (NestedScrollView) view.findViewById(R.id.scroll_text);
    textInfo = (TextView) view.findViewById(R.id.text_info);
    textSubmit = (TextView) view.findViewById(R.id.text_submit);
    editTextTitle = (EditText) view.findViewById(R.id.edit_title);
    editTextBody = (EditText) view.findViewById(R.id.edit_body);
    toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.new_post));
    toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.setNavigationOnClickListener(v -> {
        UtilsInput.hideKeyboard(editTextBody);
        mListener.onNavigationBackClick();
    });
    toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
    setUpOptionsMenu();
    textInfo.setText(getString(R.string.submitting_post, getArguments().getString(SUBREDDIT), getArguments().getString(USER)));
    String submitTextHtml = getArguments().getString(SUBMIT_TEXT_HTML);
    Log.d(TAG, "submitTextHtml: " + submitTextHtml);
    if (TextUtils.isEmpty(submitTextHtml) || "null".equals(submitTextHtml)) {
        textSubmit.setVisibility(View.GONE);
    } else {
        textSubmit.setText(UtilsReddit.getFormattedHtml(submitTextHtml));
    }
    textSubmit.setMovementMethod(LinkMovementMethod.getInstance());
    if (Reddit.PostType.LINK == postType) {
        editTextBody.setHint("URL");
    } else {
        editTextBody.setHint("Text");
    }
    View.OnFocusChangeListener onFocusChangeListener = (v, hasFocus) -> {
        if (hasFocus) {
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }
    };
    editTextTitle.setOnFocusChangeListener(onFocusChangeListener);
    editTextBody.setOnFocusChangeListener(onFocusChangeListener);
    editMarginDefault = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
    editMarginWithActions = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, getResources().getDisplayMetrics());
    textPreview = (TextView) view.findViewById(R.id.text_preview);
    viewDivider = view.findViewById(R.id.view_divider);
    toolbarActions = (Toolbar) view.findViewById(R.id.toolbar_actions);
    toolbarActions.inflateMenu(R.menu.menu_editor_actions);
    toolbarActions.setOnMenuItemClickListener(this);
    tabLayout = (TabLayout) view.findViewById(R.id.layout_tab);
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setTabTextColors(themer.getColorFilterTextMuted().getColor(), themer.getColorFilterPrimary().getColor());
    viewPager = (ViewPager) view.findViewById(R.id.view_pager);
    viewPager.setAdapter(new PagerAdapter() {

        @Override
        public CharSequence getPageTitle(int position) {
            switch(position) {
                case PAGE_POST:
                    return getString(R.string.page_post);
                case PAGE_PREVIEW:
                    return getString(R.string.page_preview);
            }
            return super.getPageTitle(position);
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            return viewPager.getChildAt(position);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
        }

        @Override
        public int getCount() {
            if (Reddit.PostType.LINK == postType) {
                tabLayout.setVisibility(View.GONE);
                toolbarActions.setVisibility(View.GONE);
                viewDivider.setVisibility(View.GONE);
                itemHideActions.setVisible(false);
                return 1;
            }
            return viewPager.getChildCount();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }
    });
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (position == PAGE_POST && toolbarActions.getVisibility() == View.VISIBLE) {
                float translationY = positionOffset * (toolbarActions.getHeight() + viewDivider.getHeight());
                viewDivider.setTranslationY(translationY);
                toolbarActions.setTranslationY(translationY);
            }
        }

        @Override
        public void onPageSelected(int position) {
            if (position == PAGE_PREVIEW) {
                if (editTextBody.length() == 0) {
                    textPreview.setText(R.string.empty_reply_preview);
                } else {
                    textPreview.setText(Html.fromHtml(Processor.process(editTextBody.getText().toString())));
                }
            }
            if (Reddit.PostType.SELF == postType) {
                itemHideActions.setVisible(position == PAGE_POST);
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    tabLayout.setupWithViewPager(viewPager);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    layoutCaptcha = (RelativeLayout) view.findViewById(R.id.layout_captcha);
    imageCaptcha = (ImageView) view.findViewById(R.id.image_captcha);
    editCaptcha = (EditText) view.findViewById(R.id.edit_captcha);
    buttonCaptchaRefresh = (ImageButton) view.findViewById(R.id.button_captcha_refresh);
    buttonCaptchaRefresh.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            loadCaptcha();
        }
    });
    if (getArguments().getBoolean(IS_EDIT, false)) {
        loadEditValues();
    } else {
        reddit.needsCaptcha().subscribe(new Observer<String>() {

            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
            }

            @Override
            public void onNext(String response) {
                if ("true".equalsIgnoreCase(response)) {
                    layoutCaptcha.setVisibility(View.VISIBLE);
                    loadCaptcha();
                }
            }
        });
    }
    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            Menu menu = toolbarActions.getMenu();
            int maxNum = (int) (view.getWidth() / TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics()));
            int numShown = 0;
            for (int index = 0; index < menu.size(); index++) {
                MenuItem menuItem = menu.getItem(index);
                menuItem.getIcon().setColorFilter(themer.getColorFilterIcon());
                if (numShown++ < maxNum - 1) {
                    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
                } else {
                    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
                }
            }
            // Toggle visibility to fix weird bug causing tabs to not be added
            tabLayout.setVisibility(View.GONE);
            tabLayout.setVisibility(View.VISIBLE);
            view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });
    return view;
}
Also used : AppBarLayout(android.support.design.widget.AppBarLayout) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ImageButton(android.widget.ImageButton) Bundle(android.os.Bundle) ControllerLinks(com.winsonchiu.reader.links.ControllerLinks) UtilsRx(com.winsonchiu.reader.utils.UtilsRx) ImageView(android.widget.ImageView) ViewPager(android.support.v4.view.ViewPager) LinkMovementMethod(android.text.method.LinkMovementMethod) MenuItem(android.view.MenuItem) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) Picasso(com.squareup.picasso.Picasso) JSONException(org.json.JSONException) Reddit(com.winsonchiu.reader.data.reddit.Reddit) JSONObject(org.json.JSONObject) ComponentStatic(com.winsonchiu.reader.dagger.components.ComponentStatic) Toast(android.widget.Toast) Menu(android.view.Menu) Link(com.winsonchiu.reader.data.reddit.Link) View(android.view.View) JsonNode(com.fasterxml.jackson.databind.JsonNode) NestedScrollView(android.support.v4.widget.NestedScrollView) Log(android.util.Log) Processor(com.github.rjeschke.txtmark.Processor) UtilsInput(com.winsonchiu.reader.utils.UtilsInput) URLUtil(android.webkit.URLUtil) LayoutInflater(android.view.LayoutInflater) Listing(com.winsonchiu.reader.data.reddit.Listing) PagerAdapter(android.support.v4.view.PagerAdapter) TextUtils(android.text.TextUtils) Observer(rx.Observer) UtilsReddit(com.winsonchiu.reader.utils.UtilsReddit) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) TypedValue(android.util.TypedValue) Toolbar(android.support.v7.widget.Toolbar) Html(android.text.Html) ViewTreeObserver(android.view.ViewTreeObserver) RelativeLayout(android.widget.RelativeLayout) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) EditText(android.widget.EditText) PagerAdapter(android.support.v4.view.PagerAdapter) TabLayout(android.support.design.widget.TabLayout) AppBarLayout(android.support.design.widget.AppBarLayout) Menu(android.view.Menu) ViewTreeObserver(android.view.ViewTreeObserver) ViewGroup(android.view.ViewGroup) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) ViewPager(android.support.v4.view.ViewPager) JSONObject(org.json.JSONObject)

Example 10 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project Reader by TheKeeperOfPie.

the class FragmentSearch method onCreateView.

// TODO: Remove/fix ResourceType warning
@SuppressWarnings("ResourceType")
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = bind(inflater.inflate(R.layout.fragment_search, container, false));
    listenerSearch = new ControllerSearch.Listener() {

        @Override
        public AdapterSearchSubreddits getAdapterSearchSubreddits() {
            return adapterSearchSubreddits;
        }

        @Override
        public AdapterSearchSubreddits getAdapterSearchSubredditsRecommended() {
            return adapterSearchSubredditsRecommended;
        }

        @Override
        public void scrollToLinks(int position) {
            layoutManagerLinks.scrollToPositionWithOffset(0, 0);
        }

        @Override
        public void scrollToLinksSubreddit(int position) {
            layoutManagerLinksSubreddit.scrollToPositionWithOffset(0, 0);
        }
    };
    int windowBackground = UtilsTheme.getAttributeColor(getContext(), android.R.attr.windowBackground, 0);
    setUpToolbar();
    adapterSearchSubreddits = new AdapterSearchSubreddits(getActivity(), new ControllerSearchBase() {

        @Override
        public Subreddit getSubreddit(int position) {
            return controllerSearch.getSubreddit(position);
        }

        @Override
        public int getSubredditCount() {
            return controllerSearch.getCountSubreddit();
        }
    }, new AdapterSearchSubreddits.ViewHolder.EventListener() {

        @Override
        public void onClickSubreddit(Subreddit subreddit) {
            controllerSearch.addViewedSubreddit(subreddit);
            controllerLinks.setParameters(subreddit.getDisplayName(), Sort.HOT, Time.ALL);
            closeKeyboard();
            mListener.onNavigationBackClick();
        }

        @Override
        public boolean supportsDrag() {
            return true;
        }

        @Override
        public void onStartDrag(AdapterSearchSubreddits.ViewHolder viewHolder) {
            itemTouchHelperSubreddits.startDrag(viewHolder);
        }

        @Override
        public void sendToTop(AdapterSearchSubreddits.ViewHolder viewHolder) {
            controllerSearch.moveSubreddit(viewHolder.getAdapterPosition(), 0);
            recyclerSearchSubreddits.postOnAnimationDelayed(() -> {
                if (layoutManagerSubreddits.findFirstVisibleItemPosition() <= 1) {
                    layoutManagerSubreddits.smoothScrollToPosition(recyclerSearchSubreddits, null, 0);
                }
            }, 150);
        }

        @Override
        public boolean isSubscriptionListShown() {
            return controllerSearch.isSubscriptionListShown();
        }
    });
    layoutManagerSubreddits = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
    recyclerSearchSubreddits.setLayoutManager(layoutManagerSubreddits);
    recyclerSearchSubreddits.setAdapter(adapterSearchSubreddits);
    recyclerSearchSubreddits.addItemDecoration(new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST));
    itemTouchHelperSubreddits = new ItemTouchHelper(new SimpleCallbackBackground(0, 0, windowBackground) {

        @Override
        public int getDragDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            if (controllerSearch.isSubscriptionListShown()) {
                return ItemTouchHelper.UP | ItemTouchHelper.DOWN;
            }
            return super.getDragDirs(recyclerView, viewHolder);
        }

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            controllerSearch.moveSubreddit(viewHolder.getAdapterPosition(), target.getAdapterPosition());
            return true;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
        }

        @Override
        public boolean isLongPressDragEnabled() {
            return false;
        }
    });
    itemTouchHelperSubreddits.attachToRecyclerView(recyclerSearchSubreddits);
    AdapterLink.ViewHolderLink.Listener listenerLink = new AdapterLink.ViewHolderLink.Listener() {

        @Override
        public void onSubmitComment(Link link, String text) {
        }

        @Override
        public void onDownloadImage(Link link) {
        }

        @Override
        public void onDownloadImage(Link link, String title, String fileName, String url) {
        }

        @Override
        public void onLoadUrl(Link link, boolean forceExternal) {
        }

        @Override
        public void onShowFullEditor(Link link) {
        }

        @Override
        public void onVote(Link link, AdapterLink.ViewHolderLink viewHolderLink, Likes vote) {
        }

        @Override
        public void onCopyText(Link link) {
        }

        @Override
        public void onEdit(Link link) {
        }

        @Override
        public void onDelete(Link link) {
        }

        @Override
        public void onReport(Link link) {
        }

        @Override
        public void onSave(Link link) {
        }

        @Override
        public void onShowComments(Link link, AdapterLink.ViewHolderLink viewHolderLink, Source source) {
        }

        @Override
        public void onShowError(String error) {
        }

        @Override
        public void onMarkNsfw(Link link) {
        }
    };
    adapterLinks = new AdapterSearchLinkList(getActivity(), new AdapterListener() {

        @Override
        public void requestMore() {
            controllerSearch.loadMoreLinks().subscribe(getReloadObserver());
        }

        @Override
        public void scrollAndCenter(int position, int height) {
            UtilsAnimation.scrollToPositionWithCentering(position, recyclerSearchLinks, false);
        }

        @Override
        public void hideToolbar() {
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }

        @Override
        public void clearDecoration() {
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }

        @Override
        public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
            recyclerSearchLinks.requestDisallowInterceptTouchEvent(disallow);
            recyclerSearchLinksSubreddit.requestDisallowInterceptTouchEvent(disallow);
            pagerSearch.requestDisallowInterceptTouchEvent(disallow);
        }

        @Override
        public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
        }
    }, new AdapterLink.ViewHolderHeader.EventListener() {

        @Override
        public void onClickSubmit(Reddit.PostType postType) {
        }

        @Override
        public void showSidebar() {
        }
    }, listenerLink, Source.SEARCH_LINKS);
    adapterLinksSubreddit = new AdapterSearchLinkList(getActivity(), new AdapterListener() {

        @Override
        public void requestMore() {
            controllerSearch.loadMoreLinksSubreddit().subscribe(getReloadObserver());
        }

        @Override
        public void scrollAndCenter(int position, int height) {
            UtilsAnimation.scrollToPositionWithCentering(position, recyclerSearchLinksSubreddit, false);
        }

        @Override
        public void hideToolbar() {
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }

        @Override
        public void clearDecoration() {
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }

        @Override
        public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
            recyclerSearchLinks.requestDisallowInterceptTouchEvent(disallow);
            recyclerSearchLinksSubreddit.requestDisallowInterceptTouchEvent(disallow);
            pagerSearch.requestDisallowInterceptTouchEvent(disallow);
        }

        @Override
        public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
        }
    }, new AdapterLink.ViewHolderHeader.EventListener() {

        @Override
        public void onClickSubmit(Reddit.PostType postType) {
        }

        @Override
        public void showSidebar() {
        }
    }, listenerLink, Source.SEARCH_LINKS_SUBREDDIT);
    layoutManagerLinks = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
    recyclerSearchLinks.setLayoutManager(layoutManagerLinks);
    recyclerSearchLinks.setAdapter(adapterLinks);
    recyclerSearchLinks.addItemDecoration(new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST));
    layoutManagerLinksSubreddit = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
    recyclerSearchLinksSubreddit.setLayoutManager(layoutManagerLinksSubreddit);
    recyclerSearchLinksSubreddit.setAdapter(adapterLinksSubreddit);
    recyclerSearchLinksSubreddit.addItemDecoration(new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST));
    adapterSearchSubredditsRecommended = new AdapterSearchSubreddits(getActivity(), new ControllerSearchBase() {

        @Override
        public Subreddit getSubreddit(int position) {
            return controllerSearch.getSubredditRecommended(position);
        }

        @Override
        public int getSubredditCount() {
            return controllerSearch.getCountSubredditRecommended();
        }
    }, new AdapterSearchSubreddits.ViewHolder.EventListener() {

        @Override
        public void onClickSubreddit(Subreddit subreddit) {
            controllerLinks.setParameters(subreddit.getDisplayName(), Sort.HOT, Time.ALL);
            closeKeyboard();
            mListener.onNavigationBackClick();
        }

        @Override
        public boolean supportsDrag() {
            return false;
        }

        @Override
        public void onStartDrag(AdapterSearchSubreddits.ViewHolder viewHolder) {
        }

        @Override
        public void sendToTop(AdapterSearchSubreddits.ViewHolder viewHolder) {
        }

        @Override
        public boolean isSubscriptionListShown() {
            return controllerSearch.isSubscriptionListShown();
        }
    });
    layoutManagerSubredditsRecommended = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
    recyclerSearchSubredditsRecommended.setLayoutManager(layoutManagerSubredditsRecommended);
    recyclerSearchSubredditsRecommended.setAdapter(adapterSearchSubredditsRecommended);
    recyclerSearchSubredditsRecommended.addItemDecoration(new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST));
    pagerSearch.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            controllerSearch.setCurrentPage(position).subscribe(getReloadObserver());
            boolean sortSubredditsShown = controllerSearch.getCurrentPage() == ControllerSearch.PAGE_SUBREDDITS || controllerSearch.getCurrentPage() == ControllerSearch.PAGE_SUBREDDITS_RECOMMENDED;
            menu.findItem(R.id.item_sort_subreddits).setEnabled(sortSubredditsShown);
            menu.findItem(R.id.item_sort_subreddits).setVisible(sortSubredditsShown);
            menu.findItem(R.id.item_sort).setEnabled(!sortSubredditsShown);
            menu.findItem(R.id.item_sort).setVisible(!sortSubredditsShown);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    final int count = controllerLinks.isOnSpecificSubreddit() ? pagerSearch.getChildCount() : pagerSearch.getChildCount() - 1;
    pagerAdapter = new PagerAdapter() {

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            return pagerSearch.getChildAt(position);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
        // No need to destroy the RecyclerViews since they'll be reused for a new query
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch(position) {
                case ControllerSearch.PAGE_SUBREDDITS:
                    return getString(R.string.subreddit);
                case ControllerSearch.PAGE_LINKS:
                    return getString(R.string.all);
                case ControllerSearch.PAGE_LINKS_SUBREDDIT:
                    return controllerLinks.getSubredditName();
                case ControllerSearch.PAGE_SUBREDDITS_RECOMMENDED:
                    return getString(R.string.recommended);
            }
            return super.getPageTitle(position);
        }

        @Override
        public int getCount() {
            return count;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }
    };
    pagerSearch.setAdapter(pagerAdapter);
    layoutTabs.setTabMode(TabLayout.MODE_SCROLLABLE);
    layoutTabs.setTabTextColors(themer.getColorFilterTextMuted().getColor(), themer.getColorFilterPrimary().getColor());
    layoutTabs.setBackgroundColor(getResources().getColor(android.R.color.transparent));
    layoutTabs.setupWithViewPager(pagerSearch);
    pagerSearch.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(layoutTabs));
    return view;
}
Also used : ItemDecorationDivider(com.winsonchiu.reader.utils.ItemDecorationDivider) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) AdapterLink(com.winsonchiu.reader.links.AdapterLink) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Source(com.winsonchiu.reader.comments.Source) PagerAdapter(android.support.v4.view.PagerAdapter) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) TabLayout(android.support.design.widget.TabLayout) AppBarLayout(android.support.design.widget.AppBarLayout) SimpleCallbackBackground(com.winsonchiu.reader.utils.SimpleCallbackBackground) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) ViewGroup(android.view.ViewGroup) ViewPager(android.support.v4.view.ViewPager) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) RecyclerView(android.support.v7.widget.RecyclerView) Subreddit(com.winsonchiu.reader.data.reddit.Subreddit) Likes(com.winsonchiu.reader.data.reddit.Likes) AdapterLink(com.winsonchiu.reader.links.AdapterLink) Link(com.winsonchiu.reader.data.reddit.Link)

Aggregations

PagerAdapter (android.support.v4.view.PagerAdapter)111 View (android.view.View)47 ViewPager (android.support.v4.view.ViewPager)39 TextView (android.widget.TextView)33 HorizontalScrollView (android.widget.HorizontalScrollView)19 ViewGroup (android.view.ViewGroup)18 LinearLayout (android.widget.LinearLayout)13 Toolbar (android.support.v7.widget.Toolbar)11 ImageView (android.widget.ImageView)11 TabLayout (android.support.design.widget.TabLayout)8 RecyclerView (android.support.v7.widget.RecyclerView)8 ArrayList (java.util.ArrayList)8 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)6 AppBarLayout (android.support.design.widget.AppBarLayout)5 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)5 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)5 ImageButton (android.widget.ImageButton)5 LargeTest (android.support.test.filters.LargeTest)4 MediumTest (android.support.test.filters.MediumTest)4 SmallTest (android.support.test.filters.SmallTest)4