예제 #1
0
        public async override void ViewDidLoad()
        {
            try {
                if (!_initial)
                {
                    this.InitLeftButton();
                }

                LongRunning = true;
                base.ViewDidLoad();

                var sites = await ServiceProxy.GetAllSites();

                foreach (var site in sites.items)
                {
                    var captured = site;

                    AddRow(new SubtitleDynamicRow {
                        Text        = site.NameDecoded,
                        Details     = site.AudienceDecoded,
                        ImageGetter = () => placeholder,
                        Action      = delegate {
                            Config.CurrentSite = captured;
                            ServiceProxy.InitSite(captured.api_site_parameter);

                            if (_initial)
                            {
                                Nav.BuildDeck();
                            }
                            else
                            {
                                Nav.LeftMenu.ReloadAllData();
                                Nav.CloseLeftAndOpen(new QuestionsLatestController());
                            }
                        },
                        AfterGetCellInit = cell => {
                            cell._image.SetImage(new NSUrl(captured.icon_url), placeholder,
                                                 delegate(UIImage image, NSError error, SDImageCacheType cacheType)
                            {
                                cell._image.Image = image;
                            });
                        }
                    });
                }

                ForceReloadData();

                _tableView.ScrollToRow(NSIndexPath.FromRowSection(0, 0), UITableViewScrollPosition.Top, false);
            }
            catch (Exception ex) {
                this.UnhandledError(ex);
            }
        }
예제 #2
0
        public void ReloadAllData()
        {
            try {
                ClearAllRows();

                var    site        = Config.CurrentSite;
                var    me          = Config.CurrentUser;
                string accessToken = Config.AccessToken;

                if (me != null)
                {
                    AddRow(new UserListRow(me)
                    {
                        Action = delegate { Nav.CloseLeftAndOpen(new UserProfileController(me)); }
                    });
                }

                AddRow(new SubtitleFixedRow
                {
                    Text    = "You are in " + site.NameDecoded,
                    Details = "tap to change",
                    Action  = delegate { Nav.CloseLeftAndOpen(new SiteChooserController(initial: false)); }
                });

                AddRow(new DefaultFixedRow
                {
                    Text   = "Browse Questions",
                    Action = delegate { Nav.CloseLeftAndOpen(new QuestionsLatestController()); }
                });

                AddRow(new DefaultFixedRow
                {
                    Text   = "Browse Tags",
                    Action = delegate { Nav.CloseLeftAndOpen(new TagsController()); }
                });

                AddRow(new DefaultFixedRow
                {
                    Text   = "Browse Users",
                    Action = delegate { Nav.CloseLeftAndOpen(new UsersController()); }
                });

                if (accessToken.IsNotNullOrEmpty())
                {
                    AddRow(new DefaultFixedRow {
                        Text   = "Favorites",
                        Action = delegate { Nav.CloseLeftAndOpen(new FavoritesByUserController(me.user_id, false)); }
                    });

                    AddRow(new DefaultFixedRow {
                        Text   = "Notifications",
                        Action = delegate { Nav.CloseLeftAndOpen(new NotificationsController()); }
                    });

                    AddRow(new DefaultFixedRow {
                        Text   = "Inbox",
                        Action = delegate { Nav.CloseLeftAndOpen(new InboxController()); }
                    });
                }

                AddRow(new DefaultFixedRow {
                    Text   = "Site Info",
                    Action = delegate { Nav.CloseLeftAndOpen(new SiteInfoController(site.api_site_parameter)); }
                });

                AddRow(new DefaultFixedRow {
                    Text   = "History",
                    Action = delegate { Nav.CloseLeftAndOpen(new QuestionsHistoryController()); }
                });

                AddRow(new DefaultFixedRow {
                    Text   = "About Stacklash",
                    Action = delegate { Nav.CloseLeftAndOpen(new AboutController()); }
                });

                AddHeaderRow(" ");

                if (accessToken.IsNotNullOrEmpty())
                {
                    AddRow(new DefaultFixedRow
                    {
                        Text   = "Logout",
                        Action = delegate {
                            foreach (NSHttpCookie cookie in NSHttpCookieStorage.SharedStorage.Cookies)
                            {
                                NSHttpCookieStorage.SharedStorage.DeleteCookie(cookie);
                            }

                            NSUrlCache.SharedCache.RemoveAllCachedResponses();

                            Config.AccessToken = null;
                            Config.CurrentUser = null;
                            Nav.BuildDeck();
                        }
                    });
                }
                else
                {
                    AddRow(new DefaultFixedRow
                    {
                        Text   = "Login",
                        Action = delegate { Nav.CloseLeftAndOpen(new LoginController()); }
                    });
                }

                ForceReloadData();
            }
            catch (Exception ex) {
                this.UnhandledError(ex);
            }
        }