public async Task LookupFriendshipAsync(IUserModel user)
        {
            IFriendshipModel model = StorageService.GetCachedFriendship(user.ScreenName);

            if (model == null)
            {
                var option = Const.GetDictionary();
                option.Add(Const.USER_ID, user.Id);
                var friendships = await tokens.Friendships.LookupAsync(option);

                if (friendships != null && friendships.Count != 0)
                {
                    model = new FriendshipModel(friendships[0]);
                }
            }
            if (model == null)
            {
                return;
            }

            var connections = model.Connections.Select(c => c.ToLower()).ToList();

            user.IsFollowing  = connections.Contains(Const.FOLLOWING);
            user.IsFollowedBy = connections.Contains(Const.FOLLOWED_BY);

            StorageService.AddOrUpdateCachedFriendship(model);
        }
Ejemplo n.º 2
0
        protected override async Task LoadMoreDataFromWeb()
        {
            int count = loadedItemsCache.Count;

            Debug.WriteLine("loadedItemsCache count is : {0}", count);
            #region add items from cache, with 10 items per action
            if (count > 0)
            {
                if (count > ITEMSPERPAGE)
                {
                    for (int i = 0; i < ITEMSPERPAGE; i++)
                    {
                        Items.Add(loadedItemsCache[i]);
                    }
                    loadedItemsCache.RemoveRange(0, ITEMSPERPAGE);
                }
                else
                {
                    foreach (var item in loadedItemsCache)
                    {
                        Items.Add(item);
                    }
                    loadedItemsCache.Clear();
                }
                await SaveTombstoningData();
            }
            #endregion
            #region load data from derived class
            else
            {
                if (Items.Count == 0)
                {
                    Debug.WriteLine("no items yet, should fetch data first.");
                    await FetchMoreDataFromWeb();

                    return;
                }
                Debug.WriteLine("load data from internet");
                var options = Const.GetDictionary();
                options.Add(Const.COUNT, Const.DEFAULTCOUNT);
                options.Add(Const.MAX_ID, Items.Last().Id - 1);
                var loadedList = await LoadDataFromWeb(options);

                Debug.WriteLine("loaded data count is : {0}", loadedList.Count);
                if (loadedList != null && loadedList.Count != 0)
                {
                    loadedItemsCache.AddRange(loadedList);
                    loadedList.First().IsTopBoundsVisible = true;
                    Items.Last().IsBottomBoundsVisible    = true;
                    await LoadMoreDataFromWeb();
                }
                else
                {
                    //no more tweets
                }
            }
            #endregion
        }
Ejemplo n.º 3
0
        public async Task LookupFriendshipAsync(IUserModel user)
        {
            var option = Const.GetDictionary();

            option.Add(Const.USER_ID, user.Id);
            var friendships = await tokens.Friendships.LookupAsync(option);

            if (friendships != null && friendships.Count != 0 &&
                friendships[0].Connections != null && friendships[0].Connections.Length != 0)
            {
                var connections = friendships[0].Connections.Select(c => c.ToLower()).ToList();

                user.IsFollowing  = connections.Contains(Const.FOLLOWING);
                user.IsFollowedBy = connections.Contains(Const.FOLLOWED_BY);
            }
        }
Ejemplo n.º 4
0
        protected async override Task FetchDataFromWeb()
        {
            var id = Items[0].InReplyToTweetId;

            if (id == null)
            {
                return;
            }
            await ShowProgressBar();

            var option = Const.GetDictionary();

            option.Add(Const.ID, id);
            var tweet = await statusController.ShowAsync(option);

            Items.Insert(0, tweet);
            listbox.ScrollTo(Items[0]);
            await HideProgressBar();
        }
        protected override async Task LoadMoreDataFromWeb()
        {
            var msgs    = new List <IDirectMessageModel>();
            var options = Const.GetDictionary();
            var maxId   = StorageService.GetSendDirectMessageMaxId();

            if (maxId != null)
            {
                options.Add(Const.MAX_ID, maxId);
            }
            var sendMsgs = await messageController.SentAsync(options);

            if (sendMsgs != null && sendMsgs.Count() != 0)
            {
                msgs.AddRange(sendMsgs);
            }
            options.Clear();
            maxId = StorageService.GetReceivedDirectMessageMaxId();
            if (maxId != null)
            {
                options.Add(Const.MAX_ID, maxId);
            }
            var receivedMsgs = await messageController.ReceivedAsync(options);

            if (receivedMsgs != null && receivedMsgs.Count() != 0)
            {
                msgs.AddRange(receivedMsgs);
            }
            StorageService.AddCachedDirectMessages(msgs);
            int skip = Items.Count;
            var list = StorageService.GetGroupedDirectMessages();

            if (list != null && list.Count != 0)
            {
                Items.Clear();
                foreach (var item in list)
                {
                    Items.Add(item);
                }
                listbox.ScrollTo(Items[Items.Count - 1]);
            }
        }
        public async void AppBar_Send()
        {
            if (string.IsNullOrEmpty(Text))
            {
                return;
            }
            var options = Const.GetDictionary();

            options.Add(Const.STATUS, Text);
            if (inReplyToStatusId.HasValue)
            {
                options.Add(Const.IN_REPLY_TO_STATUS_ID, inReplyToStatusId);
            }
            waitCursorService.IsVisible = true;
            waitCursorService.Text      = LanguageHelper["WaitCursor_SendNewTweet"];
            await StatusController.UpdateAsync(options);

            waitCursorService.IsVisible = false;
            NavigationService.UriFor <HomePageViewModel>().Navigate();
        }
Ejemplo n.º 7
0
        protected virtual async Task InitLoadDataFromWeb()
        {
            var options = Const.GetDictionary();

            options.Add(Const.COUNT, Const.DEFAULTCOUNT);
            var fetchedList = await LoadDataFromWeb(options);

            if (fetchedList != null && fetchedList.Count != 0)
            {
                Debug.WriteLine("init loaded data count is: {0}", fetchedList.Count);
                foreach (var item in fetchedList)
                {
                    Items.Add(item);
                }
                await SaveTombstoningData();
            }
            else
            {
            }
        }
        protected override async Task FetchMoreDataFromWeb()
        {
            var msgs    = new List <IDirectMessageModel>();
            var options = Const.GetDictionary();
            var sinceId = StorageService.GetSendDirectMessageSinceId();

            if (sinceId != null)
            {
                options.Add(Const.SINCE_ID, sinceId);
            }
            var sendMsgs = await messageController.SentAsync(options);

            if (sendMsgs != null && sendMsgs.Count() != 0)
            {
                msgs.AddRange(sendMsgs);
            }
            options.Clear();
            sinceId = StorageService.GetReceivedDirectMessageSinceId();
            if (sinceId != null)
            {
                options.Add(Const.SINCE_ID, sinceId);
            }
            var receivedMsgs = await messageController.ReceivedAsync(options);

            if (receivedMsgs != null && receivedMsgs.Count() != 0)
            {
                msgs.AddRange(receivedMsgs);
            }
            StorageService.AddCachedDirectMessages(msgs);
            var list = StorageService.GetGroupedDirectMessages();

            if (list != null && list.Count != 0)
            {
                Items.Clear();
                foreach (var item in list.OrderBy(m => m.Id))
                {
                    Items.Insert(0, item);
                }
                listbox.ScrollTo(Items[0]);
            }
        }
        private async void SetProfileDetail()
        {
            await ProgressService.ShowAsync();

            //initialize the user from cache
            var name   = StorageService.GetTempUserName();
            var option = Const.GetDictionary();

            option.Add(Const.USER_SCREEN_NAME, name);
            option.Add(Const.INCLUDE_ENTITIES, Const.DEFAULT_VALUE_FALSE);
            var user = await userController.ShowAsync(option);

            user.IsProfileDetail = true;

            foreach (var item in Items)
            {
                (item as IHaveAUser).User = user;
            }

            await ProgressService.HideAsync();
        }
Ejemplo n.º 10
0
        public async Task LoadMoreTweetsButtonClick(object sender, EventArgs e)
        {
            if (IsLoading)
            {
                return;
            }
            var currentShowedItem = sender as ITweetModel;

            currentShowedItem.IsLoadMoreTweetButtonVisible = false;
            missedItemsCache.First().IsTopBoundsVisible   = true;
            missedItemsCache.Last().IsBottomBoundsVisible = true;
            var index = Items.IndexOf(currentShowedItem) + 1;

            foreach (var item in missedItemsCache)
            {
                Items.Insert(index, item);
                index++;
            }
            missedItemsCache.Clear();
            var showedItem  = Items[index - 1];
            var missedMaxId = showedItem.Id;
            var sinceId     = Items[index].Id;
            var options     = Const.GetDictionary();

            options.Add(Const.COUNT, Const.DEFAULTCOUNT);
            options.Add(Const.MAX_ID, missedMaxId - 1);
            options.Add(Const.SINCE_ID, sinceId);
            var missedList = await LoadDataFromWeb(options);

            if (missedList != null && missedList.Count != 0)
            {
                //cache the missed tweets:
                Debug.WriteLine("show load more tweet button at tweet id : {0}", showedItem.Id);
                showedItem.IsLoadMoreTweetButtonVisible = true;
                missedItemsCache.AddRange(missedList);
            }
            await SaveTombstoningData();
        }
Ejemplo n.º 11
0
        protected override async Task FetchMoreDataFromWeb()
        {
            if (Items.Count == 0)
            {
                return;
            }
            var option = Const.GetDictionary();

            option.Add(Const.NEED_REFRESH, true);
            option.Add(Const.USER_ID, Items[0].Id);
            option.Add(Const.USER_SCREEN_NAME, Items[0].ScreenName);
            option.Add(Const.INCLUDE_ENTITIES, Const.DEFAULT_VALUE_FALSE);
            var profile = await userController.ShowAsync(option);

            if (profile != null)
            {
                profile.IsProfileDetail = true;
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    Items.Clear();
                    Items.Add(profile);
                });
            }
        }
Ejemplo n.º 12
0
        protected override async Task FetchMoreDataFromWeb()
        {
            int count = fetchedItemsCache.Count;

            Debug.WriteLine("fetchedItemsCache count is : {0}", count);
            #region add items from cache, with 10 items per action
            if (count > 0)
            {
                if (count > ITEMSPERPAGE)
                {
                    for (int i = 0; i < ITEMSPERPAGE; i++)
                    {
                        Items.Insert(0, fetchedItemsCache[count - 1 - i]);
                    }
                    fetchedItemsCache.RemoveRange(count - ITEMSPERPAGE, ITEMSPERPAGE);
                }
                else
                {
                    for (int i = count - 1; i >= 0; i--)
                    {
                        Items.Insert(0, fetchedItemsCache[i]);
                    }
                    fetchedItemsCache.Clear();
                }
                await SaveTombstoningData();
            }
            #endregion
            #region fetch data from derived class
            else
            {
                //step 1: fetch data with since_id:
                Debug.WriteLine("fetch data from internet");
                var options = Const.GetDictionary();
                options.Add(Const.COUNT, Const.DEFAULTCOUNT);
                long?sinceId = null;
                if (Items.Count != 0)
                {
                    sinceId = Items.First().Id;
                    Debug.WriteLine("sinceId is : {0}", sinceId);
                    options.Add(Const.SINCE_ID, sinceId);
                }
                var fetchedList = await LoadDataFromWeb(options);

                #region add to list
                if (fetchedList != null && fetchedList.Count > 0)
                {
                    Debug.WriteLine("fetced data list count is :{0}", fetchedList.Count);
                    //step 2: load data using fetchedList's last item as missed_since_id
                    options.Clear();
                    var missedMaxId = fetchedList.Last().Id;
                    Debug.WriteLine("the last fetched tweet is : {0}", missedMaxId);
                    options.Add(Const.MAX_ID, missedMaxId - 1);
                    options.Add(Const.SINCE_ID, sinceId);
                    options.Add(Const.COUNT, Const.DEFAULTCOUNT);
                    var missedList = await LoadDataFromWeb(options);

                    //step 3: no tweets means no gap,
                    //otherwise, show load more tweets button:
                    if (missedList != null && missedList.Count != 0)
                    {
                        #region remove oldest tweets
                        if (missedItemsCache.Count != 0)
                        {
                            var oldestTweet = Items.Single(t => t.IsLoadMoreTweetButtonVisible);
                            oldestTweet.IsLoadMoreTweetButtonVisible = false;
                            oldestTweet.IsBottomBoundsVisible        = false;
                            int index = Items.IndexOf(oldestTweet) + 1;
                            foreach (var item in missedItemsCache)
                            {
                                Items.Insert(index, item);
                                index++;
                            }
                            missedItemsCache.Clear();
                            while (Items.Count > index)
                            {
                                Items.RemoveAt(Items.Count - 1);
                            }
                        }
                        #endregion
                        #region cache the missed tweets
                        missedItemsCache.AddRange(missedList);
                        var showedItem = fetchedList.Last();
                        Debug.WriteLine("show load more tweet button at tweet id : {0}", showedItem.Id);
                        showedItem.IsLoadMoreTweetButtonVisible = true;
                        #endregion
                    }
                    fetchedItemsCache.AddRange(fetchedList);
                    Items.First().IsTopBoundsVisible         = true;
                    fetchedList.Last().IsBottomBoundsVisible = true;
                    await FetchMoreDataFromWeb();
                }
                #endregion
                else
                {
                    //no new tweets yet
                }
            }
            #endregion
        }