Example #1
0
        public async Task<string> PutJson(string url, Token token, HttpContent content)
        {
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Add("Accept", "application/json");
            client.DefaultRequestHeaders.Add("User-Agent", string.Format("{0}", token.TokenDescription));
            client.DefaultRequestHeaders.Add("Authorization", string.Format("Token {0}", token.AccessToken));

            using (HttpResponseMessage response = await client.PutAsync(new Uri(url), content))
            {
                string res = await response.Content.ReadAsStringAsync();
                return res;
            }
        }
Example #2
0
        public async Task<string> GetJson(string url, Token token, bool isReadme = false)
        {
            HttpClient client = new HttpClient();

            if (isReadme == true)
            {
                client.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3.html");
            }
            else
            {
                client.DefaultRequestHeaders.Add("Accept", "application/json");
            }
            
            client.DefaultRequestHeaders.Add("User-Agent", string.Format("{0}", token.TokenDescription));
            client.DefaultRequestHeaders.Add("Authorization", string.Format("Token {0}", token.AccessToken));

            using (HttpResponseMessage response = await client.GetAsync(new Uri(url)))
            {
                string res = await response.Content.ReadAsStringAsync();
                return res;
            }
        }
Example #3
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            Button signIn = FindViewById<Button>(Resource.Id.SignIn);
            ImageView userAvatar = FindViewById<ImageView>(Resource.Id.UserAvatar);
            Button getStarred = FindViewById<Button>(Resource.Id.GetStarred);
            TextView greeting = FindViewById<TextView>(Resource.Id.Greeting);

            pageInfo = FindViewById<TextView>(Resource.Id.PageInfo);
            navigation = FindViewById<LinearLayout>(Resource.Id.Navigation);
            previousPage = FindViewById<Button>(Resource.Id.PreviousPage);
            nextPage = FindViewById<Button>(Resource.Id.NextPage);

            listView = FindViewById<ListView>(Resource.Id.RepoList);

            token = await GetLocalStorage.GetLocalAccessToken();

            signIn.Click += async (sender, e) =>
            {
                var json = await _fetch.GetJson(_url.User, token);
                user = await ParseManager.Parse<User>(json);

                if (user != null)
                {
                    greeting.Text = $"Welcome {user.UserName}";
                    var bitmap = GetImageHelper.GetImageBitmapFromUrl(user.avatarUrl);
                    userAvatar.SetImageBitmap(bitmap);
                    getStarred.Enabled = true;
                    signIn.Visibility = ViewStates.Gone;
                }
            };

            getStarred.Click += async (sender, e) =>
            {
                var json = await _fetch.GetJson(_url.Starred(user), token);
                repos = await ParseManager.Parse<List<Repo>>(json);
                foreach(Repo repo in repos) 
                {
                    repo.IsStarred = true;
                };

                navigation.Visibility = ViewStates.Gone;

                listView.Adapter = new RepoListAdapter(this, token, user, repos);
            };

            listView.ItemClick += (sender, e) =>
            {
                var listView = sender as ListView;
                repo = repos[e.Position];
                var intent = new Intent(this, typeof(RepoActivity));
                StartActivity(intent);
            };

            previousPage.Click += (sender1, e1) =>
            {
                page--;
                Search();
            };

            nextPage.Click += (sender2, e2) =>
            {
                page++;
                Search();
            };
        }