public async Task Reload(Context context = null) { if (context == null) { context = Context; } ProgressAlert alert = new ProgressAlert("Refreshing scrobbles", "Please wait...", context); alert.Show(); if (SourceUser != null) { ReythScrobbles.Clear(); var res = await client.User.GetRecentScrobbles(SourceUser, null, 1, 100); if (res.Success) { ReythScrobbles.AddRange(res); } } if (client.Auth.UserSession != null) { var userRes = await client.User.GetRecentScrobbles(client.Auth.UserSession.Username, null, 1, 100); GinaScrobbles.Clear(); if (userRes.Success) { GinaScrobbles.AddRange(userRes); } } if (ReythAdapter == null) { ReythAdapter = new ScrobbleListAdapter(ReythScrobbles.ToArray(), (e, a) => { var vh = a.View.Tag as ScrobbleListAdapterViewHolder; vh.ChangeChecked(); }); } else { ReythAdapter.SetItems(ReythScrobbles); } if (GinaAdapter == null) { GinaAdapter = new ScrobbleListAdapter(GinaScrobbles.ToArray()); } else { GinaAdapter.SetItems(GinaScrobbles); } alert.Hide(); if (string.IsNullOrEmpty(SourceUser)) { var msg = new MessageAlert("Source User Not Set!", "Use the 'Set Source' option from the menu to pick the user whose scrobbles you want to sync.", context); msg.Show(); } }
public async Task <bool> Sync(LastTrack[] scrobbles) { var progress = new ProgressAlert("Syncing scrobbles", "Please wait...", Context); progress.Show(); if (!client.Auth.Authenticated) { progress.Hide(); return(false); } var newScrobbles = scrobbles.Where(o => o.TimePlayed != null && !GinaScrobbles.Any(p => p.TimePlayed == o.TimePlayed)); var list = newScrobbles.Select(o => new Scrobble(o.ArtistName, o.AlbumName, o.Name, o.TimePlayed.Value) { ChosenByUser = true, Duration = o.Duration }).ToList(); var scrobbler = new MemoryScrobbler(client.Auth); var res = await scrobbler.ScrobbleAsync(list); progress.Hide(); await Reload(); Toast.MakeText(Context, $"Synced {list.Count} scrobbles!", ToastLength.Long).Show(); return(true); }