using Android.Content;
using Android.Gms.Tasks;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Firebase.Firestore;
using System;
using System.Collections.Generic;
namespace RunAndEarn
{
internal class ScoreAdapter : BaseAdapter<Score>
{
private Context context;
private List<Score> lstScores;
private FbData fbData;
private Task tskGetScores;
/// <summary>
/// הפעולה מייצרת עצם מסוג סקור אדפטר
/// </summary>
/// <param name="context">המסך בו יש אתהליסט וויו</param>
public ScoreAdapter(Context context)
{
this.context = context;
lstScores= new List<Score>();
lstScores.Add(new Score(0,"Please Wait For The Leaderboard to Set Up"));
fbData= new FbData();
tskGetScores = fbData.GetDocument("LeaderBoard", "Records");
tskGetScores.AddOnCompleteListener((LeaderboardActivity)context);
}
public override Score this[int position] => lstScores[position];
public override int Count => lstScores.Count;
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
LayoutInflater li = ((LeaderboardActivity)context).LayoutInflater;
View view = li.Inflate(Resource.Layout.layout_score, parent, false);
TextView tvName = view.FindViewById<TextView>(Resource.Id.tvName);
TextView tvScore = view.FindViewById<TextView>(Resource.Id.tvScore);
Score score = lstScores[position];
tvName.Text = score.Username;
tvScore.Text = score.UserScore.ToString();
return view;
}
/// <summary>
/// הפעולה מעדכנת את טבלת השיאים
/// </summary>
public void SetLeaderboard() => NotifyDataSetChanged();
/// <summary>
/// הפעולה מוסיפה ציון לרשימת השיאים
/// </summary>
/// <param name="score">הציון שנכנס לרשימה</param>
public void Add(Score score)=> lstScores.Add(score);
/// <summary>
/// הפעולה מנקה את הרשימה
/// </summary>
public void ClearList()=>lstScores.Clear();
}
}