@Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { if (i == 5) { View v = LayoutInflater.from(viewGroup.getContext()) .inflate(R.layout.loadingmore, viewGroup, false); return new ContributionAdapter.EmptyViewHolder(v); } else { View v = CreateCardView.CreateView(viewGroup, false, "nomatching"); return new SubmissionViewHolder(v); } }
@Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { if (i == COMMENT) { View v = LayoutInflater.from(viewGroup.getContext()) .inflate(R.layout.profile_comment, viewGroup, false); return new ProfileCommentViewHolder(v); } else { View v = CreateCardView.CreateView(viewGroup); return new SubmissionViewHolder(v); } }
@Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { if (i == LOADING_SPINNER) { View v = LayoutInflater.from(viewGroup.getContext()) .inflate(R.layout.loadingmore, viewGroup, false); return new SubmissionFooterViewHolder(v); } else if (i == NO_MORE) { View v = LayoutInflater.from(viewGroup.getContext()) .inflate(R.layout.nomoreposts, viewGroup, false); return new SubmissionFooterViewHolder(v); } else { View v = CreateCardView.CreateView(viewGroup, custom, subreddit); return new SubmissionViewHolder(v); } }
@Override public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int i) { if (holder2 instanceof SubmissionViewHolder) { final SubmissionViewHolder holder = (SubmissionViewHolder) holder2; final Submission submission = dataSet.posts.get(i); CreateCardView.resetColorCard(holder.itemView); CreateCardView.colorCard( submission.getSubredditName().toLowerCase(), holder.itemView, subreddit, (subreddit.equals("frontpage") || (subreddit.equals("all")) || subreddit.contains(".") || subreddit.contains("+"))); holder.itemView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View arg0) { if (Authentication.didOnline || submission.getComments() != null) { holder2.itemView.setAlpha(0.65f); if (SettingValues.tabletUI && holder2.itemView.getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { Intent i2 = new Intent(holder2.itemView.getContext(), CommentsScreenPopup.class); i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit); i2.putExtra(CommentsScreenPopup.EXTRA_PAGE, holder2.getAdapterPosition()); (holder2.itemView.getContext()).startActivity(i2); } else { Intent i2 = new Intent(holder2.itemView.getContext(), CommentsScreen.class); i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition()); i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit); (holder2.itemView.getContext()).startActivity(i2); } } else { Snackbar.make( holder.itemView, R.string.offline_comments_not_loaded, Snackbar.LENGTH_SHORT) .show(); } } }); final boolean saved = submission.isSaved(); holder.itemView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (context instanceof MainActivity && ((MainActivity) context).t != null) { Tooltip.removeAll(context); Reddit.appRestart.edit().putString("tutorial_4", "A").apply(); } if (!dataSet.stillShow) { Snackbar.make( holder.itemView, holder2.itemView.getContext().getString(R.string.offline_msg), Snackbar.LENGTH_SHORT) .show(); } else { LayoutInflater inflater = LayoutInflater.from(holder2.itemView.getContext()); final View dialoglayout = inflater.inflate(R.layout.postmenu, null); AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(holder2.itemView.getContext()); final TextView title = (TextView) dialoglayout.findViewById(R.id.title); title.setText(Html.fromHtml(submission.getTitle())); ((TextView) dialoglayout.findViewById(R.id.userpopup)) .setText("/u/" + submission.getAuthor()); ((TextView) dialoglayout.findViewById(R.id.subpopup)) .setText("/r/" + submission.getSubredditName()); dialoglayout .findViewById(R.id.sidebar) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(holder2.itemView.getContext(), Profile.class); i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor()); holder2.itemView.getContext().startActivity(i); } }); dialoglayout .findViewById(R.id.wiki) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(holder2.itemView.getContext(), SubredditView.class); i.putExtra( SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName()); holder2.itemView.getContext().startActivity(i); } }); dialoglayout .findViewById(R.id.save) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (saved) { ((TextView) dialoglayout.findViewById(R.id.savedtext)) .setText(R.string.submission_save); } else { ((TextView) dialoglayout.findViewById(R.id.savedtext)) .setText(R.string.submission_post_saved); } new AsyncSave(holder.itemView).execute(submission); } }); if (saved) { ((TextView) dialoglayout.findViewById(R.id.savedtext)) .setText(R.string.submission_post_saved); } dialoglayout .findViewById(R.id.gild) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String urlString = "https://reddit.com" + submission.getPermalink(); OpenRedditLink.customIntentChooser( urlString, holder2.itemView.getContext()); } }); dialoglayout .findViewById(R.id.share) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (submission.isSelfPost()) Reddit.defaultShareText( "https://reddit.com" + submission.getPermalink(), holder2.itemView.getContext()); else { new BottomSheet.Builder(context) .title(R.string.submission_share_title) .grid() .sheet(R.menu.share_menu) .listener( new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case R.id.reddit_url: Reddit.defaultShareText( "https://reddit.com" + submission.getPermalink(), holder2.itemView.getContext()); break; case R.id.link_url: Reddit.defaultShareText( submission.getUrl(), holder2.itemView.getContext()); break; } } }) .show(); } } }); dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE); if (!Authentication.isLoggedIn || !Authentication.didOnline) { dialoglayout.findViewById(R.id.save).setVisibility(View.GONE); dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE); } title.setBackgroundColor(Palette.getColor(submission.getSubredditName())); builder.setView(dialoglayout); final Dialog d = builder.show(); if (!SettingValues.hideButton) { dialoglayout .findViewById(R.id.hide) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { final int pos = dataSet.posts.indexOf(submission); final Submission old = dataSet.posts.get(pos); dataSet.posts.remove(submission); notifyItemRemoved(pos); d.dismiss(); Hidden.setHidden(old); OfflineSubreddit.getSubreddit(dataSet.subreddit).hide(pos); Snackbar.make( listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG) .setAction( R.string.btn_undo, new View.OnClickListener() { @Override public void onClick(View v) { OfflineSubreddit.getSubreddit(dataSet.subreddit) .unhideLast(); dataSet.posts.add(pos, old); notifyItemInserted(pos); Hidden.undoHidden(old); } }) .show(); } }); } else { dialoglayout.findViewById(R.id.hide).setVisibility(View.GONE); } } return true; } }); new PopulateSubmissionViewHolder() .populateSubmissionViewHolder( holder, submission, context, false, false, dataSet.posts, listView, custom, !dataSet.stillShow, dataSet.subreddit.toLowerCase()); } if (holder2 instanceof SubmissionFooterViewHolder) { Handler handler = new Handler(); final Runnable r = new Runnable() { public void run() { notifyItemChanged( dataSet.posts.size() + 1); // the loading spinner to replaced by nomoreposts.xml } }; handler.post(r); } }
@Override public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int i) { if (holder2 instanceof SubmissionViewHolder) { final SubmissionViewHolder holder = (SubmissionViewHolder) holder2; final Submission submission = dataSet.posts.get(i); CreateCardView.resetColorCard(holder.itemView); CreateCardView.colorCard( submission.getSubredditName().toLowerCase(), holder.itemView, "nomatching", false); holder.itemView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View arg0) { DataShare.sharedSubreddit = dataSet.posts; if (Reddit.tabletUI && mContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { Intent i2 = new Intent(mContext, CommentsScreenPopup.class); i2.putExtra("page", i); (mContext).startActivity(i2); } else { Intent i2 = new Intent(mContext, CommentsScreen.class); i2.putExtra("page", i); ((Activity) mContext).startActivityForResult(i2, 2); } } }); new PopulateSubmissionViewHolder() .PopulateSubmissionViewHolder( holder, submission, mContext, false, false, dataSet.posts, listView, false); holder.itemView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { LayoutInflater inflater = ((Activity) mContext).getLayoutInflater(); final View dialoglayout = inflater.inflate(R.layout.postmenu, null); AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext); final TextView title = (TextView) dialoglayout.findViewById(R.id.title); title.setText(submission.getTitle()); ((TextView) dialoglayout.findViewById(R.id.userpopup)) .setText("/u/" + submission.getAuthor()); ((TextView) dialoglayout.findViewById(R.id.subpopup)) .setText("/r/" + submission.getSubredditName()); dialoglayout .findViewById(R.id.sidebar) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mContext, Profile.class); i.putExtra("profile", submission.getAuthor()); mContext.startActivity(i); } }); dialoglayout .findViewById(R.id.wiki) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mContext, SubredditView.class); i.putExtra("subreddit", submission.getSubredditName()); mContext.startActivity(i); } }); dialoglayout .findViewById(R.id.save) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (submission.isSaved()) { ((TextView) dialoglayout.findViewById(R.id.savedtext)) .setText(R.string.submission_save); } else { ((TextView) dialoglayout.findViewById(R.id.savedtext)) .setText(R.string.submission_post_saved); } new SubmissionAdapter.AsyncSave(holder.itemView).execute(submission); } }); if (submission.isSaved()) { ((TextView) dialoglayout.findViewById(R.id.savedtext)) .setText(R.string.submission_post_saved); } dialoglayout .findViewById(R.id.gild) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String urlString = "https://reddit.com" + submission.getPermalink(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setPackage( "com.android.chrome"); // Force open in chrome so it doesn't open back // in Slide try { mContext.startActivity(intent); } catch (ActivityNotFoundException ex) { intent.setPackage(null); mContext.startActivity(intent); } } }); dialoglayout .findViewById(R.id.share) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialogWrapper.Builder(mContext) .setTitle(R.string.submission_share_title) .setNegativeButton( R.string.submission_share_reddit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Reddit.defaultShareText( "http://reddit.com" + submission.getPermalink(), mContext); } }) .setPositiveButton( R.string.submission_share_content, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Reddit.defaultShareText(submission.getUrl(), mContext); } }) .show(); } }); if (!Authentication.isLoggedIn) { dialoglayout.findViewById(R.id.save).setVisibility(View.GONE); dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE); } title.setBackgroundColor(Pallete.getColor(submission.getSubredditName())); builder.setView(dialoglayout); final Dialog d = builder.show(); dialoglayout .findViewById(R.id.hide) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { final int pos = dataSet.posts.indexOf(submission); final Submission old = dataSet.posts.get(pos); dataSet.posts.remove(submission); notifyItemRemoved(pos); d.dismiss(); Hidden.setHidden(old); Snackbar.make( listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG) .setAction( R.string.btn_undo, new View.OnClickListener() { @Override public void onClick(View v) { dataSet.posts.add(pos, old); notifyItemInserted(pos); Hidden.undoHidden(old); } }) .show(); } }); return true; } }); int lastPosition = i; } }
@Override public void onCreate(Bundle savedInstance) { super.onCreate(savedInstance); boolean isAlternate; if (getIntent() != null && getIntent().hasExtra("secondary")) { subreddit = getIntent().getExtras().getString("secondary", "test"); isAlternate = true; } else { subreddit = ""; isAlternate = false; } subreddit = subreddit.toLowerCase(); applyColorTheme(subreddit); setContentView(R.layout.activity_settings_theme_card); int title = isAlternate ? R.string.settings_title_alternative_layout : R.string.settings_layout_default; setupAppBar(R.id.toolbar, title, true, true); final LinearLayout layout = (LinearLayout) findViewById(R.id.card); layout.removeAllViews(); layout.addView(CreateCardView.CreateView(layout, (!subreddit.isEmpty()), subreddit)); // View type// // Cards or List// final SwitchCompat cardmode = (SwitchCompat) findViewById(R.id.cardmode); cardmode.setChecked(CreateCardView.isCard(!subreddit.isEmpty())); final SwitchCompat middle = (SwitchCompat) findViewById(R.id.middlechk); if (cardmode.isChecked()) { middle.setAlpha(1f); middle.setChecked(CreateCardView.isMiddle(!subreddit.isEmpty())); middle.setClickable(true); } else { middle.setAlpha(0.5f); middle.setChecked(false); middle.setClickable(false); } cardmode.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (!isChecked) { layout.removeAllViews(); layout.addView( CreateCardView.setCardViewType( CreateCardView.CardEnum.LIST, layout, !subreddit.isEmpty(), subreddit)); } else { layout.removeAllViews(); layout.addView( CreateCardView.setCardViewType( CreateCardView.CardEnum.LARGE, layout, !subreddit.isEmpty(), subreddit)); } if (cardmode.isChecked()) { middle.setAlpha(1f); middle.setChecked(CreateCardView.isMiddle(!subreddit.isEmpty())); middle.setClickable(true); } else { middle.setAlpha(0.5f); middle.setChecked(false); middle.setClickable(false); } } }); middle.setChecked(CreateCardView.isMiddle(!subreddit.isEmpty())); middle.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { layout.removeAllViews(); layout.addView( CreateCardView.setMiddleCard(isChecked, layout, !subreddit.isEmpty(), subreddit)); } }); SwitchCompat hidebutton = (SwitchCompat) findViewById(R.id.hidebutton); layout.findViewById(R.id.hide).setVisibility(Reddit.hideButton ? View.VISIBLE : View.GONE); hidebutton.setChecked(Reddit.hideButton); hidebutton.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Reddit.hideButton = isChecked; layout .findViewById(R.id.hide) .setVisibility(Reddit.hideButton ? View.VISIBLE : View.GONE); SettingValues.prefs.edit().putBoolean("Hidebutton", isChecked).apply(); } }); // Link preview// // Big, Infobar, thumb only// final TextView infobar = (TextView) findViewById(R.id.infobar); infobar.setText( CreateCardView.getInfoBar(!subreddit.isEmpty()).toString().replace("_", " ").toLowerCase()); findViewById(R.id.infobar_click) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(EditCardsLayout.this, v); // Inflating the Popup using xml file popup.getMenu().add("Big Picture"); popup.getMenu().add("Big Picture Cropped"); popup.getMenu().add("Info Bar"); popup.getMenu().add("Thumbnail"); popup.getMenu().add("None"); // registering popup with OnMenuItemClickListener popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { layout.removeAllViews(); layout.addView( CreateCardView.setInfoBarVisible( SettingValues.InfoBar.valueOf( (item.getTitle().toString().replace(" ", "_").toUpperCase())), layout, !subreddit.isEmpty(), subreddit)); infobar.setText( CreateCardView.getInfoBar(!subreddit.isEmpty()) .toString() .replace("_", " ") .toLowerCase()); return true; } }); popup.show(); } }); // Actionbar// // Enable, collapse// final SwitchCompat actionbar = (SwitchCompat) findViewById(R.id.action); actionbar.setChecked(CreateCardView.isActionBar(!subreddit.isEmpty())); actionbar.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { layout.removeAllViews(); layout.addView( CreateCardView.setActionBarVisible( isChecked, layout, !subreddit.isEmpty(), subreddit)); } }); findViewById(R.id.reset) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences.Editor edit = SettingValues.prefs.edit(); edit.remove(subreddit + "actionBarVisible"); edit.remove(subreddit + "largeThumbnails"); edit.remove(subreddit + "defaultCardView"); edit.remove(subreddit + "NSFWPreviews"); edit.remove(subreddit + "infoBarType"); edit.apply(); layout.removeAllViews(); layout.addView(CreateCardView.CreateView(layout, !subreddit.isEmpty(), subreddit)); actionbar.setChecked(CreateCardView.isActionBar(!subreddit.isEmpty())); infobar.setText( CreateCardView.getInfoBar(!subreddit.isEmpty()) .toString() .replace("_", " ") .toLowerCase()); } }); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setTitle(""); getSupportActionBar().setDisplayHomeAsUpEnabled(true); /*todo findViewById(R.id.reset).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CreateCardView.setCardViewType(SettingValues.defaultCardView, layout, subreddit, subreddit); CreateCardView.setActionBarVisible(SettingValues.actionBarVisible, layout, subreddit, subreddit); CreateCardView.setInfoBarVisible(SettingValues.infoBar, layout, subreddit, subreddit); layout.removeAllViews(); layout.addView(CreateCardView.setLargeThumbnails(SettingValues.largeThumbnails, layout, subreddit, subreddit)); largeimage.setChecked(CreateCardView.isLarge(subreddit)); actionbar.setChecked(CreateCardView.isActionBar(subreddit)); infobar.setChecked(CreateCardView.isInfoBar(subreddit)); int chosen = list.indexOf(CreateCardView.getCardView(subreddit).getDisplayName()); sp.setSelection(chosen); } });*/ }
@Override public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int i) { if (holder2 instanceof SubmissionViewHolder) { final SubmissionViewHolder holder = (SubmissionViewHolder) holder2; final Submission submission = dataSet.posts.get(i); CreateCardView.resetColorCard(holder.itemView); CreateCardView.colorCard( submission.getSubredditName().toLowerCase(), holder.itemView, subreddit, custom); holder.itemView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View arg0) { if (dataSet.stillShow) { DataShare.sharedSubreddit = dataSet.posts; holder2.itemView.setAlpha(0.5f); if (Reddit.tabletUI && mContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { Intent i2 = new Intent(mContext, CommentsScreenPopup.class); i2.putExtra("page", holder2.getAdapterPosition()); (mContext).startActivity(i2); } else { Intent i2 = new Intent(mContext, CommentsScreen.class); i2.putExtra("page", holder2.getAdapterPosition()); (mContext).startActivity(i2); } } else { Snackbar.make( holder.itemView, "Please go online and refresh the subreddit to do that", Snackbar.LENGTH_SHORT) .show(); } } }); final boolean saved = submission.isSaved(); holder.itemView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (!dataSet.stillShow) { Snackbar.make( holder.itemView, "Please go online and refresh the subreddit to do that", Snackbar.LENGTH_SHORT) .show(); } else { LayoutInflater inflater = mContext.getLayoutInflater(); final View dialoglayout = inflater.inflate(R.layout.postmenu, null); AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext); final TextView title = (TextView) dialoglayout.findViewById(R.id.title); title.setText(submission.getTitle()); ((TextView) dialoglayout.findViewById(R.id.userpopup)) .setText("/u/" + submission.getAuthor()); ((TextView) dialoglayout.findViewById(R.id.subpopup)) .setText("/r/" + submission.getSubredditName()); dialoglayout .findViewById(R.id.sidebar) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mContext, Profile.class); i.putExtra("profile", submission.getAuthor()); mContext.startActivity(i); } }); dialoglayout .findViewById(R.id.wiki) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mContext, SubredditView.class); i.putExtra("subreddit", submission.getSubredditName()); mContext.startActivity(i); } }); dialoglayout .findViewById(R.id.save) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (saved) { ((TextView) dialoglayout.findViewById(R.id.savedtext)) .setText(R.string.submission_save); } else { ((TextView) dialoglayout.findViewById(R.id.savedtext)) .setText(R.string.submission_post_saved); } new AsyncSave(holder.itemView).execute(submission); } }); if (saved) { ((TextView) dialoglayout.findViewById(R.id.savedtext)) .setText(R.string.submission_post_saved); } dialoglayout .findViewById(R.id.gild) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String urlString = "https://reddit.com" + submission.getPermalink(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setPackage( "com.android.chrome"); // Force open in chrome so it doesn't open // back in Slide try { mContext.startActivity(intent); } catch (ActivityNotFoundException ex) { intent.setPackage(null); mContext.startActivity(intent); } } }); dialoglayout .findViewById(R.id.share) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (submission.isSelfPost()) Reddit.defaultShareText( "http://reddit.com" + submission.getPermalink(), mContext); else { new BottomSheet.Builder(mContext, R.style.BottomSheet_Dialog) .title(R.string.submission_share_title) .grid() .sheet(R.menu.share_menu) .listener( new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case R.id.reddit_url: Reddit.defaultShareText( "http://reddit.com" + submission.getPermalink(), mContext); break; case R.id.link_url: Reddit.defaultShareText( submission.getUrl(), mContext); break; } } }) .show(); } } }); dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE); if (!Authentication.isLoggedIn) { dialoglayout.findViewById(R.id.save).setVisibility(View.GONE); dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE); } title.setBackgroundColor(Pallete.getColor(submission.getSubredditName())); builder.setView(dialoglayout); final Dialog d = builder.show(); dialoglayout .findViewById(R.id.hide) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { final int pos = dataSet.posts.indexOf(submission); final Submission old = dataSet.posts.get(pos); dataSet.posts.remove(submission); notifyItemRemoved(pos); d.dismiss(); Hidden.setHidden(old); Snackbar.make( listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG) .setAction( R.string.btn_undo, new View.OnClickListener() { @Override public void onClick(View v) { dataSet.posts.add(pos, old); notifyItemInserted(pos); Hidden.undoHidden(old); } }) .show(); } }); } return true; } }); new PopulateSubmissionViewHolder() .PopulateSubmissionViewHolder( holder, submission, mContext, false, false, dataSet.posts, listView, custom, !dataSet.stillShow); holder.itemView.addOnLayoutChangeListener( new View.OnLayoutChangeListener() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void onLayoutChange( final View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { v.removeOnLayoutChangeListener(this); setAnimation(v, i); } }); } if (holder2 instanceof SubmissionFooterViewHolder) { Handler handler = new Handler(); final Runnable r = new Runnable() { public void run() { notifyItemChanged( dataSet.posts.size() + 1); // the loading spinner to replaced by nomoreposts.xml } }; handler.post(r); } views.add(holder2); }