Example #1
0
        private async void Search(string searchText)
        {
            Analytics.TrackEvent("Search: " + searchText);

            try
            {
                _giphyServiceObj = FreshIOC.Container.Resolve <GiphyService>();

                if (TrendingImages != null)
                {
                    TrendingImages.Clear();
                    Settings.Offset = 0;
                }

                SearchCacheItem existingSearchCacheItem = SearchCache.FirstOrDefault((obj) => obj.SearchString == searchText);

                if (existingSearchCacheItem == null)
                {
                    _searchCacheServiceObj.InsertSearchItem(new SearchCacheItem(searchText));
                }
                else
                {
                    // Update the search time so it appears first in the list.
                    existingSearchCacheItem.TimeSearched = DateTime.Now;
                    _searchCacheServiceObj.UpdateSearchItem(existingSearchCacheItem);
                }

                Giphy = await _giphyServiceObj.SearchGifs(searchText);

                if (Giphy != null)
                {
                    List <GifDataItem> gifDataItems = CreateGifDataItemList(Giphy.Data.ToList());
                    gifDataItems.ForEach((gifDataItem) => { TrendingImages.Add(gifDataItem); });

                    //foreach (Datum datum in Giphy.Data)
                    //{
                    //    TrendingImages.Add(datum);
                    //}
                }

                IsCancelButtonVisible        = false;
                IsTrendingImagesPanelVisible = true;
            }
            catch (Exception exception)
            {
                MainThread.BeginInvokeOnMainThread
                (
                    () =>
                {
                    CoreMethods.DisplayAlert("Uh Oh", "Something bad happened: \n" + exception.Message, "Ok");
                }
                );
            }
        }
 public void UpdateSearchItem(SearchCacheItem searchCacheItem)
 {
     sqliteAsyncConnection.UpdateAsync(searchCacheItem);
 }
 public void InsertSearchItem(SearchCacheItem searchCacheItem)
 {
     sqliteAsyncConnection.InsertAsync(searchCacheItem);
 }