使用滑行从Firebase存储(云Firestore,FirebaseUi)恢复图像

问题描述 投票:0回答:1

请引导我。我使用firestore的依赖项“ com.google.firebase:firebase-firestore”将数据保存在数据库中。然后,我使用FirebaseUi'com.firebaseui:firebase-ui-firestore使用Glide从Firebase存储检索图像,但是上下文存在问题。这是我的代码:正确的方法是什么?谢谢

public class TabAbonneAdapter extends FirestoreRecyclerAdapter<Usermodele,TabAbonneAdapter.HolderAbonne> {


    /**
     * Create a new RecyclerView adapter that listens to a Firestore Query.  See {@link
     * FirestoreRecyclerOptions} for configuration options.
     *
     * @param options
     */
    public TabAbonneAdapter(@NonNull FirestoreRecyclerOptions<Usermodele> options) {
        super(options);
        setHasStableIds(true);
    }

    @Override
    protected void onBindViewHolder(@NonNull HolderAbonne holder, final int position, @NonNull Usermodele model) {

        holder.userPseudo.setText(model.getPseudo());
        Date inscriptionInstance = model.getDateInscription();
        @SuppressLint("SimpleDateFormat")
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String dateinscrip = dateFormat.format(inscriptionInstance);
        Log.d("Date inscrption," ," = " + dateinscrip);
        holder.dateinscription.setText(dateinscrip);
        Glide.with(getContext)
                .load(model.getPhoto_url())
                .centerCrop()
                .placeholder(R.drawable.ic_aboneeprofil_avatar)
                .into(holder.userprofilImage);

    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {
        return position ;
    }



    @NonNull
    @Override
    public HolderAbonne onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_ajout,parent,false);

        return new HolderAbonne(view);
    }



    public class HolderAbonne extends RecyclerView.ViewHolder {
        ImageView userprofilImage;
        TextView  userPseudo,dateinscription;
        Button boutonAjouter;

        public HolderAbonne(@NonNull View itemView) {
            super(itemView);
           userprofilImage = (ImageView)itemView.findViewById(R.id.abonneprofilImage);
            userPseudo = (TextView)itemView.findViewById(R.id.AbonneName);
            dateinscription = (TextView)itemView.findViewById(R.id.dateinscription);
            boutonAjouter = (Button)itemView.findViewById(R.id.btnAjout);


        }

    }

}
android firebase google-cloud-firestore firebase-storage
1个回答
0
投票
Glide.with(holder.itemView.getContext()) // get context from view
.load(model.getPhoto_url())
.centerCrop()
.placeholder(R.drawable.ic_aboneeprofil_avatar)
.into(holder.userprofilImage);
© www.soinside.com 2019 - 2024. All rights reserved.