use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.
the class StorageRetriever method loadAlbums.
@Override
void loadAlbums(final Activity context, final boolean hiddenFolders) {
final long startTime = System.currentTimeMillis();
final ArrayList<Album> albums = new ArrayList<>();
// handle timeout after 10 seconds
handler = new Handler();
timeout = new Runnable() {
@Override
public void run() {
Toast.makeText(context, "timeout", Toast.LENGTH_SHORT).show();
MediaProvider.OnMediaLoadedCallback callback = getCallback();
if (callback != null) {
callback.timeout();
}
}
};
handler.postDelayed(timeout, 10000);
// load media from storage
AsyncTask.execute(new Runnable() {
@Override
public void run() {
searchStorage(context, new StorageSearchCallback() {
@Override
public void onThreadResult(ItemLoader.Result result) {
if (result != null) {
albums.addAll(result.albums);
}
}
@Override
public void done() {
if (!hiddenFolders) {
for (int i = albums.size() - 1; i >= 0; i--) {
if (albums.get(i) == null || albums.get(i).isHidden()) {
albums.remove(i);
}
}
}
// done loading media from storage
MediaProvider.OnMediaLoadedCallback callback = getCallback();
if (callback != null) {
callback.onMediaLoaded(albums);
}
cancelTimeout();
Log.d("StorageRetriever", "onMediaLoaded(" + String.valueOf(THREAD_COUNT) + "): " + String.valueOf(System.currentTimeMillis() - startTime) + " ms");
}
});
}
});
}
use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.
the class MainAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
final Album album = getData().get(position);
((AlbumHolder) holder).setAlbum(album);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(holder.itemView.getContext(), AlbumActivity.class);
// intent.putExtra(AlbumActivity.ALBUM, album);
intent.putExtra(AlbumActivity.ALBUM_PATH, album.getPath());
if (pickPhotos()) {
Context c = holder.itemView.getContext();
boolean allowMultiple = false;
if (c instanceof Activity) {
Activity a = (Activity) c;
allowMultiple = a.getIntent().getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
}
intent.setAction(MainActivity.PICK_PHOTOS);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, allowMultiple);
} else {
intent.setAction(AlbumActivity.VIEW_ALBUM);
}
ActivityOptionsCompat options;
Activity context = (Activity) holder.itemView.getContext();
if (!pickPhotos()) {
// noinspection unchecked
options = ActivityOptionsCompat.makeSceneTransitionAnimation(context);
context.startActivityForResult(intent, MainActivity.REFRESH_PHOTOS_REQUEST_CODE, options.toBundle());
} else {
View toolbar = context.findViewById(R.id.toolbar);
options = ActivityOptionsCompat.makeSceneTransitionAnimation(context, toolbar, context.getString(R.string.toolbar_transition_name));
context.startActivityForResult(intent, MainActivity.PICK_PHOTOS_REQUEST_CODE, options.toBundle());
}
}
});
}
use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.
the class NoFolderRecyclerViewAdapter method setData.
@Override
public AbstractRecyclerViewAdapter<ArrayList<Album>> setData(ArrayList<Album> data) {
if (data == null) {
return this;
}
Album album = new Album().setPath(MediaProvider.SINGLE_FOLDER_PATH);
for (int i = 0; i < data.size(); i++) {
album.getAlbumItems().addAll(data.get(i).getAlbumItems());
}
int sortBy = Settings.getInstance(context).sortAlbumsBy();
SortUtil.sort(album.getAlbumItems(), sortBy);
albumAdapter.setData(album);
notifyDataSetChanged();
return this;
}
use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.
the class IntentReceiver method view.
private void view(Intent intent) {
Uri uri = intent.getData();
if (uri == null) {
Toast.makeText(this, getString(R.string.error) + ": Uri = null", Toast.LENGTH_SHORT).show();
startActivity(new Intent(this, MainActivity.class));
this.finish();
return;
}
Album album = new Album().setPath("");
AlbumItem albumItem;
String mimeType = intent.getType();
if (mimeType != null) {
albumItem = AlbumItem.getInstance(this, uri, mimeType);
} else {
albumItem = AlbumItem.getInstance(this, uri);
}
if (albumItem == null) {
Toast.makeText(this, getString(R.string.error), Toast.LENGTH_SHORT).show();
this.finish();
return;
}
album.getAlbumItems().add(albumItem);
if (albumItem instanceof Video) {
Intent view_video = new Intent(this, VideoPlayerActivity.class).setData(uri);
startActivity(view_video);
} else {
Intent view_photo = new Intent(this, ItemActivity.class).setData(uri).putExtra(ItemActivity.ALBUM_ITEM, albumItem).putExtra(ItemActivity.VIEW_ONLY, true).putExtra(ItemActivity.ALBUM, album).putExtra(ItemActivity.ITEM_POSITION, album.getAlbumItems().indexOf(albumItem)).addFlags(intent.getFlags());
startActivity(view_photo);
}
this.finish();
}
use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.
the class ItemActivity method renameAlbumItem.
public void renameAlbumItem() {
File_POJO file = new File_POJO(albumItem.getPath(), true).setName(albumItem.getName());
Rename.Util.getRenameDialog(this, file, new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch(intent.getAction()) {
case FileOperation.RESULT_DONE:
// refresh data
final Activity activity = ItemActivity.this;
String newFilePath = intent.getStringExtra(Rename.NEW_FILE_PATH);
if (newFilePath == null) {
return;
}
int index = newFilePath.lastIndexOf("/");
final String albumPath = newFilePath.substring(0, index);
getIntent().putExtra(ALBUM_PATH, albumPath);
getIntent().putExtra(ITEM_POSITION, album.getAlbumItems().indexOf(albumItem));
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, albumPath, new MediaProvider.OnAlbumLoadedCallback() {
@Override
public void onAlbumLoaded(Album album) {
ItemActivity.this.albumItem = null;
ItemActivity.this.album = album;
ItemActivity.this.onAlbumLoaded(null);
// notify AlbumActivity
LocalBroadcastManager.getInstance(ItemActivity.this).sendBroadcast(new Intent(AlbumActivity.ALBUM_ITEM_RENAMED));
}
});
}
@Override
public void timeout() {
finish();
}
@Override
public void needPermission() {
finish();
}
});
break;
default:
break;
}
}
}).show();
}
Aggregations