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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// this function is used as an upgrade function too.
        /// </summary>
        /// <returns></returns>
        private static List <ConversationListObject> GetConversations()
        {
            List <ConversationListObject> convList = null;

            appSettings.TryGetValue <string>(HikeConstants.FILE_SYSTEM_VERSION, out _currentVersion);
            if (_currentVersion == null)
            {
                _currentVersion = "1.0.0.0";
            }

            // this will ensure that we will show tutorials in case of app upgrade from any version to version later that 1.5.0.8
            if (Utils.compareVersion(_currentVersion, "1.5.0.8") != 1) // current version is less than equal to 1.5.0.8
            {
                WriteToIsoStorageSettings(App.SHOW_FAVORITES_TUTORIAL, true);
                WriteToIsoStorageSettings(App.SHOW_NUDGE_TUTORIAL, true);
            }

            if (_currentVersion == "1.0.0.0")  // user is upgrading from version 1.0.0.0 to latest
            {
                /*
                 * 1. Read from individual files.
                 * 2. Overite old files as they are written in a wrong format
                 */
                convList = ConversationTableUtils.getAllConversations(); // this function will read according to the old logic of Version 1.0.0.0
                ConversationTableUtils.saveConvObjectListIndividual(convList);
                WriteToIsoStorageSettings(HikeViewModel.NUMBER_OF_CONVERSATIONS, convList != null ? convList.Count : 0);
                // there was no country code in first version, and as first version was released in India , we are setting value to +91
                WriteToIsoStorageSettings(COUNTRY_CODE_SETTING, "+91");
                App.WriteToIsoStorageSettings(App.SHOW_FREE_SMS_SETTING, true);
                return(convList);
            }
            else if (Utils.compareVersion(_currentVersion, "1.5.0.0") != 1) // current version is less than equal to 1.5.0.0 and greater than 1.0.0.0
            {
                /*
                 * 1. Read from Convs File
                 * 2. Store each conv in an individual file.
                 */
                convList = ConversationTableUtils.getAllConvs();
                ConversationTableUtils.saveConvObjectListIndividual(convList);
                WriteToIsoStorageSettings(HikeViewModel.NUMBER_OF_CONVERSATIONS, convList != null ? convList.Count : 0);

                string country_code = null;
                App.appSettings.TryGetValue <string>(App.COUNTRY_CODE_SETTING, out country_code);
                if (string.IsNullOrEmpty(country_code) || country_code == "+91")
                {
                    App.WriteToIsoStorageSettings(App.SHOW_FREE_SMS_SETTING, true);
                }
                else
                {
                    App.WriteToIsoStorageSettings(App.SHOW_FREE_SMS_SETTING, false);
                }
                return(convList);
            }

            else // this corresponds to the latest version and is called everytime except update launch
            {
                int convs = 0;
                appSettings.TryGetValue <int>(HikeViewModel.NUMBER_OF_CONVERSATIONS, out convs);
                convList = ConversationTableUtils.getAllConvs();

                int convListCount = convList == null ? 0 : convList.Count;
                // This shows something failed while reading from Convs , so move to backup plan i.e read from individual files
                if (convListCount != convs)
                {
                    convList = ConversationTableUtils.GetConvsFromIndividualFiles();
                }

                return(convList);
            }
        }