void ProcessSelectedUser(SelectedUserInfo selectedUser) { tapInset.Visibility = ViewStates.Gone; infoLayout.Visibility = ViewStates.Visible; title.Text = selectedUser.DisplayName; if (selectedUser.AvatarBitmap != null) { icon.SetImageBitmap(selectedUser.AvatarBitmap, true); } else { icon.SetImageBitmap(contactPicture, true); } if (selectedUser.Emails.Any()) { subtitle.Text = selectedUser.Emails.First(); subtitle.Visibility = ViewStates.Visible; } else { subtitle.Visibility = ViewStates.Invisible; } if (SelectedUserChanged != null) { SelectedUserChanged(this, EventArgs.Empty); } }
public override void OnDestroyView() { if (!Activity.IsFinishing && userBadge != null) { lastSelectedUser = userBadge.SelectedUser; try { var transaction = FragmentManager.BeginTransaction(); transaction.Remove(userBadge); transaction.Commit(); } catch { } } base.OnDestroyView(); }
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; } }); } })); }
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 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; } }); } })); }
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"); } }
public override void OnDestroyView() { if (!Activity.IsFinishing && userBadge != null) { lastSelectedUser = userBadge.SelectedUser; try { var transaction = FragmentManager.BeginTransaction (); transaction.Remove (userBadge); transaction.Commit (); } catch { } } base.OnDestroyView (); }
public override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (resultCode != Result.Ok) { isPicking = false; return; } var contactData = data.Data; var projs = new string[] { ContactsContract.Contacts.InterfaceConsts.Id, ContactsContract.Contacts.InterfaceConsts.LookupKey, ContactsContract.Contacts.InterfaceConsts.DisplayName, }; var cursor = Activity.ContentResolver.Query(contactData, projs, null, null, null); int index = -1; string contactID = null; string lookupID = null; string displayName = string.Empty; Bitmap photoBmp = null; if (cursor.MoveToFirst()) { contactID = cursor.GetString(cursor.GetColumnIndex(projs [0])); lookupID = cursor.GetString(cursor.GetColumnIndex(projs [1])); if ((index = cursor.GetColumnIndex(projs [2])) != -1) { displayName = cursor.GetString(index); } var photoStream = ContactsContract.Contacts.OpenContactPhotoInputStream(Activity.ContentResolver, contactData, false); if (photoStream != null) { photoBmp = BitmapFactory.DecodeStream(photoStream); } } cursor.Close(); // Get emails var emailCursor = Activity.ContentResolver.Query(ContactsContract.CommonDataKinds.Email.ContentUri, null, ContactsContract.CommonDataKinds.Email.InterfaceConsts.ContactId + " = ?", new[] { contactID }, null); var emails = new List <string> (emailCursor.Count); while (emailCursor.MoveToNext()) { emails.Add(emailCursor.GetString(emailCursor.GetColumnIndex(ContactsContract.CommonDataKinds.Email.Address))); } emailCursor.Close(); SelectedUser = new SelectedUserInfo { DisplayName = displayName, Emails = emails, LookupID = lookupID, ContactID = contactID, AvatarBitmap = photoBmp }; ProcessSelectedUser(SelectedUser); isPicking = false; }
public void RestoreSelectedUserInfo(SelectedUserInfo selectedUser) { SelectedUser = selectedUser; ProcessSelectedUser(selectedUser); }
public override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult (requestCode, resultCode, data); if (resultCode != Result.Ok) { isPicking = false; return; } var contactData = data.Data; var projs = new string[] { ContactsContract.Contacts.InterfaceConsts.Id, ContactsContract.Contacts.InterfaceConsts.LookupKey, ContactsContract.Contacts.InterfaceConsts.DisplayName, }; var cursor = Activity.ContentResolver.Query (contactData, projs, null, null, null); int index = -1; string contactID = null; string lookupID = null; string displayName = string.Empty; Bitmap photoBmp = null; if (cursor.MoveToFirst ()) { contactID = cursor.GetString (cursor.GetColumnIndex (projs [0])); lookupID = cursor.GetString (cursor.GetColumnIndex (projs [1])); if ((index = cursor.GetColumnIndex (projs [2])) != -1) displayName = cursor.GetString (index); var photoStream = ContactsContract.Contacts.OpenContactPhotoInputStream (Activity.ContentResolver, contactData, false); if (photoStream != null) photoBmp = BitmapFactory.DecodeStream (photoStream); } cursor.Close (); // Get emails var emailCursor = Activity.ContentResolver.Query (ContactsContract.CommonDataKinds.Email.ContentUri, null, ContactsContract.CommonDataKinds.Email.InterfaceConsts.ContactId + " = ?", new[] { contactID }, null); var emails = new List<string> (emailCursor.Count); while (emailCursor.MoveToNext ()) emails.Add (emailCursor.GetString (emailCursor.GetColumnIndex (ContactsContract.CommonDataKinds.Email.Address))); emailCursor.Close (); SelectedUser = new SelectedUserInfo { DisplayName = displayName, Emails = emails, LookupID = lookupID, ContactID = contactID, AvatarBitmap = photoBmp }; ProcessSelectedUser (SelectedUser); isPicking = false; }
void ProcessSelectedUser(SelectedUserInfo selectedUser) { tapInset.Visibility = ViewStates.Gone; infoLayout.Visibility = ViewStates.Visible; title.Text = selectedUser.DisplayName; if (selectedUser.AvatarBitmap != null) icon.SetImageBitmap (selectedUser.AvatarBitmap, true); else icon.SetImageBitmap (contactPicture, true); if (selectedUser.Emails.Any ()) { subtitle.Text = selectedUser.Emails.First (); subtitle.Visibility = ViewStates.Visible; } else { subtitle.Visibility = ViewStates.Invisible; } if (SelectedUserChanged != null) SelectedUserChanged (this, EventArgs.Empty); }
public void RestoreSelectedUserInfo(SelectedUserInfo selectedUser) { SelectedUser = selectedUser; ProcessSelectedUser (selectedUser); }