SHARE
TWEET

Untitled

a guest Jun 18th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. FirebaseRecyclerAdapter<Posts,PostsViewHolder> firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<Posts, PostsViewHolder>(options)
  2.     {
  3.         @Override
  4.         protected void onBindViewHolder(@NonNull final PostsViewHolder holder, int position, @NonNull final Posts model) {
  5.  
  6.             final String postKey=getRef(position).getKey();
  7.  
  8.             holder.itemView.setOnClickListener(new View.OnClickListener() {
  9.                 @Override
  10.                 public void onClick(View v) {
  11.                     Intent clickPostIntent=new Intent(MainActivity.this, ClickPostActivity.class);
  12.                     clickPostIntent.putExtra("postKey",postKey);
  13.                     startActivity(clickPostIntent);
  14.                 }
  15.             });
  16.  
  17.             holder.username.setText(model.getFullname());
  18.             holder.date.setText(model.getDate());
  19.             holder.time.setText(model.getTime());
  20.  
  21.             if (model.getPost_uri_link()!=null){
  22.                 holder.post_link.setText(model.getPost_uri_link());
  23.             }
  24.             else {
  25.                 holder.post_link.setVisibility(View.GONE);
  26.             }
  27.             if (model.getPost_file_name()!=null && model.getPost_file_uri()!=null) {
  28.                 holder.file_attach_name.setText(model.getPost_file_name());
  29.                 holder.file_attach_name.setOnClickListener(new View.OnClickListener() {
  30.                     @Override
  31.                     public void onClick(View v) {
  32.                         downloadFile(MainActivity.this,model.getPost_file_name(),"gs://studentcornerproject-be4c6.appspot.com/post files",model.getPost_file_uri());
  33.                     }
  34.                 });
  35.             }
  36.             else{
  37.                 holder.file_attach_name.setVisibility(View.GONE);
  38.             }
  39.  
  40.             if (model.getDescription()!=null) {
  41.                 holder.description.setText(model.getDescription());
  42.            }
  43.             else {
  44.                 holder.description.setVisibility(View.GONE);
  45.             }
  46.  
  47.             if (model.getPost_img()!=null) {
  48.                 Picasso.get().load(model.post_img).networkPolicy(NetworkPolicy.OFFLINE).placeholder(android.R.drawable.progress_indeterminate_horizontal).into(holder.post_img, new Callback() {
  49.                     @Override
  50.                     public void onSuccess() {
  51.  
  52.                         postRef.child("post_img").keepSynced(true);
  53.                     }
  54.  
  55.                     @Override
  56.                     public void onError(Exception e) {
  57.  
  58.                         Picasso.get().load(model.post_img).into(holder.post_img);
  59.                     }
  60.                 });
  61.             }
  62.             else {
  63.                 holder.post_img.setVisibility(View.GONE);
  64.             }
  65.             Picasso.get().load(model.getProfile_image()).networkPolicy(NetworkPolicy.OFFLINE).placeholder(R.drawable.profile_icon).into(holder.prof_img, new Callback() {
  66.                 @Override
  67.                 public void onSuccess() {
  68.  
  69.                 }
  70.  
  71.                 @Override
  72.                 public void onError(Exception e) {
  73.  
  74.                     Picasso.get().load(model.getProfile_image()).into(holder.prof_img);
  75.                 }
  76.             });
  77.         }
  78.  
  79.         @NonNull
  80.         @Override
  81.         public PostsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
  82.  
  83.             View view= LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.all_posts_users,viewGroup,false);
  84.             PostsViewHolder viewHolder=new PostsViewHolder(view);
  85.             return viewHolder;
  86.  
  87.         }
  88.     };
  89.     postslist.setAdapter(firebaseRecyclerAdapter);
  90.     firebaseRecyclerAdapter.startListening();
  91. }
  92.  
  93. public static class PostsViewHolder extends RecyclerView.ViewHolder
  94. {
  95.  
  96.    TextView username,date,time,description,file_attach_name,post_link;
  97.     CircleImageView prof_img;
  98.     ImageView post_img;
  99.  
  100.     public PostsViewHolder(@NonNull View itemView) {
  101.         super(itemView);
  102.         post_link=itemView.findViewById(R.id.post_link);
  103.         username=itemView.findViewById(R.id.post_user_name);
  104.         date=itemView.findViewById(R.id.post_date);
  105.         time=itemView.findViewById(R.id.post_time);
  106.         description=itemView.findViewById(R.id.post_description);
  107.         file_attach_name=itemView.findViewById(R.id.post_filename);
  108.         prof_img=itemView.findViewById(R.id.post_profile_img);
  109.         post_img=itemView.findViewById(R.id.post_image);
  110.  
  111.  
  112.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top