Search in sources :

Example 16 with Source

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

the class FilterAdapter method onDribbbleLogout.

@Override
public void onDribbbleLogout() {
    boolean changed = false;
    for (Source filter : filters) {
        if (filter.active && isAuthorisedDribbbleSource(filter)) {
            filter.active = false;
            SourceManager.updateSource(filter, context);
            dispatchFiltersChanged(filter);
            changed = true;
        }
    }
    if (changed) {
        notifyDataSetChanged();
    }
}
Also used : Source(io.plaidapp.data.Source)

Example 17 with Source

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

the class FilterAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final FilterViewHolder vh, final int position) {
    final Source filter = filters.get(position);
    vh.isSwipeable = filter.isSwipeDismissable();
    vh.filterName.setText(filter.name);
    vh.filterName.setEnabled(filter.active);
    if (filter.iconRes > 0) {
        vh.filterIcon.setImageDrawable(vh.itemView.getContext().getDrawable(filter.iconRes));
    }
    vh.filterIcon.setImageAlpha(filter.active ? FILTER_ICON_ENABLED_ALPHA : FILTER_ICON_DISABLED_ALPHA);
    vh.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isAuthorisedDribbbleSource(filter) && !DribbblePrefs.get(vh.itemView.getContext()).isLoggedIn()) {
                authoriser.requestDribbbleAuthorisation(vh.filterIcon, filter);
            } else {
                vh.itemView.setHasTransientState(true);
                ObjectAnimator fade = ObjectAnimator.ofInt(vh.filterIcon, ViewUtils.IMAGE_ALPHA, filter.active ? FILTER_ICON_DISABLED_ALPHA : FILTER_ICON_ENABLED_ALPHA);
                fade.setDuration(300);
                fade.setInterpolator(AnimationUtils.loadInterpolator(vh.itemView.getContext(), android.R.interpolator.fast_out_slow_in));
                fade.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        vh.itemView.setHasTransientState(false);
                    }
                });
                fade.start();
                filter.active = !filter.active;
                vh.filterName.setEnabled(filter.active);
                notifyItemChanged(position);
                SourceManager.updateSource(filter, vh.itemView.getContext());
                dispatchFiltersChanged(filter);
            }
        }
    });
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) Source(io.plaidapp.data.Source)

Example 18 with Source

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

the class FilterAdapter method addFilter.

/**
 * Adds a new data source to the list of filters. If the source already exists then it is simply
 * activated.
 *
 * @param toAdd the source to add
 * @return whether the filter was added (i.e. if it did not already exist)
 */
public boolean addFilter(Source toAdd) {
    // first check if it already exists
    final int count = filters.size();
    for (int i = 0; i < count; i++) {
        Source existing = filters.get(i);
        if (existing.getClass() == toAdd.getClass() && existing.key.equalsIgnoreCase(toAdd.key)) {
            // already exists, just ensure it's active
            if (!existing.active) {
                existing.active = true;
                dispatchFiltersChanged(existing);
                notifyItemChanged(i);
                SourceManager.updateSource(existing, context);
            }
            return false;
        }
    }
    // didn't already exist, so add it
    filters.add(toAdd);
    Collections.sort(filters, new Source.SourceComparator());
    dispatchFiltersChanged(toAdd);
    notifyDataSetChanged();
    SourceManager.addSource(toAdd, context);
    return true;
}
Also used : Source(io.plaidapp.data.Source)

Aggregations

Source (io.plaidapp.data.Source)18 RecyclerView (android.support.v7.widget.RecyclerView)5 View (android.view.View)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 ArrayList (java.util.ArrayList)4 FilterTouchHelperCallback (io.plaidapp.ui.recyclerview.FilterTouchHelperCallback)3 ActivityOptions (android.app.ActivityOptions)2 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)2 ViewGroup (android.view.ViewGroup)2 WindowInsets (android.view.WindowInsets)2 ActionMenuView (android.widget.ActionMenuView)2 FrameLayout (android.widget.FrameLayout)2 BindView (butterknife.BindView)2 DataManager (io.plaidapp.data.DataManager)2 InfiniteScrollListener (io.plaidapp.ui.recyclerview.InfiniteScrollListener)2 HashSet (java.util.HashSet)2