Example usage for android.support.v4.app LoaderManager getLoader

List of usage examples for android.support.v4.app LoaderManager getLoader

Introduction

In this page you can find the example usage for android.support.v4.app LoaderManager getLoader.

Prototype

public abstract <D> Loader<D> getLoader(int id);

Source Link

Document

Return the Loader with the given id or null if no matching Loader is found.

Usage

From source file:tv.loilo.promise.support.PromiseLoader.java

public static void cancelLoader(LoaderManager loaderManager, int id) {
    final Loader<?> loader = loaderManager.getLoader(id);
    if (loader == null) {
        return;/*from  w  w  w.j  a v a2 s .c  om*/
    }
    loader.cancelLoad();
}

From source file:tv.loilo.promise.support.ProgressPromiseLoader.java

public static <TData, TProgress> void attachProgressCallback(LoaderManager loaderManager, int id,
        @NonNull ProgressPromiseLoaderCallbacks<TData, TProgress> loaderCallbacks) {
    final Loader<Result<TData>> loader = loaderManager.getLoader(id);
    if (loader == null) {
        return;//from  www .  j  a  v a  2  s.  c om
    }

    @SuppressWarnings("unchecked")
    final ProgressPromiseLoader<TData, TProgress> promiseLoader = (ProgressPromiseLoader<TData, TProgress>) loader;
    promiseLoader.attachLoaderCallbacks(loaderCallbacks);
}

From source file:tv.loilo.promise.support.ProgressPromiseLoader.java

public static <TData, TProgress> void detachProgressCallback(LoaderManager loaderManager, int id,
        @NonNull ProgressPromiseLoaderCallbacks<TData, TProgress> loaderCallbacks) {
    final Loader<Result<TData>> loader = loaderManager.getLoader(id);
    if (loader == null) {
        return;//from w w w.ja v a  2 s.  c o  m
    }

    @SuppressWarnings("unchecked")
    final ProgressPromiseLoader<TData, TProgress> promiseLoader = (ProgressPromiseLoader<TData, TProgress>) loader;
    promiseLoader.detachLoaderCallbacks(loaderCallbacks);
}

From source file:com.example.levelup.core.app.ProgressDialogLoaderCallbacks.java

/**
 * If there's an existing loader, reconnect to it so the callbacks are delivered. This would
 * happen if the user made the request and wandered away from the activity (say, by an incoming
 * call or to check their email) before the loader finished. When they returned, the result
 * would be delivered here. This also dismisses any progress dialogs that may be showing. This
 * method should be called on the start of the activity.
 *//*from   w  w  w.j a va  2  s . c o  m*/
public void reconnectOrDismiss() {
    Fragment fragment = getFragment();

    if (fragment != null) {
        LoaderManager lm = fragment.getLoaderManager();
        Loader<D> existingLoader = lm.getLoader(mLoaderId);

        /*
         * Only call initLoader if there's an existing loader and it's got content waiting to be
         * delivered. This reconnects the loader to the callbacks.
         */
        if (existingLoader != null) {
            lm.initLoader(mLoaderId, null, this);
        } else {
            // This can happen if the result won't be delivered.
            dismissProgressDialog();
        }
    }
}

From source file:com.github.jobs.ui.fragment.TemplatesListFragment.java

private void queryList() {
    try {/*from   w w w. j a  v  a  2s.  com*/
        FragmentActivity activity = getActivity();
        if (activity == null || !isAdded()) {
            return;
        }
        LoaderManager loaderManager = activity.getSupportLoaderManager();
        Loader<Object> loader = loaderManager.getLoader(TEMPLATES_LOADER_ID);
        if (loader == null) {
            loaderManager.initLoader(TEMPLATES_LOADER_ID, null, this);
        } else {
            loaderManager.restartLoader(TEMPLATES_LOADER_ID, null, this);
        }
    } catch (IllegalStateException e) {
        // happens when activity is closed. We can't use isResumed since it will be false when the activity is
        // not being shown, thus it will cause problems if user loads another screen while this is still loading
    }
}

From source file:com.gh4a.activities.GistActivity.java

@Override
public void onRefresh() {
    LoaderManager lm = getSupportLoaderManager();
    lm.getLoader(0).onContentChanged();
    lm.getLoader(1).onContentChanged();//from   www.ja va 2s  .co  m
    mGist = null;
    mIsStarred = null;
    setContentShown(false);
    super.onRefresh();
}

From source file:com.armannds.eldgos.katla.popularmovies.ui.MainActivity.java

private void loadMovies(int movieFilter) {
    showMoviesGrid();/*w ww  .  j  a  v  a 2 s .  c o  m*/
    mMovieFilter = movieFilter;
    LoaderManager loaderManager = getSupportLoaderManager();
    Loader<List<Movie>> movieLoader = loaderManager.getLoader(MOVIE_LOADER);
    if (movieLoader == null) {
        loaderManager.initLoader(MOVIE_LOADER, null, this);
    } else {
        loaderManager.restartLoader(MOVIE_LOADER, null, this);
    }
    setTitle(movieFilter);
}

From source file:com.gh4a.activities.PullRequestActivity.java

@Override
public void onRefresh() {
    mIssue = null;/*from w w  w.  j a v a 2 s .c o m*/
    mPullRequest = null;
    setContentShown(false);
    mHeader.setVisibility(View.GONE);
    mHeaderColorAttrs = null;
    LoaderManager lm = getSupportLoaderManager();
    for (int i = 0; i < 3; i++) {
        lm.getLoader(i).onContentChanged();
    }
    invalidateTabs();
    super.onRefresh();
}

From source file:nu.firetech.android.pactrack.frontend.ParcelListFragment.java

@Override
public void refreshDone() {
    LoaderManager lm = getLoaderManager();
    if (lm.getLoader(PARCELS_LOADER_ID) == null) {
        lm.initLoader(PARCELS_LOADER_ID, null, this);
    } else {//from   w w w.ja  v  a 2s . co m
        lm.restartLoader(PARCELS_LOADER_ID, null, this);
    }
}

From source file:com.example.android.asynctaskloader.MainActivity.java

/**
 * This method retrieves the search text from the EditText, constructs the
 * URL (using {@link NetworkUtils}) for the github repository you'd like to find, displays
 * that URL in a TextView, and finally request that an AsyncTaskLoader performs the GET request.
 *//*from w  ww  . j  ava2 s  .  c  o m*/
private void makeGithubSearchQuery() {
    String githubQuery = mSearchBoxEditText.getText().toString();

    /*
     * If the user didn't enter anything, there's nothing to search for. In the case where no
     * search text was entered but the search button was clicked, we will display a message
     * stating that there is nothing to search for and we will not attempt to load anything.
     *
     * If there is text entered in the search box when the search button was clicked, we will
     * create the URL that will return our Github search results, display that URL, and then
     * pass that URL to the Loader. The reason we pass the URL as a String is simply a matter
     * of convenience. There are other ways of achieving this same result, but we felt this
     * was the simplest.
     */
    if (TextUtils.isEmpty(githubQuery)) {
        mUrlDisplayTextView.setText("No query entered, nothing to search for.");
        return;
    }

    URL githubSearchUrl = NetworkUtils.buildUrl(githubQuery);
    mUrlDisplayTextView.setText(githubSearchUrl.toString());

    Bundle queryBundle = new Bundle();
    queryBundle.putString(SEARCH_QUERY_URL_EXTRA, githubSearchUrl.toString());

    /*
     * Now that we've created our bundle that we will pass to our Loader, we need to decide
     * if we should restart the loader (if the loader already existed) or if we need to
     * initialize the loader (if the loader did NOT already exist).
     *
     * We do this by first store the support loader manager in the variable loaderManager.
     * All things related to the Loader go through through the LoaderManager. Once we have a
     * hold on the support loader manager, (loaderManager) we can attempt to access our
     * githubSearchLoader. To do this, we use LoaderManager's method, "getLoader", and pass in
     * the ID we assigned in its creation. You can think of this process similar to finding a
     * View by ID. We give the LoaderManager an ID and it returns a loader (if one exists). If
     * one doesn't exist, we tell the LoaderManager to create one. If one does exist, we tell
     * the LoaderManager to restart it.
     */
    LoaderManager loaderManager = getSupportLoaderManager();
    Loader<String> githubSearchLoader = loaderManager.getLoader(GITHUB_SEARCH_LOADER);
    if (githubSearchLoader == null) {
        loaderManager.initLoader(GITHUB_SEARCH_LOADER, queryBundle, this);
    } else {
        loaderManager.restartLoader(GITHUB_SEARCH_LOADER, queryBundle, this);
    }
}