Search in sources :

Example 21 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class OnBootFragment method reload.

private void reload() {
    if (mLoader == null) {
        getHandler().postDelayed(new Runnable() {

            @Override
            public void run() {
                mLoader = new AsyncTask<Void, Void, List<RecyclerViewItem>>() {

                    @Override
                    protected void onPreExecute() {
                        super.onPreExecute();
                        clearItems();
                        showProgress();
                    }

                    @Override
                    protected List<RecyclerViewItem> doInBackground(Void... voids) {
                        List<RecyclerViewItem> items = new ArrayList<>();
                        load(items);
                        return items;
                    }

                    @Override
                    protected void onPostExecute(List<RecyclerViewItem> recyclerViewItems) {
                        super.onPostExecute(recyclerViewItems);
                        for (RecyclerViewItem item : recyclerViewItems) {
                            addItem(item);
                        }
                        hideProgress();
                        mLoader = null;
                    }
                };
                mLoader.execute();
            }
        }, 250);
    }
}
Also used : AsyncTask(android.os.AsyncTask) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem)

Example 22 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class OnBootFragment method load.

private void load(List<RecyclerViewItem> items) {
    List<RecyclerViewItem> applyOnBoot = new ArrayList<>();
    TitleView applyOnBootTitle = new TitleView();
    applyOnBootTitle.setText(getString(R.string.apply_on_boot));
    List<Settings.SettingsItem> settings = mSettings.getAllSettings();
    HashMap<String, Boolean> applyOnBootEnabled = new HashMap<>();
    List<ApplyOnBootItem> applyOnBootItems = new ArrayList<>();
    for (int i = 0; i < settings.size(); i++) {
        if (!applyOnBootEnabled.containsKey(settings.get(i).getCategory())) {
            applyOnBootEnabled.put(settings.get(i).getCategory(), Prefs.getBoolean(settings.get(i).getCategory(), false, getActivity()));
        }
        if (applyOnBootEnabled.get(settings.get(i).getCategory())) {
            applyOnBootItems.add(new ApplyOnBootItem(settings.get(i).getSetting(), settings.get(i).getCategory(), i));
        }
    }
    for (int i = 0; i < applyOnBootItems.size(); i++) {
        final ApplyOnBootItem applyOnBootItem = applyOnBootItems.get(i);
        DescriptionView applyOnBootView = new DescriptionView();
        applyOnBootView.setSummary((i + 1) + ". " + applyOnBootItem.mCategory.replace("_onboot", "") + ": " + applyOnBootItem.mCommand);
        applyOnBootView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {

            @Override
            public void onClick(RecyclerViewItem item) {
                mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.delete_question, applyOnBootItem.mCommand), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                    }
                }, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        mSettings.delete(applyOnBootItem.mPosition);
                        mSettings.commit();
                        reload();
                    }
                }, new DialogInterface.OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        mDeleteDialog = null;
                    }
                }, getActivity());
                mDeleteDialog.show();
            }
        });
        applyOnBoot.add(applyOnBootView);
    }
    if (applyOnBoot.size() > 0) {
        items.add(applyOnBootTitle);
        items.addAll(applyOnBoot);
    }
    List<RecyclerViewItem> customControls = new ArrayList<>();
    TitleView customControlTitle = new TitleView();
    customControlTitle.setText(getString(R.string.custom_controls));
    for (final Controls.ControlItem controlItem : mControls.getAllControls()) {
        if (controlItem.isOnBootEnabled() && controlItem.getArguments() != null) {
            DescriptionView controlView = new DescriptionView();
            controlView.setTitle(controlItem.getTitle());
            controlView.setSummary(getString(R.string.arguments, controlItem.getArguments()));
            controlView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {

                @Override
                public void onClick(RecyclerViewItem item) {
                    mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.disable_question, controlItem.getTitle()), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                        }
                    }, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            controlItem.enableOnBoot(false);
                            mControls.commit();
                            reload();
                        }
                    }, new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialogInterface) {
                            mDeleteDialog = null;
                        }
                    }, getActivity());
                    mDeleteDialog.show();
                }
            });
            customControls.add(controlView);
        }
    }
    if (customControls.size() > 0) {
        items.add(customControlTitle);
        items.addAll(customControls);
    }
    List<RecyclerViewItem> profiles = new ArrayList<>();
    TitleView profileTitle = new TitleView();
    profileTitle.setText(getString(R.string.profile));
    for (final Profiles.ProfileItem profileItem : mProfiles.getAllProfiles()) {
        if (profileItem.isOnBootEnabled()) {
            DescriptionView profileView = new DescriptionView();
            profileView.setSummary(profileItem.getName());
            profileView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {

                @Override
                public void onClick(RecyclerViewItem item) {
                    mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.disable_question, profileItem.getName()), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                        }
                    }, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            profileItem.enableOnBoot(false);
                            mProfiles.commit();
                            reload();
                        }
                    }, new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialogInterface) {
                            mDeleteDialog = null;
                        }
                    }, getActivity());
                    mDeleteDialog.show();
                }
            });
            profiles.add(profileView);
        }
    }
    if (profiles.size() > 0) {
        items.add(profileTitle);
        items.addAll(profiles);
    }
    if (Prefs.getBoolean("initd_onboot", false, getActivity())) {
        TitleView initdTitle = new TitleView();
        initdTitle.setText(getString(R.string.initd));
        items.add(initdTitle);
        DescriptionView emulateInitd = new DescriptionView();
        emulateInitd.setSummary(getString(R.string.emulate_initd));
        emulateInitd.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {

            @Override
            public void onClick(RecyclerViewItem item) {
                mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.disable_question, getString(R.string.emulate_initd)), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                    }
                }, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Prefs.saveBoolean("initd_onboot", false, getActivity());
                        reload();
                    }
                }, new DialogInterface.OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        mDeleteDialog = null;
                    }
                }, getActivity());
                mDeleteDialog.show();
            }
        });
        items.add(emulateInitd);
    }
}
Also used : HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem) DescriptionView(com.moro.mtweaks.views.recyclerview.DescriptionView) Profiles(com.moro.mtweaks.database.tools.profiles.Profiles) Controls(com.moro.mtweaks.database.tools.customcontrols.Controls) TitleView(com.moro.mtweaks.views.recyclerview.TitleView)

Example 23 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class CreateFragment method addItems.

@Override
protected void addItems(List<RecyclerViewItem> items) {
    mEditTextViews.clear();
    mCodeViews.clear();
    for (final Items.Setting setting : mSettings) {
        if (setting.isScript()) {
            final CodeView codeView = new CodeView();
            codeView.setTitle(setting.getName(getActivity()));
            codeView.setSummary(setting.getDescription(getActivity()));
            codeView.setRequired(setting.isRequired());
            codeView.setCode(setting.getDefault());
            codeView.setTesting(setting.getUnit() != Items.Setting.Unit.APPLY);
            codeView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {

                @Override
                public void onClick(RecyclerViewItem item) {
                    Intent intent = new Intent(getActivity(), EditorActivity.class);
                    intent.putExtra(EditorActivity.TITLE_INTENT, setting.getName(getActivity()).toString());
                    intent.putExtra(EditorActivity.TEXT_INTENT, codeView.getCode());
                    startActivityForResult(intent, mSettings.indexOf(setting));
                }
            });
            codeView.setOnTestListener(new CodeView.OnTestListener() {

                @Override
                public void onTestResult(CodeView codeView, String output) {
                    showFab();
                }
            });
            items.add(codeView);
            mCodeViews.put(setting, codeView);
        } else if (setting.getUnit() != Items.Setting.Unit.ID) {
            EditTextView editTextView = new EditTextView();
            editTextView.setTitle(setting.getName(getActivity()));
            if (setting.isRequired()) {
                editTextView.setHint(getString(R.string.required));
            }
            if (setting.getUnit() == Items.Setting.Unit.INTEGER) {
                editTextView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
            }
            editTextView.setText(setting.getDefault());
            editTextView.setTextWatcher(new TextWatcher() {

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }

                @Override
                public void afterTextChanged(Editable s) {
                    showFab();
                }
            });
            items.add(editTextView);
            mEditTextViews.put(setting, editTextView);
        }
    }
}
Also used : Intent(android.content.Intent) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem) CodeView(com.moro.mtweaks.views.recyclerview.customcontrols.CodeView) EditorActivity(com.moro.mtweaks.activities.EditorActivity) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Items(com.moro.mtweaks.utils.tools.customcontrols.Items) EditTextView(com.moro.mtweaks.views.recyclerview.EditTextView)

Example 24 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class MiscFragment method wakelockInit.

private void wakelockInit(List<RecyclerViewItem> items) {
    List<RecyclerViewItem> wakelocks = new ArrayList<>();
    for (final Wakelocks.Wakelock wakelock : Wakelocks.getWakelocks()) {
        if (!wakelock.exists())
            continue;
        String description = wakelock.getDescription(getActivity());
        SwitchView switchView = new SwitchView();
        if (description == null) {
            switchView.setSummary(wakelock.getTitle(getActivity()));
        } else {
            switchView.setTitle(wakelock.getTitle(getActivity()));
            switchView.setSummary(description);
        }
        switchView.setChecked(wakelock.isEnabled());
        switchView.addOnSwitchListener(new SwitchView.OnSwitchListener() {

            @Override
            public void onChanged(SwitchView switchView, boolean isChecked) {
                wakelock.enable(isChecked, getActivity());
            }
        });
        wakelocks.add(switchView);
    }
    if (Wakelocks.hasWlanrxDivider()) {
        List<String> list = new ArrayList<>();
        for (int i = 1; i < 17; i++) {
            list.add((100 / i) + "%");
        }
        list.add("0%");
        SeekBarView wlanrxDivider = new SeekBarView();
        wlanrxDivider.setTitle(getString(R.string.wlan_rx_wakelock_divider));
        wlanrxDivider.setItems(list);
        wlanrxDivider.setProgress(Wakelocks.getWlanrxDivider());
        wlanrxDivider.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() {

            @Override
            public void onStop(SeekBarView seekBarView, int position, String value) {
                Wakelocks.setWlanrxDivider(position, getActivity());
            }

            @Override
            public void onMove(SeekBarView seekBarView, int position, String value) {
            }
        });
        wakelocks.add(wlanrxDivider);
    }
    if (Wakelocks.hasWlanctrlDivider()) {
        List<String> list = new ArrayList<>();
        for (int i = 1; i < 17; i++) {
            list.add((100 / i) + "%");
        }
        list.add("0%");
        SeekBarView wlanctrlDivider = new SeekBarView();
        wlanctrlDivider.setTitle(getString(R.string.wlan_ctrl_wakelock_divider));
        wlanctrlDivider.setItems(list);
        wlanctrlDivider.setProgress(Wakelocks.getWlanctrlDivider());
        wlanctrlDivider.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() {

            @Override
            public void onStop(SeekBarView seekBarView, int position, String value) {
                Wakelocks.setWlanctrlDivider(position, getActivity());
            }

            @Override
            public void onMove(SeekBarView seekBarView, int position, String value) {
            }
        });
        wakelocks.add(wlanctrlDivider);
    }
    if (Wakelocks.hasMsmHsicDivider()) {
        List<String> list = new ArrayList<>();
        for (int i = 1; i < 17; i++) {
            list.add((100 / i) + "%");
        }
        list.add("0%");
        SeekBarView msmHsicDivider = new SeekBarView();
        msmHsicDivider.setTitle(getString(R.string.msm_hsic_wakelock_divider));
        msmHsicDivider.setItems(list);
        msmHsicDivider.setProgress(Wakelocks.getMsmHsicDivider());
        msmHsicDivider.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() {

            @Override
            public void onStop(SeekBarView seekBarView, int position, String value) {
                Wakelocks.setMsmHsicDivider(position, getActivity());
            }

            @Override
            public void onMove(SeekBarView seekBarView, int position, String value) {
            }
        });
        wakelocks.add(msmHsicDivider);
    }
    if (Wakelocks.hasBCMDHDDivider()) {
        SeekBarView bcmdhdDivider = new SeekBarView();
        bcmdhdDivider.setTitle(getString(R.string.bcmdhd_wakelock_divider));
        bcmdhdDivider.setMax(9);
        bcmdhdDivider.setMin(1);
        bcmdhdDivider.setProgress(Wakelocks.getBCMDHDDivider() - 1);
        bcmdhdDivider.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() {

            @Override
            public void onStop(SeekBarView seekBarView, int position, String value) {
                Wakelocks.setBCMDHDDivider(position + 1, getActivity());
            }

            @Override
            public void onMove(SeekBarView seekBarView, int position, String value) {
            }
        });
        wakelocks.add(bcmdhdDivider);
    }
    if (wakelocks.size() > 0) {
        TitleView wakelockTitle = new TitleView();
        wakelockTitle.setText(getString(R.string.wakelock));
        items.add(wakelockTitle);
        items.addAll(wakelocks);
    }
}
Also used : SwitchView(com.moro.mtweaks.views.recyclerview.SwitchView) ArrayList(java.util.ArrayList) Wakelocks(com.moro.mtweaks.utils.kernel.misc.Wakelocks) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem) SeekBarView(com.moro.mtweaks.views.recyclerview.SeekBarView) TitleView(com.moro.mtweaks.views.recyclerview.TitleView)

Example 25 with RecyclerViewItem

use of com.moro.mtweaks.views.recyclerview.RecyclerViewItem in project MTweaks-KernelAdiutorMOD by morogoku.

the class PathReaderFragment method reload.

private void reload() {
    if (mLoader == null) {
        getHandler().postDelayed(new Runnable() {

            @Override
            public void run() {
                clearItems();
                mLoader = new AsyncTask<Void, Void, List<RecyclerViewItem>>() {

                    @Override
                    protected void onPreExecute() {
                        super.onPreExecute();
                        showProgress();
                    }

                    @Override
                    protected List<RecyclerViewItem> doInBackground(Void... voids) {
                        List<RecyclerViewItem> items = new ArrayList<>();
                        load(items);
                        return items;
                    }

                    @Override
                    protected void onPostExecute(List<RecyclerViewItem> recyclerViewItems) {
                        super.onPostExecute(recyclerViewItems);
                        for (RecyclerViewItem item : recyclerViewItems) {
                            addItem(item);
                        }
                        hideProgress();
                        if (itemsSize() < 1 && mError != null) {
                            Snackbar.make(getRootView(), mError, Snackbar.LENGTH_SHORT).show();
                        }
                        mLoader = null;
                    }
                };
                mLoader.execute();
            }
        }, 200);
    }
}
Also used : AsyncTask(android.os.AsyncTask) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem)

Aggregations

RecyclerViewItem (com.moro.mtweaks.views.recyclerview.RecyclerViewItem)42 ArrayList (java.util.ArrayList)26 TitleView (com.moro.mtweaks.views.recyclerview.TitleView)18 DescriptionView (com.moro.mtweaks.views.recyclerview.DescriptionView)16 SwitchView (com.moro.mtweaks.views.recyclerview.SwitchView)15 SeekBarView (com.moro.mtweaks.views.recyclerview.SeekBarView)14 CardView (com.moro.mtweaks.views.recyclerview.CardView)9 List (java.util.List)9 SelectView (com.moro.mtweaks.views.recyclerview.SelectView)8 AsyncTask (android.os.AsyncTask)6 DialogInterface (android.content.DialogInterface)5 Intent (android.content.Intent)3 Activity (android.app.Activity)2 FragmentTransaction (android.support.v4.app.FragmentTransaction)2 PopupMenu (android.support.v7.widget.PopupMenu)2 Menu (android.view.Menu)2 MenuItem (android.view.MenuItem)2 Profiles (com.moro.mtweaks.database.tools.profiles.Profiles)2 Dialog (com.moro.mtweaks.views.dialog.Dialog)2 ProgressDialog (android.app.ProgressDialog)1