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();
}
}
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);
}
}
});
}
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;
}
Aggregations