<commit_before>package ai.elimu.appstore.provider;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import ai.elimu.appstore.BaseApplication;
import ai.elimu.appstore.dao.ApplicationDao;
import ai.elimu.appstore.dao.DaoSession;
import ai.elimu.model.enums.admin.ApplicationStatus;
import timber.log.Timber;

public class ApplicationProvider extends ContentProvider {

    // The authority of this content provider
    public static final String AUTHORITY = "ai.elimu.appstore.provider";

    private static final String TABLE_APPLICATION = "application";
    private static final int CODE_APPLICATION_DIR = 2;
    public static final Uri URI_APPLICATION = Uri.parse("content://" + AUTHORITY + "/" + TABLE_APPLICATION);

    // The URI matcher
    private static final UriMatcher MATCHER = new UriMatcher(UriMatcher.NO_MATCH);

    static {
        MATCHER.addURI(AUTHORITY, TABLE_APPLICATION, CODE_APPLICATION_DIR);
    }

    @Override
    public boolean onCreate() {
        Timber.i("onCreate");
        return true;
    }

    @Nullable
    @Override
    public Cursor query(@NonNull Uri uri, @Nullable String[] strings, @Nullable String s, @Nullable String[] strings1, @Nullable String s1) {
        Timber.i("query");

        final int code = MATCHER.match(uri);
        if (code == CODE_APPLICATION_DIR) {
            Context context = getContext();
            if (context == null) {
                return null;
            }
            BaseApplication baseApplication = (BaseApplication) context;
            DaoSession daoSession = baseApplication.getDaoSession();
            ApplicationDao applicationDao = daoSession.getApplicationDao();
            Cursor cursor = applicationDao.queryBuilder()
                    .where(
//                            ApplicationDao.Properties.Locale.eq(AppPrefs.getLocale()),
                            ApplicationDao.Properties.ApplicationStatus.eq(ApplicationStatus.ACTIVE)
                    )
                    .orderAsc(ApplicationDao.Properties.ListOrder)
                    .buildCursor().forCurrentThread().query();
            cursor.setNotificationUri(context.getContentResolver(), uri);
            return cursor;
        } else {<commit_msg>#200 Add possibility to fetch Applications from ContentProvider<commit_after>package ai.elimu.appstore.provider;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import ai.elimu.appstore.BaseApplication;
import ai.elimu.appstore.dao.ApplicationDao;
import ai.elimu.appstore.dao.DaoSession;
import ai.elimu.model.enums.admin.ApplicationStatus;
import timber.log.Timber;

public class ApplicationProvider extends ContentProvider {

    // The authority of this content provider
    public static final String AUTHORITY = "ai.elimu.appstore.provider";

    private static final String TABLE_APPLICATION = "application";
    private static final int CODE_APPLICATION_DIR = 2;
    public static final Uri URI_APPLICATION = Uri.parse("content://" + AUTHORITY + "/" + TABLE_APPLICATION);

    // The URI matcher
    private static final UriMatcher MATCHER = new UriMatcher(UriMatcher.NO_MATCH);

    static {
        MATCHER.addURI(AUTHORITY, TABLE_APPLICATION, CODE_APPLICATION_DIR);
    }

    @Override
    public boolean onCreate() {
        Timber.i("onCreate");
        return true;
    }

    @Nullable
    @Override
    public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {
        Timber.i("query");

        final int code = MATCHER.match(uri);
        if (code == CODE_APPLICATION_DIR) {
            Context context = getContext();
            if (context == null) {
                return null;
            }
            BaseApplication baseApplication = (BaseApplication) context;
            DaoSession daoSession = baseApplication.getDaoSession();
            ApplicationDao applicationDao = daoSession.getApplicationDao();
            Cursor cursor = applicationDao.queryBuilder()
                    .where(
//                            ApplicationDao.Properties.Locale.eq(AppPrefs.getLocale()),
                            ApplicationDao.Properties.ApplicationStatus.eq(ApplicationStatus.ACTIVE)
                    )
                    .orderAsc(ApplicationDao.Properties.ListOrder)
                    .buildCursor().forCurrentThread().query();
            cursor.setNotificationUri(context.getContentResolver(), uri);
            return cursor;
        } else {
{'fraction_non_alphanumeric': 0.09021498894916616, 'fraction_numerical': 0.0014064697609001407, 'mean_word_length': 2.8829953198127924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '830050', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1265, 'n_words': 295}