Search in sources :

Example 1 with ItemPagerAdapter

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

the class ItemActivity method bindData.

@SuppressWarnings("ConstantConditions")
private void bindData(@Nullable final WebItem story) {
    if (story == null) {
        return;
    }
    mCustomTabsDelegate.mayLaunchUrl(Uri.parse(story.getUrl()), null, null);
    bindFavorite();
    mSessionManager.view(this, story.getId());
    mVoteButton.setVisibility(View.VISIBLE);
    mVoteButton.setOnClickListener(v -> vote(story));
    final TextView titleTextView = (TextView) findViewById(android.R.id.text2);
    if (story.isStoryType()) {
        titleTextView.setText(story.getDisplayedTitle());
        setTaskTitle(story.getDisplayedTitle());
        if (!TextUtils.isEmpty(story.getSource())) {
            TextView sourceTextView = (TextView) findViewById(R.id.source);
            sourceTextView.setText(story.getSource());
            sourceTextView.setVisibility(View.VISIBLE);
        }
    } else {
        AppUtils.setTextAppearance(titleTextView, R.style.TextAppearance_App_Small);
        titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(AppUtils.getThemedResId(this, R.attr.contentTextSize)));
        CharSequence title = AppUtils.fromHtml(story.getDisplayedTitle(), true);
        titleTextView.setText(title);
        setTaskTitle(title);
    }
    final TextView postedTextView = (TextView) findViewById(R.id.posted);
    postedTextView.setText(story.getDisplayedTime(this));
    postedTextView.append(story.getDisplayedAuthor(this, true, 0));
    postedTextView.setMovementMethod(LinkMovementMethod.getInstance());
    switch(story.getType()) {
        case Item.JOB_TYPE:
            postedTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_work_white_18dp, 0, 0, 0);
            break;
        case Item.POLL_TYPE:
            postedTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_poll_white_18dp, 0, 0, 0);
            break;
    }
    mAdapter = new ItemPagerAdapter(this, getSupportFragmentManager(), new ItemPagerAdapter.Builder().setItem(story).setShowArticle(!mExternalBrowser).setCacheMode(getIntent().getIntExtra(EXTRA_CACHE_MODE, ItemManager.MODE_DEFAULT)).setRetainInstance(true).setDefaultViewMode(mStoryViewMode));
    mAdapter.bind(mViewPager, mTabLayout, mNavButton, mReplyButton);
    mTabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager) {

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            mAppBar.setExpanded(true, true);
        }
    });
    if (story.isStoryType() && mExternalBrowser) {
        TextView buttonArticle = (TextView) findViewById(R.id.button_article);
        buttonArticle.setTransformationMethod(new AllCapsTransformationMethod(this));
        buttonArticle.setVisibility(View.VISIBLE);
        buttonArticle.setOnClickListener(v -> AppUtils.openWebUrlExternal(ItemActivity.this, story, story.getUrl(), mCustomTabsDelegate.getSession()));
    }
    if (mFullscreen) {
        setFullscreen();
    }
}
Also used : TabLayout(android.support.design.widget.TabLayout) TextView(android.widget.TextView) ItemPagerAdapter(io.github.hidroh.materialistic.widget.ItemPagerAdapter) AllCapsTransformationMethod(android.support.v7.text.AllCapsTransformationMethod)

Example 2 with ItemPagerAdapter

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

the class BaseListActivity method bindViewPager.

private void bindViewPager() {
    if (mAdapter != null) {
        mAdapter.unbind(mTabLayout);
    }
    mAdapter = new ItemPagerAdapter(this, getSupportFragmentManager(), new ItemPagerAdapter.Builder().setItem(mSelectedItem).setCacheMode(getItemCacheMode()).setShowArticle(true).setDefaultViewMode(mStoryViewMode));
    mAdapter.bind(mViewPager, mTabLayout, mNavButton, mReplyButton);
    if (mFullscreen) {
        setFullscreen();
    }
}
Also used : ItemPagerAdapter(io.github.hidroh.materialistic.widget.ItemPagerAdapter)

Example 3 with ItemPagerAdapter

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

the class BaseListActivity method onCreate.

@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    setTitle(getDefaultTitle());
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
    findViewById(R.id.toolbar).setOnClickListener(v -> {
        Scrollable scrollable = getScrollableList();
        if (scrollable != null) {
            scrollable.scrollToTop();
        }
    });
    mAppBar = (AppBarLayout) findViewById(R.id.appbar);
    mIsMultiPane = getResources().getBoolean(R.bool.multi_pane);
    if (mIsMultiPane) {
        LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter(WebFragment.ACTION_FULLSCREEN));
        mListView = findViewById(android.R.id.list);
        mTabLayout = (TabLayout) findViewById(R.id.tab_layout);
        mTabLayout.setVisibility(View.GONE);
        mViewPager = (ViewPager) findViewById(R.id.content);
        mViewPager.setVisibility(View.GONE);
        mReplyButton = (FloatingActionButton) findViewById(R.id.reply_button);
        mNavButton = (NavFloatingActionButton) findViewById(R.id.navigation_button);
        mNavButton.setNavigable(direction -> ((Navigable) ((ItemPagerAdapter) mViewPager.getAdapter()).getItem(0)).onNavigate(direction));
        AppUtils.toggleFab(mNavButton, false);
        AppUtils.toggleFab(mReplyButton, false);
    }
    mMultiWindowEnabled = Preferences.multiWindowEnabled(this);
    mStoryViewMode = Preferences.getDefaultStoryView(this);
    mExternalBrowser = Preferences.externalBrowserEnabled(this);
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().replace(android.R.id.list, instantiateListFragment(), LIST_FRAGMENT_TAG).commit();
    } else {
        mSelectedItem = savedInstanceState.getParcelable(STATE_SELECTED_ITEM);
        mFullscreen = savedInstanceState.getBoolean(STATE_FULLSCREEN);
        if (mIsMultiPane) {
            openMultiPaneItem();
        } else {
            unbindViewPager();
        }
    }
    mPreferenceObservable.subscribe(this, this::onPreferenceChanged, R.string.pref_navigation, R.string.pref_external, R.string.pref_story_display, R.string.pref_multi_window);
}
Also used : IntentFilter(android.content.IntentFilter) ItemPagerAdapter(io.github.hidroh.materialistic.widget.ItemPagerAdapter)

Aggregations

ItemPagerAdapter (io.github.hidroh.materialistic.widget.ItemPagerAdapter)3 IntentFilter (android.content.IntentFilter)1 TabLayout (android.support.design.widget.TabLayout)1 AllCapsTransformationMethod (android.support.v7.text.AllCapsTransformationMethod)1 TextView (android.widget.TextView)1