Example #1
0
        void PostedNewTab(TabObject tab)
        {
            var text = string.Format("Added {0} {1} {2}",
                                     tab.Type.Name,
                                     tab.Direction == TabDirection.Giving ? "to" : "from",
                                     tab.Recipient.DisplayName);

            Toast.MakeText(Activity, text, ToastLength.Short).Show();
            statsSpinner.Visibility = ViewStates.Visible;
            var activityFragment = FragmentManager.FindFragmentByTag("activity") as ActivityFragment;

            if (activityFragment != null)
            {
                activityFragment.AddLocalTabObject(tab);
            }
        }
Example #2
0
        void UpdateTabStatistics(TabPerson other, SelectedUserInfo selectedContact, bool force = false)
        {
            var p    = other.ToParse();
            var self = TabPerson.CurrentPerson.ToParse();

            var query = TabObject.CreateTabListQuery(self, p);

            if (force)
            {
                query.SetCachePolicy(ParseQuery.CachePolicy.NetworkElseCache);
            }
            else
            {
                query.SetCachePolicy(ParseQuery.CachePolicy.CacheElseNetwork);
                query.MaxCacheAge = 1000 * 60;                 // 1 minute
            }

            query.FindInBackground(new TabFindCallback((ps, ex) => {
                if (ex != null)
                {
                    Android.Util.Log.Error("TabStats", ex, "Error while retrieving tab list");
                    statsSpinner.Visibility = ViewStates.Invisible;
                    flashBarCtrl.ShowBar(() => UpdateTabStatistics(other, selectedContact, force),
                                         withMessageId: Resource.String.flashbar_stats_error);
                    return;
                }

                var tabs = ps.Select(TabObject.FromParse).ToArray();
                if (tabs.Length == 0)
                {
                    statsSpinner.Visibility = ViewStates.Invisible;
                    karmaBar.SetAnimatedVisibility(false);
                    return;
                }

                var counts        = tabs.GroupBy(tab => tab.Type.Name).ToArray();
                int totalPositive = 0, totalNegative = 0;
                int totalTypes    = counts.Length;

                foreach (var group in counts)
                {
                    var badge    = BadgeInstances[group.Key];
                    int positive = 0, negative = 0;

                    foreach (var tab in group)
                    {
                        if ((tab.Originator == other && tab.Direction == TabDirection.Receiving) ||
                            (tab.Originator == TabPerson.CurrentPerson && tab.Direction == TabDirection.Giving))
                        {
                            positive++;
                        }
                        if ((tab.Originator == TabPerson.CurrentPerson && tab.Direction == TabDirection.Receiving) ||
                            (tab.Originator == other && tab.Direction == TabDirection.Giving))
                        {
                            negative++;
                        }
                    }

                    totalPositive += positive;
                    totalNegative += negative;

                    Activity.RunOnUiThread(() => {
                        if (selectedContact.DisplayName != userBadge.SelectedUser.DisplayName)
                        {
                            return;
                        }
                        //badge.Count = positive - negative;
                        badge.SetCount(positive - negative, true);
                        if (--totalTypes == 0)
                        {
                            if (totalPositive == 0 && totalNegative == 0)
                            {
                                karmaBar.SetAnimatedVisibility(false);
                            }
                            else
                            {
                                karmaBar.SetAnimatedVisibility(true);
                                karmaBar.SetKarmaBasedOnValues(totalPositive, totalNegative);
                            }
                            statsSpinner.Visibility = ViewStates.Invisible;
                        }
                    });
                }
            }));
        }
Example #3
0
 public void AddLocalTabObject(TabObject tabObject)
 {
     adapter.PrependData(tabObject);
     currentDataIndex++;
 }
Example #4
0
        void RegisterNewTab(SelectedUserInfo originator, SelectedUserInfo recipient, string tabTypeName, string locationDesc = null)
        {
            var selectedPerson = (originator ?? recipient).ToPerson();
            var tabType        = TabTypes.GetTabTypes()
                                 .ContinueWith(ts => ts.Result.FirstOrDefault(t => t.Name.Equals(tabTypeName, StringComparison.OrdinalIgnoreCase)));

            var dialog = new AskLocationDialog(locator);

            if (!string.IsNullOrEmpty(locationDesc))
            {
                dialog.FillInLocation(locationDesc);
            }

            Task.Factory.ContinueWhenAll(new Task[] { selectedPerson, tabType, dialog.LocationName }, _ => {
                if (dialog.LocationName.IsCanceled)
                {
                    return;
                }
                var dir      = originator == null ? TabDirection.Giving : TabDirection.Receiving;
                var location = locator.GetLocationAndStopActiveSearching();
                locationDesc = dialog.LocationName.Result;
                locator.RefreshNamedLocation(locationDesc);
                TabPlace.RegisterPlace(locationDesc,
                                       Tuple.Create(location.Latitude, location.Longitude));

                var tab = new TabObject {
                    Originator   = TabPerson.CurrentPerson,
                    Recipient    = selectedPerson.Result,
                    Type         = tabType.Result,
                    Direction    = dir,
                    LatLng       = Tuple.Create(location.Latitude, location.Longitude),
                    LocationDesc = locationDesc,
                    Time         = DateTime.Now
                };
                Action postSave = () => {
                    UpdateTabStatistics(selectedPerson.Result, originator ?? recipient, true);
                    Activity.RunOnUiThread(() => PostedNewTab(tab));
                };
                var po = tab.ToParse();
                try {
                    po.Save();
                } catch (Exception e) {
                    Log.Error("TabSaver", e.ToString());
                    Activity.RunOnUiThread(() => flashBarCtrl.ShowBarUntil(() => {
                        po.Save();
                        postSave();
                        return(true);
                    }, withMessageId: Resource.String.flashbar_tab_error));
                    return;
                }
                postSave();
            });

            if (locationDesc == null)
            {
                var lastLocation = locator.LastKnownLocation;
                if (lastLocation != null)
                {
                    dialog.FilterWithLocation(Tuple.Create(lastLocation.Latitude, lastLocation.Longitude));
                }
                dialog.Show(FragmentManager, "location-asker");
            }
        }
Example #5
0
 public void PrependData(TabObject newData)
 {
     data.Insert (0, newData);
     NotifyDataSetChanged ();
 }
Example #6
0
 public void AddLocalTabObject(TabObject tabObject)
 {
     adapter.PrependData (tabObject);
     currentDataIndex++;
 }
        void RegisterNewTab(SelectedUserInfo originator, SelectedUserInfo recipient, string tabTypeName, string locationDesc = null)
        {
            var selectedPerson = (originator ?? recipient).ToPerson ();
            var tabType = TabTypes.GetTabTypes ()
                .ContinueWith (ts => ts.Result.FirstOrDefault (t => t.Name.Equals (tabTypeName, StringComparison.OrdinalIgnoreCase)));

            var dialog = new AskLocationDialog (locator);
            if (!string.IsNullOrEmpty (locationDesc))
                dialog.FillInLocation (locationDesc);

            Task.Factory.ContinueWhenAll (new Task[] { selectedPerson, tabType, dialog.LocationName }, _ => {
                if (dialog.LocationName.IsCanceled)
                    return;
                var dir = originator == null ? TabDirection.Giving : TabDirection.Receiving;
                var location = locator.GetLocationAndStopActiveSearching ();
                locationDesc = dialog.LocationName.Result;
                locator.RefreshNamedLocation (locationDesc);
                TabPlace.RegisterPlace (locationDesc,
                                        Tuple.Create (location.Latitude, location.Longitude));

                var tab = new TabObject {
                    Originator = TabPerson.CurrentPerson,
                    Recipient = selectedPerson.Result,
                    Type = tabType.Result,
                    Direction = dir,
                    LatLng = Tuple.Create (location.Latitude, location.Longitude),
                    LocationDesc = locationDesc,
                    Time = DateTime.Now
                };
                Action postSave = () => {
                    UpdateTabStatistics (selectedPerson.Result, originator ?? recipient, true);
                    Activity.RunOnUiThread (() => PostedNewTab (tab));
                };
                var po = tab.ToParse ();
                try {
                    po.Save ();
                } catch (Exception e) {
                    Log.Error ("TabSaver", e.ToString ());
                    Activity.RunOnUiThread (() => flashBarCtrl.ShowBarUntil (() => {
                        po.Save ();
                        postSave ();
                        return true;
                    }, withMessageId: Resource.String.flashbar_tab_error));
                    return;
                }
                postSave ();
            });

            if (locationDesc == null) {
                var lastLocation = locator.LastKnownLocation;
                if (lastLocation != null)
                    dialog.FilterWithLocation (Tuple.Create (lastLocation.Latitude, lastLocation.Longitude));
                dialog.Show (FragmentManager, "location-asker");
            }
        }
 void PostedNewTab(TabObject tab)
 {
     var text = string.Format ("Added {0} {1} {2}",
                               tab.Type.Name,
                               tab.Direction == TabDirection.Giving ? "to" : "from",
                               tab.Recipient.DisplayName);
     Toast.MakeText (Activity, text, ToastLength.Short).Show ();
     statsSpinner.Visibility = ViewStates.Visible;
     var activityFragment = FragmentManager.FindFragmentByTag ("activity") as ActivityFragment;
     if (activityFragment != null)
         activityFragment.AddLocalTabObject (tab);
 }
Example #9
0
 public void PrependData(TabObject newData)
 {
     data.Insert(0, newData);
     NotifyDataSetChanged();
 }