Search in sources :

Example 1 with RefreshListener

use of org.wordpress.android.util.helpers.SwipeToRefreshHelper.RefreshListener 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 2 with RefreshListener

use of org.wordpress.android.util.helpers.SwipeToRefreshHelper.RefreshListener 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)

Example 3 with RefreshListener

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

the class ThemeBrowserFragment method configureSwipeToRefresh.

protected void configureSwipeToRefresh(View view) {
    mSwipeToRefreshHelper = new SwipeToRefreshHelper(mThemeBrowserActivity, (CustomSwipeRefreshLayout) view.findViewById(R.id.ptr_layout), new RefreshListener() {

        @Override
        public void onRefreshStarted() {
            if (!isAdded()) {
                return;
            }
            if (!NetworkUtils.checkConnection(mThemeBrowserActivity)) {
                mSwipeToRefreshHelper.setRefreshing(false);
                mEmptyTextView.setText(R.string.no_network_title);
                return;
            }
            mThemeBrowserActivity.fetchThemes();
        }
    });
    mSwipeToRefreshHelper.setRefreshing(mShouldRefreshOnStart);
}
Also used : RefreshListener(org.wordpress.android.util.helpers.SwipeToRefreshHelper.RefreshListener) SwipeToRefreshHelper(org.wordpress.android.util.helpers.SwipeToRefreshHelper) CustomSwipeRefreshLayout(org.wordpress.android.util.widgets.CustomSwipeRefreshLayout)

Example 4 with RefreshListener

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

the class StatsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((WordPress) getApplication()).component().inject(this);
    if (WordPress.wpDB == null) {
        Toast.makeText(this, R.string.fatal_db_error, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    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.stats_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setElevation(0);
        actionBar.setTitle(R.string.stats);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    mSwipeToRefreshHelper = new SwipeToRefreshHelper(this, (CustomSwipeRefreshLayout) findViewById(R.id.ptr_layout), new RefreshListener() {

        @Override
        public void onRefreshStarted() {
            if (!NetworkUtils.checkConnection(getBaseContext())) {
                mSwipeToRefreshHelper.setRefreshing(false);
                return;
            }
            refreshStatsFromCurrentDate();
        }
    });
    setTitle(R.string.stats);
    mOuterScrollView = (NestedScrollViewExt) findViewById(R.id.scroll_view_stats);
    mOuterScrollView.setScrollViewListener(this);
    if (savedInstanceState != null) {
        mResultCode = savedInstanceState.getInt(SAVED_WP_LOGIN_STATE);
        mCurrentTimeframe = (StatsTimeframe) savedInstanceState.getSerializable(SAVED_STATS_TIMEFRAME);
        mRequestedDate = savedInstanceState.getString(SAVED_STATS_REQUESTED_DATE);
        mThereWasAnErrorLoadingStats = savedInstanceState.getBoolean(SAVED_THERE_WAS_AN_ERROR_LOADING_STATS);
        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);
        }
    } else if (getIntent() != null) {
        if (getIntent().hasExtra(SAVED_STATS_TIMEFRAME)) {
            mCurrentTimeframe = (StatsTimeframe) getIntent().getSerializableExtra(SAVED_STATS_TIMEFRAME);
        } else if (getIntent().hasExtra(ARG_DESIRED_TIMEFRAME)) {
            mCurrentTimeframe = (StatsTimeframe) getIntent().getSerializableExtra(ARG_DESIRED_TIMEFRAME);
        } else {
            // Read the value from app preferences here. Default to 0 - Insights
            mCurrentTimeframe = AppPrefs.getStatsTimeframe();
        }
        mRequestedDate = StatsUtils.getCurrentDateTZ(mSite);
        if (getIntent().hasExtra(ARG_LAUNCHED_FROM)) {
            StatsLaunchedFrom from = (StatsLaunchedFrom) getIntent().getSerializableExtra(ARG_LAUNCHED_FROM);
            if (from == StatsLaunchedFrom.STATS_WIDGET) {
                AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.STATS_WIDGET_TAPPED, mSite);
            }
        }
    }
    if (!mAccountStore.hasAccessToken()) {
        // If the user is not connected to WordPress.com, ask him to connect first.
        startWPComLoginActivity();
        return;
    }
    checkIfSiteHasAccessibleStats(mSite);
    // create the fragments without forcing the re-creation. If the activity is restarted fragments can already
    // be there, and ready to be displayed without making any network connections. A fragment calls the stats service
    // if its internal datamodel is empty.
    createFragments(false);
    if (mSpinner == null) {
        mSpinner = (Spinner) findViewById(R.id.filter_spinner);
        mTimeframeSpinnerAdapter = new TimeframeSpinnerAdapter(this, timeframes);
        mSpinner.setAdapter(mTimeframeSpinnerAdapter);
        mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (isFinishing()) {
                    return;
                }
                final StatsTimeframe selectedTimeframe = (StatsTimeframe) mTimeframeSpinnerAdapter.getItem(position);
                if (mCurrentTimeframe == selectedTimeframe) {
                    AppLog.d(T.STATS, "The selected TIME FRAME is already active: " + selectedTimeframe.getLabel());
                    return;
                }
                AppLog.d(T.STATS, "NEW TIME FRAME : " + selectedTimeframe.getLabel());
                mCurrentTimeframe = selectedTimeframe;
                AppPrefs.setStatsTimeframe(mCurrentTimeframe);
                mRequestedDate = StatsUtils.getCurrentDateTZ(mSite);
                // Need to recreate fragment here, since a new timeline was selected.
                createFragments(true);
                mSpinner.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        if (!isFinishing()) {
                            scrollToTop();
                        }
                    }
                }, StatsConstants.STATS_SCROLL_TO_DELAY);
                trackStatsAnalytics();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            // nop
            }
        });
        Toolbar spinnerToolbar = (Toolbar) findViewById(R.id.toolbar_filter);
        spinnerToolbar.setBackgroundColor(getResources().getColor(R.color.blue_medium));
    }
    selectCurrentTimeframeInActionBar();
    TextView otherRecentStatsMovedLabel = (TextView) findViewById(R.id.stats_other_recent_stats_moved);
    otherRecentStatsMovedLabel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            for (int i = 0; i < timeframes.length; i++) {
                if (timeframes[i] == StatsTimeframe.INSIGHTS) {
                    mSpinner.setSelection(i);
                    break;
                }
            }
            mSpinner.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (!isFinishing()) {
                        scrollToTop();
                    }
                }
            }, StatsConstants.STATS_SCROLL_TO_DELAY);
        }
    });
    // Track usage here
    if (savedInstanceState == null) {
        AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.STATS_ACCESSED, mSite);
        trackStatsAnalytics();
    }
}
Also used : SwipeToRefreshHelper(org.wordpress.android.util.helpers.SwipeToRefreshHelper) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) CustomSwipeRefreshLayout(org.wordpress.android.util.widgets.CustomSwipeRefreshLayout) RefreshListener(org.wordpress.android.util.helpers.SwipeToRefreshHelper.RefreshListener) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 5 with RefreshListener

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

the class MediaGridFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    mFiltersText = new String[Filter.values().length];
    View view = inflater.inflate(R.layout.media_grid_fragment, container);
    mRecycler = (RecyclerView) view.findViewById(R.id.recycler);
    mRecycler.setHasFixedSize(true);
    int numColumns = MediaGridAdapter.getColumnCount(getActivity());
    mGridManager = new GridLayoutManager(getActivity(), numColumns);
    mRecycler.setLayoutManager(mGridManager);
    mGridAdapter = new MediaGridAdapter(getActivity(), mSite, mImageLoader);
    mGridAdapter.setCallback(this);
    mGridAdapter.setAllowMultiselect(true);
    mRecycler.setAdapter(mGridAdapter);
    mEmptyView = (LinearLayout) view.findViewById(R.id.empty_view);
    mEmptyViewTitle = (TextView) view.findViewById(R.id.empty_view_title);
    mResultView = (TextView) view.findViewById(R.id.media_filter_result_text);
    mSpinner = (AppCompatSpinner) view.findViewById(R.id.media_filter_spinner);
    mSpinner.setOnItemSelectedListener(mFilterSelectedListener);
    // swipe to refresh setup
    mSwipeToRefreshHelper = new SwipeToRefreshHelper(getActivity(), (CustomSwipeRefreshLayout) view.findViewById(R.id.ptr_layout), new RefreshListener() {

        @Override
        public void onRefreshStarted() {
            if (!isAdded()) {
                return;
            }
            if (!NetworkUtils.checkConnection(getActivity())) {
                updateEmptyView(EmptyViewMessageType.NETWORK_ERROR);
                mSwipeToRefreshHelper.setRefreshing(false);
                return;
            }
            fetchMediaList(false);
        }
    });
    restoreState(savedInstanceState);
    setupSpinnerAdapter();
    return view;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) RefreshListener(org.wordpress.android.util.helpers.SwipeToRefreshHelper.RefreshListener) SwipeToRefreshHelper(org.wordpress.android.util.helpers.SwipeToRefreshHelper) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) CustomSwipeRefreshLayout(org.wordpress.android.util.widgets.CustomSwipeRefreshLayout)

Aggregations

SwipeToRefreshHelper (org.wordpress.android.util.helpers.SwipeToRefreshHelper)5 RefreshListener (org.wordpress.android.util.helpers.SwipeToRefreshHelper.RefreshListener)5 CustomSwipeRefreshLayout (org.wordpress.android.util.widgets.CustomSwipeRefreshLayout)5 ActionBar (android.support.v7.app.ActionBar)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 TextView (android.widget.TextView)2 Bundle (android.os.Bundle)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 ScrollView (android.widget.ScrollView)1 PostModel (org.wordpress.android.fluxc.model.PostModel)1 ListScrollPositionManager (org.wordpress.android.util.helpers.ListScrollPositionManager)1