Install-Package Xamarin.Firebase.UI.Storage -Version 6.3.0
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
FirebaseStorage storage = FirebaseStorage.Instance;
StorageReference storageRef = storage.GetReferenceFromUrl("gs://<your-firebase-storage-bucket>");
FirebaseRecyclerOptions<ImageModel> options = new FirebaseRecyclerOptions.Builder<ImageModel>()
.SetQuery(storageRef, ImageModel.Deserializer)
.Build();
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<ImageModel, ImageViewHolder>(options)
{
@Override
public ImageViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
View view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.image_item, parent, false);
return new ImageViewHolder(view);
}
@Override
protected void OnBindViewHolder(ImageViewHolder holder, int position, ImageModel model)
{
holder.Name.Text = model.Name;
Glide.With(holder.ItemView.Context)
.Load(model.ImageUrl)
.Into(holder.Image);
}
};
RecyclerView recyclerView = FindViewById<RecyclerView>(Resource.Id.recycler_view);
recyclerView.SetLayoutManager(new LinearLayoutManager(this));
recyclerView.SetAdapter(adapter);
public class ImageModel
{
public static ImageModel Deserializer(DataSnapshot snapshot)
{
ImageModel imageModel = new ImageModel();
imageModel.Name = snapshot.Key;
imageModel.ImageUrl = snapshot.GetValue(JsonElement.class).GetAsString();
return imageModel;
}
public string Name { get; set; }
public string ImageUrl { get; set; }
}
僅供參考