public int AddItem(PairedDevice sd, bool store) { if (sd.conFlag > 0) { int i = 0; foreach (PairedDevice device in GetAllItems().ToList()) { if (device.conFlag > 0) { device.conFlag = 0; UpdateItem(i, device, !store); } i++; } } var pIns = liMain.Count; liMain.Add(sd); NotifyItemInserted(pIns); if (store) { deviceHelper.liDevices.Add(sd.ToStoredDevice()); deviceHelper.Save(); } return(pIns); }
public void UpdateItem(int i, PairedDevice sd, bool store) { try { if (sd.conFlag > 0) { int c = 0; foreach (PairedDevice device in GetAllItems().ToList()) { if (i != c && device.conFlag > 0) { device.conFlag = 0; UpdateItem(c, device, false); } c++; } } if (sd.status != DEVICE_STAT_NONE) { if (i != lastItemExp && lastItemExp >= 0) { var a = liMain[lastItemExp]; a.status = DEVICE_STAT_NONE; liMain[lastItemExp] = a; NotifyItemChanged(lastItemExp); } lastItemExp = i; } liMain[i] = sd; if (store) { deviceHelper.liDevices[i] = sd.ToStoredDevice(); deviceHelper.Save(); } NotifyItemChanged(i); } catch (Exception e) { Toast.MakeText(Application.Context, $"Error: {e.Message}", ToastLength.Short).Show(); } }