Search in sources :

Example 26 with RecyclerViewItem

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

the class BackupFragment method itemInit.

private void itemInit(List<RecyclerViewItem> items, final Backup.PARTITION partition) {
    File file = new File(Backup.getPath(partition));
    if (file.exists()) {
        for (final File image : file.listFiles()) {
            if (image.isFile()) {
                DescriptionView descriptionView = new DescriptionView();
                descriptionView.setTitle(image.getName().replace(".img", ""));
                descriptionView.setSummary((image.length() / 1024L / 1024L) + getString(R.string.mb));
                descriptionView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {

                    @Override
                    public void onClick(RecyclerViewItem item) {
                        mItemOptionsDialog = new Dialog(getActivity()).setItems(getResources().getStringArray(R.array.backup_item_options), new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                switch(i) {
                                    case 0:
                                        restore(partition, image, false);
                                        break;
                                    case 1:
                                        delete(image);
                                        break;
                                }
                            }
                        }).setOnDismissListener(new DialogInterface.OnDismissListener() {

                            @Override
                            public void onDismiss(DialogInterface dialogInterface) {
                                mItemOptionsDialog = null;
                            }
                        });
                        mItemOptionsDialog.show();
                    }
                });
                items.add(descriptionView);
            }
        }
    }
}
Also used : DialogInterface(android.content.DialogInterface) Dialog(com.moro.mtweaks.views.dialog.Dialog) ProgressDialog(android.app.ProgressDialog) DescriptionView(com.moro.mtweaks.views.recyclerview.DescriptionView) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem) File(java.io.File)

Example 27 with RecyclerViewItem

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

the class BackupFragment method load.

private void load(List<RecyclerViewItem> items) {
    if (Backup.getBootPartition() != null) {
        List<RecyclerViewItem> boot = new ArrayList<>();
        itemInit(boot, Backup.PARTITION.BOOT);
        if (boot.size() > 0) {
            TitleView titleView = new TitleView();
            titleView.setText(getString(R.string.boot_partition));
            items.add(titleView);
            items.addAll(boot);
        }
    }
    if (Backup.getRecoveryPartition() != null) {
        List<RecyclerViewItem> recovery = new ArrayList<>();
        itemInit(recovery, Backup.PARTITION.RECOVERY);
        if (recovery.size() > 0) {
            TitleView titleView = new TitleView();
            titleView.setText(getString(R.string.recovery_partition));
            items.add(titleView);
            items.addAll(recovery);
        }
    }
    if (Backup.getFotaPartition() != null) {
        List<RecyclerViewItem> fota = new ArrayList<>();
        itemInit(fota, Backup.PARTITION.FOTA);
        if (fota.size() > 0) {
            TitleView titleView = new TitleView();
            titleView.setText(getString(R.string.fota_partition));
            items.add(titleView);
            items.addAll(fota);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) TitleView(com.moro.mtweaks.views.recyclerview.TitleView) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem)

Example 28 with RecyclerViewItem

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

the class BuildpropFragment method reload.

private void reload(final boolean read) {
    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) {
                        if (read) {
                            mProps = Buildprop.getProps();
                        }
                        List<RecyclerViewItem> items = new ArrayList<>();
                        load(items);
                        return items;
                    }

                    @Override
                    protected void onPostExecute(List<RecyclerViewItem> items) {
                        super.onPostExecute(items);
                        for (RecyclerViewItem item : items) {
                            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 29 with RecyclerViewItem

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

the class InitdFragment 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();
                        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 30 with RecyclerViewItem

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

the class ProfileFragment method load.

private void load(List<RecyclerViewItem> items) {
    mProfiles = new Profiles(getActivity());
    List<Profiles.ProfileItem> profileItems = mProfiles.getAllProfiles();
    if (mTaskerMode && profileItems.size() == 0) {
        Snackbar.make(getRootView(), R.string.no_profiles, Snackbar.LENGTH_LONG).show();
        return;
    }
    for (int i = 0; i < profileItems.size(); i++) {
        final int position = i;
        final CardView cardView = new CardView(getActivity());
        cardView.setOnMenuListener(new CardView.OnMenuListener() {

            @Override
            public void onMenuReady(final CardView cardView, PopupMenu popupMenu) {
                Menu menu = popupMenu.getMenu();
                menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.append));
                menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.edit));
                menu.add(Menu.NONE, 2, Menu.NONE, getString(R.string.details));
                final MenuItem onBoot = menu.add(Menu.NONE, 3, Menu.NONE, getString(R.string.on_boot)).setCheckable(true);
                onBoot.setChecked(mProfiles.getAllProfiles().get(position).isOnBootEnabled());
                menu.add(Menu.NONE, 4, Menu.NONE, getString(R.string.export));
                menu.add(Menu.NONE, 5, Menu.NONE, getString(R.string.delete));
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        List<Profiles.ProfileItem> items = mProfiles.getAllProfiles();
                        switch(item.getItemId()) {
                            case 0:
                                if (Utils.DONATED) {
                                    Intent intent = new Intent(getActivity(), ProfileActivity.class);
                                    intent.putExtra(ProfileActivity.POSITION_INTENT, position);
                                    startActivityForResult(intent, 2);
                                } else {
                                    mDonateDialog = ViewUtils.dialogDonate(getActivity());
                                    mDonateDialog.show();
                                }
                                break;
                            case 1:
                                if (Utils.DONATED) {
                                    Intent intent = new Intent(getActivity(), ProfileEditActivity.class);
                                    intent.putExtra(ProfileEditActivity.POSITION_INTENT, position);
                                    startActivityForResult(intent, 3);
                                } else {
                                    mDonateDialog = ViewUtils.dialogDonate(getActivity());
                                    mDonateDialog.show();
                                }
                                break;
                            case 2:
                                if (items.get(position).getName() != null) {
                                    List<Profiles.ProfileItem.CommandItem> commands = items.get(position).getCommands();
                                    if (commands.size() > 0) {
                                        setForegroundText(items.get(position).getName().toUpperCase());
                                        mDetailsFragment.setText(commands);
                                        showForeground();
                                    } else {
                                        Utils.toast(R.string.profile_empty, getActivity());
                                    }
                                }
                                break;
                            case 3:
                                onBoot.setChecked(!onBoot.isChecked());
                                items.get(position).enableOnBoot(onBoot.isChecked());
                                mProfiles.commit();
                                break;
                            case 4:
                                mExportProfile = items.get(position);
                                requestPermission(0, Manifest.permission.WRITE_EXTERNAL_STORAGE);
                                break;
                            case 5:
                                mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.sure_question), new DialogInterface.OnClickListener() {

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

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

                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                        mDeleteDialog = null;
                                    }
                                }, getActivity());
                                mDeleteDialog.show();
                                break;
                        }
                        return false;
                    }
                });
            }
        });
        final DescriptionView descriptionView = new DescriptionView();
        descriptionView.setSummary(profileItems.get(i).getName());
        descriptionView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {

            @Override
            public void onClick(RecyclerViewItem item) {
                if (mTaskerMode) {
                    mSelectDialog = ViewUtils.dialogBuilder(getString(R.string.select_question, descriptionView.getSummary()), new DialogInterface.OnClickListener() {

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

                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            ((ProfileTaskerActivity) getActivity()).finish(descriptionView.getSummary().toString(), mProfiles.getAllProfiles().get(position).getCommands());
                        }
                    }, new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialogInterface) {
                            mSelectDialog = null;
                        }
                    }, getActivity());
                    mSelectDialog.show();
                } else {
                    mApplyDialog = ViewUtils.dialogBuilder(getString(R.string.apply_question, descriptionView.getSummary()), new DialogInterface.OnClickListener() {

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

                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            for (Profiles.ProfileItem.CommandItem command : mProfiles.getAllProfiles().get(position).getCommands()) {
                                CPUFreq.ApplyCpu applyCpu;
                                if (command.getCommand().startsWith("#") && ((applyCpu = new CPUFreq.ApplyCpu(command.getCommand().substring(1))).toString() != null)) {
                                    for (String applyCpuCommand : ApplyOnBoot.getApplyCpu(applyCpu, RootUtils.getSU())) {
                                        Control.runSetting(applyCpuCommand, null, null, null);
                                    }
                                } else {
                                    Control.runSetting(command.getCommand(), null, null, null);
                                }
                            }
                        }
                    }, new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialogInterface) {
                            mApplyDialog = null;
                        }
                    }, getActivity());
                    try {
                        mApplyDialog.show();
                    } catch (NullPointerException ignored) {
                    }
                }
            }
        });
        if (mTaskerMode) {
            items.add(descriptionView);
        } else {
            cardView.addItem(descriptionView);
            items.add(cardView);
        }
    }
    if (!mTaskerMode) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(getActivity(), Widget.class));
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.profile_list);
        Tile.publishProfileTile(profileItems, getActivity());
    }
}
Also used : DialogInterface(android.content.DialogInterface) Widget(com.moro.mtweaks.services.profile.Widget) Profiles(com.moro.mtweaks.database.tools.profiles.Profiles) ComponentName(android.content.ComponentName) PopupMenu(android.support.v7.widget.PopupMenu) Menu(android.view.Menu) CardView(com.moro.mtweaks.views.recyclerview.CardView) AppWidgetManager(android.appwidget.AppWidgetManager) MenuItem(android.view.MenuItem) Intent(android.content.Intent) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem) CPUFreq(com.moro.mtweaks.utils.kernel.cpu.CPUFreq) DescriptionView(com.moro.mtweaks.views.recyclerview.DescriptionView) PopupMenu(android.support.v7.widget.PopupMenu)

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