public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { // Inflate the CardView for the photo: View itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.scripts_list_item, parent, false); // Create a ViewHolder to hold view references inside the CardView: ScriptListItemViewHolder scriptListItemViewHolder = new ScriptListItemViewHolder(itemView, OnClick); return(scriptListItemViewHolder); }
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) { ScriptListItemViewHolder scriptListItemViewHolder = holder as ScriptListItemViewHolder; lock (DatabaseContext.DbLocker) { using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase)) { ScriptModel script = db.Scripts.Skip(position).Include(x => x.TriggerPort).ThenInclude(x => x.Hardware).FirstOrDefault(); scriptListItemViewHolder.ScriptId = script.Id; // scriptListItemViewHolder.Name.Text = script.Name; if (script.TriggerPort != null) { scriptListItemViewHolder.Name.Text += $" (tg: {script.TriggerPort.Hardware.Name} > {script.TriggerPort} > {(script.TriggerPortState == true ? "ON" : (script.TriggerPortState == false ? "OFF" : "Switch"))})"; } } } }