/// <summary>
        /// Removes recommendation
        /// </summary>
        /// <param name="rec">Recommendation to remove</param>
        private void RemoveRecomendations(RecModel rec)
        {
            RecList.Remove(rec);

            // Since the recommendation was currently selected, we have to change it with another one
            if (rec == SelectedRec)
            {
                // If it was the last item, selects a new last item
                if (SelectedIndex >= RecList.Count)
                {
                    SelectedIndex = RecList.Count - 1;
                    if (SelectedIndex >= 0)
                    {
                        SelectedRec = RecList[SelectedIndex];
                    }
                }
                // If no more recommendations are left, removes selection
                if (RecList.Count == 0)
                {
                    SelectedRec = null;
                }
                else
                {
                    SelectedRec = RecList[SelectedIndex];
                }
            }

            if (RecList.Count == 0)
            {
                Messenger.Default.Send("", MessengerToken.GetMoreRecs);
                RecsView.Close();
            }
        }
Exemple #2
0
 /// <summary>
 /// Downloads all recommendations
 /// </summary>
 private void ForceDownloadRecs()
 {
     if (SerializationHelper.EmptyRecommendations())
     {
         RecList.Clear();
         UpdateRecs(this, null);
     }
 }
Exemple #3
0
        /// <summary>
        /// Tries connecting to Tinder servers and getting recommendations
        /// </summary>
        /// <returns></returns>
        public async Task <bool> GetRecs()
        {
            try
            {
                var recs = await TinderHelper.GetRecommendations();

                if (recs.Recommendations != null)
                {
                    // Out of recs
                    if (recs.Recommendations.Any(x => x.Id.Contains("tinder_rate_limited")))
                    {
                        RecList.Clear();
                        SerializationHelper.EmptyRecommendations();
                        return(false);
                    }
                    // If it's the first time getting recs
                    if (RecList == null)
                    {
                        RecList = new ObservableCollection <RecModel>(recs.Recommendations);
                    }
                    // Only useful if we force to download new recs in which case old
                    // recs would be no use anyway
                    RecList.Clear();
                    foreach (var item in recs.Recommendations)
                    {
                        RecList.Add(item);
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (TinderRequestException e)
            {
                MessageBox.Show(e.Message);
                return(false);
            }
        }