Skip to content
This repository has been archived by the owner on Sep 8, 2019. It is now read-only.

Commit

Permalink
- Bug fixes: fixed crashes with big albums + crashed with removable s…
Browse files Browse the repository at this point in the history
…torage

- added support for removable storage (view, share, ...)
- added removable storage to fileExplorer
- added option to directly print images
- added option to share multiple item at once
- minor ui changes
- code clean up
- StorageLoader speed improvements
- FileExplorer speed improvements
  • Loading branch information
kollerlukas committed Feb 20, 2017
1 parent 66452a2 commit d4de9cf
Show file tree
Hide file tree
Showing 60 changed files with 1,542 additions and 822 deletions.
7 changes: 5 additions & 2 deletions app/src/main/java/us/koller/cameraroll/IntentReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ public void viewPhoto(Intent intent) {
return;
}

Album album = new Album();
AlbumItem albumItem = AlbumItem.getInstance(this, uri.toString());
String path = uri.toString();
int index = path.lastIndexOf("/");

Album album = new Album().setPath(path.substring(0, index));
AlbumItem albumItem = AlbumItem.getInstance(this, path);
if (albumItem == null || albumItem instanceof Video) {
Toast.makeText(this, getString(R.string.error), Toast.LENGTH_SHORT).show();
this.finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.michaelflisar.dragselectrecyclerview.DragSelectTouchListener;

Expand Down Expand Up @@ -133,7 +132,8 @@ public void onClick(View view) {
|| albumItem instanceof Video) && !albumItem.error) {
Intent intent = new Intent(holder.itemView.getContext(), ItemActivity.class);
intent.putExtra(ItemActivity.ALBUM_ITEM, albumItem);
intent.putExtra(ItemActivity.ALBUM, album);
//intent.putExtra(ItemActivity.ALBUM, album);
intent.putExtra(ItemActivity.ALBUM_PATH, album.getPath());
intent.putExtra(ItemActivity.ITEM_POSITION, album.getAlbumItems().indexOf(albumItem));

ActivityOptionsCompat options =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

import us.koller.cameraroll.R;
import us.koller.cameraroll.data.AlbumItem;
import us.koller.cameraroll.util.SizedColorDrawable;
import us.koller.cameraroll.util.Util;

public class GifViewHolder extends AlbumItemHolder {

Expand All @@ -35,7 +33,6 @@ public void loadImage(final ImageView imageView, final AlbumItem albumItem) {
.asGif()
.skipMemoryCache(true)
.thumbnail(0.1f)
//.placeholder(new SizedColorDrawable(ContextCompat.getColor(context, R.color.white_translucent2), imageDimens))
.listener(new RequestListener<String, GifDrawable>() {
@Override
public boolean onException(Exception e, String model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

Expand All @@ -13,8 +11,6 @@

import us.koller.cameraroll.R;
import us.koller.cameraroll.data.AlbumItem;
import us.koller.cameraroll.util.SizedColorDrawable;
import us.koller.cameraroll.util.Util;

public class PhotoViewHolder extends AlbumItemHolder {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package us.koller.cameraroll.adapter.album.ViewHolder;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;

Expand All @@ -13,8 +11,6 @@

import us.koller.cameraroll.R;
import us.koller.cameraroll.data.AlbumItem;
import us.koller.cameraroll.util.SizedColorDrawable;
import us.koller.cameraroll.util.Util;

public class VideoViewHolder extends AlbumItemHolder {

Expand All @@ -35,7 +31,6 @@ public void loadImage(ImageView imageView, final AlbumItem albumItem) {
.asBitmap()
.skipMemoryCache(true)
.thumbnail(0.1f)
//.placeholder(new SizedColorDrawable(ContextCompat.getColor(context, R.color.white_translucent2), imageDimens))
.listener(new RequestListener<String, Bitmap>() {
@Override
public boolean onException(Exception e, String model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Environment;
import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.io.File;

import us.koller.cameraroll.R;
import us.koller.cameraroll.adapter.fileExplorer.ViewHolder.FileHolder;
import us.koller.cameraroll.data.Album;
import us.koller.cameraroll.data.AlbumItem;
import us.koller.cameraroll.data.File_POJO;
import us.koller.cameraroll.data.Provider.MediaProvider;
import us.koller.cameraroll.ui.FileExplorerActivity;
import us.koller.cameraroll.ui.ItemActivity;

public class RecyclerViewAdapter extends RecyclerView.Adapter {
Expand Down Expand Up @@ -43,7 +48,12 @@ public interface Callback {

private Callback callback;

public RecyclerViewAdapter(Callback callback) {
private FileExplorerActivity.OnDirectoryChangeCallback directoryChangeCallback;

public RecyclerViewAdapter(
FileExplorerActivity.OnDirectoryChangeCallback directoryChangeCallback,
Callback callback) {
this.directoryChangeCallback = directoryChangeCallback;
this.callback = callback;
}

Expand Down Expand Up @@ -82,37 +92,42 @@ public void onClick(View view) {
String path = file.getPath().substring(0, index);

//load Album
final Album album = new Album().setPath(path);
AlbumItem albumItem = AlbumItem.getInstance(holder.itemView.getContext(), file.getPath());
if (albumItem != null) {
album.getAlbumItems()
.add(albumItem);
final Album album;
AlbumItem albumItem = null;
if (!Environment.isExternalStorageRemovable(new File(file.getPath()))) {
album = MediaProvider.loadAlbum(path);
for (int i = 0; i < album.getAlbumItems().size(); i++) {
if (album.getAlbumItems().get(i).getPath().equals(file.getPath())) {
albumItem = album.getAlbumItems().get(i);
break;
}
}
} else {
album = new Album().setPath(path);
albumItem = AlbumItem.getInstance(holder.itemView.getContext(), file.getPath());
if (albumItem != null) {
album.getAlbumItems().add(albumItem);
}
}

//create intent
Intent intent = new Intent(holder.itemView.getContext(), ItemActivity.class)
.putExtra(ItemActivity.ALBUM_ITEM, albumItem)
.putExtra(ItemActivity.ALBUM, album)
.putExtra(ItemActivity.VIEW_ONLY, true)
.putExtra(ItemActivity.ITEM_POSITION, album.getAlbumItems().indexOf(albumItem))
.putExtra(ItemActivity.FINISH_AFTER, false);
if (album != null && albumItem != null) {
//create intent
Intent intent = new Intent(holder.itemView.getContext(), ItemActivity.class)
.putExtra(ItemActivity.ALBUM_ITEM, albumItem)
.putExtra(ItemActivity.ALBUM, album)
.putExtra(ItemActivity.ALBUM_PATH, album.getPath())
.putExtra(ItemActivity.VIEW_ONLY, true)
.putExtra(ItemActivity.ITEM_POSITION, album.getAlbumItems().indexOf(albumItem))
.putExtra(ItemActivity.FINISH_AFTER, false);

try {
holder.itemView.getContext().startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
} else {
//to keep the ripple animation
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
RecyclerViewAdapter.this.setFiles(file);
RecyclerViewAdapter.this.notifyDataSetChanged();

if (callback != null) {
callback.onDataChanged();
}
directoryChangeCallback.changeDir(file.getPath());
}
}, 300);
}
Expand Down Expand Up @@ -212,6 +227,9 @@ public void pickTarget() {

@Override
public int getItemCount() {
return files.getChildren().size();
if (files != null) {
return files.getChildren().size();
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,21 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position)
@Override
public void onClick(View view) {
Intent intent = new Intent(holder.itemView.getContext(), AlbumActivity.class);
intent.putExtra(AlbumActivity.ALBUM, album);

//intent.putExtra(AlbumActivity.ALBUM, album);
intent.putExtra(AlbumActivity.ALBUM_PATH, album.getPath());

if (pick_photos) {
intent.setAction(MainActivity.PICK_PHOTOS);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,
intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false));
} else {
intent.setAction(AlbumActivity.VIEW_ALBUM);
}

ActivityOptionsCompat options;
Activity context = (Activity) holder.itemView.getContext();

if (!pick_photos) {
options = ActivityOptionsCompat.makeSceneTransitionAnimation(context);
holder.itemView.getContext().startActivity(intent, options.toBundle());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package us.koller.cameraroll.adapter.main.ViewHolder;

import android.app.Activity;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
Expand All @@ -15,6 +13,7 @@
import us.koller.cameraroll.R;
import us.koller.cameraroll.data.Album;
import us.koller.cameraroll.data.AlbumItem;
import us.koller.cameraroll.data.Provider.MediaProvider;
import us.koller.cameraroll.ui.widget.ParallaxImageView;
import us.koller.cameraroll.util.ColorFade;

Expand All @@ -28,6 +27,12 @@ public AlbumHolder(View itemView) {

public void setAlbum(Album album) {
this.album = album;

if (album == null) {
//Error album
album = MediaProvider.getErrorAlbum();
}

((TextView) itemView.findViewById(R.id.name)).setText(album.getName());
String count = album.getAlbumItems().size()
+ (album.getAlbumItems().size() > 1 ?
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/us/koller/cameraroll/data/Album.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.io.File;
import java.util.ArrayList;

import us.koller.cameraroll.data.MediaLoader.MediaLoader;
import us.koller.cameraroll.data.Provider.MediaProvider;
import us.koller.cameraroll.util.SortUtil;

public class Album
Expand Down Expand Up @@ -41,10 +41,12 @@ public boolean isHidden() {
} else {
File dir = new File(getPath());
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].getName().equals(MediaLoader.FILE_TYPE_NO_MEDIA)) {
hidden = HIDDEN;
return true;
if (files != null) {
for (int i = 0; i < files.length; i++) {
if (files[i].getName().equals(MediaProvider.FILE_TYPE_NO_MEDIA)) {
hidden = HIDDEN;
return true;
}
}
}
}
Expand All @@ -58,7 +60,8 @@ public String getPath() {

@Override
public String getName() {
return new File(path).getName();
String name = new File(getPath()).getName();
return name != null ? name : "ERROR";
}

@Override
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/us/koller/cameraroll/data/AlbumItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import java.io.File;

import us.koller.cameraroll.util.MediaType;
import us.koller.cameraroll.util.RemovableStorageUtil;
import us.koller.cameraroll.util.SortUtil;
import us.koller.cameraroll.util.Util;

public abstract class AlbumItem
implements Parcelable, SortUtil.Sortable {
Expand All @@ -27,6 +29,8 @@ public abstract class AlbumItem
public boolean isSharedElement = false;
public boolean hasFadedIn = false;

public String TYPE = "AlbumItem";

//factory method
public static AlbumItem getInstance(Context context, String path) {
if (path == null) {
Expand Down Expand Up @@ -84,15 +88,16 @@ public long getDate(Activity context) {
}

public Uri getUri(Context context) {
Uri uri;
if (!contentUri) {
try {
File file = new File(getPath());
uri = FileProvider.getUriForFile(context,
return FileProvider.getUriForFile(context,
context.getApplicationContext().getPackageName() + ".provider", file);
return uri;
} catch (IllegalArgumentException e) {
e.printStackTrace();

//file is probably on removable storage
return RemovableStorageUtil.getContentUriFromFilePath(context, getPath());
}
}
return Uri.parse(getPath());
Expand Down Expand Up @@ -149,4 +154,10 @@ public AlbumItem[] newArray(int i) {
return new AlbumItem[i];
}
};

public static AlbumItem getErrorItem() {
AlbumItem albumItem = new Photo();
albumItem.setPath("ERROR").setName("ERROR");
return albumItem;
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/us/koller/cameraroll/data/File_POJO.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public long getDate(Activity context) {
return 0;
}

@Override
public String toString() {
return getPath();
}

public String getPath() {
return path;
}
Expand Down
Loading

0 comments on commit d4de9cf

Please sign in to comment.