Ejemplo n.º 1
0
        public HikeViewModel(List <ConversationListObject> convList)
        {
            _convMap    = new Dictionary <string, ConversationListObject>(convList.Count);
            _pendingReq = new ObservableCollection <ConversationListObject>();
            _favList    = new ObservableCollection <ConversationListObject>();

            List <ConversationBox> listConversationBox = new List <ConversationBox>();

            // this order should be maintained as _convMap should be populated before loading fav list
            for (int i = 0; i < convList.Count; i++)
            {
                ConversationListObject convListObj = convList[i];
                _convMap[convListObj.Msisdn] = convListObj;
                convListObj.ConvBoxObj       = new ConversationBox(convListObj);//context menu wil bind on page load
                listConversationBox.Add(convListObj.ConvBoxObj);
            }
            _messageListPageCollection = new ObservableCollection <ConversationBox>(listConversationBox);
            MiscDBUtil.LoadFavourites(_favList, _convMap);
            int count = 0;

            App.appSettings.TryGetValue <int>(HikeViewModel.NUMBER_OF_FAVS, out count);
            if (count != _favList.Count) // values are not loaded, move to backup plan
            {
                _favList.Clear();
                MiscDBUtil.LoadFavouritesFromIndividualFiles(_favList, _convMap);
            }
            RegisterListeners();
        }
Ejemplo n.º 2
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void processEnterName()
        {
            if (isCalled)
            {
                return;
            }
            isCalled = true;
            txtBxEnterName.IsReadOnly = false;

            Uri    nextPage;
            string country_code = null;

            App.appSettings.TryGetValue <string>(App.COUNTRY_CODE_SETTING, out country_code);

            if (string.IsNullOrEmpty(country_code) || country_code == "+91")
            {
                App.appSettings[App.SHOW_FREE_SMS_SETTING] = true;
            }
            else
            {
                App.appSettings[App.SHOW_FREE_SMS_SETTING] = false;
            }

            nextPage = new Uri("/View/WelcomeScreen.xaml", UriKind.Relative);

            nameErrorTxt.Visibility = Visibility.Collapsed;
            msgTxtBlk.Text          = AppResources.EnterName_Msg_TxtBlk;
            Thread.Sleep(1 * 500);
            try
            {
                if (_avatar != null)
                {
                    MiscDBUtil.saveAvatarImage(HikeConstants.MY_PROFILE_PIC, _avatar, false);
                }

                App.appSettings[HikeConstants.IS_NEW_INSTALLATION] = true;
                App.appSettings[App.SHOW_FAVORITES_TUTORIAL]       = true;
                App.WriteToIsoStorageSettings(App.SHOW_NUDGE_TUTORIAL, true);

                NavigationService.Navigate(nextPage);
                progressBar.Opacity   = 0;
                progressBar.IsEnabled = false;
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception handled in page EnterName Screen : " + e.StackTrace);
            }
        }
        private void deleteAccountResponse_Callback(JObject obj)
        {
            if (obj == null || "fail" == (string)obj["stat"])
            {
                logger.Info("Delete Account", "Could not delete account !!");
                return;
            }

            removeListeners();
            appSettings.Clear();
            MiscDBUtil.clearDatabase();
            /*This is used to avoid cross thread invokation exception*/
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                NavigationService.Navigate(new Uri("/View/WelcomePage.xaml", UriKind.Relative));
            });
        }
Ejemplo n.º 5
0
        public HikeViewModel()
        {
            _messageListPageCollection = new ObservableCollection <ConversationBox>();
            _convMap    = new Dictionary <string, ConversationListObject>();
            _favList    = new ObservableCollection <ConversationListObject>();
            _pendingReq = new ObservableCollection <ConversationListObject>();
            MiscDBUtil.LoadFavourites(_favList, _convMap);
            int count = 0;

            App.appSettings.TryGetValue <int>(HikeViewModel.NUMBER_OF_FAVS, out count);
            if (count != _favList.Count) // values are not loaded, move to backup plan
            {
                _favList.Clear();
                MiscDBUtil.LoadFavouritesFromIndividualFiles(_favList, _convMap);
            }
            RegisterListeners();
        }
Ejemplo n.º 6
0
        private void getStarted_click(object sender, EventArgs e)
        {
            if (isClicked)
            {
                return;
            }
            if (!App.IS_MARKETPLACE) // this is done to save the server info
            {
                App.appSettings.Save();
            }

            #region SERVER INFO
            string env = (AccountUtils.IsProd) ? "PRODUCTION" : "STAGING";
            Debug.WriteLine("SERVER SETTING : " + env);
            Debug.WriteLine("HOST : " + AccountUtils.HOST);
            Debug.WriteLine("PORT : " + AccountUtils.PORT);
            Debug.WriteLine("MQTT HOST : " + AccountUtils.MQTT_HOST);
            Debug.WriteLine("MQTT PORT : " + AccountUtils.MQTT_PORT);
            #endregion
            NetworkErrorTxtBlk.Opacity = 0;
            if (!NetworkInterface.GetIsNetworkAvailable()) // if no network
            {
                progressBar.Opacity        = 0;
                progressBar.IsEnabled      = false;
                NetworkErrorTxtBlk.Opacity = 1;
                return;
            }

            nextIconButton.IsEnabled = false;
            try
            {
                if (App.appSettings.Contains(App.IS_DB_CREATED)) // if db is created then only delete tables.
                {
                    MiscDBUtil.clearDatabase();
                }
                //App.clearAllDatabasesAsync(); // this is async function and runs on the background thread.
            }
            catch { }
            isClicked             = true;
            progressBar.Opacity   = 1;
            progressBar.IsEnabled = true;
            AccountUtils.registerAccount(null, null, new AccountUtils.postResponseFunction(registerPostResponse_Callback));
        }
Ejemplo n.º 7
0
 public void updateProfile_Callback(JObject obj)
 {
     Deployment.Current.Dispatcher.BeginInvoke(() =>
     {
         if (obj != null && HikeConstants.OK == (string)obj[HikeConstants.STAT])
         {
             avatarImage.Source    = profileImage;
             avatarImage.MaxHeight = 83;
             avatarImage.MaxWidth  = 83;
             MiscDBUtil.saveAvatarImage(HikeConstants.MY_PROFILE_PIC, _avatar, false);
         }
         else
         {
             MessageBox.Show(AppResources.Cannot_Change_Img_Error_Txt, AppResources.Something_Wrong_Txt, MessageBoxButton.OK);
         }
         //progressBarTop.IsEnabled = false;
         shellProgress.IsVisible = false;
     });
 }
Ejemplo n.º 8
0
        private void DeleteLocalStorage()
        {
            NetworkManager.turnOffNetworkManager = true;
            App.MqttManagerInstance.disconnectFromBroker(false);
            App.ClearAppSettings();
            App.WriteToIsoStorageSettings(App.IS_DB_CREATED, true);
            MiscDBUtil.clearDatabase();

            HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(HikeConstants.pushNotificationChannelName);

            if (pushChannel != null)
            {
                if (pushChannel.IsShellTileBound)
                {
                    pushChannel.UnbindToShellTile();
                }
                if (pushChannel.IsShellToastBound)
                {
                    pushChannel.UnbindToShellToast();
                }
                pushChannel.Close();
            }


            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                App.ViewModel.ClearViewModel();
                try
                {
                    progress.Hide(LayoutRoot);
                    progress = null;
                }
                catch
                {
                }
                try
                {
                    NavigationService.Navigate(new Uri("/View/WelcomePage.xaml", UriKind.Relative));
                }
                catch { }
            });
        }
Ejemplo n.º 9
0
 public bool IsPending(string ms)
 {
     if (!IsPendingListLoaded)
     {
         MiscDBUtil.LoadPendingRequests();
         IsPendingListLoaded = true;
     }
     if (_pendingReq == null)
     {
         return(false);
     }
     for (int i = 0; i < _pendingReq.Count; i++)
     {
         if (_pendingReq[i].Msisdn == ms)
         {
             return(true);
         }
     }
     return(false);
 }
        public ConversationsListPanorama()
        {
            InitializeComponent();
            mPubSub     = App.HikePubSubInstance;
            logger      = NLog.LogManager.GetCurrentClassLogger();
            appSettings = App.appSettings;
            App.ViewModel.MessageListPageCollection = new ObservableCollection <ConversationListObject>();
            this.myListBox.ItemsSource = App.ViewModel.MessageListPageCollection;
            convMap = new Dictionary <string, ConversationListObject>();
            LoadMessages();
            registerListeners();
            initAppBar();
            msisdn = (string)App.appSettings[App.MSISDN_SETTING];
            string name;

            appSettings.TryGetValue(App.ACCOUNT_NAME, out name);
            if (name != null)
            {
                accountName.Text = name;
            }

            creditsTxtBlck.Text = Convert.ToString(App.appSettings[App.SMS_SETTING]);

            photoChooserTask             = new PhotoChooserTask();
            photoChooserTask.ShowCamera  = true;
            photoChooserTask.PixelHeight = 95;
            photoChooserTask.PixelWidth  = 95;
            photoChooserTask.Completed  += new EventHandler <PhotoResult>(photoChooserTask_Completed);

            Thumbnails profileThumbnail = MiscDBUtil.getThumbNailForMSisdn(msisdn + "::large");

            if (profileThumbnail != null)
            {
                MemoryStream memStream = new MemoryStream(profileThumbnail.Avatar);
                memStream.Seek(0, SeekOrigin.Begin);

                BitmapImage empImage = new BitmapImage();
                empImage.SetSource(memStream);
                avatarImage.Source = empImage;
            }
        }
        private void LoadMessages()
        {
            List <Conversation> conversationList = ConversationTableUtils.getAllConversations();

            if (conversationList == null)
            {
                return;
            }
            for (int i = 0; i < conversationList.Count; i++)
            {
                Conversation conv        = conversationList[i];
                ConvMessage  lastMessage = MessagesTableUtils.getLastMessageForMsisdn(conv.Msisdn); // why we are not getting only lastmsg as string
                ContactInfo  contact     = UsersTableUtils.getContactInfoFromMSISDN(conv.Msisdn);

                Thumbnails             thumbnail = MiscDBUtil.getThumbNailForMSisdn(conv.Msisdn);
                ConversationListObject mObj      = new ConversationListObject((contact == null) ? conv.Msisdn : contact.Msisdn, (contact == null) ? conv.Msisdn : contact.Name, lastMessage.Message, (contact == null) ? conv.OnHike : contact.OnHike,
                                                                              TimeUtils.getTimeString(lastMessage.Timestamp), thumbnail == null ? null : thumbnail.Avatar);
                convMap.Add(conv.Msisdn, mObj);
                App.ViewModel.MessageListPageCollection.Add(mObj);
            }
        }
Ejemplo n.º 12
0
        public void onFailure(Exception value)
        {
            if ((value is ConnectionException) && ((ConnectionException)value).getCode().Equals(finalmqtt.Msg.ConnAckMessage.ConnectionStatus.BAD_USERNAME_OR_PASSWORD))
            {
                bool isPresent = false;
                if (App.appSettings.Contains(App.IS_DB_CREATED))
                {
                    isPresent = true;
                }
                App.ClearAppSettings();
                if (isPresent)
                {
                    App.WriteToIsoStorageSettings(App.IS_DB_CREATED, true);
                }
                NetworkManager.turnOffNetworkManager = true; // stop network manager
                App.MqttManagerInstance.disconnectFromBroker(false);
                MiscDBUtil.clearDatabase();

                HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(HikeConstants.pushNotificationChannelName);
                if (pushChannel != null)
                {
                    if (pushChannel.IsShellTileBound)
                    {
                        pushChannel.UnbindToShellTile();
                    }
                    if (pushChannel.IsShellToastBound)
                    {
                        pushChannel.UnbindToShellToast();
                    }
                    pushChannel.Close();
                }
                App.HikePubSubInstance.publish(HikePubSub.BAD_USER_PASS, null);
            }
            else if (hikeMqttManager.connectionStatus != HikeMqttManager.MQTTConnectionStatus.NOTCONNECTED_WAITINGFORINTERNET)
            {
                scheduler.Schedule(hikeMqttManager.connect, TimeSpan.FromSeconds(5));
            }
            hikeMqttManager.setConnectionStatus(windows_client.Mqtt.HikeMqttManager.MQTTConnectionStatus.NOTCONNECTED_UNKNOWNREASON);
        }
Ejemplo n.º 13
0
        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;
                    }
                }
            });
        }
        public void onEventReceived(string type, object obj)
        {
            if (HikePubSub.MESSAGE_RECEIVED == type || HikePubSub.SEND_NEW_MSG == type)
            {
                ConvMessage            convMessage = (ConvMessage)obj;
                ConversationListObject mObj;
                bool isNewConversation = false;

                /*This is used to avoid cross thread invokation exception*/

                if (convMap.ContainsKey(convMessage.Msisdn))
                {
                    mObj             = convMap[convMessage.Msisdn];
                    mObj.LastMessage = convMessage.Message;
                    mObj.TimeStamp   = TimeUtils.getTimeString(convMessage.Timestamp);
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        App.ViewModel.MessageListPageCollection.Remove(mObj);
                    });
                }
                else
                {
                    ContactInfo contact   = UsersTableUtils.getContactInfoFromMSISDN(convMessage.Msisdn);
                    Thumbnails  thumbnail = MiscDBUtil.getThumbNailForMSisdn(convMessage.Msisdn);
                    mObj = new ConversationListObject(convMessage.Msisdn, contact == null ? convMessage.Msisdn : contact.Name, convMessage.Message,
                                                      contact == null ? !convMessage.IsSms : contact.OnHike, TimeUtils.getTimeString(convMessage.Timestamp),
                                                      thumbnail == null ? null : thumbnail.Avatar);

                    convMap.Add(convMessage.Msisdn, mObj);
                    isNewConversation = true;
                }
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    if (App.ViewModel.MessageListPageCollection == null)
                    {
                        App.ViewModel.MessageListPageCollection = new ObservableCollection <ConversationListObject>();
                    }
                    App.ViewModel.MessageListPageCollection.Insert(0, mObj);
                });
                object[] vals = new object[2];
                vals[0] = convMessage;
                vals[1] = isNewConversation;
                if (HikePubSub.SEND_NEW_MSG == type)
                {
                    mPubSub.publish(HikePubSub.MESSAGE_SENT, vals);
                }
            }
            else if (HikePubSub.MSG_READ == type)
            {
                string msisdn = (string)obj;
                try
                {
                    ConversationListObject convObj = convMap[msisdn];
                    convObj.MessageStatus = ConvMessage.State.RECEIVED_READ;
                    //TODO : update the UI here also.
                }
                catch (KeyNotFoundException)
                {
                }
            }
            else if ((HikePubSub.USER_LEFT == type) || (HikePubSub.USER_JOINED == type))
            {
                string msisdn = (string)obj;
                try
                {
                    ConversationListObject convObj = convMap[msisdn];
                    convObj.IsOnhike = HikePubSub.USER_JOINED == type;
                }
                catch (KeyNotFoundException)
                {
                }
            }
            else if (HikePubSub.UPDATE_UI == type)
            {
                string msisdn = (string)obj;
                try
                {
                    ConversationListObject convObj = convMap[msisdn];
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        convObj.NotifyPropertyChanged("Msisdn");
                    });
                }
                catch (KeyNotFoundException)
                {
                }
            }
            else if (HikePubSub.SMS_CREDIT_CHANGED == type)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    creditsTxtBlck.Text = Convert.ToString((int)obj);
                });
            }
        }
Ejemplo n.º 15
0
        public static List <ContactInfo> getContactList(JObject obj, Dictionary <string, List <ContactInfo> > new_contacts_by_id, bool isRefresh)
        {
            try
            {
                if ((obj == null) || HikeConstants.FAIL == (string)obj[HikeConstants.STAT])
                {
                    return(null);
                }

                JObject addressbook = (JObject)obj["addressbook"];

                if (addressbook == null || new_contacts_by_id == null || new_contacts_by_id.Count == 0)
                {
                    return(null);
                }

                bool isFavSaved = false;
                bool isPendingSaved = false;
                int  hikeCount = 1, smsCount = 1;
                List <ContactInfo>             msgToShow = null;
                List <string>                  msisdns = null;
                Dictionary <string, GroupInfo> allGroupsInfo = null;
                if (!isRefresh)
                {
                    msgToShow = new List <ContactInfo>(5);
                    msisdns   = new List <string>();
                }
                else // if refresh case load groups in cache
                {
                    GroupManager.Instance.LoadGroupCache();
                    List <GroupInfo> gl = GroupTableUtils.GetAllGroups();
                    for (int i = 0; i < gl.Count; i++)
                    {
                        if (allGroupsInfo == null)
                        {
                            allGroupsInfo = new Dictionary <string, GroupInfo>();
                        }
                        allGroupsInfo[gl[i].GroupId] = gl[i];
                    }
                }

                List <ContactInfo> server_contacts = new List <ContactInfo>();
                IEnumerator <KeyValuePair <string, JToken> > keyVals = addressbook.GetEnumerator();
                KeyValuePair <string, JToken> kv;
                int count         = 0;
                int totalContacts = 0;

                while (keyVals.MoveNext())
                {
                    try
                    {
                        kv = keyVals.Current;
                        JArray             entries = (JArray)addressbook[kv.Key];
                        List <ContactInfo> cList   = new_contacts_by_id[kv.Key];
                        for (int i = 0; i < entries.Count; ++i)
                        {
                            JObject entry  = (JObject)entries[i];
                            string  msisdn = (string)entry["msisdn"];
                            if (string.IsNullOrWhiteSpace(msisdn))
                            {
                                count++;
                                continue;
                            }
                            bool        onhike = (bool)entry["onhike"];
                            ContactInfo cinfo  = cList[i];
                            ContactInfo cn     = new ContactInfo(kv.Key, msisdn, cinfo.Name, onhike, cinfo.PhoneNo);

                            if (!isRefresh)                                                   // this is case for new installation
                            {
                                if (cn.Msisdn != (string)App.appSettings[App.MSISDN_SETTING]) // do not add own number
                                {
                                    if (onhike && hikeCount <= 3 && !msisdns.Contains(cn.Msisdn))
                                    {
                                        msisdns.Add(cn.Msisdn);
                                        msgToShow.Add(cn);
                                        hikeCount++;
                                    }
                                    if (!onhike && smsCount <= 2 && cn.Msisdn.StartsWith("+91") && !msisdns.Contains(cn.Msisdn)) // allow only indian numbers for sms
                                    {
                                        msisdns.Add(cn.Msisdn);
                                        msgToShow.Add(cn);
                                        smsCount++;
                                    }
                                }
                            }
                            else // this is refresh contacts case
                            {
                                if (App.ViewModel.ConvMap.ContainsKey(cn.Msisdn)) // update convlist
                                {
                                    try
                                    {
                                        App.ViewModel.ConvMap[cn.Msisdn].ContactName = cn.Name;
                                    }
                                    catch (Exception e)
                                    {
                                        Debug.WriteLine("REFRESH CONTACTS :: Update contact exception " + e.StackTrace);
                                    }
                                }
                                else // fav and pending case
                                {
                                    ConversationListObject c = App.ViewModel.GetFav(cn.Msisdn);
                                    if (c != null) // this user is in favs
                                    {
                                        c.ContactName = cn.Name;
                                        MiscDBUtil.SaveFavourites(c);
                                        isFavSaved = true;
                                    }
                                    else
                                    {
                                        c = App.ViewModel.GetPending(cn.Msisdn);
                                        if (c != null)
                                        {
                                            c.ContactName  = cn.Name;
                                            isPendingSaved = true;
                                        }
                                    }
                                }
                                GroupManager.Instance.RefreshGroupCache(cn, allGroupsInfo);
                            }
                            server_contacts.Add(cn);
                            totalContacts++;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("AccountUtils : getContactList : Exception : " + ex.StackTrace);
                    }
                }
                if (isFavSaved)
                {
                    MiscDBUtil.SaveFavourites();
                }
                if (isPendingSaved)
                {
                    MiscDBUtil.SavePendingRequests();
                }
                msisdns = null;
                Debug.WriteLine("Total contacts with no msisdn : {0}", count);
                Debug.WriteLine("Total contacts inserted : {0}", totalContacts);
                if (!isRefresh)
                {
                    App.WriteToIsoStorageSettings(HikeConstants.AppSettings.CONTACTS_TO_SHOW, msgToShow);
                }
                return(server_contacts);
            }
            catch (ArgumentException)
            {
                return(null);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Ejemplo n.º 16
0
        private void Invite_Or_Fav_Click(object sender, EventArgs e)
        {
            #region FAV SECTION
            if (_isAddToFavPage)
            {
                bool isPendingRemoved = false;
                for (int i = 0; i < (hikeFavList == null ? 0 : hikeFavList.Count); i++)
                {
                    if (!App.ViewModel.Isfavourite(hikeFavList[i].Msisdn) && hikeFavList[i].Msisdn != App.MSISDN) // if not already favourite then only add to fav
                    {
                        ConversationListObject favObj = null;
                        if (App.ViewModel.ConvMap.ContainsKey(hikeFavList[i].Msisdn))
                        {
                            favObj       = App.ViewModel.ConvMap[hikeFavList[i].Msisdn];
                            favObj.IsFav = true;
                        }
                        else
                        {
                            favObj = new ConversationListObject(hikeFavList[i].Msisdn, hikeFavList[i].Name, hikeFavList[i].OnHike, hikeFavList[i].Avatar);
                        }

                        App.ViewModel.FavList.Insert(0, favObj);
                        if (App.ViewModel.IsPending(favObj.Msisdn)) // if this is in pending already , remove from pending and add to fav
                        {
                            App.ViewModel.PendingRequests.Remove(favObj);
                            isPendingRemoved = true;
                        }
                        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"] = hikeFavList[i].Msisdn;
                        JObject obj = new JObject();
                        obj[HikeConstants.TYPE] = HikeConstants.MqttMessageTypes.ADD_FAVOURITE;
                        obj[HikeConstants.DATA] = data;
                        App.HikePubSubInstance.publish(HikePubSub.MQTT_PUBLISH, obj);
                        MiscDBUtil.SaveFavourites(favObj);
                        App.AnalyticsInstance.addEvent(Analytics.ADD_FAVS_INVITE_USERS);
                    }
                }
                MiscDBUtil.SaveFavourites();
                if (isPendingRemoved)
                {
                    MiscDBUtil.SavePendingRequests();
                }
                App.HikePubSubInstance.publish(HikePubSub.ADD_REMOVE_FAV_OR_PENDING, null);
            }
            #endregion
            #region INVITE
            else
            {
                string inviteToken = "";
                //App.appSettings.TryGetValue<string>(HikeConstants.INVITE_TOKEN, out inviteToken);
                int count = 0;
                foreach (string key in contactsList.Keys)
                {
                    if (key == App.MSISDN)
                    {
                        continue;
                    }
                    JObject obj  = new JObject();
                    JObject data = new JObject();
                    data[HikeConstants.SMS_MESSAGE] = string.Format(AppResources.sms_invite_message, inviteToken);
                    data[HikeConstants.TIMESTAMP]   = TimeUtils.getCurrentTimeStamp();
                    data[HikeConstants.MESSAGE_ID]  = -1;
                    obj[HikeConstants.TO]           = key;
                    obj[HikeConstants.DATA]         = data;
                    obj[HikeConstants.TYPE]         = NetworkManager.INVITE;
                    App.MqttManagerInstance.mqttPublishToServer(obj);
                    count++;
                }
                if (count > 0)
                {
                    MessageBox.Show(string.Format(AppResources.InviteUsers_TotalInvitesSent_Txt, count), AppResources.InviteUsers_FriendsInvited_Txt, MessageBoxButton.OK);
                }
            }
            #endregion
            NavigationService.GoBack();
        }
Ejemplo n.º 17
0
        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]);
                }
            }
        }
Ejemplo n.º 18
0
        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();
        }
Ejemplo n.º 19
0
        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);
                }
            }
        }