@Override protected void onCreate(Bundle savedInstanceBundle) { requestWindowFeature(Window.FEATURE_PROGRESS); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceBundle); setContentView(R.layout.activity_reading); this.overlayLeft = (Button) findViewById(R.id.reading_overlay_left); this.overlayRight = (Button) findViewById(R.id.reading_overlay_right); this.overlayCount = (TextView) findViewById(R.id.reading_overlay_count); fragmentManager = getSupportFragmentManager(); storiesToMarkAsRead = new HashSet<Story>(); storiesAlreadySeen = new HashSet<Story>(); passedPosition = getIntent().getIntExtra(EXTRA_POSITION, 0); currentState = getIntent().getIntExtra(ItemsList.EXTRA_STATE, 0); getSupportActionBar().setDisplayHomeAsUpEnabled(true); contentResolver = getContentResolver(); this.apiManager = new APIManager(this); // this value is expensive to compute but doesn't change during a single runtime this.overlayRangeTopPx = (float) UIUtils.convertDPsToPixels(this, OVERLAY_RANGE_TOP_DP); this.overlayRangeBotPx = (float) UIUtils.convertDPsToPixels(this, OVERLAY_RANGE_BOT_DP); // the unread count overlay defaults to neutral colour. set it to positive if we are in focus // mode if (this.currentState == AppConstants.STATE_BEST) { ViewUtils.setViewBackground(this.overlayCount, R.drawable.positive_count_rect); } }
protected void onPostExecute(Void result) { if (viewHolder.get() != null) { FlowLayout sharedGrid = (FlowLayout) viewHolder.get().findViewById(R.id.reading_social_shareimages); FlowLayout commentGrid = (FlowLayout) viewHolder.get().findViewById(R.id.reading_social_commentimages); TextView friendCommentTotal = ((TextView) viewHolder.get().findViewById(R.id.reading_friend_comment_total)); TextView publicCommentTotal = ((TextView) viewHolder.get().findViewById(R.id.reading_public_comment_total)); ViewUtils.setupCommentCount(context, viewHolder.get(), commentCursor.getCount()); ViewUtils.setupShareCount(context, viewHolder.get(), story.sharedUserIds.length); ArrayList<String> commentIds = new ArrayList<String>(); commentCursor.moveToFirst(); for (int i = 0; i < commentCursor.getCount(); i++) { commentIds.add( commentCursor.getString( commentCursor.getColumnIndex(DatabaseConstants.COMMENT_USERID))); commentCursor.moveToNext(); } for (final String userId : story.sharedUserIds) { if (!commentIds.contains(userId)) { Cursor userCursor = resolver.query( FeedProvider.USERS_URI, null, DatabaseConstants.USER_USERID + " IN (?)", new String[] {userId}, null); if (userCursor.getCount() > 0) { UserProfile user = UserProfile.fromCursor(userCursor); userCursor.close(); ImageView image = ViewUtils.createSharebarImage(context, imageLoader, user.photoUrl, user.userId); sharedGrid.addView(image); } userCursor.close(); } } commentCursor.moveToFirst(); for (int i = 0; i < commentCursor.getCount(); i++) { final Comment comment = Comment.fromCursor(commentCursor); Cursor userCursor = resolver.query( FeedProvider.USERS_URI, null, DatabaseConstants.USER_USERID + " IN (?)", new String[] {comment.userId}, null); UserProfile user = UserProfile.fromCursor(userCursor); userCursor.close(); ImageView image = ViewUtils.createSharebarImage(context, imageLoader, user.photoUrl, user.userId); commentGrid.addView(image); commentCursor.moveToNext(); } if (publicCommentViews.size() > 0) { String commentCount = context.getString(R.string.public_comment_count); if (publicCommentViews.size() == 1) { commentCount = commentCount.substring(0, commentCount.length() - 1); } publicCommentTotal.setText(String.format(commentCount, publicCommentViews.size())); viewHolder .get() .findViewById(R.id.reading_public_comment_header) .setVisibility(View.VISIBLE); } if (friendCommentViews.size() > 0) { String commentCount = context.getString(R.string.friends_comments_count); if (friendCommentViews.size() == 1) { commentCount = commentCount.substring(0, commentCount.length() - 1); } friendCommentTotal.setText(String.format(commentCount, friendCommentViews.size())); viewHolder .get() .findViewById(R.id.reading_friend_comment_header) .setVisibility(View.VISIBLE); } for (int i = 0; i < publicCommentViews.size(); i++) { if (i == publicCommentViews.size() - 1) { publicCommentViews.get(i).findViewById(R.id.comment_divider).setVisibility(View.GONE); } ((LinearLayout) viewHolder.get().findViewById(R.id.reading_public_comment_container)) .addView(publicCommentViews.get(i)); } for (int i = 0; i < friendCommentViews.size(); i++) { if (i == friendCommentViews.size() - 1) { friendCommentViews.get(i).findViewById(R.id.comment_divider).setVisibility(View.GONE); } ((LinearLayout) viewHolder.get().findViewById(R.id.reading_friend_comment_container)) .addView(friendCommentViews.get(i)); } } commentCursor.close(); }