use of org.horaapps.leafpic.adapters.ProgressAdapter 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);
}
Aggregations