use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.
the class MainActivity method onActivityReenter.
@Override
public void onActivityReenter(final int resultCode, Intent intent) {
super.onActivityReenter(resultCode, intent);
int nestedRecyclerViewValue = getResources().getInteger(R.integer.STYLE_NESTED_RECYCLER_VIEW_VALUE);
if (intent.getAction() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && intent.getAction().equals(ItemActivity.SHARED_ELEMENT_RETURN_TRANSITION) && Settings.getInstance(this).getStyle(this, pick_photos) == nestedRecyclerViewValue) {
// handle shared-element transition, for nested nestedRecyclerView style
Bundle tmpReenterState = new Bundle(intent.getExtras());
if (tmpReenterState.containsKey(AlbumActivity.ALBUM_PATH) && tmpReenterState.containsKey(AlbumActivity.EXTRA_CURRENT_ALBUM_POSITION)) {
String albumPath = tmpReenterState.getString(AlbumActivity.ALBUM_PATH);
final int sharedElementReturnPosition = tmpReenterState.getInt(AlbumActivity.EXTRA_CURRENT_ALBUM_POSITION);
int index = -1;
ArrayList<Album> albums = MediaProvider.getAlbumsWithVirtualDirectories(this);
for (int i = 0; i < albums.size(); i++) {
if (albums.get(i).getPath().equals(albumPath)) {
index = i;
break;
}
}
if (index == -1) {
return;
}
// postponing transition until sharedElement is laid out
postponeEnterTransition();
setExitSharedElementCallback(mCallback);
final NestedRecyclerViewAlbumHolder.StartSharedElementTransitionCallback callback = new NestedRecyclerViewAlbumHolder.StartSharedElementTransitionCallback() {
@Override
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void startPostponedEnterTransition() {
// sharedElement is laid out --> start transition
MainActivity.this.startPostponedEnterTransition();
}
};
final int finalIndex = index;
recyclerView.scrollToPosition(index);
// wait until ViewHolder is laid out
recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onLayoutChange(View v, int l, int t, int r, int b, int oL, int oT, int oR, int oB) {
RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(finalIndex);
if (viewHolder != null) {
recyclerView.removeOnLayoutChangeListener(this);
} else {
// viewHolder hasn't been laid out yet --> wait
recyclerView.scrollToPosition(finalIndex);
}
if (viewHolder instanceof NestedRecyclerViewAlbumHolder) {
// found ViewHolder
sharedElementViewHolder = (NestedRecyclerViewAlbumHolder) viewHolder;
((NestedRecyclerViewAlbumHolder) viewHolder).onSharedElement(sharedElementReturnPosition, callback);
}
}
});
}
}
}
use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.
the class AlbumActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final String[] selected_items_paths;
Intent intent;
switch(item.getItemId()) {
case R.id.select_all:
SelectorModeManager manager = recyclerViewAdapter.getSelectorManager();
String[] paths = new String[album.getAlbumItems().size()];
for (int i = 0; i < album.getAlbumItems().size(); i++) {
paths[i] = album.getAlbumItems().get(i).getPath();
}
manager.selectAll(paths);
recyclerViewAdapter.notifyItemRangeChanged(0, paths.length);
break;
case R.id.share:
// share multiple items
selected_items_paths = recyclerViewAdapter.cancelSelectorMode(this);
ArrayList<Uri> uris = new ArrayList<>();
for (int i = 0; i < selected_items_paths.length; i++) {
uris.add(StorageUtil.getContentUri(this, selected_items_paths[i]));
}
intent = new Intent().setAction(Intent.ACTION_SEND_MULTIPLE).setType(MediaType.getMimeType(this, uris.get(0))).putExtra(Intent.EXTRA_STREAM, uris);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(intent, getString(R.string.share)));
}
break;
case R.id.copy:
case R.id.move:
selected_items_paths = recyclerViewAdapter.cancelSelectorMode(this);
intent = new Intent(this, FileOperationDialogActivity.class);
intent.setAction(item.getItemId() == R.id.copy ? FileOperationDialogActivity.ACTION_COPY : FileOperationDialogActivity.ACTION_MOVE);
intent.putExtra(FileOperationDialogActivity.FILES, selected_items_paths);
startActivityForResult(intent, FILE_OP_DIALOG_REQUEST);
break;
case R.id.exclude:
Provider.loadExcludedPaths(this);
if (!album.excluded) {
Provider.addExcludedPath(this, album.getPath());
album.excluded = true;
} else {
Provider.removeExcludedPath(this, album.getPath());
album.excluded = false;
}
item.setChecked(album.excluded);
break;
case R.id.pin:
Provider.loadPinnedPaths(this);
if (!album.pinned) {
Provider.pinPath(this, album.getPath());
album.pinned = true;
} else {
Provider.unpinPath(this, album.getPath());
album.pinned = false;
}
item.setChecked(album.pinned);
break;
case R.id.rename:
File_POJO file = new File_POJO(album.getPath(), false).setName(album.getName());
Rename.Util.getRenameDialog(this, file, new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final Activity activity = AlbumActivity.this;
final String newFilePath = intent.getStringExtra(Rename.NEW_FILE_PATH);
getIntent().putExtra(ALBUM_PATH, newFilePath);
boolean hiddenFolders = Settings.getInstance(activity).getHiddenFolders();
new MediaProvider(activity).loadAlbums(activity, hiddenFolders, new MediaProvider.OnMediaLoadedCallback() {
@Override
public void onMediaLoaded(ArrayList<Album> albums) {
// reload activity
MediaProvider.loadAlbum(activity, newFilePath, new MediaProvider.OnAlbumLoadedCallback() {
@Override
public void onAlbumLoaded(Album album) {
AlbumActivity.this.album = album;
AlbumActivity.this.onAlbumLoaded(null);
}
});
}
@Override
public void timeout() {
finish();
}
@Override
public void needPermission() {
finish();
}
});
}
}).show();
break;
case R.id.sort_by_date:
case R.id.sort_by_name:
item.setChecked(true);
int sort_by = item.getItemId() == R.id.sort_by_date ? SortUtil.BY_DATE : SortUtil.BY_NAME;
Settings.getInstance(this).sortAlbumBy(this, sort_by);
SortUtil.sort(album.getAlbumItems(), sort_by);
recyclerViewAdapter.notifyDataSetChanged();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
use of us.koller.cameraroll.data.models.Album 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.Album in project Camera-Roll-Android-App by kollerlukas.
the class NestedRecyclerViewAlbumHolder method setAlbum.
@Override
public void setAlbum(Album album) {
Album oldAlbum = getAlbum();
super.setAlbum(album);
if (album.equals(oldAlbum)) {
onItemChanged();
return;
}
int oldHeight = nestedRecyclerView.getHeight();
// make RecyclerView either single ore double lined, depending on the album size
int lineCount = album.getAlbumItems().size() > SINGLE_LINE_MAX_ITEM_COUNT ? 2 : 1;
int height = (int) getContext().getResources().getDimension(R.dimen.nested_recyclerView_line_height) * lineCount;
if (oldHeight != height) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
nestedRecyclerView.setLayoutParams(params);
itemDecoration.setSpanCount(lineCount);
RecyclerView.LayoutManager layoutManager;
if (album.getAlbumItems().size() > SINGLE_LINE_MAX_ITEM_COUNT) {
layoutManager = new GridLayoutManager(getContext(), lineCount, GridLayoutManager.HORIZONTAL, false);
} else {
layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
}
nestedRecyclerView.setLayoutManager(layoutManager);
nestedRecyclerView.setHasFixedSize(true);
}
if (nestedRecyclerView.getAdapter() != null) {
NestedAdapter adapter = (NestedAdapter) nestedRecyclerView.getAdapter();
adapter.setData(album);
} else {
NestedAdapter adapter = new NestedAdapter(callback, nestedRecyclerView, album, false);
adapter.setSelectorModeManager(manager);
nestedRecyclerView.setAdapter(adapter);
}
}
use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.
the class MediaProvider method loadAlbums.
public void loadAlbums(final Activity context, final boolean hiddenFolders, OnMediaLoadedCallback callback) {
if (!MediaProvider.checkPermission(context)) {
callback.needPermission();
return;
}
int mode = getMode(context);
switch(mode) {
case MODE_STORAGE:
retriever = new StorageRetriever();
break;
case MODE_MEDIASTORE:
retriever = new MediaStoreRetriever();
break;
default:
break;
}
if (retriever != null) {
setCallback(callback);
retriever.loadAlbums(context, hiddenFolders, new OnMediaLoadedCallback() {
@Override
public void onMediaLoaded(ArrayList<Album> albums) {
// remove excluded albums
for (int i = albums.size() - 1; i >= 0; i--) {
if (albums.get(i) == null || albums.get(i).excluded) {
albums.remove(i);
}
}
SortUtil.sortAlbums(context, albums);
setAlbums(albums);
OnMediaLoadedCallback callback = getCallback();
if (callback != null) {
callback.onMediaLoaded(albums);
}
}
@Override
public void timeout() {
OnMediaLoadedCallback callback = getCallback();
if (callback != null) {
callback.timeout();
}
}
@Override
public void needPermission() {
OnMediaLoadedCallback callback = getCallback();
if (callback != null) {
callback.needPermission();
}
}
});
} else {
if (callback != null) {
callback.onMediaLoaded(null);
}
}
}
Aggregations