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

Commit

Permalink
- improvements in Loading speed
Browse files Browse the repository at this point in the history
- bug fixes
  • Loading branch information
kollerlukas committed Jan 30, 2017
1 parent bdce24e commit ae51e89
Show file tree
Hide file tree
Showing 27 changed files with 613 additions and 390 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ android {
applicationId "us.koller.cameraroll"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionCode 3
versionName "v1.0"
renderscriptTargetApi 25
renderscriptSupportModeEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled true
Expand All @@ -30,6 +31,7 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
Expand All @@ -46,4 +48,4 @@ dependencies {
compile 'com.github.chrisbanes:PhotoView:1.3.1'

compile 'com.github.MFlisar:DragSelectRecyclerView:0.2'
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package us.koller.cameraroll.adapter.album;

import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.graphics.drawable.Drawable;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -14,7 +14,6 @@

import com.michaelflisar.dragselectrecyclerview.DragSelectTouchListener;

import java.io.File;
import java.util.ArrayList;

import us.koller.cameraroll.R;
Expand All @@ -26,6 +25,7 @@
import us.koller.cameraroll.data.AlbumItem;
import us.koller.cameraroll.data.Gif;
import us.koller.cameraroll.data.Photo;
import us.koller.cameraroll.data.Video;
import us.koller.cameraroll.ui.ItemActivity;

public class RecyclerViewAdapter extends RecyclerView.Adapter {
Expand Down Expand Up @@ -114,7 +114,11 @@ public void onClick(View view) {

if (selector_mode) {
onItemSelected((AlbumItemHolder) holder);
} else if (albumItem instanceof Photo || albumItem instanceof Gif) {

//notify DragSelectTouchListener
int position = album.getAlbumItems().indexOf(albumItem);
dragSelectTouchListener.startDragSelection(position);
} else if (albumItem instanceof Photo || albumItem instanceof Gif || albumItem instanceof Video) {
Intent intent = new Intent(holder.itemView.getContext(), ItemActivity.class);
intent.putExtra(ItemActivity.ALBUM_ITEM, albumItem);
intent.putExtra(ItemActivity.ALBUM, album);
Expand All @@ -126,21 +130,11 @@ public void onClick(View view) {
holder.itemView.findViewById(R.id.image),
albumItem.getPath());
holder.itemView.getContext().startActivity(intent, options.toBundle());
} else {
File file = new File(albumItem.getPath());
Uri uri = FileProvider.getUriForFile(holder.itemView.getContext(),
holder.itemView.getContext().getApplicationContext().getPackageName() + ".provider", file);

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
holder.itemView.getContext().startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(holder.itemView.getContext(), "No App found to play your video", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}

/*else if (albumItem instanceof Video){
AlbumActivity.videoOnClick((Activity) holder.itemView.getContext(), albumItem);
}*/
}
});

Expand All @@ -157,13 +151,15 @@ public boolean onLongClick(View view) {

//notify AlbumActivity
callback.onSelectorModeEnter();
}

//notify DragSelectTouchListener
onItemSelected((AlbumItemHolder) holder);

//notify DragSelectTouchListener
if (selected_items[album.getAlbumItems().indexOf(((AlbumItemHolder) holder).albumItem)]) {
int position = album.getAlbumItems().indexOf(albumItem);
dragSelectTouchListener.startDragSelection(position);
}

onItemSelected((AlbumItemHolder) holder);
return true;
}
});
Expand Down Expand Up @@ -195,6 +191,19 @@ private void onItemSelected(AlbumItemHolder holder) {
= !selected_items[album.getAlbumItems().indexOf(holder.albumItem)];
holder.itemView.findViewById(R.id.image)
.setSelected(selected_items[album.getAlbumItems().indexOf(holder.albumItem)]);

//fade selected indicator
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
boolean selected = selected_items[album.getAlbumItems().indexOf(holder.albumItem)];
Drawable foreground = holder.itemView.findViewById(R.id.image).getForeground();

ObjectAnimator
.ofPropertyValuesHolder(foreground,
PropertyValuesHolder.ofInt("alpha",
selected ? 0 : 255,
selected ? 255 : 0)).start();
}

callback.onItemSelected(getSelectedItemCount());
checkForNoSelectedItems();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

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

public class VideoViewHolder extends AlbumItemHolder {
Expand All @@ -34,32 +33,30 @@ void loadImage(ImageView imageView, final AlbumItem albumItem) {
(int) ((float) screenWidth / columnCount),
(int) ((float) screenWidth / columnCount)};

if (albumItem instanceof Video) {
Glide.with(context)
.load(albumItem.getPath())
.asBitmap()
.thumbnail(0.1f)
.skipMemoryCache(true)
.override(imageDimens[0], imageDimens[1])
.listener(new RequestListener<String, Bitmap>() {
@Override
public boolean onException(Exception e, String model,
Target<Bitmap> target, boolean isFirstResource) {
return false;
Glide.with(context)
.load(albumItem.getPath())
.asBitmap()
.thumbnail(0.1f)
.skipMemoryCache(true)
.override(imageDimens[0], imageDimens[1])
.listener(new RequestListener<String, Bitmap>() {
@Override
public boolean onException(Exception e, String model,
Target<Bitmap> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(Bitmap resource, String model,
Target<Bitmap> target, boolean isFromMemoryCache,
boolean isFirstResource) {
if (!albumItem.hasFadedIn) {
fadeIn();
}

@Override
public boolean onResourceReady(Bitmap resource, String model,
Target<Bitmap> target, boolean isFromMemoryCache,
boolean isFirstResource) {
if (!albumItem.hasFadedIn) {
fadeIn();
}
return false;
}
})
.error(R.drawable.error_placeholder)
.into(imageView);
}
return false;
}
})
.error(R.drawable.error_placeholder)
.into(imageView);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package us.koller.cameraroll.adapter.item.ViewHolder;

import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
Expand All @@ -8,7 +9,8 @@

import us.koller.cameraroll.R;
import us.koller.cameraroll.data.AlbumItem;
import us.koller.cameraroll.util.ViewUtil;
import us.koller.cameraroll.ui.ItemActivity;
import us.koller.cameraroll.util.ItemViewUtil;

public class GifViewHolder extends ViewHolder {

Expand All @@ -24,16 +26,16 @@ public View getView(ViewGroup container) {
v.removeView(v.findViewById(R.id.subsampling));
View view = v.findViewById(R.id.image);
if (albumItem.isSharedElement) {
ViewUtil.bindTransitionView((ImageView) view, albumItem);
ItemViewUtil.bindTransitionView((ImageView) view, albumItem);
} else {
ViewUtil.bindGif(this, (ImageView) view, albumItem);
ItemViewUtil.bindGif(this, (ImageView) view, albumItem);
}
return v;
}

public void reloadGif() {
View view = itemView.findViewById(R.id.image);
ViewUtil.bindGif(this, (ImageView) view, albumItem);
ItemViewUtil.bindGif(this, (ImageView) view, albumItem);
}

public void setAttacher(ImageView imageView) {
Expand All @@ -51,9 +53,10 @@ public void onViewTap(View view, float x, float y) {
}

@Override
public void onSharedElement() {
public void onSharedElement(final ItemActivity.Callback callback) {
if (attacher != null) {
attacher.cleanup();
}
callback.callback();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package us.koller.cameraroll.adapter.item.ViewHolder;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
Expand All @@ -11,7 +10,7 @@
import us.koller.cameraroll.data.AlbumItem;
import us.koller.cameraroll.data.Photo;
import us.koller.cameraroll.ui.ItemActivity;
import us.koller.cameraroll.util.ViewUtil;
import us.koller.cameraroll.util.ItemViewUtil;

public class PhotoViewHolder extends ViewHolder {

Expand All @@ -26,12 +25,12 @@ public View getView(ViewGroup container) {
super.setOnClickListener(view);
final View transitionView = itemView.findViewById(R.id.image);

ViewUtil.bindTransitionView((ImageView) transitionView, albumItem);
ItemViewUtil.bindTransitionView((ImageView) transitionView, albumItem);
if (albumItem.isSharedElement) {
view.setVisibility(View.INVISIBLE);
} else {
transitionView.setVisibility(View.INVISIBLE);
ViewUtil.bindSubsamplingImageView(
ItemViewUtil.bindSubsamplingImageView(
(SubsamplingScaleImageView) view,
(Photo) albumItem, transitionView);
}
Expand All @@ -43,7 +42,7 @@ public void swapView(final boolean isReturning) {
final View transitionView = itemView.findViewById(R.id.image);
if (!isReturning) {
view.setVisibility(View.VISIBLE);
ViewUtil.bindSubsamplingImageView(
ItemViewUtil.bindSubsamplingImageView(
(SubsamplingScaleImageView) view,
(Photo) albumItem, transitionView);
} else {
Expand All @@ -52,7 +51,7 @@ public void swapView(final boolean isReturning) {
}
}

public void scaleDown(final ItemActivity.Callback callback) {
private void scaleDown(final ItemActivity.Callback callback) {
final SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) itemView.findViewById(R.id.subsampling);
if (imageView != null) {
try {
Expand All @@ -75,7 +74,12 @@ public void onComplete() {
}

@Override
public void onSharedElement() {

public void onSharedElement(final ItemActivity.Callback callback) {
scaleDown(new ItemActivity.Callback() {
@Override
public void callback() {
callback.callback();
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package us.koller.cameraroll.adapter.item.ViewHolder;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import us.koller.cameraroll.R;
import us.koller.cameraroll.data.AlbumItem;
import us.koller.cameraroll.ui.AlbumActivity;
import us.koller.cameraroll.ui.ItemActivity;
import us.koller.cameraroll.util.ItemViewUtil;

public class VideoViewHolder extends ViewHolder {

public VideoViewHolder(AlbumItem albumItem, int position) {
super(albumItem, position);
}

@Override
public View getView(ViewGroup container) {
ViewGroup v = super.inflateView(container);
v.removeView(v.findViewById(R.id.subsampling));
View view = v.findViewById(R.id.image);
if (albumItem.isSharedElement) {
ItemViewUtil.bindTransitionView((ImageView) view, albumItem);
} else {
itemView = v;
bindView();
}
return v;
}

public void bindView() {
View view = itemView.findViewById(R.id.image);
ViewGroup v = ItemViewUtil.bindImageViewForVideo((ImageView) view, albumItem);
View playButton = v.findViewWithTag(ItemViewUtil.VIDEO_PLAY_BUTTON_TAG);
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlbumActivity.videoOnClick((Activity) view.getContext(), albumItem);
}
});
playButton.setAlpha(0.0f);
playButton.animate().alpha(0.54f).start();
}

@Override
public void onSharedElement(final ItemActivity.Callback callback) {
callback.callback();
}
}
Loading

0 comments on commit ae51e89

Please sign in to comment.