本文整理匯總了Java中io.plaidapp.data.Source類的典型用法代碼示例。如果您正苦於以下問題:Java Source類的具體用法?Java Source怎麽用?Java Source使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Source類屬於io.plaidapp.data包,在下文中一共展示了Source類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addFilter
import io.plaidapp.data.Source; //導入依賴的package包/類
/**
* 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, FilterAnimator.FILTER_ENABLED);
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;
}
示例2: onCreateViewHolder
import io.plaidapp.data.Source; //導入依賴的package包/類
@Override
public FilterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
final FilterViewHolder holder = new FilterViewHolder(LayoutInflater.from(viewGroup
.getContext()).inflate(R.layout.filter_item, viewGroup, false));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final int position = holder.getAdapterPosition();
if (position == RecyclerView.NO_POSITION) return;
final Source filter = filters.get(position);
if (isAuthorisedDribbbleSource(filter) &&
!DribbblePrefs.get(holder.itemView.getContext()).isLoggedIn()) {
authoriser.requestDribbbleAuthorisation(holder.filterIcon, filter);
} else {
filter.active = !filter.active;
holder.filterName.setEnabled(filter.active);
notifyItemChanged(position, filter.active ? FilterAnimator.FILTER_ENABLED
: FilterAnimator.FILTER_DISABLED);
SourceManager.updateSource(filter, holder.itemView.getContext());
dispatchFiltersChanged(filter);
}
}
});
return holder;
}
示例3: onCreateViewHolder
import io.plaidapp.data.Source; //導入依賴的package包/類
@Override
public FilterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
final FilterViewHolder holder = new FilterViewHolder(LayoutInflater.from(viewGroup
.getContext()).inflate(R.layout.filter_item, viewGroup, false));
holder.itemView.setOnClickListener(v -> {
final int position = holder.getAdapterPosition();
if (position == RecyclerView.NO_POSITION) return;
final Source filter = filters.get(position);
if (isAuthorisedDribbbleSource(filter) &&
!DribbblePrefs.get(holder.itemView.getContext()).isLoggedIn()) {
authoriser.requestDribbbleAuthorisation(holder.filterIcon, filter);
} else {
filter.active = !filter.active;
holder.filterName.setEnabled(filter.active);
notifyItemChanged(position, filter.active ? FilterAnimator.FILTER_ENABLED
: FilterAnimator.FILTER_DISABLED);
SourceManager.updateSource(filter, holder.itemView.getContext());
dispatchFiltersChanged(filter);
}
});
return holder;
}
示例4: getSources
import io.plaidapp.data.Source; //導入依賴的package包/類
public static List<Source> getSources(Context context) {
SharedPreferences prefs = context.getSharedPreferences(SOURCES_PREF, Context.MODE_PRIVATE);
Set<String> sourceKeys = prefs.getStringSet(KEY_SOURCES, null);
if (sourceKeys == null) {
setupDefaultSources(context, prefs.edit());
return getDefaultSources(context);
}
List<Source> sources = new ArrayList<>(sourceKeys.size());
for (String sourceKey : sourceKeys) {
if (sourceKey.startsWith(Source.DribbbleSearchSource.DRIBBBLE_QUERY_PREFIX)) {
sources.add(new Source.DribbbleSearchSource(
sourceKey.replace(Source.DribbbleSearchSource.DRIBBBLE_QUERY_PREFIX, ""),
prefs.getBoolean(sourceKey, false)));
} else if (sourceKey.startsWith(Source.DesignerNewsSearchSource
.DESIGNER_NEWS_QUERY_PREFIX)) {
sources.add(new Source.DesignerNewsSearchSource(
sourceKey.replace(Source.DesignerNewsSearchSource
.DESIGNER_NEWS_QUERY_PREFIX, ""),
prefs.getBoolean(sourceKey, false)));
} else {
// TODO improve this O(n2) search
sources.add(getSource(context, sourceKey, prefs.getBoolean(sourceKey, false)));
}
}
Collections.sort(sources, new Source.SourceComparator());
return sources;
}
示例5: addSource
import io.plaidapp.data.Source; //導入依賴的package包/類
public static void addSource(Source toAdd, Context context) {
SharedPreferences prefs = context.getSharedPreferences(SOURCES_PREF, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
Set<String> sourceKeys = prefs.getStringSet(KEY_SOURCES, null);
sourceKeys.add(toAdd.key);
editor.putStringSet(KEY_SOURCES, sourceKeys);
editor.putBoolean(toAdd.key, toAdd.active);
editor.apply();
}
示例6: removeSource
import io.plaidapp.data.Source; //導入依賴的package包/類
public static void removeSource(Source source, Context context) {
SharedPreferences prefs = context.getSharedPreferences(SOURCES_PREF, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
Set<String> sourceKeys = prefs.getStringSet(KEY_SOURCES, null);
sourceKeys.remove(source.key);
editor.putStringSet(KEY_SOURCES, sourceKeys);
editor.remove(source.key);
editor.apply();
}
示例7: setupDefaultSources
import io.plaidapp.data.Source; //導入依賴的package包/類
private static void setupDefaultSources(Context context, SharedPreferences.Editor editor) {
ArrayList<Source> defaultSources = getDefaultSources(context);
Set<String> keys = new HashSet<>(defaultSources.size());
for (Source source : defaultSources) {
keys.add(source.key);
editor.putBoolean(source.key, source.active);
}
editor.putStringSet(KEY_SOURCES, keys);
editor.commit();
}
示例8: getSource
import io.plaidapp.data.Source; //導入依賴的package包/類
private static @Nullable Source getSource(Context context, String key, boolean active) {
for (Source source : getDefaultSources(context)) {
if (source.key.equals(key)) {
source.active = active;
return source;
}
}
return null;
}
示例9: getDefaultSources
import io.plaidapp.data.Source; //導入依賴的package包/類
private static ArrayList<Source> getDefaultSources(Context context) {
ArrayList<Source> defaultSources = new ArrayList<>(11);
defaultSources.add(new Source.DesignerNewsSource(SOURCE_DESIGNER_NEWS_POPULAR, 100,
context.getString(R.string.source_designer_news_popular), true));
defaultSources.add(new Source.DesignerNewsSource(SOURCE_DESIGNER_NEWS_RECENT, 101,
context.getString(R.string.source_designer_news_recent), false));
// 200 sort order range left for DN searches
defaultSources.add(new Source.DribbbleSource(SOURCE_DRIBBBLE_POPULAR, 300,
context.getString(R.string.source_dribbble_popular), true));
defaultSources.add(new Source.DribbbleSource(SOURCE_DRIBBBLE_FOLLOWING, 301,
context.getString(R.string.source_dribbble_following), false));
defaultSources.add(new Source.DribbbleSource(SOURCE_DRIBBBLE_USER_SHOTS, 302,
context.getString(R.string.source_dribbble_user_shots), false));
defaultSources.add(new Source.DribbbleSource(SOURCE_DRIBBBLE_USER_LIKES, 303,
context.getString(R.string.source_dribbble_user_likes), false));
defaultSources.add(new Source.DribbbleSource(SOURCE_DRIBBBLE_RECENT, 304,
context.getString(R.string.source_dribbble_recent), false));
defaultSources.add(new Source.DribbbleSource(SOURCE_DRIBBBLE_DEBUTS, 305,
context.getString(R.string.source_dribbble_debuts), false));
defaultSources.add(new Source.DribbbleSource(SOURCE_DRIBBBLE_ANIMATED, 306,
context.getString(R.string.source_dribbble_animated), false));
defaultSources.add(new Source.DribbbleSearchSource(context.getString(R.string
.source_dribbble_search_material_design), true));
// 400 sort order range left for dribbble searches
defaultSources.add(new Source(SOURCE_PRODUCT_HUNT, 500,
context.getString(R.string.source_product_hunt),
R.drawable.ic_product_hunt, false));
return defaultSources;
}
示例10: FilterAdapter
import io.plaidapp.data.Source; //導入依賴的package包/類
public FilterAdapter(@NonNull Context context,
@NonNull List<Source> filters,
@NonNull FilterAuthoriser authoriser) {
this.context = context.getApplicationContext();
this.filters = filters;
this.authoriser = authoriser;
setHasStableIds(true);
}
示例11: removeFilter
import io.plaidapp.data.Source; //導入依賴的package包/類
public void removeFilter(Source removing) {
int position = filters.indexOf(removing);
filters.remove(position);
notifyItemRemoved(position);
dispatchFilterRemoved(removing);
SourceManager.removeSource(removing, context);
}
示例12: enableFilterByKey
import io.plaidapp.data.Source; //導入依賴的package包/類
public void enableFilterByKey(@NonNull String key, @NonNull Context context) {
final int count = filters.size();
for (int i = 0; i < count; i++) {
Source filter = filters.get(i);
if (filter.key.equals(key)) {
if (!filter.active) {
filter.active = true;
notifyItemChanged(i, FilterAnimator.FILTER_ENABLED);
dispatchFiltersChanged(filter);
SourceManager.updateSource(filter, context);
}
return;
}
}
}
示例13: onDribbbleLogout
import io.plaidapp.data.Source; //導入依賴的package包/類
@Override
public void onDribbbleLogout() {
for (int i = 0; i < filters.size(); i++) {
Source filter = filters.get(i);
if (filter.active && isAuthorisedDribbbleSource(filter)) {
filter.active = false;
SourceManager.updateSource(filter, context);
dispatchFiltersChanged(filter);
notifyItemChanged(i, FilterAnimator.FILTER_DISABLED);
}
}
}
示例14: onBindViewHolder
import io.plaidapp.data.Source; //導入依賴的package包/類
@Override
public void onBindViewHolder(final FilterViewHolder holder, int position) {
final Source filter = filters.get(position);
holder.isSwipeable = filter.isSwipeDismissable();
holder.filterName.setText(filter.name);
holder.filterName.setEnabled(filter.active);
if (filter.iconRes > 0) {
holder.filterIcon.setImageDrawable(
holder.itemView.getContext().getDrawable(filter.iconRes));
}
holder.filterIcon.setImageAlpha(filter.active ? FILTER_ICON_ENABLED_ALPHA :
FILTER_ICON_DISABLED_ALPHA);
}
示例15: onItemDismiss
import io.plaidapp.data.Source; //導入依賴的package包/類
@Override
public void onItemDismiss(int position) {
Source removing = filters.get(position);
if (removing.isSwipeDismissable()) {
removeFilter(removing);
}
}