Search in sources :

Example 1 with SortingOrder

use of org.horaapps.leafpic.data.sort.SortingOrder in project LeafPic by HoraApps.

the class AlbumsFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Album selectedAlbum = adapter.getFirstSelectedAlbum();
    switch(item.getItemId()) {
        case R.id.select_all:
            if (adapter.getSelectedCount() == adapter.getItemCount())
                adapter.clearSelected();
            else
                adapter.selectAll();
            return true;
        case R.id.pin_album:
            if (selectedAlbum != null) {
                boolean b = selectedAlbum.togglePinAlbum();
                db().setPined(selectedAlbum.getPath(), b);
                adapter.clearSelected();
                adapter.sort();
            }
            return true;
        case R.id.clear_album_cover:
            if (selectedAlbum != null) {
                selectedAlbum.removeCoverAlbum();
                db().setCover(selectedAlbum.getPath(), null);
                adapter.clearSelected();
                adapter.notifyItemChanaged(selectedAlbum);
                // TODO: 4/5/17 updateui
                return true;
            }
            return false;
        case R.id.hide:
            final AlertDialog hideDialog = AlertDialogsHelper.getTextDialog(((ThemedActivity) getActivity()), hidden ? R.string.unhide : R.string.hide, hidden ? R.string.unhide_album_message : R.string.hide_album_message);
            hideDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(hidden ? R.string.unhide : R.string.hide).toUpperCase(), (dialog, id) -> {
                ArrayList<String> hiddenPaths = AlbumsHelper.getLastHiddenPaths();
                for (Album album : adapter.getSelectedAlbums()) {
                    if (hidden) {
                        // unhide
                        AlbumsHelper.unHideAlbum(album.getPath(), getContext());
                        hiddenPaths.remove(album.getPath());
                    } else {
                        // hide
                        AlbumsHelper.hideAlbum(album.getPath(), getContext());
                        hiddenPaths.add(album.getPath());
                    }
                }
                AlbumsHelper.saveLastHiddenPaths(hiddenPaths);
                adapter.removeSelectedAlbums();
                updateToolbar();
            });
            if (!hidden) {
                hideDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.exclude).toUpperCase(), (dialog, which) -> {
                    for (Album album : adapter.getSelectedAlbums()) {
                        db().excludeAlbum(album.getPath());
                        excuded.add(album.getPath());
                    }
                    adapter.removeSelectedAlbums();
                });
            }
            hideDialog.setButton(DialogInterface.BUTTON_NEGATIVE, this.getString(R.string.cancel).toUpperCase(), (dialogInterface, i) -> hideDialog.dismiss());
            hideDialog.show();
            return true;
        case R.id.shortcut:
            AlbumsHelper.createShortcuts(getContext(), adapter.getSelectedAlbums());
            adapter.clearSelected();
            return true;
        case R.id.name_sort_mode:
            adapter.changeSortingMode(SortingMode.NAME);
            AlbumsHelper.setSortingMode(SortingMode.NAME);
            item.setChecked(true);
            return true;
        case R.id.date_taken_sort_mode:
            adapter.changeSortingMode(SortingMode.DATE);
            AlbumsHelper.setSortingMode(SortingMode.DATE);
            item.setChecked(true);
            return true;
        case R.id.size_sort_mode:
            adapter.changeSortingMode(SortingMode.SIZE);
            AlbumsHelper.setSortingMode(SortingMode.SIZE);
            item.setChecked(true);
            return true;
        case R.id.numeric_sort_mode:
            adapter.changeSortingMode(SortingMode.NUMERIC);
            AlbumsHelper.setSortingMode(SortingMode.NUMERIC);
            item.setChecked(true);
            return true;
        case R.id.ascending_sort_order:
            item.setChecked(!item.isChecked());
            SortingOrder sortingOrder = SortingOrder.fromValue(item.isChecked());
            adapter.changeSortingOrder(sortingOrder);
            AlbumsHelper.setSortingOrder(sortingOrder);
            return true;
        case R.id.exclude:
            final AlertDialog.Builder excludeDialogBuilder = new AlertDialog.Builder(getActivity(), getDialogStyle());
            final View excludeDialogLayout = LayoutInflater.from(getContext()).inflate(R.layout.dialog_exclude, null);
            TextView textViewExcludeTitle = excludeDialogLayout.findViewById(R.id.text_dialog_title);
            TextView textViewExcludeMessage = excludeDialogLayout.findViewById(R.id.text_dialog_message);
            final Spinner spinnerParents = excludeDialogLayout.findViewById(R.id.parents_folder);
            spinnerParents.getBackground().setColorFilter(getIconColor(), PorterDuff.Mode.SRC_ATOP);
            ((CardView) excludeDialogLayout.findViewById(R.id.message_card)).setCardBackgroundColor(getCardBackgroundColor());
            textViewExcludeTitle.setBackgroundColor(getPrimaryColor());
            textViewExcludeTitle.setText(getString(R.string.exclude));
            if (adapter.getSelectedCount() > 1) {
                textViewExcludeMessage.setText(R.string.exclude_albums_message);
                spinnerParents.setVisibility(View.GONE);
            } else {
                textViewExcludeMessage.setText(R.string.exclude_album_message);
                spinnerParents.setAdapter(getThemeHelper().getSpinnerAdapter(adapter.getFirstSelectedAlbum().getParentsFolders()));
            }
            textViewExcludeMessage.setTextColor(getTextColor());
            excludeDialogBuilder.setView(excludeDialogLayout);
            excludeDialogBuilder.setPositiveButton(this.getString(R.string.exclude).toUpperCase(), (dialog, id) -> {
                if (adapter.getSelectedCount() > 1) {
                    for (Album album : adapter.getSelectedAlbums()) {
                        db().excludeAlbum(album.getPath());
                        excuded.add(album.getPath());
                    }
                    adapter.removeSelectedAlbums();
                } else {
                    String path = spinnerParents.getSelectedItem().toString();
                    db().excludeAlbum(path);
                    excuded.add(path);
                    adapter.removeAlbumsThatStartsWith(path);
                    adapter.forceSelectedCount(0);
                }
                updateToolbar();
            });
            excludeDialogBuilder.setNegativeButton(this.getString(R.string.cancel).toUpperCase(), null);
            excludeDialogBuilder.show();
            return true;
        case R.id.delete:
            /* class DeleteAlbums extends AsyncTask<String, Integer, Boolean> {

                    //private AlertDialog dialog;
                    List<Album> selectedAlbums;
                    DeleteAlbumsDialog newFragment;


                    @Override
                    protected void onPreExecute() {
                        super.onPreExecute();
                        newFragment = new DeleteAlbumsDialog();
                        Bundle b = new Bundle();
                        b.putParcelableArrayList("albums", ((ArrayList<Album>) adapter.getSelectedAlbums()));

                        newFragment.setArguments(b);
                        newFragment.show(getFragmentManager(), "dialog");
                        //newFragment.setTitle("asd");

                        //dialog = AlertDialogsHelper.getProgressDialog(((ThemedActivity) getActivity()), getString(R.string.delete), getString(R.string.deleting_images));
                        //dialog.show();


                    }

                    @Override
                    protected Boolean doInBackground(String... arg0) {

                        return true;
                    }

                    @Override
                    protected void onPostExecute(Boolean result) {
                        */
            /*if (result) {
                            if (albumsMode) {
                                albumsAdapter.clearSelected();
                                //albumsAdapter.notifyDataSetChanged();
                            } else {
                                if (getAlbum().getMedia().size() == 0) {
                                    getAlbums().removeCurrentAlbum();
                                    albumsAdapter.notifyDataSetChanged();
                                    displayAlbums();
                                } else
                                    oldMediaAdapter.swapDataSet(getAlbum().getMedia());
                            }
                        } else requestSdCardPermissions();

                        supportInvalidateOptionsMenu();
                        checkNothing();
                        dialog.dismiss();*/
            /*
                    }
                }*/
            final AlertDialog alertDialog = AlertDialogsHelper.getTextDialog(((ThemedActivity) getActivity()), R.string.delete, R.string.delete_album_message);
            alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, this.getString(R.string.cancel).toUpperCase(), (dialogInterface, i) -> alertDialog.dismiss());
            alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, this.getString(R.string.delete).toUpperCase(), (dialog1, id) -> {
                if (Security.isPasswordOnDelete()) {
                    Security.authenticateUser(((ThemedActivity) getActivity()), new Security.AuthCallBack() {

                        @Override
                        public void onAuthenticated() {
                        /*new DeleteAlbums().execute();*/
                        }

                        @Override
                        public void onError() {
                            Toast.makeText(getContext(), R.string.wrong_password, Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            /* else new DeleteAlbums().execute();*/
            });
            alertDialog.show();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Spinner(android.widget.Spinner) CardView(android.support.v7.widget.CardView) Album(org.horaapps.leafpic.data.Album) Security(org.horaapps.leafpic.util.Security) BindView(butterknife.BindView) View(android.view.View) CardView(android.support.v7.widget.CardView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ThemedActivity(org.horaapps.liz.ThemedActivity) SortingOrder(org.horaapps.leafpic.data.sort.SortingOrder) TextView(android.widget.TextView)

Example 2 with SortingOrder

use of org.horaapps.leafpic.data.sort.SortingOrder in project LeafPic by HoraApps.

the class RvMediaFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.all_media_filter:
            album.setFilterMode(FilterMode.ALL);
            item.setChecked(true);
            reload();
            return true;
        case R.id.video_media_filter:
            album.setFilterMode(FilterMode.VIDEO);
            item.setChecked(true);
            reload();
            return true;
        case R.id.image_media_filter:
            album.setFilterMode(FilterMode.IMAGES);
            item.setChecked(true);
            reload();
            return true;
        case R.id.gifs_media_filter:
            album.setFilterMode(FilterMode.GIF);
            item.setChecked(true);
            reload();
            return true;
        case R.id.sharePhotos:
            Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
            HashMap<String, Integer> types = new HashMap<>();
            ArrayList<Uri> files = new ArrayList<>();
            for (Media f : adapter.getSelected()) {
                String mimeType = MimeTypeUtils.getTypeMime(f.getMimeType());
                int count = 0;
                if (types.containsKey(mimeType)) {
                    count = types.get(mimeType);
                }
                types.put(mimeType, count);
                files.add(LegacyCompatFileProvider.getUri(getContext(), f.getFile()));
            }
            Set<String> fileTypes = types.keySet();
            if (fileTypes.size() > 1) {
                Toast.makeText(getContext(), R.string.waring_share_multiple_file_types, Toast.LENGTH_SHORT).show();
            }
            int max = -1;
            String type = null;
            for (String fileType : fileTypes) {
                Integer count = types.get(fileType);
                if (count > max) {
                    type = fileType;
                }
            }
            intent.setType(type + "/*");
            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(Intent.createChooser(intent, getResources().getText(R.string.send_to)));
            return true;
        case R.id.set_as_cover:
            String path = adapter.getFirstSelected().getPath();
            album.setCover(path);
            db().setCover(album.getPath(), path);
            adapter.clearSelected();
            return true;
        case R.id.action_palette:
            Intent paletteIntent = new Intent(getActivity(), PaletteActivity.class);
            paletteIntent.setData(adapter.getFirstSelected().getUri());
            startActivity(paletteIntent);
            return true;
        case R.id.rename:
            final EditText editTextNewName = new EditText(getActivity());
            editTextNewName.setText(StringUtils.getPhotoNameByPath(adapter.getFirstSelected().getPath()));
            AlertDialog renameDialog = AlertDialogsHelper.getInsertTextDialog(((ThemedActivity) getActivity()), editTextNewName, R.string.rename_photo_action);
            renameDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok_action).toUpperCase(), (dialog, which) -> {
                if (editTextNewName.length() != 0) {
                    boolean b = MediaHelper.renameMedia(getActivity(), adapter.getFirstSelected(), editTextNewName.getText().toString());
                    if (!b) {
                        StringUtils.showToast(getActivity(), getString(R.string.rename_error));
                    // adapter.notifyDataSetChanged();
                    } else
                        // Deselect media if rename successful
                        adapter.clearSelected();
                } else
                    StringUtils.showToast(getActivity(), getString(R.string.nothing_changed));
            });
            renameDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel).toUpperCase(), (dialog, which) -> dialog.dismiss());
            renameDialog.show();
            return true;
        case R.id.select_all:
            if (adapter.getSelectedCount() == adapter.getItemCount())
                adapter.clearSelected();
            else
                adapter.selectAll();
            return true;
        case R.id.name_sort_mode:
            adapter.changeSortingMode(SortingMode.NAME);
            HandlingAlbums.getInstance(getContext()).setSortingMode(album.getPath(), SortingMode.NAME.getValue());
            album.setSortingMode(SortingMode.NAME);
            item.setChecked(true);
            return true;
        case R.id.date_taken_sort_mode:
            adapter.changeSortingMode(SortingMode.DATE);
            HandlingAlbums.getInstance(getContext()).setSortingMode(album.getPath(), SortingMode.DATE.getValue());
            album.setSortingMode(SortingMode.DATE);
            item.setChecked(true);
            return true;
        case R.id.size_sort_mode:
            adapter.changeSortingMode(SortingMode.SIZE);
            HandlingAlbums.getInstance(getContext()).setSortingMode(album.getPath(), SortingMode.SIZE.getValue());
            album.setSortingMode(SortingMode.SIZE);
            item.setChecked(true);
            return true;
        case R.id.numeric_sort_mode:
            adapter.changeSortingMode(SortingMode.NUMERIC);
            HandlingAlbums.getInstance(getContext()).setSortingMode(album.getPath(), SortingMode.NUMERIC.getValue());
            album.setSortingMode(SortingMode.NUMERIC);
            item.setChecked(true);
            return true;
        case R.id.ascending_sort_order:
            item.setChecked(!item.isChecked());
            SortingOrder sortingOrder = SortingOrder.fromValue(item.isChecked());
            adapter.changeSortingOrder(sortingOrder);
            HandlingAlbums.getInstance(getContext()).setSortingOrder(album.getPath(), sortingOrder.getValue());
            album.setSortingOrder(sortingOrder);
            return true;
        case R.id.delete:
            ProgressAdapter errorsAdapter = new ProgressAdapter(getContext());
            ArrayList<Media> selected = adapter.getSelected();
            AlertDialog alertDialog = AlertDialogsHelper.getProgressDialogWithErrors(((ThemedActivity) getActivity()), R.string.deleting_images, errorsAdapter, selected.size());
            alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, this.getString(R.string.cancel).toUpperCase(), (dialog, id) -> {
                alertDialog.dismiss();
            });
            alertDialog.show();
            MediaHelper.deleteMedia(getContext(), selected).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(m -> {
                adapter.remove(m);
                errorsAdapter.add(new ProgressAdapter.ListItem(m.getName()), false);
            }, throwable -> {
                if (throwable instanceof DeleteException)
                    errorsAdapter.add(new ProgressAdapter.ListItem((DeleteException) throwable), true);
            }, () -> {
                if (errorsAdapter.getItemCount() == 0)
                    alertDialog.dismiss();
                adapter.clearSelected();
            });
            return true;
        // TODO: 11/21/16 move away from here
        case R.id.affix:
            // region Async MediaAffix
            class affixMedia extends AsyncTask<Affix.Options, Integer, Void> {

                private AlertDialog dialog;

                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                    dialog = AlertDialogsHelper.getProgressDialog((ThemedActivity) getActivity(), getString(R.string.affix), getString(R.string.affix_text));
                    dialog.show();
                }

                @Override
                protected Void doInBackground(Affix.Options... arg0) {
                    ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
                    for (int i = 0; i < adapter.getSelectedCount(); i++) {
                        if (!adapter.getSelected().get(i).isVideo())
                            bitmapArray.add(adapter.getSelected().get(i).getBitmap());
                    }
                    if (bitmapArray.size() > 1)
                        Affix.AffixBitmapList(getActivity(), bitmapArray, arg0[0]);
                    else
                        getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(getContext(), R.string.affix_error, Toast.LENGTH_SHORT).show();
                            }
                        });
                    return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                    adapter.clearSelected();
                    dialog.dismiss();
                }
            }
            // endregion
            final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), getDialogStyle());
            final View dialogLayout = getLayoutInflater().inflate(R.layout.dialog_affix, null);
            dialogLayout.findViewById(R.id.affix_title).setBackgroundColor(getPrimaryColor());
            ((CardView) dialogLayout.findViewById(R.id.affix_card)).setCardBackgroundColor(getCardBackgroundColor());
            // ITEMS
            final SwitchCompat swVertical = dialogLayout.findViewById(R.id.affix_vertical_switch);
            final SwitchCompat swSaveHere = dialogLayout.findViewById(R.id.save_here_switch);
            final LinearLayout llSwVertical = dialogLayout.findViewById(R.id.ll_affix_vertical);
            final LinearLayout llSwSaveHere = dialogLayout.findViewById(R.id.ll_affix_save_here);
            final RadioGroup radioFormatGroup = dialogLayout.findViewById(R.id.radio_format);
            final TextView txtQuality = dialogLayout.findViewById(R.id.affix_quality_title);
            final SeekBar seekQuality = dialogLayout.findViewById(R.id.seek_bar_quality);
            // region Example
            final LinearLayout llExample = dialogLayout.findViewById(R.id.affix_example);
            llExample.setBackgroundColor(getBackgroundColor());
            llExample.setVisibility(Hawk.get("show_tips", true) ? View.VISIBLE : View.GONE);
            final LinearLayout llExampleH = dialogLayout.findViewById(R.id.affix_example_horizontal);
            // llExampleH.setBackgroundColor(getCardBackgroundColor());
            final LinearLayout llExampleV = dialogLayout.findViewById(R.id.affix_example_vertical);
            // llExampleV.setBackgroundColor(getCardBackgroundColor());
            // endregion
            // region THEME STUFF
            getThemeHelper().setScrollViewColor(dialogLayout.findViewById(R.id.affix_scrollView));
            /**
             * TextViews *
             */
            int color = getTextColor();
            ((TextView) dialogLayout.findViewById(R.id.affix_vertical_title)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.compression_settings_title)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.save_here_title)).setTextColor(color);
            // Example Stuff
            ((TextView) dialogLayout.findViewById(R.id.affix_example_horizontal_txt1)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.affix_example_horizontal_txt2)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.affix_example_vertical_txt1)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.affix_example_vertical_txt2)).setTextColor(color);
            /**
             * Sub TextViews *
             */
            color = getThemeHelper().getSubTextColor();
            ((TextView) dialogLayout.findViewById(R.id.save_here_sub)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.affix_vertical_sub)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.affix_format_sub)).setTextColor(color);
            txtQuality.setTextColor(color);
            /**
             * Icons *
             */
            color = getIconColor();
            ((ThemedIcon) dialogLayout.findViewById(R.id.affix_quality_icon)).setColor(color);
            ((ThemedIcon) dialogLayout.findViewById(R.id.affix_format_icon)).setColor(color);
            ((ThemedIcon) dialogLayout.findViewById(R.id.affix_vertical_icon)).setColor(color);
            ((ThemedIcon) dialogLayout.findViewById(R.id.save_here_icon)).setColor(color);
            // Example bg
            color = getCardBackgroundColor();
            dialogLayout.findViewById(R.id.affix_example_horizontal_txt1).setBackgroundColor(color);
            dialogLayout.findViewById(R.id.affix_example_horizontal_txt2).setBackgroundColor(color);
            dialogLayout.findViewById(R.id.affix_example_vertical_txt1).setBackgroundColor(color);
            dialogLayout.findViewById(R.id.affix_example_vertical_txt2).setBackgroundColor(color);
            seekQuality.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN));
            seekQuality.getThumb().setColorFilter(new PorterDuffColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN));
            getThemeHelper().themeRadioButton(dialogLayout.findViewById(R.id.radio_jpeg));
            getThemeHelper().themeRadioButton(dialogLayout.findViewById(R.id.radio_png));
            getThemeHelper().themeRadioButton(dialogLayout.findViewById(R.id.radio_webp));
            getThemeHelper().setSwitchCompactColor(swSaveHere, getAccentColor());
            getThemeHelper().setSwitchCompactColor(swVertical, getAccentColor());
            // #endregion
            seekQuality.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    txtQuality.setText(StringUtils.html(String.format(Locale.getDefault(), "%s <b>%d</b>", getString(R.string.quality), progress)));
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }
            });
            seekQuality.setProgress(50);
            swVertical.setClickable(false);
            llSwVertical.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    swVertical.setChecked(!swVertical.isChecked());
                    getThemeHelper().setSwitchCompactColor(swVertical, getAccentColor());
                    llExampleH.setVisibility(swVertical.isChecked() ? View.GONE : View.VISIBLE);
                    llExampleV.setVisibility(swVertical.isChecked() ? View.VISIBLE : View.GONE);
                }
            });
            swSaveHere.setClickable(false);
            llSwSaveHere.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    swSaveHere.setChecked(!swSaveHere.isChecked());
                    getThemeHelper().setSwitchCompactColor(swSaveHere, getAccentColor());
                }
            });
            builder.setView(dialogLayout);
            builder.setPositiveButton(this.getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    Bitmap.CompressFormat compressFormat;
                    switch(radioFormatGroup.getCheckedRadioButtonId()) {
                        case R.id.radio_jpeg:
                        default:
                            compressFormat = Bitmap.CompressFormat.JPEG;
                            break;
                        case R.id.radio_png:
                            compressFormat = Bitmap.CompressFormat.PNG;
                            break;
                        case R.id.radio_webp:
                            compressFormat = Bitmap.CompressFormat.WEBP;
                            break;
                    }
                    Affix.Options options = new Affix.Options(swSaveHere.isChecked() ? adapter.getFirstSelected().getPath() : Affix.getDefaultDirectoryPath(), compressFormat, seekQuality.getProgress(), swVertical.isChecked());
                    new affixMedia().execute(options);
                }
            });
            builder.setNegativeButton(this.getString(R.string.cancel).toUpperCase(), null);
            builder.show();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) RadioGroup(android.widget.RadioGroup) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) DeleteException(org.horaapps.leafpic.util.file.DeleteException) ArrayList(java.util.ArrayList) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Uri(android.net.Uri) Bitmap(android.graphics.Bitmap) ThemedActivity(org.horaapps.liz.ThemedActivity) SortingOrder(org.horaapps.leafpic.data.sort.SortingOrder) TextView(android.widget.TextView) EditText(android.widget.EditText) SeekBar(android.widget.SeekBar) Media(org.horaapps.leafpic.data.Media) AsyncTask(android.os.AsyncTask) CardView(android.support.v7.widget.CardView) Intent(android.content.Intent) BindView(butterknife.BindView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Affix(org.horaapps.leafpic.util.Affix) ThemedIcon(org.horaapps.liz.ui.ThemedIcon) ProgressAdapter(org.horaapps.leafpic.adapters.ProgressAdapter) LinearLayout(android.widget.LinearLayout) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 3 with SortingOrder

use of org.horaapps.leafpic.data.sort.SortingOrder in project LeafPic by HoraApps.

the class SingleMediaActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.rotate_180:
            rotateImage(180);
            break;
        case R.id.rotate_right_90:
            rotateImage(90);
            break;
        case R.id.rotate_left_90:
            rotateImage(-90);
            break;
        case R.id.action_copy:
            SelectAlbumBuilder.with(getSupportFragmentManager()).title(getString(R.string.copy_to)).onFolderSelected(path -> {
                Media currentMedia = getCurrentMedia();
                boolean b = MediaHelper.copyMedia(getApplicationContext(), currentMedia, path);
                if (!b)
                    Toast.makeText(getApplicationContext(), R.string.copy_error, Toast.LENGTH_SHORT).show();
            }).show();
            break;
        case R.id.name_sort_mode:
            HandlingAlbums.getInstance(getApplicationContext()).setSortingMode(album.getPath(), SortingMode.NAME.getValue());
            album.setSortingMode(SortingMode.NAME);
            this.album.sortPhotos();
            adapter.swapDataSet(media);
            item.setChecked(true);
            return true;
        case R.id.date_taken_sort_mode:
            HandlingAlbums.getInstance(getApplicationContext()).setSortingMode(album.getPath(), SortingMode.DATE.getValue());
            album.setSortingMode(SortingMode.DATE);
            this.album.sortPhotos();
            adapter.swapDataSet(media);
            item.setChecked(true);
            return true;
        case R.id.size_sort_mode:
            HandlingAlbums.getInstance(getApplicationContext()).setSortingMode(album.getPath(), SortingMode.SIZE.getValue());
            album.setSortingMode(SortingMode.SIZE);
            this.album.sortPhotos();
            adapter.swapDataSet(media);
            item.setChecked(true);
            return true;
        case R.id.type_sort_action:
            HandlingAlbums.getInstance(getApplicationContext()).setSortingMode(album.getPath(), SortingMode.TYPE.getValue());
            album.setSortingMode(SortingMode.TYPE);
            this.album.sortPhotos();
            adapter.swapDataSet(media);
            item.setChecked(true);
            return true;
        case R.id.numeric_sort_mode:
            HandlingAlbums.getInstance(getApplicationContext()).setSortingMode(album.getPath(), SortingMode.NUMERIC.getValue());
            album.setSortingMode(SortingMode.NUMERIC);
            this.album.sortPhotos();
            adapter.swapDataSet(media);
            item.setChecked(true);
            return true;
        case R.id.ascending_sort_order:
            item.setChecked(!item.isChecked());
            SortingOrder sortingOrder = SortingOrder.fromValue(item.isChecked());
            HandlingAlbums.getInstance(getApplicationContext()).setSortingOrder(album.getPath(), sortingOrder.getValue());
            album.setSortingOrder(sortingOrder);
            this.album.sortPhotos();
            adapter.swapDataSet(media);
            return true;
        case R.id.action_share:
            // TODO: 16/10/17 check if it works everywhere
            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType(getCurrentMedia().getMimeType());
            Uri uri1 = LegacyCompatFileProvider.getUri(this, getCurrentMedia().getFile());
            share.putExtra(Intent.EXTRA_STREAM, uri1);
            share.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(Intent.createChooser(share, getString(R.string.send_to)));
            return true;
        case R.id.action_edit:
            // TODO: 16/10/17 redo
            Uri mDestinationUri = Uri.fromFile(new File(getCacheDir(), "croppedImage.png"));
            Uri uri = Uri.fromFile(new File(getCurrentMedia().getPath()));
            UCrop uCrop = UCrop.of(uri, mDestinationUri);
            uCrop.withOptions(getUcropOptions());
            uCrop.start(SingleMediaActivity.this);
            break;
        case R.id.action_use_as:
            Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
            intent.setDataAndType(LegacyCompatFileProvider.getUri(this, getCurrentMedia().getFile()), getCurrentMedia().getMimeType());
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(Intent.createChooser(intent, getString(R.string.use_as)));
            return true;
        case R.id.action_open_with:
            Intent intentopenWith = new Intent(Intent.ACTION_VIEW);
            intentopenWith.setDataAndType(LegacyCompatFileProvider.getUri(this, getCurrentMedia().getFile()), getCurrentMedia().getMimeType());
            intentopenWith.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(Intent.createChooser(intentopenWith, getString(R.string.open_with)));
            break;
        case R.id.action_delete:
            final AlertDialog textDialog = AlertDialogsHelper.getTextDialog(SingleMediaActivity.this, R.string.delete, R.string.delete_photo_message);
            textDialog.setButton(DialogInterface.BUTTON_NEGATIVE, this.getString(R.string.cancel).toUpperCase(), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    textDialog.dismiss();
                }
            });
            textDialog.setButton(DialogInterface.BUTTON_POSITIVE, this.getString(R.string.delete).toUpperCase(), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    if (Security.isPasswordOnDelete()) {
                        Security.authenticateUser(SingleMediaActivity.this, new Security.AuthCallBack() {

                            @Override
                            public void onAuthenticated() {
                                deleteCurrentMedia();
                            }

                            @Override
                            public void onError() {
                                Toast.makeText(getApplicationContext(), R.string.wrong_password, Toast.LENGTH_SHORT).show();
                            }
                        });
                    } else
                        deleteCurrentMedia();
                }
            });
            textDialog.show();
            return true;
        case R.id.action_move:
            SelectAlbumBuilder.with(getSupportFragmentManager()).title(getString(R.string.move_to)).exploreMode(true).force(true).onFolderSelected(path -> {
                Media currentMedia = getCurrentMedia();
                boolean success = MediaHelper.moveMedia(getApplicationContext(), currentMedia, path);
                if (success) {
                    media.remove(currentMedia);
                    if (media.size() == 0) {
                        displayAlbums();
                    }
                } else {
                    Toast.makeText(getApplicationContext(), R.string.move_error, Toast.LENGTH_SHORT).show();
                }
                adapter.notifyDataSetChanged();
                updatePageTitle(mViewPager.getCurrentItem());
            }).show();
            return true;
        case R.id.action_rename:
            final EditText editTextNewName = new EditText(this);
            editTextNewName.setText(StringUtils.getPhotoNameByPath(getCurrentMedia().getPath()));
            AlertDialog renameDialog = AlertDialogsHelper.getInsertTextDialog(this, editTextNewName, R.string.rename_photo_action);
            renameDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (editTextNewName.length() != 0) {
                        Media currentMedia = getCurrentMedia();
                        boolean b = MediaHelper.renameMedia(getApplicationContext(), currentMedia, editTextNewName.getText().toString());
                        if (!b) {
                            StringUtils.showToast(getApplicationContext(), getString(R.string.rename_error));
                        // adapter.notifyDataSetChanged();
                        }
                    } else
                        StringUtils.showToast(getApplicationContext(), getString(R.string.nothing_changed));
                }
            });
            renameDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel).toUpperCase(), (dialog, which) -> dialog.dismiss());
            renameDialog.show();
            break;
        case R.id.action_edit_with:
            Intent editIntent = new Intent(Intent.ACTION_EDIT);
            editIntent.setDataAndType(LegacyCompatFileProvider.getUri(this, getCurrentMedia().getFile()), getCurrentMedia().getMimeType());
            editIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(Intent.createChooser(editIntent, getString(R.string.edit_with)));
            break;
        case R.id.action_details:
            final AlertDialog detailsDialog = AlertDialogsHelper.getDetailsDialog(this, getCurrentMedia());
            detailsDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok_action).toUpperCase(), (dialog, which) -> dialog.dismiss());
            detailsDialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.fix_date).toUpperCase(), (dialog, which) -> {
                // todo
                // if (!getCurrentMedia().fixDate())
                Toast.makeText(SingleMediaActivity.this, R.string.unable_to_fix_date, Toast.LENGTH_SHORT).show();
            });
            detailsDialog.show();
            break;
        case R.id.action_settings:
            SettingsActivity.startActivity(this);
            break;
        case R.id.action_palette:
            Intent paletteIntent = new Intent(getApplicationContext(), PaletteActivity.class);
            paletteIntent.setData(LegacyCompatFileProvider.getUri(this, getCurrentMedia().getFile()));
            paletteIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(paletteIntent);
            break;
        case R.id.slide_show:
            isSlideShowOn = !isSlideShowOn;
            if (isSlideShowOn) {
                handler.postDelayed(slideShowRunnable, SLIDE_SHOW_INTERVAL);
                hideSystemUI();
            } else
                handler.removeCallbacks(slideShowRunnable);
            supportInvalidateOptionsMenu();
    }
    return super.onOptionsItemSelected(item);
}
Also used : LegacyCompatFileProvider(org.horaapps.leafpic.util.LegacyCompatFileProvider) Bundle(android.os.Bundle) SortingMode(org.horaapps.leafpic.data.sort.SortingMode) HandlingAlbums(org.horaapps.leafpic.data.HandlingAlbums) Uri(android.net.Uri) WindowManager(android.view.WindowManager) Media(org.horaapps.leafpic.data.Media) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) Hawk(com.orhanobut.hawk.Hawk) Handler(android.os.Handler) ActivityInfo(android.content.pm.ActivityInfo) StorageHelper(org.horaapps.leafpic.data.StorageHelper) View(android.view.View) ArgbEvaluator(android.animation.ArgbEvaluator) MediaHelper(org.horaapps.leafpic.data.MediaHelper) Schedulers(io.reactivex.schedulers.Schedulers) StringUtils(org.horaapps.leafpic.util.StringUtils) ImageFragment(org.horaapps.leafpic.fragments.ImageFragment) Log(android.util.Log) R(org.horaapps.leafpic.R) Surface(android.view.Surface) Fragment(android.support.v4.app.Fragment) ContextCompat(android.support.v4.content.ContextCompat) GoogleMaterial(com.mikepenz.google_material_typeface_library.GoogleMaterial) Measure(org.horaapps.leafpic.util.Measure) Serializable(java.io.Serializable) TextView(android.widget.TextView) HackyViewPager(org.horaapps.leafpic.views.HackyViewPager) CPHelper(org.horaapps.leafpic.data.provider.CPHelper) RelativeLayout(android.widget.RelativeLayout) SelectAlbumBuilder(org.horaapps.leafpic.SelectAlbumBuilder) DepthPageTransformer(org.horaapps.leafpic.animations.DepthPageTransformer) Nullable(android.support.annotation.Nullable) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Context(android.content.Context) AlertDialogsHelper(org.horaapps.leafpic.util.AlertDialogsHelper) ButterKnife(butterknife.ButterKnife) Album(org.horaapps.leafpic.data.Album) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) MediaFilter(org.horaapps.leafpic.data.filter.MediaFilter) NonNull(android.support.annotation.NonNull) Prefs(org.horaapps.leafpic.util.preferences.Prefs) UCrop(com.yalantis.ucrop.UCrop) MenuItem(android.view.MenuItem) BaseMediaFragment(org.horaapps.leafpic.fragments.BaseMediaFragment) ArrayList(java.util.ArrayList) SortingOrder(org.horaapps.leafpic.data.sort.SortingOrder) DeleteException(org.horaapps.leafpic.util.file.DeleteException) Toast(android.widget.Toast) Menu(android.view.Menu) Settings(android.provider.Settings) Build(android.os.Build) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) DialogInterface(android.content.DialogInterface) CommunityMaterial(com.mikepenz.community_material_typeface_library.CommunityMaterial) Parcelable(android.os.Parcelable) MediaPagerAdapter(org.horaapps.leafpic.adapters.MediaPagerAdapter) ColorPalette(org.horaapps.liz.ColorPalette) AnimationUtils(org.horaapps.leafpic.util.AnimationUtils) File(java.io.File) AlbumSettings(org.horaapps.leafpic.data.AlbumSettings) MediaComparators(org.horaapps.leafpic.data.sort.MediaComparators) AlertDialog(android.support.v7.app.AlertDialog) Glide(com.bumptech.glide.Glide) Toolbar(android.support.v7.widget.Toolbar) Bitmap(android.graphics.Bitmap) Configuration(android.content.res.Configuration) CallSuper(android.support.annotation.CallSuper) SharedMediaActivity(org.horaapps.leafpic.activities.base.SharedMediaActivity) Collections(java.util.Collections) EditText(android.widget.EditText) Security(org.horaapps.leafpic.util.Security) ValueAnimator(android.animation.ValueAnimator) InputStream(java.io.InputStream) AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) Media(org.horaapps.leafpic.data.Media) UCrop(com.yalantis.ucrop.UCrop) Intent(android.content.Intent) Uri(android.net.Uri) SortingOrder(org.horaapps.leafpic.data.sort.SortingOrder) File(java.io.File)

Aggregations

AlertDialog (android.support.v7.app.AlertDialog)3 View (android.view.View)3 TextView (android.widget.TextView)3 BindView (butterknife.BindView)3 SortingOrder (org.horaapps.leafpic.data.sort.SortingOrder)3 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Bitmap (android.graphics.Bitmap)2 Uri (android.net.Uri)2 CardView (android.support.v7.widget.CardView)2 RecyclerView (android.support.v7.widget.RecyclerView)2 EditText (android.widget.EditText)2 ArrayList (java.util.ArrayList)2 Media (org.horaapps.leafpic.data.Media)2 DeleteException (org.horaapps.leafpic.util.file.DeleteException)2 ArgbEvaluator (android.animation.ArgbEvaluator)1 ValueAnimator (android.animation.ValueAnimator)1 Context (android.content.Context)1 ActivityInfo (android.content.pm.ActivityInfo)1 Configuration (android.content.res.Configuration)1