예제 #1
0
        public void RefreshIfDirty()
        {
            Database db = App.Kp2a.GetDb();

            if (db.Dirty.Contains(Group))
            {
                db.Dirty.Remove(Group);
                ListAdapter.NotifyDataSetChanged();
            }
        }
예제 #2
0
        /*
         * public BrowseActivity()
         * {
         * }
         *
         * public BrowseActivity(IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer) : base(javaReference, transfer)
         * {
         * }
         */

        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Browse);

            var weakThis = new WeakReference <BrowseActivity>(this);

            var listView = FindViewById <ListView>(Resource.Id.listView);
            var button   = FindViewById <Button>(Resource.Id.button);

            Observable.FromEventPattern(button, nameof(button.Click))
            .SetCommand(ViewModel.NavigateToNew);
            Observable.FromEventPattern <AdapterView.ItemClickEventArgs>(listView, nameof(listView.ItemClick))
            .Select(arg => weakThis.Resolve()?.Items[arg.EventArgs.Position])
            .SetCommand(ViewModel.NavigateToDetail);

            var adapter = new ListAdapter <Models.Item>(Items, (row, item) =>
            {
                var strongThis = weakThis.Resolve();
                if (strongThis == null)
                {
                    return(null);
                }
                var view   = strongThis.LayoutInflater.Inflate(Resource.Layout.ListItem_Browse, null);
                var holder = new ViewHolder
                {
                    TitleTextView       = view.FindViewById <TextView>(Resource.Id.text_title),
                    DescriptionTextView = view.FindViewById <TextView>(Resource.Id.text_description)
                };
                view.Tag = holder;
                return(view);
            }, (row, item, view) =>
            {
                var holder = view.Tag as ViewHolder;
                holder.TitleTextView.Text       = item.Title;
                holder.DescriptionTextView.Text = item.Description;
            });

            listView.Adapter = adapter;

            ViewModel.Items.Where(v => v != null).Subscribe(items =>
            {
                var strongThis = weakThis.Resolve();
                if (strongThis == null)
                {
                    return;
                }
                strongThis.Items.Clear();
                strongThis.Items.AddRange(items);
                adapter.NotifyDataSetChanged();
            });
        }
예제 #3
0
        /// <summary>
        /// Loading more 10 tweets
        /// </summary>
        private void LoadMoreTweets()
        {
            RunOnUiThread(() => { _headerButton.Text = "Loading"; });

            var newTweets = TwitterManager.GetTweets(10, _tweets[_tweets.Count - 1].Id);

            if (newTweets != null && newTweets.Count != 0)
            {
                _tweets.AddRange(newTweets);

                RunOnUiThread(() =>
                {
                    _listAdapter = new ListAdapter(this, _tweets);
                    _listAdapter.NotifyDataSetChanged();
                    _listView.InvalidateViews();
                });
            }

            RunOnUiThread(() => { _headerButton.Text = "Load older tweets"; });
        }
예제 #4
0
        /// <summary>
        /// Loading tweets on application start
        /// </summary>
        private void LoadTweets()
        {
            _tweets = TwitterManager.GetTweets(20, null);

            var listAdapter = new ListAdapter(this, _tweets);

            RunOnUiThread(() =>
                              {
                                  _listView.Adapter = listAdapter;
                                  listAdapter.NotifyDataSetChanged();
                                  _listView.InvalidateViews();
                                  _headerButton.Text = "Load older tweets";

                                  _headerButton.Click +=
                                      delegate { ThreadPool.QueueUserWorkItem(lm => LoadMoreTweets()); };
                              });
        }