Example usage for android.support.v4.content Loader isStarted

List of usage examples for android.support.v4.content Loader isStarted

Introduction

In this page you can find the example usage for android.support.v4.content Loader isStarted.

Prototype

public boolean isStarted() 

Source Link

Document

Return whether this load has been started.

Usage

From source file:org.dvbviewer.controller.ui.fragments.ChannelList.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setListAdapter(mAdapter);//  www  .j  a  va  2 s  .  c  om
    getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    registerForContextMenu(getListView());
    int loaderId = LOADER_CHANNELLIST;
    /**
     * Prfung ob das EPG in der Senderliste angezeigt werden soll.
     */
    if (!Config.CHANNELS_SYNCED) {
        loaderId = LOADER_REFRESH_CHANNELLIST;
    } else if ((showNowPlaying && !showNowPlayingWifi)
            || (showNowPlaying && showNowPlayingWifi && mNetworkInfo.isConnected())) {
        loaderId = LOADER_EPG;
    }
    setEmptyText(showFavs ? getResources().getString(R.string.no_favourites)
            : getResources().getString(R.string.no_channels));
    Loader<Cursor> loader = getLoaderManager().initLoader(loaderId, savedInstanceState, this);
    setListShown(!(!isResumed() || loader.isStarted()));
    setSelection(selectedPosition);
}

From source file:at.tomtasche.reader.ui.activity.DocumentActivity.java

private void showProgress(final Loader<Document> loader, final boolean upload) {
    if (progressDialog != null)
        return;//ww  w .j a v  a2  s.c  o m

    try {
        progressDialog = new ProgressDialogFragment(upload);

        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        progressDialog.show(transaction, ProgressDialogFragment.FRAGMENT_TAG);

        if (!upload) {
            final FileLoader fileLoader = (FileLoader) loader;

            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (progressDialog == null)
                        return;

                    progressDialog.setProgress(fileLoader.getProgress());

                    if (loader.isStarted())
                        handler.postDelayed(this, 1000);
                }
            }, 1000);
        }
    } catch (IllegalStateException e) {
        e.printStackTrace();

        progressDialog = null;
    }
}

From source file:cz.maresmar.sfm.view.MainActivity.java

@Override
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor cursor) {
    switch (loader.getId()) {
    case USER_LOADER_ID: {
        Timber.d("User data loaded");

        // Removes old profiles
        mProfiles.clear();/*from w ww. j a v  a 2 s  .c  o  m*/

        // Insert new profiles
        if (cursor.moveToFirst()) {
            do {
                Long userId = cursor.getLong(0);
                String userName = cursor.getString(1);
                Uri iconUri = Uri.parse(cursor.getString(2));

                ProfileDrawerItem profile = new ProfileDrawerItem().withIdentifier(userId).withName(userName)
                        .withIcon(iconUri);
                mProfiles.addProfiles(profile);
            } while (cursor.moveToNext());
        }

        // Select default user
        if (mSelectedUserId == SettingsContract.LAST_USER_UNKNOWN && mProfiles.getActiveProfile() != null) {
            mSelectedUserId = mProfiles.getActiveProfile().getIdentifier();
        }

        // Set last user in UI
        if (mSelectedUserId != SettingsContract.LAST_USER_UNKNOWN) {
            mProfiles.setActiveProfile(mSelectedUserId);
        }

        // Insert control entries
        mProfiles.addProfiles(ADD_USER_DRAWER_ITEM, MANAGE_USER_DRAWER_ITEM);

        // Load correct user info for selected user (could be from backup)
        Loader portalLoader = getSupportLoaderManager().getLoader(PORTAL_LOADER_ID);
        if (portalLoader == null || !portalLoader.isStarted()) {
            getSupportLoaderManager().initLoader(PORTAL_LOADER_ID, null, this);
            getSupportLoaderManager().initLoader(EDIT_ACTIONS_COUNT_LOADER_ID, null, this);
        }
        // Should be always reused because of users recreation
        getSupportLoaderManager().initLoader(CREDENTIAL_LOADER_ID, null, this);
        break;
    }
    case PORTAL_LOADER_ID: {
        Timber.d("Portal data loaded");

        // Clear old portals
        int oldPortalCount = mPortalDrawerItem.getSubItems().size();
        mPortalDrawerItem.getSubItems().clear();

        // Insert new portals
        boolean selectedFound = false;
        if (cursor.moveToFirst()) {
            do {
                Long portalId = cursor.getLong(0);
                String portalName = cursor.getString(1);
                int credit = cursor.getInt(2);

                SecondaryDrawerItem portalItem = new SecondaryDrawerItem().withIdentifier(portalId)
                        .withName(portalName).withDescription(MenuUtils.getPriceStr(this, credit))
                        .withTag(PORTAL_ITEM_DRAWER_TAG);

                // Updates selected fragment if new user hasn't the old one
                if (portalId == mSelectedFragmentId) {
                    portalItem.withSetSelected(true);
                    setTitle(portalName);
                    selectedFound = true;
                } else if (cursor.isLast() && !selectedFound && mSelectedFragmentId >= 0) {
                    mSelectedFragmentId = portalId;
                    portalItem.withSetSelected(true);
                    setTitle(portalName);
                    showToolbar();
                }

                mPortalDrawerItem.withSubItems(portalItem);
            } while (cursor.moveToNext());
        }

        // Insert control entries
        mPortalDrawerItem.withSubItems(ADD_PORTAL_DRAWER_ITEM, MANAGE_PORTAL_DRAWER_ITEM);

        // Notify about changes
        if (mPortalDrawerItem.isExpanded()) {
            mDrawer.getExpandableExtension()
                    .notifyAdapterSubItemsChanged(mDrawer.getPosition(mPortalDrawerItem), oldPortalCount);
        }

        // Set default title as title on empty cursor
        if (cursor.getCount() == 0) {
            setTitle(R.string.drawer_portal);
            showToolbar();
        }

        // Show saved fragment in UI
        showOrResetFragment(mSelectedFragmentId);

        break;
    }
    case CREDENTIAL_LOADER_ID: {
        Timber.d("Credential data loaded");

        if (mProfiles.getActiveProfile() == null)
            return;

        // Prepare result
        StringBuilder builder = new StringBuilder();
        if (cursor.moveToFirst()) {
            do {

                if (builder.length() > 0) {
                    builder.append("; ");
                }

                int rawCredit = cursor.getInt(1);
                builder.append(MenuUtils.getPriceStr(this, rawCredit));
            } while (cursor.moveToNext());
        }

        // Show result
        ((ProfileDrawerItem) mProfiles.getActiveProfile()).withEmail(builder.toString()).withNameShown(true);
        mProfiles.updateProfile(mProfiles.getActiveProfile());
        break;
    }
    case EDIT_ACTIONS_COUNT_LOADER_ID:
        Timber.i("Edit actions count loaded");
        if (cursor.moveToFirst()) {
            if (cursor.getInt(0) > 0) {
                setMenuEditUiShown(true);
            } else {
                setMenuEditUiShown(false);
            }
        }

        if (BuildConfig.DEBUG) {
            Assert.isOne(cursor.getCount());
        }
        break;
    default:
        throw new UnsupportedOperationException("Unknown loader id: " + loader.getId());
    }
}