public void addSourceData(List<FeedObject> newSources) { Log.e("aaa", "add source data, data size: " + data.size()); for (FeedObject feed : data) { Log.e("aaa", "old feed: " + feed.getTitle()); } for (FeedObject newFeed : newSources) { boolean isPresent = false; for (FeedObject feed : data) { if (feed.getId().equals(newFeed.getId())) { isPresent = true; } } // boolean isPresent = data.contains(feed); Log.e("aaa", "feed: " + newFeed.getTitle() + " - is present: " + isPresent); if (!isPresent) { data.add(newFeed); notifyItemInserted(data.size()); } } }
@Override public void onBindViewHolder(final ViewHolder holder, int position) { final FeedObject feed = data.get(position); URL feedUrl = null; if (feed != null) { final String feedId = feed.getId(); // Download the background image if (feed.getImageUrl() != null && !feed.getImageUrl().equals("null")) { Picasso.with(context) .load(feed.getImageUrl()) .resize(DDGUtils.displayStats.feedItemWidth, DDGUtils.displayStats.feedItemHeight) .centerCrop() .placeholder(android.R.color.transparent) .into(holder.imageViewBackground); } final String feedType = feed.getType(); holder.imageViewFeedIcon.setType(feedType); // stored source id in imageview // holder.imageViewFeedIcon.setOnClickListener(sourceClickListener); final View itemView = holder.itemView; final String sourceType = holder.imageViewFeedIcon.getType(); holder.imageViewFeedIcon.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // BusProvider.getInstance().post(new SourceFilterEvent(itemView, sourceType, feed)); if (DDGControlVar.targetSource != null) { DDGControlVar.targetSource = null; BusProvider.getInstance().post(new FeedCancelSourceFilterEvent()); } else { DDGControlVar.targetSource = sourceType; DDGControlVar.hasUpdatedFeed = false; Log.e("aaa", "ddg target source: " + DDGControlVar.targetSource); BusProvider.getInstance().post(new SourceFilterEvent(itemView, sourceType, feed)); filterSource(sourceType); } } }); /* holder.imageViewFeedIcon.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(DDGControlVar.targetSource!=null) { DDGControlVar.targetSource=null; unmarkSource(); getFilter().filter(feedType); } else { DDGControlVar.targetSource=feedType; markSource(feedId); getFilter().filter(feedType); } } });*/ /* final View iconParent = (View) view.findViewById(R.id.feedWrapper); iconParent.post(new Runnable() { public void run() { // Post in the parent's message queue to make sure the parent // lays out its children before we call getHitRect() Rect delegateArea = new Rect(); AsyncImageView delegate = holder.imageViewFeedIcon; delegate.getHitRect(delegateArea); delegateArea.top = 0; delegateArea.bottom = iconParent.getBottom(); delegateArea.left = 0; // right side limit also considers the space that is available from TextView, without text displayed // in TextView padding area on the left delegateArea.right = holder.textViewTitle.getLeft() + holder.textViewTitle.getPaddingLeft(); TouchDelegate expandedArea = new TouchDelegate(delegateArea, delegate); // give the delegate to an ancestor of the view we're delegating the area to if (View.class.isInstance(delegate.getParent())) { ((View) delegate.getParent()) .setTouchDelegate(expandedArea); } }; }); */ // Set the Title // holder.textViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, DDGControlVar.mainTextSize); holder.textViewTitle.setText(feed.getTitle()); /* String feedId = feed.getId(); if(DDGControlVar.readArticles.contains(feedId)){ holder.textViewTitle.setTextColor(Color.GRAY); }*/ // FIXME : it'd be good to reset color to default color for textview in layout XML holder.textViewTitle.setTextColor(context.getResources().getColor(R.color.feed_title)); if (DDGControlVar.readArticles.contains(feedId)) { holder.textViewTitle.setTextColor( context.getResources().getColor(R.color.feed_title_viewed)); } // set the category // todo insert size final String category = feed.getCategory(); holder.textViewCategory.setText(category.toUpperCase()); /* holder.textViewCategory.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Log.e("aaa", "catgory clicked: "+category); } });*/ // holder.textViewCategory.setOnClickListener(categoryClickListener); holder.frameCategoryContainer.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (DDGControlVar.targetCategory != null) { DDGControlVar.targetCategory = null; BusProvider.getInstance().post(new FeedCancelCategoryFilterEvent()); } else { DDGControlVar.targetCategory = category; filterCategory(category); } } }); /* final View view = cv; holder.textViewCategory.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(DDGControlVar.targetCategory!=null) { Log.e("aaa", "should remove filter: "+category); DDGControlVar.targetCategory = null; unmarkCategory(); //getFilter().filter(category); } else if(DDGControlVar.targetSource!=null) { Log.e("aaa", "must add filter: "+category); //DDGControlVar.targetCategory = category; //markCategory(feedId); //getFilter().filter(category); } view.animate().setDuration(1000).alpha(0) } });*/ holder.frameMenuContainer.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { showMenu(holder.imageViewMenu, feed); } }); /* //set the toolbar Menu if(DDGApplication.getDB().isSaved(feedId)) { holder.toolbar.getMenu().findItem(R.id.action_add_favorite).setVisible(false); holder.toolbar.getMenu().findItem(R.id.action_remove_favorite).setVisible(true); } else { holder.toolbar.getMenu().findItem(R.id.action_add_favorite).setVisible(true); holder.toolbar.getMenu().findItem(R.id.action_remove_favorite).setVisible(false); } holder.toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch(menuItem.getItemId()) { case R.id.action_add_favorite: Log.e("aaa", "action add favourites"); BusProvider.getInstance().post(new SaveStoryEvent(feed)); holder.toolbar.getMenu().findItem(R.id.action_add_favorite).setVisible(false); holder.toolbar.getMenu().findItem(R.id.action_remove_favorite).setVisible(true); //add to favourites return true; case R.id.action_remove_favorite: BusProvider.getInstance().post(new UnSaveStoryEvent(feed.getId())); holder.toolbar.getMenu().findItem(R.id.action_add_favorite).setVisible(true); holder.toolbar.getMenu().findItem(R.id.action_remove_favorite).setVisible(false); return true; case R.id.action_share: Log.e("aaa", "action share"); BusProvider.getInstance().post(new ShareFeedEvent(feed.getTitle(), feed.getUrl())); //action share return true; case R.id.action_external: Log.e("aaa", "action external view in chrome"); BusProvider.getInstance().post(new SendToExternalBrowserEvent(getContext(), feed.getUrl())); //view in chrome return true; default: return false; } } });*/ if (feed.getFeed() != null && !feed.getFeed().equals("null")) { try { feedUrl = new URL(feed.getFeed()); } catch (MalformedURLException e) { e.printStackTrace(); } if (feedUrl != null) { String host = feedUrl.getHost(); if (host.indexOf(".") != host.lastIndexOf(".")) { // Cut off the beginning, because we don't want/need it host = host.substring(host.indexOf(".") + 1); } Bitmap bitmap = DDGApplication.getImageCache().getBitmapFromCache("DUCKDUCKICO--" + feedType, false); if (bitmap != null) { holder.imageViewFeedIcon.setBitmap(bitmap); } } holder.itemView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { BusProvider.getInstance().post(new MainFeedItemSelectedEvent(feed)); } }); holder.itemView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { // BusProvider.getInstance().post(new MainFeedItemLongClickEvent(feed)); showMenu(holder.imageViewMenu, feed); return true; } }); } } /* if(false && holder.itemView != null) { if((markedItem != null && markedItem.equals(feed.getId())) || (markedSource!=null && markedSource.equals(feed.getId()))) { blinkanimation.reset(); holder.itemView.startAnimation(blinkanimation); } else { holder.itemView.setAnimation(null); } }*/ }