Example usage for android.app LoaderManager destroyLoader

List of usage examples for android.app LoaderManager destroyLoader

Introduction

In this page you can find the example usage for android.app LoaderManager destroyLoader.

Prototype

public abstract void destroyLoader(int id);

Source Link

Document

Stops and removes the loader with the given ID.

Usage

From source file:com.tct.mail.ui.AbstractActivityController.java

/**
 * Load conversation list when click the star toggle in actionbar.
 *///w w w  .  j av a 2  s  .c  om
private void loadConvListByStarToggle(Account nextAccount, Folder nextFolder) {
    final Bundle args = new Bundle(3); //TS: zheng.zou 2016-1-14 EMAIL TASK_1431225 MOD
    if (nextAccount != null) {
        args.putParcelable(BUNDLE_ACCOUNT_KEY, nextAccount);
    } else {
        args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount);
    }
    if (nextFolder != null) {
        args.putParcelable(BUNDLE_FOLDER_KEY, nextFolder);
    } else {
        LogUtils.e(LOG_TAG, new Error(), "AAC.loadConvListByStarToggle(): Got an empty folder");
    }
    args.putInt(BUNDLE_CONVERSATION_ORDER_KEY, SortHelper.getCurrentSort()); //TS: zheng.zou 2016-1-14 EMAIL TASK_1431225 ADD
    final LoaderManager lm = mActivity.getLoaderManager();
    lm.destroyLoader(LOADER_CONVERSATION_LIST);
    lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks);
}

From source file:com.tct.mail.ui.AbstractActivityController.java

@Override
public void loadAccountInbox() {
    boolean handled = false;
    if (mFolderWatcher != null) {
        final Folder inbox = mFolderWatcher.getDefaultInbox(mAccount);
        if (inbox != null) {
            onFolderChanged(inbox, false /* force */);
            handled = true;//from w ww .jav  a 2  s.c  om
        }
    }
    if (!handled) {
        LogUtils.d(LOG_TAG, "Starting a LOADER_ACCOUNT_INBOX for %s", mAccount);
        restartOptionalLoader(LOADER_ACCOUNT_INBOX, mFolderCallbacks, Bundle.EMPTY);
        //TS: chaozhang 2015-6-26 EMAIL BUGFIX_1022808 ADD_S
        LogUtils.d(LOG_TAG, "Restart a LOADER_ACCOUNT_INBOX");
        // if the inbox has not be prepared when we change to new account, we must revert everything
        /// that depends on a mailbox. such as loader, actionbar @{
        final LoaderManager lm = mActivity.getLoaderManager();
        lm.destroyLoader(LOADER_FOLDER_CURSOR);
        //  Also destroy the loader LOADER_CONVERSATION_LIST.
        lm.destroyLoader(LOADER_CONVERSATION_LIST);
        mInbox = null;
        mFolder = null;
        mActionBarController.setFolder(mFolder);
        perhapsEnterWaitMode();
        return;
        //TS: chaozhang 2015-6-26 EMAIL BUGFIX_1022808 ADD_E
    }
    final int mode = mViewMode.getMode();
    if (mode == ViewMode.UNKNOWN || mode == ViewMode.WAITING_FOR_ACCOUNT_INITIALIZATION) {
        mViewMode.enterConversationListMode();
    }
}

From source file:com.chen.mail.ui.AbstractActivityController.java

/**
 * Sets the current folder if it is different from the object provided here. This method does
 * NOT notify the folder observers that a change has happened. Observers are notified when we
 * get an updated folder from the loaders, which will happen as a consequence of this method
 * (since this method starts/restarts the loaders).
 * @param folder The folder to assign/*from  www .j av  a 2s. c om*/
 */
private void updateFolder(Folder folder) {
    if (folder == null || !folder.isInitialized()) {
        LogUtils.e(LOG_TAG, new Error(), "AAC.setFolder(%s): Bad input", folder);
        return;
    }
    if (folder.equals(mFolder)) {
        LogUtils.d(LOG_TAG, "AAC.setFolder(%s): Input matches mFolder", folder);
        return;
    }
    final boolean wasNull = mFolder == null;
    LogUtils.d(LOG_TAG, "AbstractActivityController.setFolder(%s)", folder.name);
    final LoaderManager lm = mActivity.getLoaderManager();
    // updateFolder is called from AAC.onLoadFinished() on folder changes.  We need to
    // ensure that the folder is different from the previous folder before marking the
    // folder changed.
    setHasFolderChanged(folder);
    mFolder = folder;

    // We do not need to notify folder observers yet. Instead we start the loaders and
    // when the load finishes, we will get an updated folder. Then, we notify the
    // folderObservers in onLoadFinished.
    mActionBarView.setFolder(mFolder);

    // Only when we switch from one folder to another do we want to restart the
    // folder and conversation list loaders (to trigger onCreateLoader).
    // The first time this runs when the activity is [re-]initialized, we want to re-use the
    // previous loader's instance and data upon configuration change (e.g. rotation).
    // If there was not already an instance of the loader, init it.
    if (lm.getLoader(LOADER_FOLDER_CURSOR) == null) {
        lm.initLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks);
    } else {
        lm.restartLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks);
    }
    if (!wasNull && lm.getLoader(LOADER_CONVERSATION_LIST) != null) {
        // If there was an existing folder AND we have changed
        // folders, we want to restart the loader to get the information
        // for the newly selected folder
        lm.destroyLoader(LOADER_CONVERSATION_LIST);
    }
    final Bundle args = new Bundle(2);
    args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount);
    args.putParcelable(BUNDLE_FOLDER_KEY, mFolder);
    lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks);
}

From source file:com.android.mail.ui.AbstractActivityController.java

/**
 * Sets the current folder if it is different from the object provided here. This method does
 * NOT notify the folder observers that a change has happened. Observers are notified when we
 * get an updated folder from the loaders, which will happen as a consequence of this method
 * (since this method starts/restarts the loaders).
 * @param folder The folder to assign/*from   w  w  w .j a  v a2  s  .com*/
 */
private void updateFolder(Folder folder) {
    if (folder == null || !folder.isInitialized()) {
        LogUtils.e(LOG_TAG, new Error(), "AAC.setFolder(%s): Bad input", folder);
        return;
    }
    if (folder.equals(mFolder)) {
        LogUtils.d(LOG_TAG, "AAC.setFolder(%s): Input matches mFolder", folder);
        return;
    }
    final boolean wasNull = mFolder == null;
    LogUtils.d(LOG_TAG, "AbstractActivityController.setFolder(%s)", folder.name);
    final LoaderManager lm = mActivity.getLoaderManager();
    // updateFolder is called from AAC.onLoadFinished() on folder changes.  We need to
    // ensure that the folder is different from the previous folder before marking the
    // folder changed.
    setHasFolderChanged(folder);
    mFolder = folder;

    // We do not need to notify folder observers yet. Instead we start the loaders and
    // when the load finishes, we will get an updated folder. Then, we notify the
    // folderObservers in onLoadFinished.
    mActionBarController.setFolder(mFolder);

    // Only when we switch from one folder to another do we want to restart the
    // folder and conversation list loaders (to trigger onCreateLoader).
    // The first time this runs when the activity is [re-]initialized, we want to re-use the
    // previous loader's instance and data upon configuration change (e.g. rotation).
    // If there was not already an instance of the loader, init it.
    if (lm.getLoader(LOADER_FOLDER_CURSOR) == null) {
        lm.initLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks);
    } else {
        lm.restartLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks);
    }
    if (!wasNull && lm.getLoader(LOADER_CONVERSATION_LIST) != null) {
        // If there was an existing folder AND we have changed
        // folders, we want to restart the loader to get the information
        // for the newly selected folder
        lm.destroyLoader(LOADER_CONVERSATION_LIST);
    }
    final Bundle args = new Bundle(2);
    args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount);
    args.putParcelable(BUNDLE_FOLDER_KEY, mFolder);
    args.putBoolean(BUNDLE_IGNORE_INITIAL_CONVERSATION_LIMIT_KEY, mIgnoreInitialConversationLimit);
    mIgnoreInitialConversationLimit = false;
    lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks);
}

From source file:com.tct.mail.ui.AbstractActivityController.java

/**
 * TCT: Move data load code to an independent function, if we just want refresh loader data.
 * call this to refresh cursor data(local search or update folder)
 *//*from ww w  . j  a  v a2 s.  co  m*/
private void loadConversationListData(boolean folderUpdated) {
    if (mFolder == null || !mFolder.isInitialized()) {
        LogUtils.e(LOG_TAG, new Error(), "AAC.setFolder(%s): Bad input", mFolder);
        return;
    }
    final LoaderManager lm = mActivity.getLoaderManager();

    if (mConvListContext != null && mConvListContext.isLocalSearchExecuted()) {
        final Bundle args = new Bundle(4);
        args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount);
        args.putParcelable(BUNDLE_FOLDER_KEY, mFolder);
        args.putString(SearchParams.BUNDLE_QUERY_FIELD, mConvListContext.getSearchField());
        args.putString(SearchParams.BUNDLE_QUERY_TERM, mConvListContext.getSearchQuery());
        LogUtils.logFeature(LogTag.SEARCH_TAG,
                "loadConversationListData for local search query [%s], field [%s]",
                mConvListContext.getSearchQuery(), mConvListContext.getSearchField());
        ///TCT: Before we start the local search loader, need cancel the normal conversation list
        // loader to avoid no need load and wrong result display by the load finish delay.@{
        if (lm.getLoader(LOADER_CONVERSATION_LIST) != null) {
            lm.destroyLoader(LOADER_CONVERSATION_LIST);
        }
        // @}

        lm.restartLoader(LOADER_LOCALSEARCH_CONVERSATION_LIST, args, mListCursorCallbacks);
    } else {

        ///TCT: Before we start the normal search loader, need cancel the local search conversation list
        // loader to avoid no need load and wrong result display by the load finish delay.@{
        if (lm.getLoader(LOADER_LOCALSEARCH_CONVERSATION_LIST) != null) {

            lm.destroyLoader(LOADER_LOCALSEARCH_CONVERSATION_LIST);

        }
        // @}

        // TS: kaifeng.lu 2015-09-8 EMAIL BUGFIX-1065353 DEL_S
        //            final ConversationCursorLoader ccl = (ConversationCursorLoader) ((Object) lm
        //                    .getLoader(LOADER_CONVERSATION_LIST));

        //            if (ccl != null && !ccl.getUri().equals(mFolder.conversationListUri) && folderUpdated) {

        // If there was an existing folder AND we have changed
        // folders, we want to restart the loader to get the information
        // for the newly selected folder
        //                lm.destroyLoader(LOADER_CONVERSATION_LIST);

        //            }
        // TS: kaifeng.lu 2015-09-8 EMAIL BUGFIX-1065353 DEL_E

        final Bundle args = new Bundle(2);
        args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount);
        args.putParcelable(BUNDLE_FOLDER_KEY, mFolder);
        args.putBoolean(BUNDLE_IGNORE_INITIAL_CONVERSATION_LIMIT_KEY, mIgnoreInitialConversationLimit);
        mIgnoreInitialConversationLimit = false;
        lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks);
    }
}

From source file:com.tct.mail.ui.AbstractActivityController.java

/**
 * Sets the current folder if it is different from the object provided here. This method does
 * NOT notify the folder observers that a change has happened. Observers are notified when we
 * get an updated folder from the loaders, which will happen as a consequence of this method
 * (since this method starts/restarts the loaders).
 * @param folder The folder to assign// w w w .j a v  a 2  s .  co  m
 */
private void updateFolder(Folder folder) {
    if (folder == null || !folder.isInitialized()) {
        LogUtils.e(LOG_TAG, new Error(), "AAC.setFolder(%s): Bad input", folder);
        return;
    }
    if (folder.equals(mFolder)) {
        LogUtils.d(LOG_TAG, "AAC.setFolder(%s): Input matches mFolder", folder);
        return;
    }
    final boolean wasNull = mFolder == null;
    LogUtils.d(LOG_TAG, "AbstractActivityController.setFolder(%s)", folder.name);
    final LoaderManager lm = mActivity.getLoaderManager();
    // updateFolder is called from AAC.onLoadFinished() on folder changes.  We need to
    // ensure that the folder is different from the previous folder before marking the
    // folder changed.
    setHasFolderChanged(folder);
    mFolder = folder;

    // We do not need to notify folder observers yet. Instead we start the loaders and
    // when the load finishes, we will get an updated folder. Then, we notify the
    // folderObservers in onLoadFinished.
    mActionBarController.setFolder(mFolder);
    //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-S
    mActivity.invalidateOptionsMenu();
    //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-E

    // Only when we switch from one folder to another do we want to restart the
    // folder and conversation list loaders (to trigger onCreateLoader).
    // The first time this runs when the activity is [re-]initialized, we want to re-use the
    // previous loader's instance and data upon configuration change (e.g. rotation).
    // If there was not already an instance of the loader, init it.
    if (lm.getLoader(LOADER_FOLDER_CURSOR) == null) {
        lm.initLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks);
    } else {
        lm.restartLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks);
    }
    if (!wasNull && lm.getLoader(LOADER_CONVERSATION_LIST) != null) {
        // If there was an existing folder AND we have changed
        // folders, we want to restart the loader to get the information
        // for the newly selected folder
        lm.destroyLoader(LOADER_CONVERSATION_LIST);
    }
    /// TCT: Fix the empty view will always flash out here. no need show empty view when folde changing,
    // folders, we want to restart the loader to get the information    /// cause loadConversationListData would always destroy loader,and the cursor always be empty when do this. @{
    // for the newly selected folder
    final ConversationListFragment conversationList = getConversationListFragment();
    // TS: zheng.zou 2015-05-8 EMAIL BUGFIX-976970 DEL_S
    //        lm.destroyLoader(LOADER_CONVERSATION_LIST);
    // TS: zheng.zou 2015-05-8 EMAIL BUGFIX-976970 DEL_E
    if (conversationList != null) {
        conversationList.getListView().setEmptyView(null);
    }
    loadConversationListData(true);
}