Search in sources :

Example 6 with CursorLoader

use of androidx.loader.content.CursorLoader in project AmazeFileManager by TeamAmaze.

the class MainActivity method onCreateLoader.

@NonNull
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Uri uri = Uri.withAppendedPath(Uri.parse("content://" + CloudContract.PROVIDER_AUTHORITY), "/keys.db/secret_keys");
    String[] projection = new String[] { CloudContract.COLUMN_ID, CloudContract.COLUMN_CLIENT_ID, CloudContract.COLUMN_CLIENT_SECRET_KEY };
    switch(id) {
        case REQUEST_CODE_CLOUD_LIST_KEY:
            Uri uriAppendedPath = uri;
            switch(OpenMode.getOpenMode(args.getInt(ARGS_KEY_LOADER, 2))) {
                case GDRIVE:
                    uriAppendedPath = ContentUris.withAppendedId(uri, 2);
                    break;
                case DROPBOX:
                    uriAppendedPath = ContentUris.withAppendedId(uri, 3);
                    break;
                case BOX:
                    uriAppendedPath = ContentUris.withAppendedId(uri, 4);
                    break;
                case ONEDRIVE:
                    uriAppendedPath = ContentUris.withAppendedId(uri, 5);
                    break;
            }
            return new CursorLoader(this, uriAppendedPath, projection, null, null, null);
        case REQUEST_CODE_CLOUD_LIST_KEYS:
            try {
                List<CloudEntry> cloudEntries = cloudHandler.getAllEntries();
                // we want keys for services saved in database, and the cloudrail app key which
                // is at index 1
                String[] ids = new String[cloudEntries.size() + 1];
                ids[0] = 1 + "";
                for (int i = 1; i <= cloudEntries.size(); i++) {
                    // we need to get only those cloud details which user wants
                    switch(cloudEntries.get(i - 1).getServiceType()) {
                        case GDRIVE:
                            ids[i] = 2 + "";
                            break;
                        case DROPBOX:
                            ids[i] = 3 + "";
                            break;
                        case BOX:
                            ids[i] = 4 + "";
                            break;
                        case ONEDRIVE:
                            ids[i] = 5 + "";
                            break;
                    }
                }
                return new CursorLoader(this, uri, projection, CloudContract.COLUMN_ID, ids, null);
            } catch (CloudPluginException e) {
                e.printStackTrace();
                Toast.makeText(this, getResources().getString(R.string.cloud_error_plugin), Toast.LENGTH_LONG).show();
            }
        default:
            Uri undefinedUriAppendedPath = ContentUris.withAppendedId(uri, 7);
            return new CursorLoader(this, undefinedUriAppendedPath, projection, null, null, null);
    }
}
Also used : CursorLoader(androidx.loader.content.CursorLoader) CloudPluginException(com.amaze.filemanager.file_operations.exceptions.CloudPluginException) CloudEntry(com.amaze.filemanager.database.models.explorer.CloudEntry) Uri(android.net.Uri) NonNull(androidx.annotation.NonNull)

Example 7 with CursorLoader

use of androidx.loader.content.CursorLoader in project Applozic-Android-SDK by AppLozic.

the class ContactDatabase method getSearchCursorLoader.

public Loader<Cursor> getSearchCursorLoader(final String searchString, final String[] userIdArray, final Integer parentGroupKey, final String pinnedContactUserId) {
    return new CursorLoader(context, null, null, null, null, MobiComDatabaseHelper.DISPLAY_NAME + " asc") {

        @Override
        public Cursor loadInBackground() {
            if (TextUtils.isEmpty(userPreferences.getUserId())) {
                return null;
            }
            SQLiteDatabase db = dbHelper.getReadableDatabase();
            Cursor cursor;
            String query = null;
            if (parentGroupKey != null && parentGroupKey != 0) {
                query = "Select DISTINCT(c.userId) as _id,c.fullName,c.contactNO,c.displayName,c.contactImageURL,c.contactImageLocalURI,c.email,c.applicationId,c.connected,c.lastSeenAt,c.unreadCount,c.blocked,c.blockedBy,c.status,c.contactType,c.userTypeId,c.deletedAtTime,c.notificationAfterTime,c.userRoleType,c.lastMessagedAt,c.userMetadata from contact c join channel_User_X cux on cux.userId = c.userId where ( cux.channelKey = '" + parentGroupKey + "' OR cux.parentGroupKey = '" + parentGroupKey + "' ) AND c.userId NOT IN ('" + userPreferences.getUserId().replaceAll("'", "''") + "')";
                if (!TextUtils.isEmpty(searchString)) {
                    query = query + " AND c.fullName like '%" + searchString.replaceAll("'", "''") + "%'";
                } else {
                    // if searching, then no need ignore pinned contact
                    if (!TextUtils.isEmpty(pinnedContactUserId)) {
                        query = query + " AND c.userId NOT IN ('" + pinnedContactUserId.replaceAll("'", "''") + "')";
                    }
                }
                query = query + " order by c.fullName,c.userId asc ";
                cursor = db.rawQuery(query, null);
            } else {
                query = "select userId as _id, fullName, contactNO, " + "displayName,contactImageURL,contactImageLocalURI,email," + "applicationId,connected,lastSeenAt,unreadCount,blocked," + "blockedBy,status,contactType,userTypeId,deletedAtTime,notificationAfterTime,userRoleType,userMetadata,lastMessagedAt from " + CONTACT + " where deletedAtTime=0 ";
                if (userIdArray != null && userIdArray.length > 0) {
                    String placeHolderString = Utils.makePlaceHolders(userIdArray.length);
                    if (!TextUtils.isEmpty(searchString)) {
                        query = query + " and fullName like '%" + searchString.replaceAll("'", "''") + "%' and  userId  IN (" + placeHolderString + ")";
                    } else {
                        query = query + " and userId IN (" + placeHolderString + ")";
                    }
                    query = query + " order by connected desc,lastSeenAt desc ";
                    cursor = db.rawQuery(query, userIdArray);
                } else {
                    if (ApplozicClient.getInstance(context).isShowMyContacts()) {
                        if (!TextUtils.isEmpty(searchString)) {
                            query = query + " and fullName like '%" + searchString.replaceAll("'", "''") + "%' AND contactType != 0 AND userId NOT IN ('" + userPreferences.getUserId().replaceAll("'", "''") + "')";
                        } else {
                            query = query + " and contactType != 0 AND userId != '" + userPreferences.getUserId() + "'";
                        }
                    } else {
                        if (!TextUtils.isEmpty(searchString)) {
                            query = query + " and fullName like '%" + searchString.replaceAll("'", "''") + "%' AND userId NOT IN ('" + userPreferences.getUserId().replaceAll("'", "''") + "')";
                        } else {
                            query = query + " and userId != '" + userPreferences.getUserId() + "'";
                        }
                    }
                    if (TextUtils.isEmpty(searchString) && !TextUtils.isEmpty(pinnedContactUserId)) {
                        // ignore pinned contact only if search input is empty
                        query = query + " AND userId NOT IN ('" + pinnedContactUserId.replaceAll("'", "''") + "')";
                    }
                    query = query + " order by fullName COLLATE NOCASE,userId COLLATE NOCASE asc ";
                    cursor = db.rawQuery(query, null);
                }
            }
            return cursor;
        }
    };
}
Also used : CursorLoader(androidx.loader.content.CursorLoader) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 8 with CursorLoader

use of androidx.loader.content.CursorLoader in project keepass2android by PhilippC.

the class FragmentFiles method onCreateLoader.

// onDestroy()
/*
     * LOADERMANAGER.LOADERCALLBACKS
     */
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    mLoading = true;
    mNewLoader = true;
    mViewGroupFiles.setVisibility(View.GONE);
    mViewLoadingHandler.postDelayed(new Runnable() {

        @Override
        public void run() {
            mViewLoading.setVisibility(View.VISIBLE);
        }
    }, DisplayPrefs.DELAY_TIME_FOR_SHORT_ANIMATION);
    getActivity().supportInvalidateOptionsMenu();
    final Uri path = ((Uri) args.getParcelable(PATH));
    buildAddressBar(path);
    String positiveRegex = getArguments().getString(FileChooserActivity.EXTRA_POSITIVE_REGEX_FILTER);
    String negativeRegex = getArguments().getString(FileChooserActivity.EXTRA_NEGATIVE_REGEX_FILTER);
    if (BuildConfig.DEBUG)
        Log.d(CLASSNAME, "onCreateLoader() >> path = " + path);
    return new CursorLoader(getActivity(), BaseFile.genContentUriBase(path.getAuthority()).buildUpon().appendPath(path.getLastPathSegment()).appendQueryParameter(BaseFile.PARAM_TASK_ID, Integer.toString(mIdLoaderData)).appendQueryParameter(BaseFile.PARAM_SHOW_HIDDEN_FILES, Boolean.toString(getArguments().getBoolean(FileChooserActivity.EXTRA_DISPLAY_HIDDEN_FILES))).appendQueryParameter(BaseFile.PARAM_FILTER_MODE, Integer.toString(mFilterMode)).appendQueryParameter(BaseFile.PARAM_SORT_BY, Integer.toString(DisplayPrefs.getSortType(getActivity()))).appendQueryParameter(BaseFile.PARAM_SORT_ASCENDING, Boolean.toString(DisplayPrefs.isSortAscending(getActivity()))).appendQueryParameter(BaseFile.PARAM_LIMIT, Integer.toString(mMaxFileCount)).appendQueryParameter(BaseFile.PARAM_POSITIVE_REGEX_FILTER, TextUtils.isEmpty(positiveRegex) ? "" : positiveRegex).appendQueryParameter(BaseFile.PARAM_NEGATIVE_REGEX_FILTER, TextUtils.isEmpty(negativeRegex) ? "" : negativeRegex).build(), null, null, null, null);
}
Also used : CursorLoader(androidx.loader.content.CursorLoader) Uri(android.net.Uri)

Example 9 with CursorLoader

use of androidx.loader.content.CursorLoader in project collect by opendatakit.

the class CursorLoaderFactory method createSavedInstancesCursorLoader.

public CursorLoader createSavedInstancesCursorLoader(CharSequence charSequence, String sortOrder) {
    CursorLoader cursorLoader;
    if (charSequence.length() == 0) {
        cursorLoader = createSavedInstancesCursorLoader(sortOrder);
    } else {
        String selection = DatabaseInstanceColumns.DELETED_DATE + " IS NULL and " + DatabaseInstanceColumns.DISPLAY_NAME + " LIKE ?";
        String[] selectionArgs = { "%" + charSequence + "%" };
        cursorLoader = getInstancesCursorLoader(selection, selectionArgs, sortOrder);
    }
    return cursorLoader;
}
Also used : CursorLoader(androidx.loader.content.CursorLoader)

Example 10 with CursorLoader

use of androidx.loader.content.CursorLoader in project collect by opendatakit.

the class CursorLoaderFactory method getFormsCursorLoader.

/**
 * Returns a loader filtered by the specified charSequence in the specified sortOrder. If
 * newestByFormId is true, only the most recently-downloaded version of each form is included.
 */
public CursorLoader getFormsCursorLoader(CharSequence charSequence, String sortOrder, boolean newestByFormId) {
    CursorLoader cursorLoader;
    if (charSequence.length() == 0) {
        Uri formUri = newestByFormId ? FormsContract.getContentNewestFormsByFormIdUri(currentProjectProvider.getCurrentProject().getUuid()) : FormsContract.getUri(currentProjectProvider.getCurrentProject().getUuid());
        cursorLoader = new CursorLoader(Collect.getInstance(), getUriWithAnalyticsParam(formUri), null, DatabaseFormColumns.DELETED_DATE + " IS NULL", new String[] {}, sortOrder);
    } else {
        String selection = DatabaseFormColumns.DISPLAY_NAME + " LIKE ? AND " + DatabaseFormColumns.DELETED_DATE + " IS NULL";
        String[] selectionArgs = { "%" + charSequence + "%" };
        Uri formUri = newestByFormId ? FormsContract.getContentNewestFormsByFormIdUri(currentProjectProvider.getCurrentProject().getUuid()) : FormsContract.getUri(currentProjectProvider.getCurrentProject().getUuid());
        cursorLoader = new CursorLoader(Collect.getInstance(), getUriWithAnalyticsParam(formUri), null, selection, selectionArgs, sortOrder);
    }
    return cursorLoader;
}
Also used : CursorLoader(androidx.loader.content.CursorLoader) Uri(android.net.Uri)

Aggregations

CursorLoader (androidx.loader.content.CursorLoader)12 Uri (android.net.Uri)4 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 NonNull (androidx.annotation.NonNull)2 CloudEntry (com.amaze.filemanager.database.models.explorer.CloudEntry)1 CloudPluginException (com.amaze.filemanager.file_operations.exceptions.CloudPluginException)1 Test (org.junit.Test)1