protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); if (PhoneApplicationService.Current.State.ContainsKey("objectForFileTransfer")) { object[] fileTapped = (object[])PhoneApplicationService.Current.State["objectForFileTransfer"]; long messsageId = (long)fileTapped[0]; msisdn = (string)fileTapped[1]; string filePath = HikeConstants.FILES_BYTE_LOCATION + "/" + msisdn + "/" + Convert.ToString(messsageId); byte[] filebytes; MiscDBUtil.readFileFromIsolatedStorage(filePath, out filebytes); this.FileImage.Source = UI_Utils.Instance.createImageFromBytes(filebytes); } else if (PhoneApplicationService.Current.State.ContainsKey("displayProfilePic")) { string fileName; object[] profilePicTapped = (object[])PhoneApplicationService.Current.State["displayProfilePic"]; msisdn = (string)profilePicTapped[0]; string filePath = msisdn + HikeConstants.FULL_VIEW_IMAGE_PREFIX; //check if image is already stored byte[] fullViewBytes = MiscDBUtil.getThumbNailForMsisdn(filePath); if (fullViewBytes != null && fullViewBytes.Length > 0) { this.FileImage.Source = UI_Utils.Instance.createImageFromBytes(fullViewBytes); } else if (MiscDBUtil.hasCustomProfileImage(msisdn)) { fileName = msisdn + HikeConstants.FULL_VIEW_IMAGE_PREFIX; loadingProgress.Opacity = 1; if (!Utils.isGroupConversation(msisdn)) { AccountUtils.createGetRequest(AccountUtils.BASE + "/account/avatar/" + msisdn + "?fullsize=true", getProfilePic_Callback, true, fileName); } else { AccountUtils.createGetRequest(AccountUtils.BASE + "/group/" + msisdn + "/avatar?fullsize=true", getProfilePic_Callback, true, fileName); } } else { fileName = UI_Utils.Instance.getDefaultAvatarFileName(msisdn, Utils.isGroupConversation(msisdn)); byte[] defaultImageBytes = MiscDBUtil.getThumbNailForMsisdn(fileName); if (defaultImageBytes == null || defaultImageBytes.Length == 0) { loadingProgress.Opacity = 1; AccountUtils.createGetRequest(AccountUtils.AVATAR_BASE + "/static/avatars/" + fileName, getProfilePic_Callback, false, fileName); } else { this.FileImage.Source = UI_Utils.Instance.createImageFromBytes(defaultImageBytes); } } } }
public void getProfilePic_Callback(byte[] fullBytes, object fName) { string fileName = fName as string; if (fullBytes != null && fullBytes.Length > 0) { MiscDBUtil.saveAvatarImage(fileName, fullBytes, false); } Deployment.Current.Dispatcher.BeginInvoke(() => { loadingProgress.Opacity = 0; if (fullBytes != null && fullBytes.Length > 0) { this.FileImage.Source = UI_Utils.Instance.createImageFromBytes(fullBytes); } else { byte[] smallThumbnailImage = MiscDBUtil.getThumbNailForMsisdn(msisdn); if (smallThumbnailImage != null && smallThumbnailImage.Length > 0) { this.FileImage.Source = UI_Utils.Instance.createImageFromBytes(smallThumbnailImage); } else { BitmapImage defaultImage = null; if (Utils.isGroupConversation(msisdn)) { defaultImage = UI_Utils.Instance.getDefaultGroupAvatar(msisdn); } else { defaultImage = UI_Utils.Instance.getDefaultAvatar(msisdn); } this.FileImage.Source = defaultImage; } } }); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); while (NavigationService.CanGoBack) { NavigationService.RemoveBackEntry(); } if (isFirstLaunch) { PushHelper.Instance.registerPushnotifications(); string msisdn = (string)App.appSettings[App.MSISDN_SETTING]; msisdn = msisdn.Substring(msisdn.Length - 10); StringBuilder userMsisdn = new StringBuilder(); userMsisdn.Append(msisdn.Substring(0, 3)).Append("-").Append(msisdn.Substring(3, 3)).Append("-").Append(msisdn.Substring(6)).Append("!"); string country_code = null; App.appSettings.TryGetValue <string>(App.COUNTRY_CODE_SETTING, out country_code); txtBlckPhoneNumber.Text = " " + (country_code == null ? "+91" : country_code) + "-" + userMsisdn.ToString(); if (!App.appSettings.Contains(ContactUtils.IS_ADDRESS_BOOK_SCANNED)) { if (ContactUtils.ContactState == ContactUtils.ContactScanState.ADDBOOK_NOT_SCANNING) { ContactUtils.getContacts(new ContactUtils.contacts_Callback(ContactUtils.contactSearchCompleted_Callback)); } BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (ss, ee) => { while (ContactUtils.ContactState != ContactUtils.ContactScanState.ADDBOOK_SCANNED) { Thread.Sleep(100); } // now addressbook is scanned Debug.WriteLine("Posting addbook from thread 1.... "); string token = (string)App.appSettings["token"]; AccountUtils.postAddressBook(ContactUtils.contactsMap, new AccountUtils.postResponseFunction(postAddressBook_Callback)); }; bw.RunWorkerAsync(); } isFirstLaunch = false; } txtBxEnterName.Hint = AppResources.EnterName_Name_Hint; if (App.IS_TOMBSTONED) /* **************************** HANDLING TOMBSTONE *************************** */ { object obj = null; if (this.State.TryGetValue("txtBxEnterName", out obj)) { txtBxEnterName.Text = (string)obj; txtBxEnterName.Select(txtBxEnterName.Text.Length, 0); obj = null; } if (this.State.TryGetValue("nameErrorTxt.Visibility", out obj)) { nameErrorTxt.Visibility = (Visibility)obj; nameErrorTxt.Text = (string)this.State["nameErrorTxt.Text"]; } } if (PhoneApplicationService.Current.State.ContainsKey("fbName")) { string name = PhoneApplicationService.Current.State["fbName"] as string; txtBxEnterName.Text = name; txtBxEnterName.Hint = string.Empty; nextIconButton.IsEnabled = true; } if (reloadImage) // this will handle both deactivation and tombstone { if (PhoneApplicationService.Current.State.ContainsKey("img")) { _avatar = (byte[])PhoneApplicationService.Current.State["img"]; reloadImage = false; } else { _avatar = MiscDBUtil.getThumbNailForMsisdn(HikeConstants.MY_PROFILE_PIC); } if (_avatar != null) { try { MemoryStream memStream = new MemoryStream(_avatar); memStream.Seek(0, SeekOrigin.Begin); BitmapImage empImage = new BitmapImage(); empImage.SetSource(memStream); avatarImage.Source = empImage; } catch { avatarImage.Source = UI_Utils.Instance.getDefaultAvatar((string)App.appSettings[App.MSISDN_SETTING]); } } else { avatarImage.Source = UI_Utils.Instance.getDefaultAvatar((string)App.appSettings[App.MSISDN_SETTING]); } } }
private void initPageBasedOnState() { groupId = PhoneApplicationService.Current.State[HikeConstants.GROUP_ID_FROM_CHATTHREAD] as string; groupName = PhoneApplicationService.Current.State[HikeConstants.GROUP_NAME_FROM_CHATTHREAD] as string; gi = GroupTableUtils.getGroupInfoForId(groupId); if (gi == null) { return; } if (!App.IS_TOMBSTONED) { groupImage.Source = App.ViewModel.ConvMap[groupId].AvatarImage; } else { string grpId = groupId.Replace(":", "_"); byte[] avatar = MiscDBUtil.getThumbNailForMsisdn(grpId); if (avatar == null) { groupImage.Source = UI_Utils.Instance.getDefaultGroupAvatar(grpId); } else { MemoryStream memStream = new MemoryStream(avatar); memStream.Seek(0, SeekOrigin.Begin); BitmapImage empImage = new BitmapImage(); empImage.SetSource(memStream); groupImage.Source = empImage; } GroupManager.Instance.LoadGroupParticipants(groupId); } if (Utils.isDarkTheme()) { addUserImage.Source = new BitmapImage(new Uri("images/add_users_white.png", UriKind.Relative)); } this.groupNameTxtBox.Text = groupName; List <GroupParticipant> hikeUsersList = new List <GroupParticipant>(); List <GroupParticipant> smsUsersList = GetHikeAndSmsUsers(GroupManager.Instance.GroupCache[groupId], hikeUsersList); GroupParticipant self = new GroupParticipant(groupId, (string)App.appSettings[App.ACCOUNT_NAME], App.MSISDN, true); hikeUsersList.Add(self); hikeUsersList.Sort(); for (int i = 0; i < (hikeUsersList != null ? hikeUsersList.Count : 0); i++) { GroupParticipant gp = hikeUsersList[i]; if (gi.GroupOwner == gp.Msisdn) { gp.IsOwner = true; } if (gi.GroupOwner == (string)App.appSettings[App.MSISDN_SETTING] && gp.Msisdn != gi.GroupOwner) // if this user is owner { gp.RemoveFromGroup = Visibility.Visible; } else { gp.RemoveFromGroup = Visibility.Collapsed; } groupMembersOC.Add(gp); } for (int i = 0; i < (smsUsersList != null ? smsUsersList.Count : 0); i++) { GroupParticipant gp = smsUsersList[i]; if (gi.GroupOwner == (string)App.appSettings[App.MSISDN_SETTING]) // if this user is owner { gp.RemoveFromGroup = Visibility.Visible; } else { gp.RemoveFromGroup = Visibility.Collapsed; } groupMembersOC.Add(gp); smsUsers++; } this.inviteBtn.IsEnabled = EnableInviteBtn; this.groupChatParticipants.ItemsSource = groupMembersOC; registerListeners(); }
private void MenuItem_Tap_AddRemoveFav(object sender, System.Windows.Input.GestureEventArgs e) { ListBoxItem selectedListBoxItem = this.groupChatParticipants.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem; if (selectedListBoxItem == null) { return; } GroupParticipant gp = selectedListBoxItem.DataContext as GroupParticipant; if (gp != null) { if (gp.IsFav) // already fav , remove request { MessageBoxResult result = MessageBox.Show(AppResources.Conversations_RemFromFav_Confirm_Txt, AppResources.RemFromFav_Txt, MessageBoxButton.OKCancel); if (result == MessageBoxResult.Cancel) { return; } gp.IsFav = false; ConversationListObject favObj = App.ViewModel.GetFav(gp.Msisdn); App.ViewModel.FavList.Remove(favObj); if (App.ViewModel.ConvMap.ContainsKey(gp.Msisdn)) { (App.ViewModel.ConvMap[gp.Msisdn]).IsFav = false; } JObject data = new JObject(); data["id"] = gp.Msisdn; JObject obj = new JObject(); obj[HikeConstants.TYPE] = HikeConstants.MqttMessageTypes.REMOVE_FAVOURITE; obj[HikeConstants.DATA] = data; mPubSub.publish(HikePubSub.MQTT_PUBLISH, obj); App.HikePubSubInstance.publish(HikePubSub.ADD_REMOVE_FAV_OR_PENDING, null); MiscDBUtil.SaveFavourites(); MiscDBUtil.DeleteFavourite(gp.Msisdn); int count = 0; App.appSettings.TryGetValue <int>(HikeViewModel.NUMBER_OF_FAVS, out count); App.WriteToIsoStorageSettings(HikeViewModel.NUMBER_OF_FAVS, count - 1); App.AnalyticsInstance.addEvent(Analytics.REMOVE_FAVS_CONTEXT_MENU_GROUP_INFO); } else // add to fav { gp.IsFav = true; ConversationListObject favObj; if (App.ViewModel.ConvMap.ContainsKey(gp.Msisdn)) { favObj = App.ViewModel.ConvMap[gp.Msisdn]; favObj.IsFav = true; } else { favObj = new ConversationListObject(gp.Msisdn, gp.Name, gp.IsOnHike, MiscDBUtil.getThumbNailForMsisdn(gp.Msisdn)); } App.ViewModel.FavList.Insert(0, favObj); if (App.ViewModel.IsPending(gp.Msisdn)) { App.ViewModel.PendingRequests.Remove(favObj); MiscDBUtil.SavePendingRequests(); } MiscDBUtil.SaveFavourites(); MiscDBUtil.SaveFavourites(favObj); int count = 0; App.appSettings.TryGetValue <int>(HikeViewModel.NUMBER_OF_FAVS, out count); App.WriteToIsoStorageSettings(HikeViewModel.NUMBER_OF_FAVS, count + 1); JObject data = new JObject(); data["id"] = gp.Msisdn; JObject obj = new JObject(); obj[HikeConstants.TYPE] = HikeConstants.MqttMessageTypes.ADD_FAVOURITE; obj[HikeConstants.DATA] = data; mPubSub.publish(HikePubSub.MQTT_PUBLISH, obj); App.HikePubSubInstance.publish(HikePubSub.ADD_REMOVE_FAV_OR_PENDING, null); App.AnalyticsInstance.addEvent(Analytics.ADD_FAVS_CONTEXT_MENU_GROUP_INFO); } } }