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();
}
}
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());
});
}
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);
}
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;
});
}
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);
}
}
}
}
}
Aggregations