Search in sources :

Example 1 with ListScrollPositionManager

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

Aggregations

Bundle (android.os.Bundle)1 ActionBar (android.support.v7.app.ActionBar)1 PostModel (org.wordpress.android.fluxc.model.PostModel)1 ListScrollPositionManager (org.wordpress.android.util.helpers.ListScrollPositionManager)1 SwipeToRefreshHelper (org.wordpress.android.util.helpers.SwipeToRefreshHelper)1 RefreshListener (org.wordpress.android.util.helpers.SwipeToRefreshHelper.RefreshListener)1 CustomSwipeRefreshLayout (org.wordpress.android.util.widgets.CustomSwipeRefreshLayout)1