Search in sources :

Example 1 with SwipeToRefreshHelper

use of org.wordpress.android.util.helpers.SwipeToRefreshHelper in project WordPress-Android by wordpress-mobile.

the class StatsSingleItemDetailsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.stats_activity_single_post_details);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    // pull to refresh setup
    mSwipeToRefreshHelper = new SwipeToRefreshHelper(this, (CustomSwipeRefreshLayout) findViewById(R.id.ptr_layout), new SwipeToRefreshHelper.RefreshListener() {

        @Override
        public void onRefreshStarted() {
            if (!NetworkUtils.checkConnection(getBaseContext())) {
                mSwipeToRefreshHelper.setRefreshing(false);
                return;
            }
            refreshStats();
        }
    });
    TextView mStatsForLabel = (TextView) findViewById(R.id.stats_summary_title);
    mGraphContainer = (LinearLayout) findViewById(R.id.stats_bar_chart_fragment_container);
    mStatsViewsLabel = (TextView) findViewById(R.id.stats_views_label);
    mStatsViewsTotals = (TextView) findViewById(R.id.stats_views_totals);
    mMonthsAndYearsModule = (LinearLayout) findViewById(R.id.stats_months_years_module);
    mMonthsAndYearsHeader = (RelativeLayout) findViewById(R.id.stats_months_years_header);
    mMonthsAndYearsList = (LinearLayout) findViewById(R.id.stats_months_years_list_linearlayout);
    mMonthsAndYearsEmptyPlaceholder = (LinearLayout) findViewById(R.id.stats_months_years_empty_module_placeholder);
    mAveragesModule = (LinearLayout) findViewById(R.id.stats_averages_module);
    mAveragesHeader = (RelativeLayout) findViewById(R.id.stats_averages_list_header);
    mAveragesList = (LinearLayout) findViewById(R.id.stats_averages_list_linearlayout);
    mAveragesEmptyPlaceholder = (LinearLayout) findViewById(R.id.stats_averages_empty_module_placeholder);
    mRecentWeeksModule = (LinearLayout) findViewById(R.id.stats_recent_weeks_module);
    mRecentWeeksHeader = (RelativeLayout) findViewById(R.id.stats_recent_weeks_list_header);
    mRecentWeeksList = (LinearLayout) findViewById(R.id.stats_recent_weeks_list_linearlayout);
    mRecentWeeksEmptyPlaceholder = (LinearLayout) findViewById(R.id.stats_recent_weeks_empty_module_placeholder);
    mYearsIdToExpandedMap = new SparseBooleanArray();
    mAveragesIdToExpandedMap = new SparseBooleanArray();
    mRecentWeeksIdToExpandedMap = new SparseBooleanArray();
    setTitle(R.string.stats);
    mOuterScrollView = (ScrollViewExt) findViewById(R.id.scroll_view_stats);
    if (savedInstanceState != null) {
        mRemoteItemID = savedInstanceState.getString(ARG_REMOTE_ITEM_ID);
        mRemoteBlogID = savedInstanceState.getLong(ARG_REMOTE_BLOG_ID, 0);
        mRemoteItemType = savedInstanceState.getString(ARG_REMOTE_ITEM_TYPE);
        mItemTitle = savedInstanceState.getString(ARG_ITEM_TITLE);
        mItemURL = savedInstanceState.getString(ARG_ITEM_URL);
        mRestResponseParsed = (PostViewsModel) savedInstanceState.getSerializable(ARG_REST_RESPONSE);
        mSelectedBarGraphIndex = savedInstanceState.getInt(ARG_SELECTED_GRAPH_BAR, -1);
        mPrevNumberOfBarsGraph = savedInstanceState.getInt(ARG_PREV_NUMBER_OF_BARS, -1);
        final int yScrollPosition = savedInstanceState.getInt(SAVED_STATS_SCROLL_POSITION);
        if (yScrollPosition != 0) {
            mOuterScrollView.postDelayed(new Runnable() {

                public void run() {
                    if (!isFinishing()) {
                        mOuterScrollView.scrollTo(0, yScrollPosition);
                    }
                }
            }, StatsConstants.STATS_SCROLL_TO_DELAY);
        }
        if (savedInstanceState.containsKey(ARG_AVERAGES_EXPANDED_ROWS)) {
            mAveragesIdToExpandedMap = savedInstanceState.getParcelable(ARG_AVERAGES_EXPANDED_ROWS);
        }
        if (savedInstanceState.containsKey(ARG_RECENT_EXPANDED_ROWS)) {
            mRecentWeeksIdToExpandedMap = savedInstanceState.getParcelable(ARG_RECENT_EXPANDED_ROWS);
        }
        if (savedInstanceState.containsKey(ARG_YEARS_EXPANDED_ROWS)) {
            mYearsIdToExpandedMap = savedInstanceState.getParcelable(ARG_YEARS_EXPANDED_ROWS);
        }
    } else if (getIntent() != null && getIntent().getExtras() != null) {
        Bundle extras = getIntent().getExtras();
        mRemoteItemID = extras.getString(ARG_REMOTE_ITEM_ID);
        mRemoteBlogID = extras.getLong(ARG_REMOTE_BLOG_ID, 0);
        mRemoteItemType = extras.getString(ARG_REMOTE_ITEM_TYPE);
        mItemTitle = extras.getString(ARG_ITEM_TITLE);
        mItemURL = extras.getString(ARG_ITEM_URL);
        mRestResponseParsed = (PostViewsModel) extras.getSerializable(ARG_REST_RESPONSE);
        mSelectedBarGraphIndex = extras.getInt(ARG_SELECTED_GRAPH_BAR, -1);
    }
    if (mRemoteBlogID == 0 || mRemoteItemID == null) {
        Toast.makeText(this, R.string.stats_generic_error, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    if (savedInstanceState == null) {
        AnalyticsUtils.trackWithSiteId(AnalyticsTracker.Stat.STATS_SINGLE_POST_ACCESSED, mRemoteBlogID);
    }
    // Setup the main top label that opens the post in the Reader where possible
    if (mItemTitle != null || mItemURL != null) {
        mStatsForLabel.setVisibility(View.VISIBLE);
        mStatsForLabel.setText(mItemTitle != null ? mItemTitle : mItemURL);
        // make the label clickable if the URL is available
        if (mItemURL != null) {
            mStatsForLabel.setTextColor(getResources().getColor(R.color.stats_link_text_color));
            mStatsForLabel.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    final Context ctx = v.getContext();
                    StatsUtils.openPostInReaderOrInAppWebview(ctx, mRemoteBlogID, mRemoteItemID, mRemoteItemType, mItemURL);
                }
            });
        } else {
            mStatsForLabel.setTextColor(getResources().getColor(R.color.grey_darken_20));
        }
    } else {
        mStatsForLabel.setVisibility(View.GONE);
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) SwipeToRefreshHelper(org.wordpress.android.util.helpers.SwipeToRefreshHelper) View(android.view.View) GraphView(com.jjoe64.graphview.GraphView) TextView(android.widget.TextView) PostViewsModel(org.wordpress.android.ui.stats.models.PostViewsModel) CustomSwipeRefreshLayout(org.wordpress.android.util.widgets.CustomSwipeRefreshLayout) SparseBooleanArray(android.util.SparseBooleanArray) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar)

Example 2 with SwipeToRefreshHelper

use of org.wordpress.android.util.helpers.SwipeToRefreshHelper in project WordPress-Android by wordpress-mobile.

the class FilteredRecyclerView method init.

private void init() {
    inflate(getContext(), R.layout.filtered_list_component, this);
    int spacingHorizontal = 0;
    int spacingVertical = DisplayUtils.dpToPx(getContext(), 1);
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mRecyclerView.addItemDecoration(new RecyclerItemDecoration(spacingHorizontal, spacingVertical));
    mToolbar = (Toolbar) findViewById(R.id.toolbar_with_spinner);
    mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);
    mEmptyView = (TextView) findViewById(R.id.empty_view);
    // progress bar that appears when loading more items
    mProgressLoadMore = (ProgressBar) findViewById(R.id.progress_loading);
    mProgressLoadMore.setVisibility(View.GONE);
    mSwipeToRefreshHelper = new SwipeToRefreshHelper(getContext(), (CustomSwipeRefreshLayout) findViewById(R.id.ptr_layout), new SwipeToRefreshHelper.RefreshListener() {

        @Override
        public void onRefreshStarted() {
            post(new Runnable() {

                @Override
                public void run() {
                    if (!NetworkUtils.checkConnection(getContext())) {
                        mSwipeToRefreshHelper.setRefreshing(false);
                        updateEmptyView(EmptyViewMessageType.NETWORK_ERROR);
                        return;
                    }
                    if (mFilterListener != null) {
                        mFilterListener.onLoadData();
                    }
                }
            });
        }
    });
    if (mSpinner == null) {
        mSpinner = (Spinner) findViewById(R.id.filter_spinner);
    }
}
Also used : RecyclerItemDecoration(org.wordpress.android.widgets.RecyclerItemDecoration) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeToRefreshHelper(org.wordpress.android.util.helpers.SwipeToRefreshHelper) CustomSwipeRefreshLayout(org.wordpress.android.util.widgets.CustomSwipeRefreshLayout)

Example 3 with SwipeToRefreshHelper

use of org.wordpress.android.util.helpers.SwipeToRefreshHelper in project WordPress-Android by wordpress-mobile.

the class SelectCategoriesActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((WordPress) getApplication()).component().inject(this);
    mDispatcher.register(this);
    if (savedInstanceState == null) {
        mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE);
    } else {
        mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
    }
    if (mSite == null) {
        ToastUtils.showToast(this, R.string.blog_not_found, ToastUtils.Duration.SHORT);
        finish();
        return;
    }
    setContentView(R.layout.select_categories);
    setTitle(getResources().getString(R.string.select_categories));
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    mListView = (ListView) findViewById(android.R.id.list);
    mListScrollPositionManager = new ListScrollPositionManager(mListView, false);
    mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    mListView.setItemsCanFocus(false);
    mEmptyView = (TextView) findViewById(R.id.empty_view);
    mListView.setEmptyView(mEmptyView);
    mSelectedCategories = new HashSet<>();
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        if (extras.containsKey(KEY_POST)) {
            PostModel post = (PostModel) extras.getSerializable(KEY_POST);
            if (post != null) {
                for (Long categoryId : post.getCategoryIdList()) {
                    mSelectedCategories.add(categoryId);
                }
            }
        }
    }
    // swipe to refresh setup
    mSwipeToRefreshHelper = new SwipeToRefreshHelper(this, (CustomSwipeRefreshLayout) findViewById(R.id.ptr_layout), new RefreshListener() {

        @Override
        public void onRefreshStarted() {
            if (!NetworkUtils.checkConnection(getBaseContext())) {
                mSwipeToRefreshHelper.setRefreshing(false);
                return;
            }
            refreshCategories();
        }
    });
    populateCategoryList();
    if (NetworkUtils.isNetworkAvailable(this)) {
        mEmptyView.setText(R.string.empty_list_default);
        if (isCategoryListEmpty()) {
            refreshCategories();
        }
    } else {
        mEmptyView.setText(R.string.no_network_title);
    }
}
Also used : Bundle(android.os.Bundle) ListScrollPositionManager(org.wordpress.android.util.helpers.ListScrollPositionManager) RefreshListener(org.wordpress.android.util.helpers.SwipeToRefreshHelper.RefreshListener) SwipeToRefreshHelper(org.wordpress.android.util.helpers.SwipeToRefreshHelper) PostModel(org.wordpress.android.fluxc.model.PostModel) ActionBar(android.support.v7.app.ActionBar) CustomSwipeRefreshLayout(org.wordpress.android.util.widgets.CustomSwipeRefreshLayout)

Example 4 with SwipeToRefreshHelper

use of org.wordpress.android.util.helpers.SwipeToRefreshHelper in project WordPress-Android by wordpress-mobile.

the class ReaderPostDetailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.reader_fragment_post_detail, container, false);
    CustomSwipeRefreshLayout swipeRefreshLayout = (CustomSwipeRefreshLayout) view.findViewById(R.id.swipe_to_refresh);
    //this fragment hides/shows toolbar with scrolling, which messes up ptr animation position
    //so we have to set it manually
    int swipeToRefreshOffset = getResources().getDimensionPixelSize(R.dimen.toolbar_content_offset);
    swipeRefreshLayout.setProgressViewOffset(false, 0, swipeToRefreshOffset);
    mSwipeToRefreshHelper = new SwipeToRefreshHelper(getActivity(), swipeRefreshLayout, new SwipeToRefreshHelper.RefreshListener() {

        @Override
        public void onRefreshStarted() {
            if (!isAdded()) {
                return;
            }
            updatePost();
        }
    });
    mScrollView = (WPScrollView) view.findViewById(R.id.scroll_view_reader);
    mScrollView.setScrollDirectionListener(this);
    mLayoutFooter = (ViewGroup) view.findViewById(R.id.layout_post_detail_footer);
    mLikingUsersView = (ReaderLikingUsersView) view.findViewById(R.id.layout_liking_users_view);
    mLikingUsersDivider = view.findViewById(R.id.layout_liking_users_divider);
    mLikingUsersLabel = view.findViewById(R.id.text_liking_users_label);
    // setup the ReaderWebView
    mReaderWebView = (ReaderWebView) view.findViewById(R.id.reader_webview);
    mReaderWebView.setCustomViewListener(this);
    mReaderWebView.setUrlClickListener(this);
    mReaderWebView.setPageFinishedListener(this);
    // hide footer and scrollView until the post is loaded
    mLayoutFooter.setVisibility(View.INVISIBLE);
    mScrollView.setVisibility(View.INVISIBLE);
    View relatedPostsContainer = view.findViewById(R.id.container_related_posts);
    mGlobalRelatedPostsView = (ReaderSimplePostContainerView) relatedPostsContainer.findViewById(R.id.related_posts_view_global);
    mLocalRelatedPostsView = (ReaderSimplePostContainerView) relatedPostsContainer.findViewById(R.id.related_posts_view_local);
    mSignInButton = (WPTextView) view.findViewById(R.id.nux_sign_in_button);
    mSignInButton.setOnClickListener(mSignInClickListener);
    final ProgressBar progress = (ProgressBar) view.findViewById(R.id.progress_loading);
    if (mPostSlugsResolutionUnderway) {
        progress.setVisibility(View.VISIBLE);
    }
    showPost();
    return view;
}
Also used : SwipeToRefreshHelper(org.wordpress.android.util.helpers.SwipeToRefreshHelper) ReaderSimplePostContainerView(org.wordpress.android.ui.reader.views.ReaderSimplePostContainerView) ReaderSimplePostView(org.wordpress.android.ui.reader.views.ReaderSimplePostView) ReaderWebView(org.wordpress.android.ui.reader.views.ReaderWebView) View(android.view.View) WebView(android.webkit.WebView) WPScrollView(org.wordpress.android.widgets.WPScrollView) ReaderPostDetailHeaderView(org.wordpress.android.ui.reader.views.ReaderPostDetailHeaderView) TextView(android.widget.TextView) WPTextView(org.wordpress.android.widgets.WPTextView) ReaderIconCountView(org.wordpress.android.ui.reader.views.ReaderIconCountView) ReaderLikingUsersView(org.wordpress.android.ui.reader.views.ReaderLikingUsersView) ProgressBar(android.widget.ProgressBar) CustomSwipeRefreshLayout(org.wordpress.android.util.widgets.CustomSwipeRefreshLayout)

Example 5 with SwipeToRefreshHelper

use of org.wordpress.android.util.helpers.SwipeToRefreshHelper in project WordPress-Android by wordpress-mobile.

the class PostsListFragment method initSwipeToRefreshHelper.

private void initSwipeToRefreshHelper() {
    mSwipeToRefreshHelper = new SwipeToRefreshHelper(getActivity(), (CustomSwipeRefreshLayout) getView().findViewById(R.id.ptr_layout), new RefreshListener() {

        @Override
        public void onRefreshStarted() {
            if (!isAdded()) {
                return;
            }
            if (!NetworkUtils.checkConnection(getActivity())) {
                setRefreshing(false);
                updateEmptyView(EmptyViewMessageType.NETWORK_ERROR);
                return;
            }
            requestPosts(false);
        }
    });
}
Also used : RefreshListener(org.wordpress.android.util.helpers.SwipeToRefreshHelper.RefreshListener) SwipeToRefreshHelper(org.wordpress.android.util.helpers.SwipeToRefreshHelper) CustomSwipeRefreshLayout(org.wordpress.android.util.widgets.CustomSwipeRefreshLayout)

Aggregations

SwipeToRefreshHelper (org.wordpress.android.util.helpers.SwipeToRefreshHelper)10 CustomSwipeRefreshLayout (org.wordpress.android.util.widgets.CustomSwipeRefreshLayout)10 TextView (android.widget.TextView)6 ActionBar (android.support.v7.app.ActionBar)5 View (android.view.View)5 RefreshListener (org.wordpress.android.util.helpers.SwipeToRefreshHelper.RefreshListener)5 Bundle (android.os.Bundle)3 Toolbar (android.support.v7.widget.Toolbar)2 AdapterView (android.widget.AdapterView)2 RecyclerItemDecoration (org.wordpress.android.widgets.RecyclerItemDecoration)2 FragmentManager (android.app.FragmentManager)1 FragmentTransaction (android.app.FragmentTransaction)1 Context (android.content.Context)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SparseBooleanArray (android.util.SparseBooleanArray)1 WebView (android.webkit.WebView)1 ProgressBar (android.widget.ProgressBar)1 ScrollView (android.widget.ScrollView)1