<commit_before>package com.lukekorth.android_500px.helpers;

import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Point;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import com.lukekorth.android_500px.models.Photos;

public class Utils {

    public static boolean shouldGetPhotos(Context context) {
        return Settings.isEnabled(context) && Utils.needMorePhotos(context) &&
                isCurrentNetworkOk(context);
    }

    public static boolean shouldUpdateWallpaper(Context context) {
        return Settings.isEnabled(context) && (((Settings.getLastUpdated(context) +
                 (Settings.getUpdateInterval(context) * 1000)) < System.currentTimeMillis()));
    }

    public static boolean isCurrentNetworkOk(Context context) {
        return !Settings.useOnlyWifi(context) ||
                (Settings.useOnlyWifi(context) && Utils.isConnectedToWifi(context));
    }

    public static boolean needMorePhotos(Context context) {
        int remainingPhotos = Photos.unseenPhotoCount(context);
        if (remainingPhotos <= 10) {
            setFetchingPhotos(context, true);
            return true;
        } else if (remainingPhotos >= 144) {
            setFetchingPhotos(context, false);
            return false;
        } else {
            return isFetchingPhotos(context);
        }
    }

    public static boolean isFetchingPhotos(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context)
                .getBoolean("fetching_photos", false);
    }

    public static void setFetchingPhotos(Context context, boolean fetching) {
        PreferenceManager.getDefaultSharedPreferences(context)
                .edit()
                .putBoolean("fetching_photos", fetching)
                .apply();
    }

    public static boolean isConnectedToWifi(Context context) {
        ConnectivityManager connectivityManager =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
        return (activeNetwork != null && activeNetwork.isConnectedOrConnecting() &&
                activeNetwork.getType() == ConnectivityManager.TYPE_WIFI);
    }

    public static int dpToPx(Context context, int dp) {
        return Math.round(dp * (context.getResources().getDisplayMetrics().xdpi / DisplayMetrics.DENSITY_DEFAULT));
    }

    public static int getWallpaperHeight(Context context) {
        return WallpaperManager.getInstance(context).getDesiredMinimumHeight();
    }

    public static int getWallpaperWidth(Context context) {
        return WallpaperManager.getInstance(context).getDesiredMinimumWidth();
    }

    public static int getScreenHeight(Context context) {
        return getScreenResolution(context).y;
    }

    public static int getScreenWidth(Context context) {
        return getScreenResolution(context).x;
    }

    private static Point getScreenResolution(Context context) {<commit_msg>Simplify need more photos check<commit_after>package com.lukekorth.android_500px.helpers;

import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Point;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import com.lukekorth.android_500px.models.Photos;

public class Utils {

    public static boolean shouldGetPhotos(Context context) {
        return Settings.isEnabled(context) && Utils.needMorePhotos(context) &&
                isCurrentNetworkOk(context);
    }

    public static boolean shouldUpdateWallpaper(Context context) {
        return Settings.isEnabled(context) && (((Settings.getLastUpdated(context) +
                 (Settings.getUpdateInterval(context) * 1000)) < System.currentTimeMillis()));
    }

    public static boolean isCurrentNetworkOk(Context context) {
        return !Settings.useOnlyWifi(context) ||
                (Settings.useOnlyWifi(context) && Utils.isConnectedToWifi(context));
    }

    public static boolean needMorePhotos(Context context) {
        int remainingPhotos = Photos.unseenPhotoCount(context);
        return remainingPhotos <= 10 && remainingPhotos < 144;
    }

    public static boolean isConnectedToWifi(Context context) {
        ConnectivityManager connectivityManager =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
        return (activeNetwork != null && activeNetwork.isConnectedOrConnecting() &&
                activeNetwork.getType() == ConnectivityManager.TYPE_WIFI);
    }

    public static int dpToPx(Context context, int dp) {
        return Math.round(dp * (context.getResources().getDisplayMetrics().xdpi / DisplayMetrics.DENSITY_DEFAULT));
    }

    public static int getWallpaperHeight(Context context) {
        return WallpaperManager.getInstance(context).getDesiredMinimumHeight();
    }

    public static int getWallpaperWidth(Context context) {
        return WallpaperManager.getInstance(context).getDesiredMinimumWidth();
    }

    public static int getScreenHeight(Context context) {
        return getScreenResolution(context).y;
    }

    public static int getScreenWidth(Context context) {
        return getScreenResolution(context).x;
    }

    private static Point getScreenResolution(Context context) {
{'fraction_non_alphanumeric': 0.08647017045454546, 'fraction_numerical': 0.005326704545454545, 'mean_word_length': 3.557443365695793, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, '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': '534513', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1409, 'n_words': 290}