Java 类android.support.v7.widget.util.SortedListAdapterCallback 实例源码

项目:fast-list    文件:SortedListAdapter.java   
public SortedListAdapter() {
  mUsers = new SortedList<>(User.class, new SortedListAdapterCallback<User>(this) {
    @Override
    public boolean areContentsTheSame(User oldItem, User newItem) {
      return User.areContentsTheSame(oldItem, newItem);
    }

    @Override
    public boolean areItemsTheSame(User item1, User item2) {
      return User.areItemsTheSame(item1, item2);
    }

    @Override
    public int compare(User o1, User o2) {
      return User.compare(o1, o2);
    }
  });
}
项目:AutoAdapter    文件:SortedAdapterDataStructure.java   
public SortedAdapterDataStructure(@NonNull final SortedAutoAdapter autoAdapter) {
    super(OrderableRenderer.class, new SortedListAdapterCallback<OrderableRenderer>(autoAdapter) {
        @Override
        public int compare(OrderableRenderer o1, OrderableRenderer o2) {
            return autoAdapter.compare(o1, o2);
        }

        @Override
        public boolean areContentsTheSame(OrderableRenderer oldItem, OrderableRenderer newItem) {
            return autoAdapter.areContentsTheSame(oldItem, newItem);
        }

        @Override
        public boolean areItemsTheSame(OrderableRenderer item1, OrderableRenderer item2) {
            return autoAdapter.areItemsTheSame(item1, item2);
        }
    });
}
项目:playbook-android-sortedlist    文件:GroupedArticleDataset.java   
public GroupedArticleDataset(final RecyclerView recyclerView,
    final RecyclerView.Adapter adapter) {
  this.sortedList = new SortedList<>(GroupedArticle.class,
      new SortedList.BatchedCallback<>(new SortedListAdapterCallback<GroupedArticle>(adapter) {
        @Override public int compare(GroupedArticle a1, GroupedArticle a2) {
          return a1.compare(a2, getComparator());
        }

        @Override
        public boolean areContentsTheSame(GroupedArticle oldItem, GroupedArticle newItem) {
          return oldItem.areContentsTheSame(newItem);
        }

        @Override public boolean areItemsTheSame(GroupedArticle item1, GroupedArticle item2) {
          return item1.areItemsTheSame(item2);
        }

        @Override public void onInserted(int position, int count) {
          super.onInserted(position, count);
          recyclerView.scrollToPosition(position);
        }
      }));
}
项目:playbook-android-sortedlist    文件:SortedListShouldBeSortedAdapter.java   
public SortedListShouldBeSortedAdapter(ArrayList<Article> articles) {
  articleSortedList =
      new SortedList<>(Article.class, new SortedListAdapterCallback<Article>(this) {
        @Override public int compare(Article o1, Article o2) {
          return o1.compare(o2);
        }

        @Override public boolean areContentsTheSame(Article oldItem, Article newItem) {
          return oldItem.areContentsTheSame(newItem);
        }

        @Override public boolean areItemsTheSame(Article item1, Article item2) {
          return item1.areItemsTheSame(item2);
        }
      });
  articleSortedList.addAll(articles);
}
项目:playbook-android-sortedlist    文件:SortedListBatchOperationsAdapter.java   
public SortedListBatchOperationsAdapter(ArrayList<Article> articles) {
  super(articles);
  articleSortedList = new SortedList<>(Article.class,
      new SortedList.BatchedCallback<>(new SortedListAdapterCallback<Article>(this) {
        @Override public int compare(Article o1, Article o2) {
          return o1.compare(o2);
        }

        @Override public boolean areContentsTheSame(Article oldItem, Article newItem) {
          return oldItem.areContentsTheSame(newItem);
        }

        @Override public boolean areItemsTheSame(Article item1, Article item2) {
          return item1.areItemsTheSame(item2);
        }
      }));
  articleSortedList.beginBatchedUpdates();
  articleSortedList.addAll(articles);
  articleSortedList.endBatchedUpdates();
}
项目:playbook-android-sortedlist    文件:ArticleRowDataset.java   
public ArticleRowDataset(final RecyclerView recyclerView, final RecyclerView.Adapter adapter) {
  this.sortedList = new SortedList<>(ArticleRow.class,
      new SortedList.BatchedCallback<>(new SortedListAdapterCallback<ArticleRow>(adapter) {
        @Override public int compare(ArticleRow a1, ArticleRow a2) {
          return a1.compare(a2);
        }

        @Override public boolean areContentsTheSame(ArticleRow oldItem, ArticleRow newItem) {
          return oldItem.areContentsTheSame(newItem);
        }

        @Override public boolean areItemsTheSame(ArticleRow item1, ArticleRow item2) {
          return item1.areItemsTheSame(item2);
        }

        @Override public void onInserted(int position, int count) {
          super.onInserted(position, count);
          recyclerView.scrollToPosition(position);
        }
      }));
  addInitialData();
}
项目:playbook-android-sortedlist    文件:ArticleSortOptionsActivity.java   
public ArticleDataset(final RecyclerView recyclerView, final RecyclerView.Adapter adapter) {
  this.sortedList = new SortedList<>(Article.class,
      new SortedList.BatchedCallback<>(new SortedListAdapterCallback<Article>(adapter) {
        @Override public int compare(Article a1, Article a2) {
          return getComparator().compare(a1, a2);
        }

        @Override public boolean areContentsTheSame(Article oldItem, Article newItem) {
          return oldItem.areContentsTheSame(newItem);
        }

        @Override public boolean areItemsTheSame(Article item1, Article item2) {
          return item1.areItemsTheSame(item2);
        }

        @Override public void onInserted(int position, int count) {
          super.onInserted(position, count);
          recyclerView.scrollToPosition(position);
        }
      }));
}
项目:playbook-android-sortedlist    文件:SortedListAdapter.java   
public SortedListAdapter() {
  this.sortedList = new SortedList<>(Integer.class, new SortedListAdapterCallback<Integer>(this) {
    @Override public int compare(Integer item1, Integer item2) {
      return item1.compareTo(item2);
    }

    @Override public boolean areContentsTheSame(Integer oldItem, Integer newItem) {
      return oldItem.equals(newItem);
    }

    @Override public boolean areItemsTheSame(Integer item1, Integer item2) {
      return item1.intValue() == item2.intValue();
    }
  });
  ;
}
项目:playbook-android-sortedlist    文件:ArticleDataset.java   
public ArticleDataset(final RecyclerView recyclerView, final RecyclerView.Adapter adapter) {
  this.sortedList = new SortedList<>(Article.class,
      new SortedList.BatchedCallback<>(new SortedListAdapterCallback<Article>(adapter) {
        @Override public int compare(Article a1, Article a2) {
          return getComparator().compare(a1, a2);
        }

        @Override public boolean areContentsTheSame(Article oldItem, Article newItem) {
          return oldItem.areContentsTheSame(newItem);
        }

        @Override public boolean areItemsTheSame(Article item1, Article item2) {
          return item1.areItemsTheSame(item2);
        }

        @Override public void onInserted(int position, int count) {
          super.onInserted(position, count);
          recyclerView.scrollToPosition(position);
        }
      }));
}
项目:Game-of-Thrones    文件:SortedMessageCollection.java   
public SortedMessageCollection(RecyclerView.Adapter adapter) {
  messageList = new SortedList<Message>(Message.class, new SortedListAdapterCallback<Message>(adapter) {
    @Override
    public int compare(Message o1, Message o2) {
      return o1.compareTo(o2);
    }

    @Override
    public boolean areContentsTheSame(Message oldItem, Message newItem) {
      return oldItem.equals(newItem);
    }

    @Override
    public boolean areItemsTheSame(Message item1, Message item2) {
      return item1.getId().equals(item2.getId());
    }
  });
}
项目:appbarsyncedfab    文件:ItemsAdapter.java   
public ItemsAdapter(OnItemClickListener onItemClickListener) {
    this.onItemClickListener = onItemClickListener;
    dataset = new SortedList<>(Long.class, new SortedListAdapterCallback<Long>(this) { // yes, we're leaking half-constructed this. Currently, it's fine.
        @Override
        public int compare(Long left, Long right) {
            // Long.compare(left, right)
            return left < right ? -1 : (left.longValue() == right.longValue() ? 0 : 1);
        }

        @Override
        public boolean areContentsTheSame(Long oldItem, Long newItem) {
            // Object.equals(oldItem, newItem)
            return (oldItem == null) ? (newItem == null) : oldItem.equals(newItem);
        }

        @Override
        public boolean areItemsTheSame(Long item1, Long item2) {
            // Object.equals(item1, item2)
            return (item1 == null) ? (item2 == null) : item1.equals(item2);
        }
    });
    setHasStableIds(true);
}
项目:quotes    文件:QuoteAdapter.java   
public QuoteAdapter() {
    quoteList = new SortedList(Quote.class, new SortedListAdapterCallback<Quote>(this) {
        @Override
        public int compare(Quote o1, Quote o2) {
            return o1.compareTo(o2);
        }

        @Override
        public boolean areContentsTheSame(Quote oldItem, Quote newItem) {
            return oldItem.equals(newItem);
        }

        @Override
        public boolean areItemsTheSame(Quote item1, Quote item2) {
            return item1.getId().equals(item2.getId());
        }
    });
}
项目:RecyclerViewCursorAdapter    文件:RecyclerViewCursorAdapter.java   
/** If you just need a plain sortedlist */
public RecyclerViewCursorAdapter(@NonNull Class<T> klass, @Nullable Cursor cursor) {

    setSortedList(new SortedList<>(klass, new SortedListAdapterCallback<T>(this) {
        @Override
        public int compare(T o1, T o2) {
            return 0;
        }

        @Override
        public boolean areContentsTheSame(T oldItem, T newItem) {
            return false;
        }

        @Override
        public boolean areItemsTheSame(T item1, T item2) {
            return false;
        }
    }));

    setCursor(cursor);

}
项目:materialize    文件:FilteredSortedListAdapter.java   
public FilteredSortedListAdapter(Class<T> type, FilteredSortedList.Filter<T> filter) {
    this.data = new FilteredSortedList<>(type, new SortedListAdapterCallback<T>(this) {
        @Override
        public int compare(T lhs, T rhs) {
            return FilteredSortedListAdapter.this.compare(lhs, rhs);
        }

        @Override
        public boolean areContentsTheSame(T oldItem, T newItem) {
            return FilteredSortedListAdapter.this.areContentsTheSame(oldItem, newItem);
        }

        @Override
        public boolean areItemsTheSame(T item1, T item2) {
            return FilteredSortedListAdapter.this.areItemsTheSame(item1, item2);
        }
    }, filter);
}
项目:Exoplayer2Radio    文件:CollectionAdapter.java   
public CollectionAdapter (Activity activity, File folder) {
    // set main variables
    mActivity = activity;
    mFolder = folder;
    mStationIDSelected = 0;
    mStationList = new SortedList<Station>(Station.class, new SortedListAdapterCallback<Station>(this) {

        @Override
        public int compare(Station station1, Station station2) {
            // Compares two stations: returns "1" if name if this station is greater than name of given station
            return station1.getStationName().compareToIgnoreCase(station2.getStationName());
        }

        @Override
        public boolean areContentsTheSame(Station oldStation, Station newStation) {
            return oldStation.getStationName().equals(newStation.getStationName());
        }

        @Override
        public boolean areItemsTheSame(Station station1, Station station2) {
            // return station1.equals(station2);
            return areContentsTheSame(station1, station2);
        }
    });

    // fill station list
    loadCollection();

    // load state
    // loadAppState(mActivity);

}
项目:Open-Quran-Radio    文件:CollectionAdapter.java   
public CollectionAdapter(Activity activity, File folder) {
    // set main variables
    mActivity = activity;
    mFolder = folder;
    mStationIDSelected = 0;
    mStationList = new SortedList<Station>(Station.class, new SortedListAdapterCallback<Station>(this) {

        @Override
        public int compare(Station station1, Station station2) {
            // Compares two stations: returns "1" if name if this station is greater than name of given station
            int result = Integer.compare(station2.IS_FAVOURITE, station1.IS_FAVOURITE);
            if (result == 0) {//equal
                result = station1.CATEGORY.compareToIgnoreCase(station2.CATEGORY);
                if (result == 0) {
                    result = station1.TITLE.compareToIgnoreCase(station2.TITLE);
                }
            }
            return result;
        }

        @Override
        public boolean areContentsTheSame(Station oldStation, Station newStation) {
            return oldStation.StreamURI.equals(newStation.StreamURI);
        }

        @Override
        public boolean areItemsTheSame(Station station1, Station station2) {
            // return station1.equals(station2);
            return areContentsTheSame(station1, station2);
        }
    });

    // fill station list
    loadCollection();

}
项目:lucky-calories    文件:UserListFragment.java   
public UserListFragment() {
    // Required empty public constructor

    usersTransformer = new Transformer
            .Builder()
            .build(io.swagger.client.model.User.class);

    usersAdapter = new UsersAdapter();
    usersList = new SortedList<>(UserModel.class,
            new SortedListAdapterCallback<UserModel>(usersAdapter) {
                @Override
                public int compare(UserModel u1, UserModel u2) {
                    if(u1.getName() == null)
                        return -1;

                    if(u2.getName() == null)
                        return 1;

                    return u1.getName().compareTo(u2.getName());
                }

                @Override
                public boolean areContentsTheSame(UserModel oldItem, UserModel newItem) {
                    return oldItem.getName().equals(newItem.getName());
                }

                @Override
                public boolean areItemsTheSame(UserModel item1, UserModel item2) {
                    return item1.getId() == item2.getId();
                }
            });

}
项目:sagetv-miniclient    文件:ServersAdapter.java   
public ServersAdapter(Context ctx) {
    this.context = ctx;
    this.layoutInflater = LayoutInflater.from(context);

    // get the saved servers, and add them
    items = new SortedList<ServerInfo>(ServerInfo.class, new SortedListAdapterCallback<ServerInfo>(this) {
        @Override
        public int compare(ServerInfo o1, ServerInfo o2) {
            // sort by date accessed and then name
            int compare = 0;
            if (o1.lastConnectTime < o2.lastConnectTime) compare = 1;
            if (o1.lastConnectTime > o2.lastConnectTime) compare = -1;
            if (compare == 0) {
                return o1.name.compareTo(o2.name);
            }
            return compare;
        }

        @Override
        public boolean areContentsTheSame(ServerInfo oldItem, ServerInfo newItem) {
            return oldItem.equals(newItem);
        }

        @Override
        public boolean areItemsTheSame(ServerInfo item1, ServerInfo item2) {
            return item1.equals(item2);
        }
    });

    log.debug("Begin Adding Saved Servers");
    addAll(MiniclientApplication.get(ctx.getApplicationContext()).getClient().getServers().getSavedServers());
    log.debug("End Adding Saved Servers");
}
项目:android-support-learn    文件:SortedListActivity.java   
public SortedListAdapter(LayoutInflater layoutInflater, Item... items) {
    mLayoutInflater = layoutInflater;
    mData = new SortedList<Item>(Item.class, new SortedListAdapterCallback<Item>(this) {
        @Override
        public int compare(Item t0, Item t1) {
            if (t0.mIsDone != t1.mIsDone) {
                return t0.mIsDone ? 1 : -1;
            }
            int txtComp = t0.mText.compareTo(t1.mText);
            if (txtComp != 0) {
                return txtComp;
            }
            if (t0.id < t1.id) {
                return -1;
            } else if (t0.id > t1.id) {
                return 1;
            }
            return 0;
        }

        @Override
        public boolean areContentsTheSame(Item oldItem,
                Item newItem) {
            return oldItem.mText.equals(newItem.mText);
        }

        @Override
        public boolean areItemsTheSame(Item item1, Item item2) {
            return item1.id == item2.id;
        }
    });
    for (Item item : items) {
        mData.add(item);
    }
}
项目:dev-summit-architecture-demo    文件:FeedAdapter.java   
public FeedAdapter(Context context) {
    mLayoutInflater = LayoutInflater.from(context);
    mList = new SortedList<>(FeedItem.class,
            new SortedListAdapterCallback<FeedItem>(this) {
                @Override
                public int compare(FeedItem o1, FeedItem o2) {
                    Post p2 = o2.getPost();
                    Post p1 = o1.getPost();
                    if (p1.isPending() != p2.isPending()) {
                        return p1.isPending() ? -1 : 1;
                    }
                    return (int) (p2.getCreated() - p1.getCreated());
                }

                @SuppressWarnings("SimplifiableIfStatement")
                @Override
                public boolean areContentsTheSame(FeedItem oldItem,
                        FeedItem newItem) {
                    Post oldPost = oldItem.getPost();
                    Post newPost = newItem.getPost();
                    if (oldPost.getId() != newPost.getId()) {
                        return false;
                    }
                    if (!oldPost.getText().equals(newPost.getText())) {
                        return false;
                    }
                    if (!oldItem.getUser().getName().equals(newItem.getUser().getName())) {
                        return false;
                    }
                    return oldItem.getPost().isPending() == newItem.getPost().isPending();
                }

                @Override
                public boolean areItemsTheSame(FeedItem item1, FeedItem item2) {
                    return item1.getPost().getId() == item2.getPost().getId();
                }
            });
}
项目:Android-Password-Store    文件:AutofillRecyclerAdapter.java   
AutofillRecyclerAdapter(List<AppInfo> allApps, final PackageManager pm
        , AutofillPreferenceActivity activity) {
    SortedList.Callback<AppInfo> callback = new SortedListAdapterCallback<AppInfo>(this) {
        // don't take into account secondary text. This is good enough
        // for the limited add/remove usage for websites
        @Override
        public int compare(AppInfo o1, AppInfo o2) {
         return o1.appName.toLowerCase().compareTo(o2.appName.toLowerCase());
        }

        @Override
        public boolean areContentsTheSame(AppInfo oldItem, AppInfo newItem) {
         return oldItem.appName.equals(newItem.appName);
        }

        @Override
        public boolean areItemsTheSame(AppInfo item1, AppInfo item2) {
         return item1.appName.equals(item2.appName);
        }
    };
    this.apps = new SortedList<>(AppInfo.class, callback);
    this.apps.addAll(allApps);
    this.allApps = new ArrayList<>(allApps);
    this.activity = activity;
    try {
        browserIcon = activity.getPackageManager().getApplicationIcon("com.android.browser");
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}