private static Set<String> arraySetOf(String... suffixes) { return new ArraySet<>(Arrays.asList(suffixes)); }
@Override protected void bindItem(final ItemViewHolder holder, int position) { final Item story = getItem(position); if (mHighlightUpdated) { holder.setUpdated(story, mAdded.contains(story), mPromoted.containsKey(story.getId()) ? mPromoted.get(story.getId()) : 0); } holder.setChecked(isSelected(story.getId()) || !TextUtils.isEmpty(mUsername) && TextUtils.equals(mUsername, story.getBy())); holder.setViewed(story.isViewed()); if (story.getLocalRevision() < mFavoriteRevision) { story.setFavorite(false); } holder.setFavorite(story.isFavorite()); holder.bindMoreOptions(anchor -> showMoreOptions(anchor, story, holder), true); }
return; mAdded.clear(); mPromoted.clear(); DiffUtil.calculateDiff(new DiffUtil.Callback() {
if (METHOD_PURGE.equals(method)) { final ArraySet<String> knownAuth = new ArraySet<>(); List<ProviderInfo> providers = getContext().getPackageManager() .queryContentProviders(getContext().getPackageName(), getContext().getApplicationInfo().uid, 0); for (ProviderInfo providerInfo : providers) { knownAuth.add(providerInfo.authority); final ArraySet<String> packageAuth = new ArraySet<>(); List<ProviderInfo> providers = getContext().getPackageManager() .queryContentProviders(getContext().getPackageName(), getContext().getApplicationInfo().uid, 0); for (ProviderInfo providerInfo : providers) { packageAuth.add(providerInfo.authority); if (!packageAuth.isEmpty()) { purgeByAuthority(new Predicate<String>() { @Override
private ZWSignCalendar getContent(int position) { ZWSignCalendar calendarView; if (destroyViews.size() != 0) { calendarView = destroyViews.valueAt(0); destroyViews.remove(calendarView); } else { calendarView = new ZWSignCalendar(getContext()); calendarView.init(config); viewSet.add(calendarView); } calendarView.setSignRecords(signRecords); calendarView.selectDate(position); calendarView.setTag(position); return calendarView; }
@Override public void destroyItem(ViewGroup container, int position, Object object) { destroyViews.add((ZWCalendar) object); container.removeView((View) object); } }
@Override public int getItemCount() { if (mShowAll) { return mItems.size(); } else { return mAdded.size(); } }
private ZWCalendar getContent(int position) { ZWCalendar calendarView; if (destroyViews.size() != 0) { calendarView = destroyViews.valueAt(0); destroyViews.remove(calendarView); } else { calendarView = new ZWCalendar(getContext()); calendarView.init(config); calendarView.setDateSelectListener(new ZWCalendar.DateSelectListener() { @Override public void dateSelect(int year, int month, int day, int week) { selectYear = year; selectMonth = month; selectDay = day; for (ZWCalendar view : viewSet) { view.initSelect(selectYear, selectMonth, selectDay); } if (listener != null) { listener.select(year, month + 1, day, week == 0 ? 7 : week); } } }); viewSet.add(calendarView); } calendarView.setSignRecords(signRecords); calendarView.selectDate(position); calendarView.setTag(position); return calendarView; }
@Override public void destroyItem(ViewGroup container, int position, Object object) { destroyViews.add((ZWSignCalendar) object); container.removeView((View) object); } }
@Synthetic void notifyUpdated() { if (mUpdateListener != null) { mUpdateListener.onUpdated(mShowAll, mAdded.size(), v -> { setShowAll(!mShowAll); notifyUpdated(); notifyDataSetChanged(); }); } }
@Nullable private static ItemsToLoad getItemsToLoad(@NonNull final PlayQueue playQueue) { // The current item has higher priority final int currentIndex = playQueue.getIndex(); final PlayQueueItem currentItem = playQueue.getItem(currentIndex); if (currentItem == null) return null; // The rest are just for seamless playback // Although timeline is not updated prior to the current index, these sources are still // loaded into the cache for faster retrieval at a potentially later time. final int leftBound = Math.max(0, currentIndex - MediaSourceManager.WINDOW_SIZE); final int rightLimit = currentIndex + MediaSourceManager.WINDOW_SIZE + 1; final int rightBound = Math.min(playQueue.size(), rightLimit); final Set<PlayQueueItem> neighbors = new ArraySet<>( playQueue.getStreams().subList(leftBound,rightBound)); // Do a round robin final int excess = rightLimit - playQueue.size(); if (excess >= 0) { neighbors.addAll(playQueue.getStreams().subList(0, Math.min(playQueue.size(), excess))); } neighbors.remove(currentItem); return new ItemsToLoad(currentItem, neighbors); }
private void handleDocumentsProvider(ProviderInfo info) { // Ignore stopped packages for now; we might query them // later during UI interaction. if ((info.applicationInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0) { if (LOGD) Log.d(TAG, "Ignoring stopped authority " + info.authority); mTaskStoppedAuthorities.add(info.authority); return; } // Try using cached roots if filtering boolean cacheHit = false; if (mAuthority != null && !mAuthority.equals(info.authority)) { synchronized (mLock) { if (mTaskRoots.putAll(info.authority, mRoots.get(info.authority))) { if (LOGD) Log.d(TAG, "Used cached roots for " + info.authority); cacheHit = true; } } } // Cache miss, or loading everything if (!cacheHit) { mTaskRoots.putAll(info.authority, loadRootsForAuthority(mContext.getContentResolver(), info.authority)); } } }
@Override public boolean apply(String authority) { // Purge unknown authorities return !knownAuth.contains(authority); } });
/** * Load roots from authorities that are in stopped state. Normal * {@link UpdateTask} passes ignore stopped applications. */ private void loadStoppedAuthorities() { final ContentResolver resolver = mContext.getContentResolver(); synchronized (mLock) { for (String authority : mStoppedAuthorities) { if (LOGD) Log.d(TAG, "Loading stopped authority " + authority); mRoots.putAll(authority, loadRootsForAuthority(resolver, authority)); } mStoppedAuthorities.clear(); } }
private MediaSourceManager(@NonNull final PlaybackListener listener, @NonNull final PlayQueue playQueue, final long loadDebounceMillis, final long playbackNearEndGapMillis, final long progressUpdateIntervalMillis) { if (playQueue.getBroadcastReceiver() == null) { throw new IllegalArgumentException("Play Queue has not been initialized."); } if (playbackNearEndGapMillis < progressUpdateIntervalMillis) { throw new IllegalArgumentException("Playback end gap=[" + playbackNearEndGapMillis + " ms] must be longer than update interval=[ " + progressUpdateIntervalMillis + " ms] for them to be useful."); } this.playbackListener = listener; this.playQueue = playQueue; this.playbackNearEndGapMillis = playbackNearEndGapMillis; this.progressUpdateIntervalMillis = progressUpdateIntervalMillis; this.nearEndIntervalSignal = getEdgeIntervalSignal(); this.loadDebounceMillis = loadDebounceMillis; this.debouncedSignal = PublishSubject.create(); this.debouncedLoader = getDebouncedLoader(); this.playQueueReactor = EmptySubscription.INSTANCE; this.loaderReactor = new CompositeDisposable(); this.isBlocked = new AtomicBoolean(false); this.playlist = new ManagedMediaSourcePlaylist(); this.loadingItems = Collections.synchronizedSet(new ArraySet<>()); playQueue.getBroadcastReceiver() .observeOn(AndroidSchedulers.mainThread()) .subscribe(getReactor()); }
if (mObservedAuthorities.add(authority)) {
@Override public boolean apply(String authority) { // Purge authority matches return packageAuth.contains(authority); } });