async Task fillStreams(Settings settings) { if (settings.userId == 0) { return; } Protocol.StreamList streams = await Network.GetStreamList(settings.authToken, (int)settings.userId); if (streams.succeeded()) { // Fill the spinner itself. _streamIds = streams.streams.Select(x => x.id).ToArray(); var adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, streams.streams.Select(x => x.name).ToArray()); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); var defaultStreamSpinner = FindViewById <Spinner>(Resource.Id.defaultStream); defaultStreamSpinner.Adapter = adapter; // If we already have a default stream, select it in the list. if (settings.defaultStream > 0) { // Figure out which index it was. int index = -1; for (int i = 0; i < _streamIds.Length; ++i) { if (_streamIds[i] == settings.defaultStream) { index = i; break; } } if (index >= 0) { defaultStreamSpinner.SetSelection(index); } } else { // There was no default stream - set the first available one if we have one. if (streams.streams.Length > 0) { settings.defaultStream = streams.streams[0].id; settings.commit(); } } } }
/// <summary> /// Gets a list of all available streams from the LifeStream server. /// </summary> /// <returns>A StreamList object containing an error or the list of streams.</returns> static public async Task <Protocol.StreamList> GetStreamList(string authToken, int?userOnly) { string url = "api/stream/list"; if (userOnly.HasValue) { url += "?userid=" + userOnly.Value; } JsonValue results = await HttpGetToJsonAsync(Settings.BaseUrl + url, authToken); var streams = new Protocol.StreamList(results); if (streams.succeeded()) { Log.Info(LogTag, "Successfully queried for {0} streams", streams.streams.Length); } else { Log.Error(LogTag, "Could not query for streams: {0}", streams.error); } return(streams); }