0

Hello i want get by image from firestorage so I make custom adapter do my so I write this code and surf internet and read books but i can't get information... need help

package com.example.lazywarriorsapp;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;

import java.util.ArrayList;

public class CustomAdapterLw extends BaseAdapter {

    private ArrayList<CustomListItemsLw> customListItemsLwArrayList =
            new ArrayList<CustomListItemsLw>();

    public CustomAdapterLw() {
    }

    @Override
    public int getCount()
    {
        return customListItemsLwArrayList.size();
    }


    @Override
    public Object getItem(int position)
    {
        return customListItemsLwArrayList.get(position) ;
    }


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


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final int pos = position;
        final Context context = parent.getContext();
        String imageStr = "gs://lazywarriorsserver-6147a.appspot.com/";

        if(convertView == null)
        {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.custom_list_item_lw, parent, false);
        }

        ImageView imageView = (ImageView)convertView.findViewById(R.id.defaultImage); 
        TextView title = (TextView) convertView.findViewById(R.id.customlisttitle); 
        TextView dongeupmyen = (TextView) convertView.findViewById(R.id.dongeupmyen);
        TextView needpoint = (TextView) convertView.findViewById(R.id.needpoint);
        TextView date = (TextView) convertView.findViewById(R.id.date);

        title.setSingleLine(true);
        title.setEllipsize(TextUtils.TruncateAt.MARQUEE);
        title.setSelected(true);

        CustomListItemsLw customListItemsLw = customListItemsLwArrayList.get(position);

--------------------------------Here it is--------------------------------------
        imageView.setImageDrawable(customListItemsLw.getDefaultImage());
--------------------------------------------------------------------------------
        title.setText(customListItemsLw.getTitle());
        dongeupmyen.setText(customListItemsLw.getDongeupmyen());
        needpoint.setText(customListItemsLw.getNeedpoint());
        date.setText(customListItemsLw.getDate());

        return convertView;
    }

    public void addItem(Drawable imageView, String title, String dongeupmyen, String needpoint, String date)
    {
        CustomListItemsLw item = new CustomListItemsLw();

        item.setDefaultImage(imageView);
        item.setTitle(title);
        item.setDongeupmyen(dongeupmyen);
        item.setNeedpoint(needpoint);
        item.setDate(date);


        customListItemsLwArrayList.add(item);
    }



}

and i write this in main activity but error here

-------------------------------and here-------------------------------------------------
cadapter.addItem(pictiureUri + drawimagename),
----------------------------------------------------------------------------------------
        "" + snapshot.getData().get("title").toString()
                + "[" + snapshot.getData().get("joinperson").toString()
                + "/" + snapshot.getData().get("personalcount").toString() + "]",
        "" + snapshot.getData().get("dongeupmyen").toString(),
        "" + snapshot.getData().get("needpoint").toString() + "P",

        "" + simpleDateFormat.format(startDate) + " ~ " + simpleDateFormat.format(endDate) + "    "
                + snapshot.getData().get("week").toString() + "per/week");

that says addItem(android.graphics.drawable.Drawable, java.lang.String, java.lang.String, java.lang.String, java.lang.String)' in 'com.example so i try change another code and more

'addItem(android.graphics.drawable.Drawable, java.lang.String, java.lang.String, java.lang.String, java.lang.String)' in 'com.example.MyApp.CustomAdapterLw' cannot be applied to '(java.lang.String)'

i don't know how to get image from firestore by url...

1 Answers1

0

Check This Help you or not

 private void sendSelectedData(Uri fileUri) {


        if (!checker.equals("image")) {
            //for ther type
        } else if (checker.equals("image")) {

            uploadTask(fileUri);



            StorageReference storageReference = FirebaseStorage.getInstance().getReference().child("Image Files");
            DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("sender", s);
            hashMap.put("reciver", r);
            hashMap.put("message", "test");
            DatabaseReference userkey = reference.child("image_chat").child(s).child(r).push().push();

            String pushid = userkey.getKey();

            final StorageReference filerpath = storageReference.child(pushid + ".jpg");

            uploadTask = filerpath.putFile(fileUri);
            uploadTask.continueWithTask(new Continuation() {
                @Override
                public Object then(@NonNull Task task) throws Exception {
                    if (!task.isSuccessful()) {
                        throw task.getException();
                    }

                    return filerpath.getDownloadUrl();
                }
            }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                @Override
                public void onComplete(@NonNull Task<Uri> task) {
                    if (task.isSuccessful()) {
                        Uri downloadUri = task.getResult();
                        myUrl = downloadUri.toString();
                        DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
                        HashMap<String, Object> hashMap = new HashMap<>();
                        String type = "image";
                        hashMap.put("url", myUrl);
                        hashMap.put("type", type);
                        //reference.child("Chats").push().setValue(hashMap);
                        long id = Calendar.getInstance().getTimeInMillis();
                        hashMap.put("id",id);
                        dialog.dismiss();
                    }
                }
            });


        } else {
            Toast.makeText(this, "Nothing Selected", Toast.LENGTH_SHORT).show();
        }
    }