Search in sources :

Example 16 with Media

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

the class MainActivity method onMediaClick.

@Override
public void onMediaClick(Album album, ArrayList<Media> media, int position) {
    if (!pickMode) {
        Intent intent = new Intent(getApplicationContext(), SingleMediaActivity.class);
        intent.putExtra(SingleMediaActivity.EXTRA_ARGS_ALBUM, album);
        try {
            intent.setAction(SingleMediaActivity.ACTION_OPEN_ALBUM);
            intent.putExtra(SingleMediaActivity.EXTRA_ARGS_MEDIA, media);
            intent.putExtra(SingleMediaActivity.EXTRA_ARGS_POSITION, position);
            startActivity(intent);
        } catch (Exception e) {
            // Putting too much data into the Bundle
            // TODO: Find a better way to pass data between the activities - possibly a key to
            // access a HashMap or a unique value of a singleton Data Repository of some sort.
            intent.setAction(SingleMediaActivity.ACTION_OPEN_ALBUM_LAZY);
            intent.putExtra(SingleMediaActivity.EXTRA_ARGS_MEDIA, media.get(position));
            startActivity(intent);
        }
    } else {
        Media m = media.get(position);
        Uri uri = LegacyCompatFileProvider.getUri(getApplicationContext(), m.getFile());
        Intent res = new Intent();
        res.setData(uri);
        res.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        setResult(RESULT_OK, res);
        finish();
    }
}
Also used : Media(org.horaapps.leafpic.data.Media) Intent(android.content.Intent) Uri(android.net.Uri)

Example 17 with Media

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

the class SingleMediaActivity method deleteCurrentMedia.

private void deleteCurrentMedia() {
    Media currentMedia = getCurrentMedia();
    MediaHelper.deleteMedia(getApplicationContext(), currentMedia).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(deleted -> {
        media.remove(deleted);
        if (media.size() == 0) {
            displayAlbums();
        }
    }, err -> {
        if (err instanceof DeleteException)
            Toast.makeText(this, R.string.delete_error, Toast.LENGTH_SHORT).show();
        else
            Toast.makeText(this, err.getMessage(), Toast.LENGTH_SHORT).show();
    }, () -> {
        adapter.notifyDataSetChanged();
        updatePageTitle(mViewPager.getCurrentItem());
    });
}
Also used : DeleteException(org.horaapps.leafpic.util.file.DeleteException) Media(org.horaapps.leafpic.data.Media)

Example 18 with Media

use of org.horaapps.leafpic.data.Media 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)

Example 19 with Media

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

the class AlbumsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final AlbumsAdapter.ViewHolder holder, int position) {
    // TODO Calvin: Major Refactor - No business logic here.
    Album a = albums.get(position);
    holder.refreshTheme(getThemeHelper(), cardViewStyle, a.isSelected());
    Media f = a.getCover();
    RequestOptions options = new RequestOptions().signature(f.getSignature()).format(DecodeFormat.PREFER_ARGB_8888).centerCrop().placeholder(placeholder).error(org.horaapps.leafpic.R.drawable.ic_error).diskCacheStrategy(DiskCacheStrategy.RESOURCE);
    Glide.with(holder.picture.getContext()).load(f.getPath()).apply(options).into(holder.picture);
    int accentColor = getThemeHelper().getAccentColor();
    if (accentColor == getThemeHelper().getPrimaryColor())
        accentColor = ColorPalette.getDarkerColor(accentColor);
    int textColor = getThemeHelper().getColor(getThemeHelper().getBaseTheme().equals(Theme.LIGHT) ? R.color.md_album_color_2 : R.color.md_album_color);
    if (a.isSelected())
        textColor = getThemeHelper().getColor(R.color.md_album_color);
    holder.mediaLabel.setTextColor(textColor);
    holder.llCount.setVisibility(Prefs.showMediaCount() ? View.VISIBLE : View.GONE);
    holder.name.setText(StringUtils.htmlFormat(a.getName(), textColor, false, true));
    holder.nMedia.setText(StringUtils.htmlFormat(String.valueOf(a.getCount()), accentColor, true, false));
    holder.path.setVisibility(Prefs.showAlbumPath() ? View.VISIBLE : View.GONE);
    holder.path.setText(a.getPath());
    // START Animation MAKES BUG ON FAST TAP ON CARD
    // Animation anim;
    // anim = AnimationUtils.loadAnimation(holder.albumCard.getContext(), R.anim.slide_fade_card);
    // holder.albumCard.startAnimation(anim);
    // ANIMS
    // holder.card.animate().alpha(1).setDuration(250);
    holder.card.setOnClickListener(v -> {
        if (selecting()) {
            notifySelected(a.toggleSelected());
            notifyItemChanged(position);
        } else
            actionsListener.onItemSelected(position);
    });
    holder.card.setOnLongClickListener(v -> {
        notifySelected(a.toggleSelected());
        notifyItemChanged(position);
        return true;
    });
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) Media(org.horaapps.leafpic.data.Media) Album(org.horaapps.leafpic.data.Album)

Example 20 with Media

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

the class MediaAdapter method selectAllUpTo.

/**
 * On longpress, it finds the last or the first selected image before or after the targetIndex
 * and selects them all.
 *
 * @param
 */
public void selectAllUpTo(Media m) {
    int targetIndex = media.indexOf(m);
    int indexRightBeforeOrAfter = -1;
    int indexNow;
    // TODO: 4/5/17 rewrite?
    for (Media sm : getSelected()) {
        indexNow = media.indexOf(sm);
        if (indexRightBeforeOrAfter == -1)
            indexRightBeforeOrAfter = indexNow;
        if (indexNow > targetIndex)
            break;
        indexRightBeforeOrAfter = indexNow;
    }
    if (indexRightBeforeOrAfter != -1) {
        for (int index = Math.min(targetIndex, indexRightBeforeOrAfter); index <= Math.max(targetIndex, indexRightBeforeOrAfter); index++) {
            if (media.get(index) != null) {
                if (media.get(index).setSelected(true)) {
                    notifySelected(true);
                    notifyItemChanged(index);
                }
            }
        }
    }
}
Also used : Media(org.horaapps.leafpic.data.Media)

Aggregations

Media (org.horaapps.leafpic.data.Media)20 ArrayList (java.util.ArrayList)8 Album (org.horaapps.leafpic.data.Album)8 File (java.io.File)7 Uri (android.net.Uri)6 Intent (android.content.Intent)5 DeleteException (org.horaapps.leafpic.util.file.DeleteException)5 DialogInterface (android.content.DialogInterface)4 Bitmap (android.graphics.Bitmap)4 AlertDialog (android.support.v7.app.AlertDialog)4 View (android.view.View)4 EditText (android.widget.EditText)4 Cursor (android.database.Cursor)3 TextView (android.widget.TextView)3 ArgbEvaluator (android.animation.ArgbEvaluator)2 ValueAnimator (android.animation.ValueAnimator)2 Context (android.content.Context)2 ActivityInfo (android.content.pm.ActivityInfo)2 Configuration (android.content.res.Configuration)2 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)2