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

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

Introduction

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

Prototype

public abstract <D> Loader<D> restartLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> callback);

Source Link

Document

Starts a new or restarts an existing android.content.Loader in this manager, registers the callbacks to it, and (if the activity/fragment is currently started) starts loading it.

Usage

From source file:org.getlantern.firetweet.fragment.support.UserFragment.java

private void getFriendship() {
    mRelationship = null;//from ww w . j  a v a  2  s.  c o m
    final ParcelableUser user = getUser();
    final LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ID_FRIENDSHIP);
    final Bundle args = new Bundle();
    args.putLong(EXTRA_ACCOUNT_ID, user.account_id);
    args.putLong(EXTRA_USER_ID, user.id);
    if (!mGetFriendShipLoaderInitialized) {
        lm.initLoader(LOADER_ID_FRIENDSHIP, args, mFriendshipLoaderCallbacks);
        mGetFriendShipLoaderInitialized = true;
    } else {
        lm.restartLoader(LOADER_ID_FRIENDSHIP, args, mFriendshipLoaderCallbacks);
    }
}

From source file:org.getlantern.firetweet.fragment.support.UserFragment.java

public void getUserInfo(final long accountId, final long userId, final String screenName,
        final boolean omitIntentExtra) {
    final LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ID_USER);//from  ww  w.  j  a  v a2  s. com
    lm.destroyLoader(LOADER_ID_FRIENDSHIP);
    final Bundle args = new Bundle();
    args.putLong(EXTRA_ACCOUNT_ID, accountId);
    args.putLong(EXTRA_USER_ID, userId);
    args.putString(EXTRA_SCREEN_NAME, screenName);
    args.putBoolean(EXTRA_OMIT_INTENT_EXTRA, omitIntentExtra);
    if (!mGetUserInfoLoaderInitialized) {
        lm.initLoader(LOADER_ID_USER, args, mUserInfoLoaderCallbacks);
        mGetUserInfoLoaderInitialized = true;
    } else {
        lm.restartLoader(LOADER_ID_USER, args, mUserInfoLoaderCallbacks);
    }
    if (accountId == -1 || userId == -1 && screenName == null) {
        mCardContent.setVisibility(View.GONE);
        mErrorRetryContainer.setVisibility(View.GONE);
    }
}

From source file:org.mariotaku.twidere.fragment.support.UserFragment.java

public void getUserInfo(final long accountId, final long userId, final String screenName,
        final boolean omitIntentExtra) {
    final LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ID_USER);/*from   w  w  w  .  j  a v a  2 s.  co  m*/
    lm.destroyLoader(LOADER_ID_FRIENDSHIP);
    final Bundle args = new Bundle();
    args.putLong(EXTRA_ACCOUNT_ID, accountId);
    args.putLong(EXTRA_USER_ID, userId);
    args.putString(EXTRA_SCREEN_NAME, screenName);
    args.putBoolean(EXTRA_OMIT_INTENT_EXTRA, omitIntentExtra);
    if (!mGetUserInfoLoaderInitialized) {
        lm.initLoader(LOADER_ID_USER, args, mUserInfoLoaderCallbacks);
        mGetUserInfoLoaderInitialized = true;
    } else {
        lm.restartLoader(LOADER_ID_USER, args, mUserInfoLoaderCallbacks);
    }
    if (accountId == -1 || userId == -1 && screenName == null) {
        mCardContent.setVisibility(View.GONE);
        mHeaderErrorContainer.setVisibility(View.GONE);
    }
}

From source file:org.mariotaku.twidere.fragment.UserFragment.java

private void getFriendship() {
    final ParcelableUser user = getUser();
    if (user == null)
        return;/*from   w w w  .  j  a  v  a  2s  .c  o m*/
    mRelationship = null;
    final LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ID_FRIENDSHIP);
    final Bundle args = new Bundle();
    args.putParcelable(EXTRA_ACCOUNT_KEY, user.account_key);
    args.putParcelable(EXTRA_USER, user);
    if (!mGetFriendShipLoaderInitialized) {
        lm.initLoader(LOADER_ID_FRIENDSHIP, args, mFriendshipLoaderCallbacks);
        mGetFriendShipLoaderInitialized = true;
    } else {
        lm.restartLoader(LOADER_ID_FRIENDSHIP, args, mFriendshipLoaderCallbacks);
    }
}

From source file:org.mariotaku.twidere.fragment.UserFragment.java

public void getUserInfo(final UserKey accountKey, final UserKey userKey, final String screenName,
        final boolean omitIntentExtra) {
    final LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ID_USER);/*ww w.  j  a  v a2  s. co m*/
    lm.destroyLoader(LOADER_ID_FRIENDSHIP);
    final Bundle args = new Bundle();
    args.putParcelable(EXTRA_ACCOUNT_KEY, accountKey);
    args.putParcelable(EXTRA_USER_KEY, userKey);
    args.putString(EXTRA_SCREEN_NAME, screenName);
    args.putBoolean(EXTRA_OMIT_INTENT_EXTRA, omitIntentExtra);
    if (!mGetUserInfoLoaderInitialized) {
        lm.initLoader(LOADER_ID_USER, args, mUserInfoLoaderCallbacks);
        mGetUserInfoLoaderInitialized = true;
    } else {
        lm.restartLoader(LOADER_ID_USER, args, mUserInfoLoaderCallbacks);
    }
    if (accountKey == null || userKey == null && screenName == null) {
        mCardContent.setVisibility(View.GONE);
        mHeaderErrorContainer.setVisibility(View.GONE);
    }
}

From source file:com.gh.bmd.jrt.android.v4.core.LoaderInvocation.java

@Override
@SuppressWarnings("unchecked")
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "class comparison with == is done")
public void onCall(@Nonnull final List<? extends INPUT> inputs, @Nonnull final ResultChannel<OUTPUT> result) {

    final Logger logger = mLogger;
    final Object context = mContext.get();

    if (context == null) {

        logger.dbg("avoiding running invocation since context is null");
        return;/*from  w  ww .j av  a  2  s . c o  m*/
    }

    final Context loaderContext;
    final LoaderManager loaderManager;

    if (context instanceof FragmentActivity) {

        final FragmentActivity activity = (FragmentActivity) context;
        loaderContext = activity.getApplicationContext();
        loaderManager = activity.getSupportLoaderManager();
        logger.dbg("running invocation bound to activity: %s", activity);

    } else if (context instanceof Fragment) {

        final Fragment fragment = (Fragment) context;
        loaderContext = fragment.getActivity().getApplicationContext();
        loaderManager = fragment.getLoaderManager();
        logger.dbg("running invocation bound to fragment: %s", fragment);

    } else {

        throw new IllegalArgumentException("invalid context type: " + context.getClass().getCanonicalName());
    }

    int loaderId = mLoaderId;

    if (loaderId == ContextRoutineBuilder.AUTO) {

        loaderId = mConstructor.getDeclaringClass().hashCode();

        for (final Object arg : mArgs) {

            loaderId = 31 * loaderId + recursiveHashCode(arg);
        }

        loaderId = 31 * loaderId + inputs.hashCode();
        logger.dbg("generating invocation ID: %d", loaderId);
    }

    final Loader<InvocationResult<OUTPUT>> loader = loaderManager.getLoader(loaderId);
    final boolean isClash = isClash(loader, loaderId, inputs);
    final WeakIdentityHashMap<Object, SparseArray<WeakReference<RoutineLoaderCallbacks<?>>>> callbackMap = sCallbackMap;
    SparseArray<WeakReference<RoutineLoaderCallbacks<?>>> callbackArray = callbackMap.get(context);

    if (callbackArray == null) {

        callbackArray = new SparseArray<WeakReference<RoutineLoaderCallbacks<?>>>();
        callbackMap.put(context, callbackArray);
    }

    final WeakReference<RoutineLoaderCallbacks<?>> callbackReference = callbackArray.get(loaderId);
    RoutineLoaderCallbacks<OUTPUT> callbacks = (callbackReference != null)
            ? (RoutineLoaderCallbacks<OUTPUT>) callbackReference.get()
            : null;

    if ((callbacks == null) || (loader == null) || isClash) {

        final RoutineLoader<INPUT, OUTPUT> routineLoader;

        if (!isClash && (loader != null) && (loader.getClass() == RoutineLoader.class)) {

            routineLoader = (RoutineLoader<INPUT, OUTPUT>) loader;

        } else {

            routineLoader = null;
        }

        final RoutineLoaderCallbacks<OUTPUT> newCallbacks = createCallbacks(loaderContext, loaderManager,
                routineLoader, inputs, loaderId);

        if (callbacks != null) {

            logger.dbg("resetting existing callbacks [%d]", loaderId);
            callbacks.reset();
        }

        callbackArray.put(loaderId, new WeakReference<RoutineLoaderCallbacks<?>>(newCallbacks));
        callbacks = newCallbacks;
    }

    logger.dbg("setting result cache type [%d]: %s", loaderId, mCacheStrategyType);
    callbacks.setCacheStrategy(mCacheStrategyType);

    final OutputChannel<OUTPUT> outputChannel = callbacks.newChannel();

    if (isClash) {

        logger.dbg("restarting loader [%d]", loaderId);
        loaderManager.restartLoader(loaderId, Bundle.EMPTY, callbacks);

    } else {

        logger.dbg("initializing loader [%d]", loaderId);
        loaderManager.initLoader(loaderId, Bundle.EMPTY, callbacks);
    }

    result.pass(outputChannel);
}