Search in sources :

Example 1 with FilterTouchHelperCallback

use of io.plaidapp.ui.recyclerview.FilterTouchHelperCallback in project sbt-android by scala-android.

the class HomeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    ButterKnife.bind(this);
    drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    // toolbar.inflateMenu(R.menu.main);
    setActionBar(toolbar);
    if (savedInstanceState == null) {
        animateToolbar();
    }
    dribbblePrefs = DribbblePrefs.get(this);
    designerNewsPrefs = DesignerNewsPrefs.get(this);
    filtersAdapter = new FilterAdapter(this, SourceManager.getSources(this), new FilterAdapter.FilterAuthoriser() {

        @Override
        public void requestDribbbleAuthorisation(View sharedElemeent, Source forSource) {
            Intent login = new Intent(HomeActivity.this, DribbbleLogin.class);
            login.putExtra(FabDialogMorphSetup.EXTRA_SHARED_ELEMENT_START_COLOR, ContextCompat.getColor(HomeActivity.this, R.color.background_dark));
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(HomeActivity.this, sharedElemeent, getString(R.string.transition_dribbble_login));
            startActivityForResult(login, getAuthSourceRequestCode(forSource), options.toBundle());
        }
    });
    dataManager = new DataManager(this, filtersAdapter) {

        @Override
        public void onDataLoaded(List<? extends PlaidItem> data) {
            adapter.addAndResort(data);
            checkEmptyState();
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    grid.setAdapter(adapter);
    layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            return adapter.getItemColumnSpan(position);
        }
    });
    grid.setLayoutManager(layoutManager);
    grid.addOnScrollListener(gridScroll);
    grid.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {

        @Override
        public void onLoadMore() {
            dataManager.loadAllDataSources();
        }
    });
    grid.setHasFixedSize(true);
    // drawer layout treats fitsSystemWindows specially so we have to handle insets ourselves
    drawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

        @Override
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            // inset the toolbar down by the status bar height
            ViewGroup.MarginLayoutParams lpToolbar = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
            lpToolbar.topMargin += insets.getSystemWindowInsetTop();
            lpToolbar.rightMargin += insets.getSystemWindowInsetRight();
            toolbar.setLayoutParams(lpToolbar);
            // inset the grid top by statusbar+toolbar & the bottom by the navbar (don't clip)
            grid.setPadding(grid.getPaddingLeft(), insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(HomeActivity.this), // landscape
            grid.getPaddingRight() + insets.getSystemWindowInsetRight(), grid.getPaddingBottom());
            // inset the fab for the navbar
            ViewGroup.MarginLayoutParams lpFab = (ViewGroup.MarginLayoutParams) fab.getLayoutParams();
            // portrait
            lpFab.bottomMargin += insets.getSystemWindowInsetBottom();
            // landscape
            lpFab.rightMargin += insets.getSystemWindowInsetRight();
            fab.setLayoutParams(lpFab);
            // we place a background behind the status bar to combine with it's semi-transparent
            // color to get the desired appearance.  Set it's height to the status bar height
            View statusBarBackground = findViewById(R.id.status_bar_background);
            FrameLayout.LayoutParams lpStatus = (FrameLayout.LayoutParams) statusBarBackground.getLayoutParams();
            lpStatus.height = insets.getSystemWindowInsetTop();
            statusBarBackground.setLayoutParams(lpStatus);
            // inset the filters list for the status bar / navbar
            // need to set the padding end for landscape case
            final boolean ltr = filtersList.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
            filtersList.setPaddingRelative(filtersList.getPaddingStart(), filtersList.getPaddingTop() + insets.getSystemWindowInsetTop(), filtersList.getPaddingEnd() + (ltr ? insets.getSystemWindowInsetRight() : 0), filtersList.getPaddingBottom() + insets.getSystemWindowInsetBottom());
            // clear this listener so insets aren't re-applied
            drawer.setOnApplyWindowInsetsListener(null);
            return insets.consumeSystemWindowInsets();
        }
    });
    setupTaskDescription();
    filtersList.setAdapter(filtersAdapter);
    filtersAdapter.addFilterChangedListener(filtersChangedListener);
    filtersAdapter.addFilterChangedListener(dataManager);
    dataManager.loadAllDataSources();
    ItemTouchHelper.Callback callback = new FilterTouchHelperCallback(filtersAdapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(filtersList);
    checkEmptyState();
    checkConnectivity();
}
Also used : FilterTouchHelperCallback(io.plaidapp.ui.recyclerview.FilterTouchHelperCallback) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) DataManager(io.plaidapp.data.DataManager) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ActionMenuView(android.widget.ActionMenuView) Source(io.plaidapp.data.Source) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) WindowInsets(android.view.WindowInsets) GridLayoutManager(android.support.v7.widget.GridLayoutManager) FrameLayout(android.widget.FrameLayout) InfiniteScrollListener(io.plaidapp.ui.recyclerview.InfiniteScrollListener) ActivityOptions(android.app.ActivityOptions)

Example 2 with FilterTouchHelperCallback

use of io.plaidapp.ui.recyclerview.FilterTouchHelperCallback in project plaid by nickbutcher.

the class HomeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    ButterKnife.bind(this);
    drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    setActionBar(toolbar);
    if (savedInstanceState == null) {
        animateToolbar();
    }
    setExitSharedElementCallback(FeedAdapter.createSharedElementReenterCallback(this));
    dribbblePrefs = DribbblePrefs.get(this);
    designerNewsPrefs = DesignerNewsPrefs.get(this);
    filtersAdapter = new FilterAdapter(this, SourceManager.getSources(this), new FilterAdapter.FilterAuthoriser() {

        @Override
        public void requestDribbbleAuthorisation(View sharedElement, Source forSource) {
            Intent login = new Intent(HomeActivity.this, DribbbleLogin.class);
            MorphTransform.addExtras(login, ContextCompat.getColor(HomeActivity.this, R.color.background_dark), sharedElement.getHeight() / 2);
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(HomeActivity.this, sharedElement, getString(R.string.transition_dribbble_login));
            startActivityForResult(login, getAuthSourceRequestCode(forSource), options.toBundle());
        }
    });
    dataManager = new DataManager(this, filtersAdapter) {

        @Override
        public void onDataLoaded(List<? extends PlaidItem> data) {
            adapter.addAndResort(data);
            checkEmptyState();
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    grid.setAdapter(adapter);
    layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            return adapter.getItemColumnSpan(position);
        }
    });
    grid.setLayoutManager(layoutManager);
    grid.addOnScrollListener(toolbarElevation);
    grid.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {

        @Override
        public void onLoadMore() {
            dataManager.loadAllDataSources();
        }
    });
    grid.setHasFixedSize(true);
    grid.addItemDecoration(new GridItemDividerDecoration(adapter.getDividedViewHolderClasses(), this, R.dimen.divider_height, R.color.divider));
    grid.setItemAnimator(new HomeGridItemAnimator());
    // drawer layout treats fitsSystemWindows specially so we have to handle insets ourselves
    drawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

        @Override
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            // inset the toolbar down by the status bar height
            ViewGroup.MarginLayoutParams lpToolbar = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
            lpToolbar.topMargin += insets.getSystemWindowInsetTop();
            lpToolbar.leftMargin += insets.getSystemWindowInsetLeft();
            lpToolbar.rightMargin += insets.getSystemWindowInsetRight();
            toolbar.setLayoutParams(lpToolbar);
            // inset the grid top by statusbar+toolbar & the bottom by the navbar (don't clip)
            grid.setPadding(// landscape
            grid.getPaddingLeft() + insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(HomeActivity.this), // landscape
            grid.getPaddingRight() + insets.getSystemWindowInsetRight(), grid.getPaddingBottom() + insets.getSystemWindowInsetBottom());
            // inset the fab for the navbar
            ViewGroup.MarginLayoutParams lpFab = (ViewGroup.MarginLayoutParams) fab.getLayoutParams();
            // portrait
            lpFab.bottomMargin += insets.getSystemWindowInsetBottom();
            // landscape
            lpFab.rightMargin += insets.getSystemWindowInsetRight();
            fab.setLayoutParams(lpFab);
            View postingStub = findViewById(R.id.stub_posting_progress);
            ViewGroup.MarginLayoutParams lpPosting = (ViewGroup.MarginLayoutParams) postingStub.getLayoutParams();
            // portrait
            lpPosting.bottomMargin += insets.getSystemWindowInsetBottom();
            // landscape
            lpPosting.rightMargin += insets.getSystemWindowInsetRight();
            postingStub.setLayoutParams(lpPosting);
            // we place a background behind the status bar to combine with it's semi-transparent
            // color to get the desired appearance.  Set it's height to the status bar height
            View statusBarBackground = findViewById(R.id.status_bar_background);
            FrameLayout.LayoutParams lpStatus = (FrameLayout.LayoutParams) statusBarBackground.getLayoutParams();
            lpStatus.height = insets.getSystemWindowInsetTop();
            statusBarBackground.setLayoutParams(lpStatus);
            // inset the filters list for the status bar / navbar
            // need to set the padding end for landscape case
            final boolean ltr = filtersList.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
            filtersList.setPaddingRelative(filtersList.getPaddingStart(), filtersList.getPaddingTop() + insets.getSystemWindowInsetTop(), filtersList.getPaddingEnd() + (ltr ? insets.getSystemWindowInsetRight() : 0), filtersList.getPaddingBottom() + insets.getSystemWindowInsetBottom());
            // clear this listener so insets aren't re-applied
            drawer.setOnApplyWindowInsetsListener(null);
            return insets.consumeSystemWindowInsets();
        }
    });
    setupTaskDescription();
    filtersList.setAdapter(filtersAdapter);
    filtersList.setItemAnimator(new FilterAdapter.FilterAnimator());
    filtersAdapter.registerFilterChangedCallback(filtersChangedCallbacks);
    dataManager.loadAllDataSources();
    ItemTouchHelper.Callback callback = new FilterTouchHelperCallback(filtersAdapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(filtersList);
    checkEmptyState();
}
Also used : FilterTouchHelperCallback(io.plaidapp.ui.recyclerview.FilterTouchHelperCallback) Source(io.plaidapp.data.Source) GridItemDividerDecoration(io.plaidapp.ui.recyclerview.GridItemDividerDecoration) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) WindowInsets(android.view.WindowInsets) ActivityOptions(android.app.ActivityOptions) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) DataManager(io.plaidapp.data.DataManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) GridLayoutManager(android.support.v7.widget.GridLayoutManager) FrameLayout(android.widget.FrameLayout) InfiniteScrollListener(io.plaidapp.ui.recyclerview.InfiniteScrollListener)

Aggregations

ActivityOptions (android.app.ActivityOptions)2 Intent (android.content.Intent)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 WindowInsets (android.view.WindowInsets)2 FrameLayout (android.widget.FrameLayout)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 DataManager (io.plaidapp.data.DataManager)2 Source (io.plaidapp.data.Source)2 FilterTouchHelperCallback (io.plaidapp.ui.recyclerview.FilterTouchHelperCallback)2 InfiniteScrollListener (io.plaidapp.ui.recyclerview.InfiniteScrollListener)2 ActionMenuView (android.widget.ActionMenuView)1 BindView (butterknife.BindView)1 GridItemDividerDecoration (io.plaidapp.ui.recyclerview.GridItemDividerDecoration)1