use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.
the class ExifEditorActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exif_editor);
AlbumItem albumItem = getIntent().getParcelableExtra(ALBUM_ITEM);
if (savedInstanceState != null && savedInstanceState.containsKey(EDITED_ITEMS)) {
editedItems = savedInstanceState.getParcelableArrayList(EDITED_ITEMS);
} else {
editedItems = new ArrayList<>();
}
if (albumItem == null) {
this.finish();
return;
}
String mimeType = MediaType.getMimeType(this, albumItem.getUri(this));
if (!MediaType.doesSupportWritingExifMimeType(mimeType)) {
Toast.makeText(this, "Editing Exif values is only supported for JPEG images", Toast.LENGTH_SHORT).show();
this.finish();
return;
}
exifInterface = null;
try {
exifInterface = new ExifInterface(albumItem.getPath());
} catch (IOException e) {
e.printStackTrace();
}
if (exifInterface == null) {
this.finish();
return;
}
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
final RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(new RecyclerViewAdapter(new RecyclerViewAdapter.OnEditCallback() {
@Override
public void onItemEdited(String tag, String newValue) {
for (ExifUtil.ExifItem item : editedItems) {
if (item.getTag().equals(tag)) {
item.setValue(newValue);
showSaveButton(true);
return;
}
}
// ExifItem wasn't previously edited
ExifUtil.ExifItem item = getItem(tag);
item.setValue(newValue);
editedItems.add(item);
showSaveButton(true);
}
@Override
public ExifUtil.ExifItem getItem(String tag) {
for (ExifUtil.ExifItem item : editedItems) {
if (item.getTag().equals(tag)) {
return item;
}
}
return new ExifUtil.ExifItem(tag, exifInterface.getAttribute(tag));
}
}));
final ViewGroup rootView = findViewById(R.id.root_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
toolbar.setPadding(toolbar.getPaddingStart() + insets.getSystemWindowInsetLeft(), toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(), toolbar.getPaddingEnd() + insets.getSystemWindowInsetRight(), toolbar.getPaddingBottom());
recyclerView.setPadding(recyclerView.getPaddingStart() + insets.getSystemWindowInsetLeft(), recyclerView.getPaddingTop(), recyclerView.getPaddingEnd() + insets.getSystemWindowInsetRight(), recyclerView.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// clear this listener so insets aren't re-applied
rootView.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
} else {
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// hacky way of getting window insets on pre-Lollipop
int[] screenSize = Util.getScreenSize(ExifEditorActivity.this);
int[] windowInsets = new int[] { Math.abs(screenSize[0] - rootView.getLeft()), Math.abs(screenSize[1] - rootView.getTop()), Math.abs(screenSize[2] - rootView.getRight()), Math.abs(screenSize[3] - rootView.getBottom()) };
toolbar.setPadding(toolbar.getPaddingStart() + windowInsets[0], toolbar.getPaddingTop() + windowInsets[1], toolbar.getPaddingEnd() + windowInsets[2], toolbar.getPaddingBottom());
recyclerView.setPadding(recyclerView.getPaddingStart() + windowInsets[0], recyclerView.getPaddingTop(), recyclerView.getPaddingEnd() + windowInsets[2], recyclerView.getPaddingBottom() + windowInsets[3]);
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
}
use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.
the class AlbumActivity method deleteAlbumItemsSnackbar.
public void deleteAlbumItemsSnackbar(String[] selected_items) {
if (!MediaProvider.checkPermission(this)) {
return;
}
final int[] indices = new int[selected_items.length];
final AlbumItem[] deletedItems = new AlbumItem[selected_items.length];
for (int i = selected_items.length - 1; i >= 0; i--) {
for (int k = 0; k < album.getAlbumItems().size(); k++) {
AlbumItem albumItem = album.getAlbumItems().get(k);
if (selected_items[i].equals(albumItem.getPath())) {
indices[i] = k;
deletedItems[i] = albumItem;
album.getAlbumItems().remove(k);
recyclerViewAdapter.notifyItemRemoved(k);
}
}
}
int messageRes = selected_items.length == 1 ? R.string.file_deleted : R.string.files_deleted;
String message = getString(messageRes, selected_items.length);
// noinspection deprecation
snackbar = Snackbar.make(findViewById(R.id.root_view), message, Snackbar.LENGTH_LONG).setAction(R.string.undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i = 0; i < deletedItems.length; i++) {
AlbumItem albumItem = deletedItems[i];
int index = indices[i];
album.getAlbumItems().add(index, albumItem);
recyclerViewAdapter.notifyItemInserted(index);
}
}
}).setCallback(new Snackbar.Callback() {
@Override
public void onDismissed(Snackbar snackbar, int event) {
super.onDismissed(snackbar, event);
if (event != Snackbar.Callback.DISMISS_EVENT_ACTION) {
deleteAlbumItems(deletedItems, indices);
}
}
});
Util.showSnackbar(snackbar);
}
use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.
the class ItemAdapter method instantiateItem.
@NonNull
@Override
public Object instantiateItem(@NonNull final ViewGroup container, int position) {
AlbumItem albumItem = album.getAlbumItems().get(position);
ViewHolder viewHolder;
if (albumItem instanceof Video) {
viewHolder = new VideoViewHolder(albumItem, position);
} else if (albumItem instanceof Gif) {
viewHolder = new GifViewHolder(albumItem, position);
} else if (albumItem instanceof RAWImage) {
viewHolder = new RAWImageViewHolder(albumItem, position);
} else {
viewHolder = new PhotoViewHolder(albumItem, position);
}
viewHolders.add(viewHolder);
View v = viewHolder.getView(container);
container.addView(v);
if (callback != null) {
boolean b = callback.onInstantiateItem(viewHolder);
if (!b) {
callback = null;
}
}
return v;
}
use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.
the class FileExplorerAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
final File_POJO file = files.getChildren().get(position);
((FileHolder) holder).setFile(file);
((FileHolder) holder).setSelected(selected_items[position]);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mode == SELECTOR_MODE) {
onItemSelect(file);
} else if (file.isMedia) {
int index = file.getPath().lastIndexOf("/");
String path = file.getPath().substring(0, index);
// load Album
final Album album = new Album().setPath(path);
AlbumItem albumItem = AlbumItem.getInstance(file.getPath());
if (albumItem != null) {
album.getAlbumItems().add(albumItem);
}
if (albumItem != null) {
// create intent
Intent intent = new Intent(holder.itemView.getContext(), IntentReceiver.class).setAction(Intent.ACTION_VIEW).setData(albumItem.getUri(holder.itemView.getContext()));
holder.itemView.getContext().startActivity(intent);
}
} else {
// to keep the ripple animation
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
directoryChangeCallback.changeDir(file.getPath());
}
}, 300);
}
}
});
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
onItemSelect(file);
return true;
}
});
// clicking on folder icons also selects this item
holder.itemView.findViewById(R.id.folder_indicator).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onItemSelect(file);
}
});
}
use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.
the class MediaStoreRetriever method checkHiddenFolders.
private ArrayList<Album> checkHiddenFolders(final Activity context) {
ArrayList<Album> hiddenAlbums = new ArrayList<>();
// Scan all no Media files
String nonMediaCondition = MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_NONE;
// Files with name contain .nomedia
String selection = nonMediaCondition + " AND " + MediaStore.Files.FileColumns.TITLE + " LIKE ?";
String[] params = new String[] { "%" + MediaProvider.FILE_TYPE_NO_MEDIA + "%" };
// make query for non media files with file title contain ".nomedia" as
// text on External Media URI
Cursor cursor = context.getContentResolver().query(MediaStore.Files.getContentUri("external"), new String[] { MediaStore.Files.FileColumns.DATA }, selection, params, MediaStore.Images.Media.DATE_TAKEN);
if (cursor == null || cursor.getCount() == 0) {
return hiddenAlbums;
}
if (cursor.moveToFirst()) {
int pathColumn = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
do {
String path = cursor.getString(pathColumn);
path = path.replace(MediaProvider.FILE_TYPE_NO_MEDIA, "");
File dir = new File(path);
final Album album = new Album().setPath(path);
File[] files = dir.listFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
AlbumItem albumItem = AlbumItem.getInstance(files[i].getPath());
if (albumItem != null) {
album.getAlbumItems().add(albumItem);
}
}
}
if (album.getAlbumItems().size() > 0) {
hiddenAlbums.add(album);
}
} while (cursor.moveToNext());
}
cursor.close();
return hiddenAlbums;
}
Aggregations