Search in sources :

Example 1 with SearchDataManager

use of io.plaidapp.data.SearchDataManager in project plaid by nickbutcher.

the class SearchActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);
    setupSearchView();
    dataManager = new SearchDataManager(this) {

        @Override
        public void onDataLoaded(List<? extends PlaidItem> data) {
            if (data != null && data.size() > 0) {
                if (results.getVisibility() != View.VISIBLE) {
                    TransitionManager.beginDelayedTransition(container, getTransition(R.transition.search_show_results));
                    progress.setVisibility(View.GONE);
                    results.setVisibility(View.VISIBLE);
                    fab.setVisibility(View.VISIBLE);
                }
                adapter.addAndResort(data);
            } else {
                TransitionManager.beginDelayedTransition(container, getTransition(R.transition.auto));
                progress.setVisibility(View.GONE);
                setNoResultsVisibility(View.VISIBLE);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    setExitSharedElementCallback(FeedAdapter.createSharedElementReenterCallback(this));
    results.setAdapter(adapter);
    results.setItemAnimator(new SlideInItemAnimator());
    GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

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

        @Override
        public void onLoadMore() {
            dataManager.loadMore();
        }
    });
    results.setHasFixedSize(true);
    setupTransitions();
    onNewIntent(getIntent());
    ShortcutHelper.reportSearchUsed(this);
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) SlideInItemAnimator(io.plaidapp.ui.recyclerview.SlideInItemAnimator) SearchDataManager(io.plaidapp.data.SearchDataManager) InfiniteScrollListener(io.plaidapp.ui.recyclerview.InfiniteScrollListener) Point(android.graphics.Point)

Example 2 with SearchDataManager

use of io.plaidapp.data.SearchDataManager in project sbt-android by scala-android.

the class SearchActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);
    setupSearchView();
    auto = TransitionInflater.from(this).inflateTransition(R.transition.auto);
    dataManager = new SearchDataManager(this) {

        @Override
        public void onDataLoaded(List<? extends PlaidItem> data) {
            if (data != null && data.size() > 0) {
                if (results.getVisibility() != View.VISIBLE) {
                    TransitionManager.beginDelayedTransition(container, auto);
                    progress.setVisibility(View.GONE);
                    results.setVisibility(View.VISIBLE);
                    fab.setVisibility(View.VISIBLE);
                    fab.setAlpha(0.6f);
                    fab.setScaleX(0f);
                    fab.setScaleY(0f);
                    fab.animate().alpha(1f).scaleX(1f).scaleY(1f).setStartDelay(800L).setDuration(300L).setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in));
                }
                adapter.addAndResort(data);
            } else {
                TransitionManager.beginDelayedTransition(container, auto);
                progress.setVisibility(View.GONE);
                setNoResultsVisibility(View.VISIBLE);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    results.setAdapter(adapter);
    GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

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

        @Override
        public void onLoadMore() {
            dataManager.loadMore();
        }
    });
    results.setHasFixedSize(true);
    results.addOnScrollListener(gridScroll);
    // extract the search icon's location passed from the launching activity, minus 4dp to
    // compensate for different paddings in the views
    searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
    searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0);
    // translate icon to match the launching screen then animate back into position
    searchBackContainer.setTranslationX(searchBackDistanceX);
    searchBackContainer.animate().translationX(0f).setDuration(650L).setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in));
    // transform from search icon to back icon
    AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this, R.drawable.avd_search_to_back);
    searchBack.setImageDrawable(searchToBack);
    searchToBack.start();
    // for some reason the animation doesn't always finish (leaving a part arrow!?) so after
    // the animation set a static drawable. Also animation callbacks weren't added until API23
    // so using post delayed :(
    // TODO fix properly!!
    searchBack.postDelayed(new Runnable() {

        @Override
        public void run() {
            searchBack.setImageDrawable(ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded));
        }
    }, 600);
    // fade in the other search chrome
    searchBackground.animate().alpha(1f).setDuration(300L).setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
    searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L).setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in)).setListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            searchView.requestFocus();
            ImeUtils.showIme(searchView);
        }
    });
    // animate in a scrim over the content behind
    scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            scrim.getViewTreeObserver().removeOnPreDrawListener(this);
            AnimatorSet showScrim = new AnimatorSet();
            showScrim.playTogether(ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX, searchBackground.getBottom(), 0, (float) Math.hypot(searchBackDistanceX, scrim.getHeight() - searchBackground.getBottom())), ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT, ContextCompat.getColor(SearchActivity.this, R.color.scrim)));
            showScrim.setDuration(400L);
            showScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in));
            showScrim.start();
            return false;
        }
    });
    onNewIntent(getIntent());
}
Also used : AnimatorSet(android.animation.AnimatorSet) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) GridLayoutManager(android.support.v7.widget.GridLayoutManager) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SearchDataManager(io.plaidapp.data.SearchDataManager) InfiniteScrollListener(io.plaidapp.ui.recyclerview.InfiniteScrollListener) ViewTreeObserver(android.view.ViewTreeObserver)

Aggregations

GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 SearchDataManager (io.plaidapp.data.SearchDataManager)2 InfiniteScrollListener (io.plaidapp.ui.recyclerview.InfiniteScrollListener)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 Point (android.graphics.Point)1 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)1 ViewTreeObserver (android.view.ViewTreeObserver)1 SlideInItemAnimator (io.plaidapp.ui.recyclerview.SlideInItemAnimator)1