Commit 9ece7d38 authored by Donald Shtjefni's avatar Donald Shtjefni

Merge pull request #26 from DNLDsht/single-photo-view-improvement

Single photo view improvement
parents 292a517c 57232102
......@@ -45,13 +45,13 @@
</intent-filter>
</activity>
<activity android:name=".PhotoActivity"
android:label="Album"
android:parentActivityName=".PhotosActivity"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".PhotoPagerActivity"
android:label="Album"
android:parentActivityName=".PhotosActivity"
android:theme="@style/Theme.AppCompat.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".PhotosActivity"/>
android:name="android.support.PARENT_ACTIVITY"
android:value=".PhotosActivity"/>
<intent-filter>
<action android:name="android.intent.action.albumPhoto"/>
<category android:name="android.intent.category.DEFAULT"/>
......
......@@ -47,7 +47,8 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
Album a = albums.get(position);
a.setPath();
Glide.clear(holder.picture);
//Glide.clear(holder.picture);
Glide.with(holder.picture.getContext())
.load(a.getPathCoverAlbum())
.asBitmap()
......
package com.leafpic.app.Adapters;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.leafpic.app.Base.Photo;
import com.leafpic.app.Fragments.ImageFragment;
import com.leafpic.app.R;
import java.util.ArrayList;
/**
* Created by dnld on 18/02/16.
*/
public class MediaPagerAdapter extends FragmentPagerAdapter {
ArrayList<Photo> photos;
View.OnTouchListener listener;
public void setOnTouchListener(View.OnTouchListener l){ listener = l; }
public MediaPagerAdapter(FragmentManager fm, ArrayList<Photo> photos) {
super(fm);
this.photos=photos;
}
@Override
public Fragment getItem(int pos) {
Photo p = photos.get(pos);
ImageFragment fragment = ImageFragment.newInstance(p.Path,300,300);
fragment.setOnTouchListener(listener);
return fragment;
}
@Override
public int getCount() {
return photos.size();
}
}
\ No newline at end of file
package com.leafpic.app.Adapters;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.koushikdutta.ion.Ion;
import com.leafpic.app.Base.Photo;
import com.leafpic.app.R;
import java.util.ArrayList;
/**
* Created by dnld on 1/11/16.
*/
public class PhotosPagerAdapter extends android.support.v4.view.PagerAdapter {
Context mContext;
LayoutInflater mLayoutInflater;
ArrayList<Photo> mResources;
private View.OnClickListener onClickListener;
public PhotosPagerAdapter(Context context, ArrayList<Photo> ph) {
mContext = context;
mResources = ph;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void setOnClickListener(View.OnClickListener ls) {
onClickListener = ls;
}
@Override
public int getCount() {
return mResources.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Photo f = mResources.get(position);
View itemView;
if (f.MIME.equals("image/gif")) {
itemView = mLayoutInflater.inflate(R.layout.gif_pager_layout, container, false);
ImageView picture = (ImageView) itemView.findViewById(R.id.media_view);
picture.setOnClickListener(onClickListener);
Ion.with(container.getContext())
.load(f.Path)
.intoImageView(picture);
} else {
itemView = mLayoutInflater.inflate(R.layout.image_pager_item, container, false);
final SubsamplingScaleImageView picture = (SubsamplingScaleImageView) itemView.findViewById(R.id.media_view);
Glide.with(container.getContext())
.load(mResources.get(position).Path)
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
picture.setImage(ImageSource.bitmap(bitmap));
}
});
picture.setOnClickListener(onClickListener);
picture.setMaxScale(10);
}
container.addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
\ No newline at end of file
package com.leafpic.app.Fragments;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.leafpic.app.R;
/**
* Created by dnld on 18/02/16.
*/
public class ImageFragment extends Fragment {
// Store instance variables
private String path;
private int width;
private int height;
private View.OnTouchListener onTouchListener;
// newInstance constructor for creating fragment with arguments
public static ImageFragment newInstance(String path,int width,int height) {
ImageFragment fragmentFirst = new ImageFragment();
Bundle args = new Bundle();
args.putInt("width", width);
args.putInt("height", height);
args.putString("path", path);
fragmentFirst.setArguments(args);
return fragmentFirst;
}
public void setOnTouchListener(View.OnTouchListener l){onTouchListener = l;}
// Store instance variables based on arguments passed
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
width = getArguments().getInt("width", 300);
height = getArguments().getInt("height", 300);
path = getArguments().getString("path");
}
int times=0;
// Inflate the view for the fragment based on layout XML
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.image_pager_item, container, false);
final SubsamplingScaleImageView picture = (SubsamplingScaleImageView) view.findViewById(R.id.media_view);
// if (picture!=null)
// Glide.clear(picture);
Glide.with(container.getContext())
.load(path)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.IMMEDIATE)
.dontAnimate()
.override(width, height)
.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 (!isFromMemoryCache) {
Log.e("ViewerPager", "Image not from cache:" + model + " " + target.toString());
} else {
Log.e("ViewerPager", "Image from cache:" + model + " " + target.toString());
}
return false;
}
})
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
picture.setImage(ImageSource.bitmap(bitmap));
}
});
times++;
//TODO load full image size when starting zooming
picture.setOnImageEventListener(new SubsamplingScaleImageView.OnImageEventListener() {
@Override
public void onReady() {
}
@Override
public void onImageLoaded() {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (times == 1)
Glide.with(getContext())
.load(path)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.IMMEDIATE)
.dontAnimate()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
picture.setImage(ImageSource.bitmap(bitmap));
}
});
times++;
}
}, 250);
}
@Override
public void onPreviewLoadError(Exception e) {
}
@Override
public void onImageLoadError(Exception e) {
}
@Override
public void onTileLoadError(Exception e) {
}
});
picture.setOnTouchListener(onTouchListener);
picture.setMaxScale(10);
return view;
}
}
\ No newline at end of file
......@@ -11,7 +11,9 @@ import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
......@@ -122,7 +124,7 @@ public class PhotosActivity extends AppCompatActivity {
invalidateOptionsMenu();
} else {
photos.setCurrentPhoto(is.getTag().toString());
Intent intent = new Intent(PhotosActivity.this, PhotoActivity.class);
Intent intent = new Intent(PhotosActivity.this, PhotoPagerActivity.class);
Bundle b = new Bundle();
b.putParcelable("album", photos);
intent.putExtras(b);
......@@ -238,7 +240,6 @@ public class PhotosActivity extends AppCompatActivity {
int c;
try {
if ((c = photos.getSelectedCount()) != 0) {
toolbar.setCollapsible(false);
collapsingToolbarLayout.setTitle(c + "/" + photos.photos.size());
toolbar.setNavigationIcon(new IconicsDrawable(this)
......
......@@ -34,7 +34,7 @@ public class SelectAlbumActivity extends AppCompatActivity {
SelectAlbumAdapter adapt;
String photoPaths;
String photosIndexes;
boolean hidden=true;
boolean hidden=false;
int code;
HandlingPhotos p;//= new HandlingPhotos(SelectAlbumActivity.this);
......@@ -89,9 +89,9 @@ public class SelectAlbumActivity extends AppCompatActivity {
}
private void loadAlbumPreview(){
if (hidden == false)
albums.loadPreviewHiddenAlbums();
if (hidden) albums.loadPreviewHiddenAlbums();
else albums.loadPreviewAlbums();
hidden=!hidden;
mRecyclerView = (RecyclerView) findViewById(R.id.grid_albums);
......
......@@ -7,7 +7,7 @@
android:layout_height="match_parent"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:orientation="vertical"
tools:context=".MainActivity"
tools:context=".PhotoPagerActivity"
android:background="@color/background_material_dark">
<LinearLayout
......
......@@ -2,7 +2,7 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:theme="@style/ThemeOverlay.AppCompat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
......
......@@ -2,7 +2,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
tools:context=".PhotoPagerActivity"
>
<!-- general Stuff -->
<!-- Albums Stuff -->
......
......@@ -3,14 +3,14 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".PhotosActivity"
>
>
<item android:id="@+id/sortPhotos"
android:title="Sort"
android:orderInCategory="1"
android:icon="@mipmap/ic_sort_white_24dp"
app:showAsAction="ifRoom"
>
>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".PhotosActivity">
......@@ -48,7 +48,7 @@
android:icon="@mipmap/ic_share_white_24dp"
android:title="Share"
app:showAsAction="ifRoom"
/>
/>
<item
android:id="@+id/deleteAction"
android:icon="@mipmap/ic_delete_white_24dp"
......@@ -59,12 +59,12 @@
android:id="@+id/copyAction"
android:title="Copy to"
app:showAsAction="never"
/>
/>
<item
android:id="@+id/moveAction"
android:title="Move to"
app:showAsAction="never"
/>
/>
<item
android:id="@+id/excludeAlbumButton"
android:title="@string/exclude_album_action"
......@@ -79,12 +79,12 @@
android:id="@+id/renameAlbum"
android:title="@string/rename_album_action"
app:showAsAction="never"
/>
/>
<item
android:id="@+id/setAsAlbumPreview"
android:title="Set as Preview"
app:showAsAction="never"
/>
/>
<item android:id="@+id/select_all_albums_action"
android:title="Select all"
app:showAsAction="never"
......
......@@ -41,7 +41,10 @@
<item name="windowActionBar">false</item>
</style>
-->
<style name="AlertDialogCustom" parent="Theme.AppCompat.Dialog">
<style name="AlertDialogDark" parent="Theme.AppCompat.Dialog">
</style>
<style name="AlertDialogLight" parent="Theme.AppCompat.Light.Dialog">
</style>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment