About WebView in RecyclerView? - android

I use the WebView in the first item of RecyclerView, webview load the url include image or video, when i click the image or the video, recyclerview will scroll to the top and webview will continue to load, video will play, how i resolve it?
some code:
public class NewsDetailAdapter extends PageRecyclerAdapter<NewsDetailInfo, ViewHolder> {
private static final boolean DEBUG = true;
public static final int VIEW_TYPE_WEB = 1;
public static final int VIEW_TYPE_COMMENT_TITLE = 2;
public static final int VIEW_TYPE_COMMENT = 3;
private XWebView mWebView;
private OnItemClickListener mItemClickListener;
public NewsDetailAdapter(Context context, XWebView webView, List<NewsDetailInfo> data, OnItemClickListener listener, OnErrorClickListener errorListener) {
super(context, data, errorListener);
mWebView = webView;
mItemClickListener = listener;
}
#Override
public int getListItemViewType(int position) {
return getItem(position).itemType;
}
#Override
public ViewHolder onCreateHolder(LayoutInflater inflater, ViewGroup parent,
int viewType) {
switch (viewType) {
case VIEW_TYPE_WEB:
return new WebViewHolder(inflater.inflate(R.layout.layout_webview, parent, false));
case VIEW_TYPE_COMMENT_TITLE:
return new SimpleTextHolder(inflater.inflate(R.layout.layout_comment_title, parent, false));
case VIEW_TYPE_COMMENT:
return new ListItemHolder(inflater.inflate(R.layout.list_item_comment, parent, false));
}
return null;
}
#Override
public void onBindHolder(ViewHolder viewHolder, final int position) {
if (viewHolder instanceof SimpleTextHolder) {
SimpleTextHolder holder = (SimpleTextHolder) viewHolder;
holder.mText.setText(getItem(position).text);
} else if (viewHolder instanceof ListItemHolder) {
ListItemHolder holder = (ListItemHolder) viewHolder;
holder.mUsername.setText(TextUtils.isEmpty(getItem(position).user.username) ? "匿名" : getItem(position).user.username);
holder.mCommentContent.setText(getItem(position).content);
holder.mPublishTime.setText(TimeUtils.parseToHumnanizeTime(getItem(position).publishTime));
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mItemClickListener != null) {
mItemClickListener.onItemClick(getItem(position));
}
}
});
}
}
class WebViewHolder extends ViewHolder {
public WebViewHolder(View itemView) {
super(itemView);
FrameLayout frameLayout = (FrameLayout) itemView.findViewById(R.id.web_view_container);
frameLayout.addView(mWebView);
**itemView.requestFocus();** // add this code will resolve it;
}
}
class SimpleTextHolder extends ViewHolder {
TextView mText;
public SimpleTextHolder(View itemView) {
super(itemView);
mText = (TextView) itemView.findViewById(R.id.title);
}
}
class ListItemHolder extends ViewHolder {
ImageView mImageView;
TextView mUsername;
TextView mCommentContent;
TextView mPublishTime;
public ListItemHolder(View itemView) {
super(itemView);
mImageView = (ImageView) itemView.findViewById(R.id.portrait);
mUsername = (TextView) itemView.findViewById(R.id.username);
mCommentContent = (TextView) itemView.findViewById(R.id.comment_content);
mPublishTime = (TextView) itemView.findViewById(R.id.publish_time);
}
}
public interface OnItemClickListener {
void onItemClick(NewsDetailInfo info);
}
}

Related

How to implement alphabetical Section RecyclerView in android without any external library?

Hello all am new for android development am trying to make section recyclerview header like items must comes under first charc how can i achieve this so far i have done this with third party library now i like to do it myself please someone help me how to do this here what i have tried before:
public class accountheader extends StatelessSection implements View.OnClickListener{
private accountheader.OnItemClickListener onItemClickListener;
String title;
List<AccountModel> listobj;
Context context;
public accountheader(String title, List<AccountModel> list, Context context) {
super(R.layout.section_ex1_header, R.layout.recyclerviewitem);
this.title = title;
this.listobj = list;
this.context=context;
}
public void setOnItemClickListener(final accountheader.OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}
#Override
public int getContentItemsTotal() {
return listobj.size();
}
#Override
public RecyclerView.ViewHolder getItemViewHolder(View view) {
return new ItemViewHolder(view);
}
#Override
public void onBindItemViewHolder(RecyclerView.ViewHolder holder, final int position) {
final ItemViewHolder viewHolder = (ItemViewHolder) holder;
TextView companyname=viewHolder.CompanyName;
TextView companygroup=viewHolder.CompanyGroup;
TextView acm=viewHolder.AccountManager;
TextView companytype=viewHolder.CompanyType;
ImageView caption=viewHolder.caption;
viewHolder.click.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent(context, AccountView.class);
int name=listobj.get(position).getId();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.d("n",String.valueOf(name));
context.startActivity(intent);
}
});
companyname.setText(listobj.get(position).getCompanyName());
companygroup.setText(listobj.get(position).getCompanyGroup());
acm.setText(listobj.get(position).getAccountManagerText());
ColorGenerator generator = ColorGenerator.DEFAULT;
TextDrawable drawable = TextDrawable.builder()
.buildRound((listobj.get(position).getCompanyName().substring(0,1)).toUpperCase(), generator.getRandomColor());
viewHolder.caption.setImageDrawable(drawable);
}
#Override
public RecyclerView.ViewHolder getHeaderViewHolder(View view) {
return new HeaderViewHolder(view);
}
#Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) {
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
headerHolder.tvTitle.setText(title);
}
#Override
public void onClick(View v) {
final RecyclerView recyclerView = (RecyclerView) v.getParent();
int position = recyclerView.getChildLayoutPosition(v);
if (position != RecyclerView.NO_POSITION) {
this.onItemClickListener.onItemClicked(position);
}
}
public interface OnItemClickListener {
void onItemClicked(int position);
}
}
class HeaderViewHolder extends RecyclerView.ViewHolder {
final TextView tvTitle;
public HeaderViewHolder(View view) {
super(view);
tvTitle = (TextView) view.findViewById(R.id.tvTitle);
}
}
class ItemViewHolder extends RecyclerView.ViewHolder {
View click;
TextView CompanyName;
TextView CompanyGroup;
TextView AccountManager;
TextView CompanyType;
ImageView caption;
ItemViewHolder(View itemView) {
super(itemView);
click=itemView;
CompanyName=(TextView)itemView.findViewById(R.id.header);
CompanyGroup=(TextView)itemView.findViewById(R.id.middle);
AccountManager=(TextView)itemView.findViewById(R.id.footer);
CompanyType=(TextView)itemView.findViewById(R.id.status);
caption=(ImageView)itemView.findViewById(R.id.imageView);
}
}
This is how i implemented in activity:
SectionedRecyclerViewAdapter sectionAdapter = new SectionedRecyclerViewAdapter();
accountheader Accountheader=null;
for(char alphabet = 'A'; alphabet <= 'Z';alphabet++) {
List<AccountModel> contacts = getContactsWithLetter(alphabet,list);
Accountheader=new accountheader(String.valueOf(alphabet), contacts,getApplicationContext());
if (contacts.size() > 0) {
sectionAdapter.addSection(Accountheader);
}
}
recyclerView.setAdapter(sectionAdapter);
private List<AccountModel> getContactsWithLetter(char letter,List<AccountModel>list) {
List<AccountModel> contacts = new ArrayList<>();
for (AccountModel accountModel:list) {
if (accountModel.getCompanyGroup().charAt(0) == letter) {
contacts.add(accountModel);
}
}
return contacts;
}
How can i achieve this without any third party library can someone please guide me:

Send data from CardView in RecyclerView to new fragment?

So I have a CardView in a RecyclerView which has some data inside it. I would like to click on a specific card and launch a new fragment that displays specific data from the data in the CardView (more details about the data in the CardView). Here is the relevant code.
I don't have the most experience in programming and Android in general, any help would be appreciated!
DetailsFragment: `
public class DetailsFragment extends Fragment {
private CardView cardView;
private RecyclerView rv;
private List<Detail> detailList = new ArrayList<>();
public DetailsFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_details, container, false);
Context context = getActivity();
cardView = (CardView) rootView.findViewById(R.id.cv);
rv = (RecyclerView) rootView.findViewById(R.id.rv);
final LinearLayoutManager llm = new LinearLayoutManager(context);
rv.setLayoutManager(llm);
RVDetailAdapter adapter = new RVDetailAdapter(detailList);
rv.setAdapter(adapter);
initializeData();
initializeAdapter();
return rootView;
}
private void initializeData() {
detailList = new ArrayList<>();
// not sure here
detailList.add(new Detail(" "));
}
private void initializeAdapter(){
RVDetailAdapter adapter = new RVDetailAdapter(detailList);
rv.setAdapter(adapter);
}
}
RVNewsAdapater:
public class RVNewsAdapter extends RecyclerView.Adapter<RVNewsAdapter.NewsViewHolder> {
public static final String KEY_LINK ="link";
public static class NewsViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
private static final String TAG = "Hello";
CardView cv;
TextView date;
TextView link;
TextView title;
TextView today;
public NewsViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.cv);
date = (TextView) itemView.findViewById(R.id.date);
link = (TextView) itemView.findViewById(R.id.link);
title = (TextView) itemView.findViewById(R.id.heading);
today = (TextView) itemView.findViewById(R.id.today);
itemView.setOnClickListener(this);
}
#Override
public void onClick(View view) {
Context context = view.getContext();
Intent intent = null;
for(int postion = 0; postion<42; postion++) {
intent = new Intent(context, Details.class);
}
context.startActivity(intent);
}
}
List<News> news;
RVNewsAdapter(List<News> news) {
this.news = news;
}
#Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
#Override
public RVNewsAdapter.NewsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.itemnewsfeed, viewGroup, false);
NewsViewHolder nvh = new NewsViewHolder(v);
return nvh;
}
#Override
public void onBindViewHolder(NewsViewHolder newsViewHolder, int i) {
newsViewHolder.date.setText(news.get(i).date);
newsViewHolder.link.setText(news.get(i).link);
newsViewHolder.title.setText(news.get(i).title);
newsViewHolder.today.setText(news.get(i).today);
}
#Override
public int getItemCount() {
if (news != null) {
return news.size();
}
return 0;
}
}
RVDetailAdapter:
public class RVDetailAdapter extends RecyclerView.Adapter<RVDetailAdapter.DetailViewHolder> {
public static class DetailViewHolder extends RecyclerView.ViewHolder {
TextView link;
public DetailViewHolder(View itemView) {
super(itemView);
link = (TextView) itemView.findViewById(R.id.link);
}
}
List<Detail> detail;
RVDetailAdapter(List<Detail> detail) {
this.detail = detail;
}
#Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
#Override
public RVDetailAdapter.DetailViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.itemnewsfeed, viewGroup, false);
DetailViewHolder dvh = new DetailViewHolder(v);
return dvh;
}
#Override
public void onBindViewHolder(DetailViewHolder detailViewHolder, int i) {
detailViewHolder.link.setText(detail.get(i).link);
}
#Override
public int getItemCount() {
if (detail != null) {
return detail.size();
}
return 0;
}
}
Not sure if you're still looking for an answer, but I just saw the post and thought I'd give you one option.
When I'm using a RecyclerView (doesn't matter if it's using the CardView or not, it's the same for any list item), I create a a click listener for the view item in the Adapter. When the user clicks the item/cardview, I dispatch an item click event. It's your choice on how you respond - you can use a standard callback interface (and pass in your listener when you create the adapter) or use something like EventBus.
Here's an example of the code you would add to your adapter class:
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(itemLayout, parent, false);
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
itemClick(view);
}
});
return new ViewHolder(view);
}
private void itemClick(View view) {
//Handle item event here
//EventBus.getDefault().post(new ItemSelectedEvent(/*send apprpopriate data*/));
}

Picasso in recyclerview can not auto refresh the display when complete load?

i use picasso to display an image in recyclerview, but it won't auto refresh the item when load image complete, i have to manually scroll to make the image be displayed. What have i do to fix it, to make the item of recyclerview auto update the display when completed load?
this is my adapter class :
public class LocationListRecyclerViewAdapter extends RecyclerView
.Adapter<LocationListRecyclerViewAdapter
.DataObjectHolder> {
private static String LOG_TAG = "LocationListRecyclerViewAdapter";
private ArrayList<LocationObject> mDataset;
private static MyClickListener myClickListener;
private Context mContext;
static String imageUrls;
public static String[] thumbnailUrl;
private LayoutInflater inflater;
public LocationListRecyclerViewAdapter(Context context, ArrayList<LocationObject> mDataset) {
this.mContext = context;
this.mDataset = mDataset;
}
public static class DataObjectHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView locName;
TextView locAddress;
TextView locDistance;
RoundedImageView roundedImageView;
public DataObjectHolder(View itemView) {
super(itemView);
this.locName = (TextView) itemView.findViewById(R.id.location_name);
this.locAddress = (TextView) itemView.findViewById(R.id.location_address);
this.locDistance = (TextView) itemView.findViewById(R.id.location_distance);
this.roundedImageView = (RoundedImageView) itemView.findViewById(R.id.thumbnail_location);
Log.i(LOG_TAG, "Adding Listener");
itemView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
myClickListener.onItemClick(getAdapterPosition(), v);
}
}
public void setOnItemClickListener(MyClickListener myClickListener) {
this.myClickListener = myClickListener;
}
public LocationListRecyclerViewAdapter(ArrayList<LocationObject> myDataset) {
mDataset = myDataset;
}
#Override
public DataObjectHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.location_listcard_item, parent, false);
this.mContext = parent.getContext();
thumbnailUrl = new String[10];
TextView locName = (TextView) view.findViewById(R.id.location_name);
TextView locAddress = (TextView) view.findViewById(R.id.location_address);
TextView locDistance = (TextView) view.findViewById(R.id.location_distance);
Typeface helvetica = Typeface.createFromAsset(parent.getContext().getApplicationContext().getAssets(),"fonts/Helvetica.otf");
locName.setTypeface(helvetica);
locAddress.setTypeface(helvetica);
locDistance.setTypeface(helvetica);
DataObjectHolder dataObjectHolder = new DataObjectHolder(view);
return dataObjectHolder;
}
> #Override
> public void onBindViewHolder(DataObjectHolder holder, int position) {
LocationObject item = mDataset.get(position);
holder.locName.setText(mDataset.get(position).getLocationName());
holder.locAddress.setText(mDataset.get(position).getLocationAddress());
holder.locDistance.setText(String.valueOf(mDataset.get(position).getLocationDistance())+"m");
Log.i(position+" photos"," = "+mDataset.get(position).getLocationPhoto());
//mContext
Picasso.with(holder.roundedImageView.getContext()).cancelRequest(holder.roundedImageView);
Picasso.with(holder.roundedImageView.getContext())
.load(mDataset.get(position).getLocationPhoto())
.error(R.drawable.placeholder)
.placeholder(R.drawable.placeholder)
.resize(200,200)
.into(holder.roundedImageView);
holder.itemView.setTag(item);
}
public void addItem(LocationObject dataObj, int index) {
mDataset.add(index, dataObj);
notifyItemInserted(index);
}
public void deleteItem(int index) {
mDataset.remove(index);
notifyItemRemoved(index);
}
#Override
public int getItemCount() {
return mDataset.size();
}
public interface MyClickListener {
public void onItemClick(int position, View v);
}
}
Let Picasso do its job, you do not need to interfere in the download process, the library itself knows when to cancel the request if necessary.
Always helpful before you use the library, carefully explore all of its fine points of using.
http://square.github.io/picasso/
#Override
public void onBindViewHolder(DataObjectHolder holder, int position) {
LocationObject item = mDataset.get(position);
holder.locName.setText(item.getLocationName());
holder.locAddress.setText(item.getLocationAddress());
holder.locDistance.setText(String.valueOf(item.getLocationDistance())+" m");
Picasso.with(mContext)
.load(item.getLocationPhoto())
.placeholder(R.drawable.placeholder)
.resize(200,200)
.centerCrop()
.into(holder.roundedImageView);
}

How to access rating bar's rating in recyclerview

I am using card view and recycler view with footer.
It is survey form with textview showing questions and ratingbar.
There will be more than one questions and footer will have textarea and submit button.
I tried to get the rating bar's rating on click of submit button but I am getting the rating of the last cardview of the recyclerview.
Below is the code I am using to get the ratings.
submitResponse() method is called on click of submit button and I am writing the code to get the rating's of all the cardview in it.
public class SurveyDetailsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int FOOTER_VIEW = 1;
static List<SurveyQuestions> surveyQuestionses= new ArrayList<>();
public static Activity ctx;
public static ScheduleData scheduleData;
public static SurveyDetailsViewHolder vh;
public SurveyDetailsAdapter(List<SurveyQuestions> surveyQuestionses,Activity ctx,ScheduleData scheduleData) {
this.surveyQuestionses = surveyQuestionses;
this.ctx=ctx;
this.scheduleData=scheduleData;
}
#Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v;
if (viewType == FOOTER_VIEW) {
v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_footer, parent, false);
FooterViewHolder vh = new FooterViewHolder(v);
return vh;
}
v = LayoutInflater.from(parent.getContext()).inflate(R.layout.survey_details_view_layout, parent, false);
SurveyDetailsViewHolder pvh = new SurveyDetailsViewHolder(v);
return pvh;
}
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
// holder.time.setText(String.valueOf(scheduleData.get(position).starttime+"-"+String.valueOf(scheduleData.get(position).endtime)));
// holder.title.setText(String.valueOf(scheduleData.get(position).title));
// holder.date.setText(String.valueOf(scheduleData.get(position).date));
try {
if (holder instanceof SurveyDetailsViewHolder) {
vh = (SurveyDetailsViewHolder) holder;
vh.question.setText(surveyQuestionses.get(position).question);
// vh.bindView(position);
} else if (holder instanceof FooterViewHolder) {
FooterViewHolder vh = (FooterViewHolder) holder;
}
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public int getItemCount() {
if (surveyQuestionses == null) {
return 0;
}
if (surveyQuestionses.size() == 0) {
return 1;
}
return surveyQuestionses.size()+1;
}
// Now define getItemViewType of your own.
#Override
public int getItemViewType(int position) {
if (position ==surveyQuestionses.size()) {
// This is where we'll add footer.
return FOOTER_VIEW;
}
return super.getItemViewType(position);
}
#Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public class FooterViewHolder extends RecyclerView.ViewHolder {
EditText comments;
MainActivity mainActivity = (MainActivity) ctx;
public FooterViewHolder(final View itemView) {
super(itemView);
itemView.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Do whatever you want on clicking the item
submitResponse();
Toast.makeText(mainActivity.getApplicationContext(),"Thank you.", Toast.LENGTH_SHORT).show();
mainActivity.switchContent(Surveys.FRAGMENT_TAG);
}
});
}
public void submitResponse(){
comments=(EditText)itemView.findViewById(R.id.comments);
List<String> rat= new ArrayList<String>();
for(int i=0;i<surveyQuestionses.size();i++){
rat.add(String.valueOf(SurveyDetailsViewHolder.ratingBar.getRating()));
}
for(int j=0;j<rat.size();j++){
Toast.makeText(mainActivity.getApplicationContext(),rat.get(0).toString()+rat.get(1).toString()+rat.get(2).toString(), Toast.LENGTH_SHORT).show();
}
}
}
// So you're done with adding a footer and its action on onClick.
// Now set the default ViewHolder for NormalViewHolder
public static class SurveyDetailsViewHolder extends RecyclerView.ViewHolder {
public static CardView cv;
TextView question;
public static RatingBar ratingBar;
SurveyDetailsViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.card_view_layout);
question = (TextView) itemView.findViewById(R.id.que1);
ratingBar = (RatingBar) itemView.findViewById(R.id.ratingBar);
}
}
}
You have SurveyQuestion POJO. Add your POJO new field , you can call it rating
public class SurveyQuestion {
public float rating = 0.0f; //this will be default value, if user has not rate, this value will be passed
// Your other variabes, constructors etc.
}
Then, you need to listen your rating bar changes on your RecyclerView Adapter
public static class SurveyDetailsViewHolder extends RecyclerView.ViewHolder {
public static CardView cv;
TextView question;
public static RatingBar ratingBar;
SurveyDetailsViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.card_view_layout);
question = (TextView) itemView.findViewById(R.id.que1);
ratingBar = (RatingBar) itemView.findViewById(R.id.ratingBar);
ratingBar .setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
#Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
surveyQuestionses.get(getPosition()).rating = ratingBar.getRating();
}
});
}
}
Lastly on your submitResponse() method you can access your ratings from your surveyQuestionses list.
public void submitResponse(){
comments=(EditText)itemView.findViewById(R.id.comments);
List<String> rat= new ArrayList<String>();
for(int i=0;i<surveyQuestionses.size();i++){
rat.add(String.valueOf(surveyQuestionses.rating));
}
}

Recycler View creating duplicate items

I am using Recycler View for creating a list of items and I am getting a duplicate items in the list. I have passed a list of 30 size into the Recycler View Adapter. The created list has 30 items but there are only 3 unique items, all other are repetition of 3 unique items. I am not able to find the bug.
public class CollectionAdapter extends RecyclerView.Adapter<CollectionAdapter.CollectionViewHolder> {
private List<CollectionDataTypeModel> mDataSet = new ArrayList<CollectionDataTypeModel>();
private Activity mActivity;
private String mType;
public CollectionAdapter(List<CollectionDataTypeModel> mDataSet, Activity activity, String type) {
this.mActivity = activity;
this.mDataSet = mDataSet;
this.mType = type;
}
#Override
public CollectionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.collection_cardview_layout, parent, false);
CollectionViewHolder vh = new CollectionViewHolder(v);
return vh;
}
#Override
public void onBindViewHolder(final CollectionViewHolder holder, int position) {
final CollectionDataTypeModel collectionData = mDataSet.get(position);
Log.d("Colelction Adapter","name : "+collectionData.getCollectionName());
holder.titleText.setText(collectionData.getCollectionName()+"");
holder.secondaryText.setText(collectionData.getPoiCount()+" attractions");
if (mType.equalsIgnoreCase("Collection")) {
Glide.with(mActivity).load(R.drawable.aman).asBitmap().centerCrop().into(new BitmapImageViewTarget(holder.profileImage) {
#Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mActivity.getResources(), resource);
circularBitmapDrawable.setCircular(true);
holder.profileImage.setImageDrawable(circularBitmapDrawable);
}
});
} else if (mType.equalsIgnoreCase("Destination")) {
holder.profileImageRipple.setVisibility(View.GONE);
} else if (mType.equalsIgnoreCase("Download")) {
holder.profileImageRipple.setVisibility(View.GONE);
holder.viewIcon.setImageResource(R.drawable.clear_icon);
holder.viewCount.setVisibility(View.INVISIBLE);
}
// holder.collectionImage.setImageResource(R.drawable.goldentemple);
Glide.with(mActivity).load(collectionData.getCollectionImage()).into(holder.collectionImage);
holder.likeCount.setText(Integer.toString(collectionData.getLikeCount()));
holder.viewCount.setText(Integer.toString(collectionData.getViewCount()));
holder.likeIconRipple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
#Override
public void onComplete(RippleView rippleView) {
// if(holder.likeIcon.getDrawable()==mActivity.getDrawable(R.drawable.like_icon))
{
holder.likeIcon.setImageResource(R.drawable.like_fill_icon);
}
// else
{
// holder.likeIcon.setImageResource(R.drawable.like_icon);
}
}
});
holder.collectionImageRipple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
#Override
public void onComplete(RippleView rippleView) {
EventBus.getDefault().post(new CollectionMessageEvent(collectionData));
}
});
}
#Override
public int getItemCount() {
return mDataSet.size();
}
#Override
public long getItemId(int position) {
return super.getItemId(position);
}
public static class CollectionViewHolder extends RecyclerView.ViewHolder {
TextView titleText;
ImageView collectionImage;
TextView secondaryText;
TextView likeCount;
TextView viewCount;
ImageView profileImage;
ImageView viewIcon;
RippleView collectionImageRipple;
RippleView profileImageRipple;
RippleView likeIconRipple;
ImageView likeIcon;
public CollectionViewHolder(View itemView) {
super(itemView);
// View bottombar = findById(itemView,R.id.bottomBar);
collectionImage = findById(itemView, R.id.collection_image);
collectionImageRipple = findById(itemView, R.id.collection_image_ripple);
profileImage = findById(itemView, R.id.profileimage);
profileImageRipple = findById(itemView, R.id.profileimage_ripple);
titleText = findById(itemView, R.id.title_text);
secondaryText = findById(itemView, R.id.secondary_text);
likeCount = findById(itemView, R.id.like_count);
likeIcon = findById(itemView, R.id.like_icon);
likeIconRipple = findById(itemView, R.id.like_icon_ripple);
viewCount = findById(itemView, R.id.view_count);
viewIcon = findById(itemView, R.id.view_icon);
}
}
}

Categories

Resources