use of me.ccrama.redditslide.SubmissionViews.PopulateNewsViewHolder in project Slide by ccrama.
the class SubmissionNewsAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (holder2 instanceof NewsViewHolder) {
final NewsViewHolder holder = (NewsViewHolder) holder2;
final Submission submission = dataSet.posts.get(i);
CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, subreddit, (subreddit.equals("frontpage") || subreddit.equals("mod") || subreddit.equals("friends") || (subreddit.equals("all")) || subreddit.contains(".") || subreddit.contains("+")));
holder.itemView.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (Authentication.didOnline || submission.getComments() != null) {
holder.title.setAlpha(0.54f);
if (context instanceof MainActivity) {
final MainActivity a = (MainActivity) context;
if (a.singleMode && a.commentPager && a.adapter instanceof MainActivity.OverviewPagerAdapterComment) {
if (a.openingComments != submission) {
clicked = holder2.getAdapterPosition();
a.openingComments = submission;
a.toOpenComments = a.pager.getCurrentItem() + 1;
a.currentComment = holder.getAdapterPosition() - 1;
((MainActivity.OverviewPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
((MainActivity.OverviewPagerAdapterComment) (a).adapter).size = a.toOpenComments + 1;
try {
a.adapter.notifyDataSetChanged();
} catch (Exception ignored) {
}
}
a.pager.postDelayed(new Runnable() {
@Override
public void run() {
a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
}
}, 400);
} else {
Intent i2 = new Intent(context, CommentsScreen.class);
i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
i2.putExtra("fullname", submission.getFullName());
context.startActivityForResult(i2, 940);
clicked = holder2.getAdapterPosition();
}
} else if (context instanceof SubredditView) {
final SubredditView a = (SubredditView) context;
if (a.singleMode && a.commentPager) {
if (a.openingComments != submission) {
clicked = holder2.getAdapterPosition();
a.openingComments = submission;
a.currentComment = holder.getAdapterPosition() - 1;
((SubredditView.OverviewPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
((SubredditView.OverviewPagerAdapterComment) a.adapter).size = 3;
a.adapter.notifyDataSetChanged();
}
a.pager.postDelayed(new Runnable() {
@Override
public void run() {
a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
}
}, 400);
} else {
Intent i2 = new Intent(context, CommentsScreen.class);
i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
i2.putExtra("fullname", submission.getFullName());
context.startActivityForResult(i2, 940);
clicked = holder2.getAdapterPosition();
}
}
} else {
if (!Reddit.appRestart.contains("offlinepopup")) {
new AlertDialogWrapper.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.appRestart.edit().putString("offlinepopup", "").apply();
}
}).show();
} else {
Snackbar s = Snackbar.make(holder.itemView, R.string.cache_no_comments_found_snackbar, Snackbar.LENGTH_SHORT);
s.setAction(R.string.misc_more_info, new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialogWrapper.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.appRestart.edit().putString("offlinepopup", "").apply();
}
}).show();
}
});
View view = s.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
}
}
});
new PopulateNewsViewHolder().populateNewsViewHolder(holder, submission, context, false, false, dataSet.posts, listView, custom, dataSet.offline, dataSet.subreddit.toLowerCase(Locale.ENGLISH), null);
}
if (holder2 instanceof SubmissionFooterViewHolder) {
Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
notifyItemChanged(dataSet.posts.size() + // the loading spinner to replaced by nomoreposts.xml
1);
}
};
handler.post(r);
if (holder2.itemView.findViewById(R.id.reload) != null) {
holder2.itemView.findViewById(R.id.reload).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dataSet.loadMore(context, displayer, true);
}
});
}
}
if (holder2 instanceof SpacerViewHolder) {
View header = (context).findViewById(R.id.header);
int height = header.getHeight();
if (height == 0) {
header.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
height = header.getMeasuredHeight();
holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
layoutParams.setFullSpan(true);
holder2.itemView.setLayoutParams(layoutParams);
}
} else {
holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
layoutParams.setFullSpan(true);
holder2.itemView.setLayoutParams(layoutParams);
}
}
}
}
Aggregations