<commit_before>/*
 * Copyright (C) 2015-2016 <NAME> <<EMAIL>>
 *
 * This file is part of Kernel Adiutor.
 *
 * Kernel Adiutor is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Kernel Adiutor is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Kernel Adiutor.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package com.grarak.kerneladiutor.fragments.kernel;

import com.grarak.kerneladiutor.R;
import com.grarak.kerneladiutor.fragments.ApplyOnBootFragment;
import com.grarak.kerneladiutor.fragments.RecyclerViewFragment;
import com.grarak.kerneladiutor.utils.Utils;
import com.grarak.kerneladiutor.utils.kernel.lmk.LMK;
import com.grarak.kerneladiutor.views.recyclerview.DescriptionView;
import com.grarak.kerneladiutor.views.recyclerview.RecyclerViewItem;
import com.grarak.kerneladiutor.views.recyclerview.SeekBarView;
import com.grarak.kerneladiutor.views.recyclerview.SwitchView;
import com.grarak.kerneladiutor.views.recyclerview.TitleView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * Created by willi on 29.06.16.
 */
public class LMKFragment extends RecyclerViewFragment {

    private static final LinkedHashMap<Integer, String> sProfiles = new LinkedHashMap<>();

    static {
        sProfiles.put(R.string.very_light, "512,1024,1280,2048,3072,4096");
        sProfiles.put(R.string.light, "1024,2048,2560,4096,6144,8192");
        sProfiles.put(R.string.medium, "1024,2048,4096,8192,12288,16384");
        sProfiles.put(R.string.aggressive, "2048,4096,8192,16384,24576,32768");
        sProfiles.put(R.string.very_aggressive, "4096,8192,16384,32768,49152,65536");
    }

    private List<SeekBarView> mMinFrees = new ArrayList<>();

    @Override
    protected void init() {
        super.init();

        addViewPagerFragment(ApplyOnBootFragment.newInstance(this));
    }

    @Override
    protected void addItems(List<RecyclerViewItem> items) {
        if (LMK.hasAdaptive()) {
            adaptiveInit(items);
        }
        minfreeInit(items);
        profileInit(items);
        swapWait(items);
    }

    private void adaptiveInit(List<RecyclerViewItem> items) {
        SwitchView adaptive = new SwitchView();<commit_msg>LMKFragment: Adjust profiles according to memtotal<commit_after>/*
 * Copyright (C) 2015-2016 <NAME> <<EMAIL>>
 *
 * This file is part of Kernel Adiutor.
 *
 * Kernel Adiutor is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Kernel Adiutor is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Kernel Adiutor.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package com.grarak.kerneladiutor.fragments.kernel;

import com.grarak.kerneladiutor.R;
import com.grarak.kerneladiutor.fragments.ApplyOnBootFragment;
import com.grarak.kerneladiutor.fragments.RecyclerViewFragment;
import com.grarak.kerneladiutor.utils.Device;
import com.grarak.kerneladiutor.utils.Utils;
import com.grarak.kerneladiutor.utils.kernel.lmk.LMK;
import com.grarak.kerneladiutor.views.recyclerview.DescriptionView;
import com.grarak.kerneladiutor.views.recyclerview.RecyclerViewItem;
import com.grarak.kerneladiutor.views.recyclerview.SeekBarView;
import com.grarak.kerneladiutor.views.recyclerview.SwitchView;
import com.grarak.kerneladiutor.views.recyclerview.TitleView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * Created by willi on 29.06.16.
 */
public class LMKFragment extends RecyclerViewFragment {

    private final LinkedHashMap<Integer, String> sProfiles = new LinkedHashMap<>();

    private List<SeekBarView> mMinFrees = new ArrayList<>();

    @Override
    protected void init() {
        super.init();

        sProfiles.clear();
        sProfiles.put(R.string.very_light, getAdjustedSize(1, 2, 3, 4, 5, 6));
        sProfiles.put(R.string.light, getAdjustedSize(2, 3, 4, 5, 6, 7));
        sProfiles.put(R.string.medium, getAdjustedSize(3, 4, 5, 6, 7, 9));
        sProfiles.put(R.string.aggressive, getAdjustedSize(2, 3, 6, 10, 14, 15));
        sProfiles.put(R.string.very_aggressive, getAdjustedSize(3, 4, 5, 11, 15, 16));

        addViewPagerFragment(ApplyOnBootFragment.newInstance(this));
    }

    private String getAdjustedSize(int... offsets) {
        long memTotal = Device.MemInfo.getTotalMem() * 1024L / 100L / 4L;
        StringBuilder stringBuilder = new StringBuilder();
        for (int offset : offsets) {
            stringBuilder.append(String.valueOf((int) memTotal * offset)).append(",");
        }
        stringBuilder.setLength(stringBuilder.length() - 1);
        return stringBuilder.toString();
    }

    @Override
    protected void addItems(List<RecyclerViewItem> items) {
        if (LMK.hasAdaptive()) {
            adaptiveInit(items);
        }
        minfreeInit(items);
        profileInit(items);
        swapWait(items);
    }

    private void adaptiveInit(List<RecyclerViewItem> items) {
        SwitchView adaptive = new SwitchView();
{'fraction_non_alphanumeric': 0.10536170212765958, 'fraction_numerical': 0.0345531914893617, 'mean_word_length': 3.8925895087427143, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6126490', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1791, 'n_words': 457}