예제 #1
0
        public override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RetainInstance = true;
            if (Utils.IsNetworkConnected(Activity))
            {
                try
                {
                    var client = new WebClient();
                    client.Headers.Set(HttpRequestHeader.UserAgent, "android:com.trivia.buff:v1.3.0 (by /u/camradal)");
                    var triviaTask = client.DownloadStringTaskAsync("http://reddit.com/r/todayilearned.json");

                    var result   = JObject.Parse(await triviaTask);
                    var items    = Serializer.GetItems(result);
                    var lastItem = result["data"]["after"].ToString();

                    _triviaItemAdapter = new TriviaItemAdapter(Activity, items.ToList());
                    ListAdapter        = new EndlessTriviaItemAdapter(_triviaItemAdapter, lastItem, "http://reddit.com/r/todayilearned.json?after={0}");
                }
                catch (Exception e)
                {
                    _error   = true;
                    _message = e.Message;
                }
            }
            else
            {
                _error   = true;
                _message = "No network connection";
            }
        }
예제 #2
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            RequestWindowFeature(WindowFeatures.IndeterminateProgress);

            if (Intent.Action == Intent.ActionSearch)
            {
                if (Utils.IsNetworkConnected(this))
                {
                    try
                    {
                        SetProgressBarIndeterminateVisibility(true);
                        var query  = Intent.GetStringExtra(SearchManager.Query);
                        var client = new WebClient();
                        client.Headers.Set(HttpRequestHeader.UserAgent, "android:com.trivia.buff:v1.3.0 (by /u/camradal)");
                        var triviaTask = client.DownloadStringTaskAsync(SearchUrl + query);

                        var result   = JObject.Parse(await triviaTask);
                        var items    = Serializer.GetItems(result);
                        var lastItem = result["data"]["after"].ToString();

                        _triviaItemAdapter = new TriviaItemAdapter(this, items.ToList());
                        ListAdapter        = new EndlessTriviaItemAdapter(_triviaItemAdapter, lastItem, SearchUrl + query + "&after={0}");
                    }
                    catch (Exception e)
                    {
                        Toast.MakeText(this, e.Message, ToastLength.Short).Show();
                    }
                }
                else
                {
                    Toast.MakeText(this, "No network connection", ToastLength.Short).Show();
                }
                SetProgressBarIndeterminateVisibility(false);
            }
        }