예제 #1
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var  repo = repos[position];
            View view = convertView;

            if (view == null)
            {
                view = context.LayoutInflater.Inflate(Resource.Layout.RepoList, null);
                var starButton = view.FindViewById <ImageView>(Resource.Id.StarButton);
                if (repo.IsStarred == true)
                {
                    starButton.SetImageResource(Resource.Drawable.ic_star_white_24dp);
                    starButton.Click += (sender, e) =>
                    {
                        Unstar(sender, e, repo);
                        repos.RemoveAt(position);
                        NotifyDataSetChanged();
                    };
                }
                else if (repo.IsStarred == false)
                {
                    starButton.Click += (sender, e) =>
                    {
                        Star(sender, e, repo);
                        starButton.SetImageResource(Resource.Drawable.ic_star_white_24dp);
                    };
                }
                ;
            }
            view.FindViewById <TextView>(Resource.Id.Line1).Text = $"{repo.Owner.Name} - {repo.Name}";
            view.FindViewById <TextView>(Resource.Id.Line2).Text = $"Last Updated: {repo.Updated.ToLocalTime()}";
            view.FindViewById <ImageView>(Resource.Id.OwnerAvatar).SetImageBitmap(GetImageHelper.GetImageBitmapFromUrl(repo.Owner.AvatarUrl));
            return(view);
        }
예제 #2
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();
            };
        }