예제 #1
0
        /// <summary>
        /// Handler when page is retrieved successfully. Store the list of contacts in memory and
        /// fetch the next page. If this is the last page, display them.
        /// </summary>
        /// <param name="page">Page with list of contacts.</param>
        private void RefreshListPageReady(MLContacts.ListPage page)
        {
            #if PLATFORM_LUMIN
            foreach (MLContacts.Contact contact in page.ContactsList)
            {
                loadedContacts[contact.ID] = contact;
            }

            OnRefreshPageList(page);

            if (page.Status == MLContacts.ListPage.PageStatus.LastPage)
            {
                return;
            }

            // Automatically fetches the next page; triggering RefreshListPageReady when done or HandlePageFailed on failure.
            MLResult result = page.NextPage();
            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: MLContactsBehavior failed to request the next page while refreshing the list, disabling script. Reason was: {0}", result);
                enabled = false;
                return;
            }
            #endif
        }
예제 #2
0
        /// <summary>
        /// Handler when page is retrieved successfully. Store the list of contacts in memory and
        /// fetch the next page. If this is the last page, display them.
        /// </summary>
        /// <param name="page">Page with list of contacts.</param>
        private void HandleRefreshListPage(MLContacts.ListPage page)
        {
            _needToReloadContacts = false;

            #if PLATFORM_LUMIN
            if (page.Status == MLContacts.ListPage.PageStatus.LastPage)
            {
                _listPage.PopulateList(new List <MLContacts.Contact>(_contacts.loadedContacts.Values));
            }
            #endif
        }
예제 #3
0
        /// <summary>
        /// Fetches all contacts matching the query, if any.
        /// </summary>
        /// <param name="query">The query string to use for searching.</param>
        public void LoadContactsFromAPI(string query = "")
        {
            #if PLATFORM_LUMIN
            if (!MLContacts.IsStarted)
            {
                return;
            }

            loadedContacts.Clear();

            MLResult            result;
            MLContacts.ListPage fillPage = null;

            if (string.IsNullOrEmpty(query))
            {
                fillPage = MLContacts.CreateListPage(MLContacts.DefaultFetchLimit, out result, RefreshListPageReady, HandlePageFailed);
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("Error: MLContactsBehavior failed to create the contacts list page, disabling script. Reason: {0}", result);
                    enabled = false;
                    return;
                }
            }
            else
            {
                // Change second parameter to limit searching by name, email address, or phone number only.
                fillPage = MLContacts.CreateSearchPage(query, MLContacts.SearchField.All, MLContacts.DefaultFetchLimit, out result, RefreshListPageReady, HandlePageFailed);
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("Error: MLContactsBehavior failed to create the contacts search page, disabling script. Reason: {0}", result);
                    enabled = false;
                    return;
                }
            }

            // Begin fetching contacts.
            result = fillPage.NextPage();
            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: MLContactsBehavior failed to request the next page of contacts, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }
            #endif
        }
예제 #4
0
 /// <summary>
 /// Handler when page failed to retrieve.
 /// </summary>
 /// <param name="page">Page that failed.</param>
 /// <param name="result">Result of the operation.</param>
 private void HandlePageFailed(MLContacts.ListPage page, MLResult result)
 {
     Debug.LogErrorFormat("Error: MLContactsBehavior failed to retreive a page. Reason was: {0}", result);
 }