Commit 9b540c9e authored by Gilbert Ndresaj's avatar Gilbert Ndresaj

Merge pull request #2 from DNLDsht/master

+ select album activity
parents f4f2f660 1296bff8
......@@ -15,6 +15,10 @@
android:label="Intro Activity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"
/>
<activity android:name=".SelectAlbumActivity"
android:label="Select Album"
android:theme="@style/Theme.AppCompat.NoActionBar"
/>
<activity android:name=".SettingsActivity"
android:label="Setting"
......
......@@ -24,6 +24,7 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
ArrayList<Album> albums;
private int layout_ID;
private View.OnClickListener mOnClickListener;
private View.OnLongClickListener mOnLongClickListener;
......@@ -37,7 +38,6 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
View v = LayoutInflater.from(parent.getContext()).inflate(layout_ID, parent, false);
v.setOnClickListener(mOnClickListener);
v.setOnLongClickListener(mOnLongClickListener);
return new ViewHolder(v);
}
......@@ -45,10 +45,8 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
public void onBindViewHolder(AlbumsAdapter.ViewHolder holder, int position) {
Album a = albums.get(position);
a.setPath();
//holder.picture.setTag(a.getPathCoverAlbum());
//ImageLoader.getInstance().displayImage(a.getPathCoverAlbum(), holder.picture, defaultOptions);
Glide.clear(holder.picture);
Glide.with(holder.picture.getContext())
.load(a.getPathCoverAlbum())
.asBitmap()
......@@ -57,7 +55,7 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
.into(holder.picture);
holder.name.setText(Html.fromHtml("<i><font>" + a.DisplayName + "</font></i>"));
// color='"+R.color.toolbar+"'
SharedPreferences SP;
SP = PreferenceManager.getDefaultSharedPreferences(holder.picture.getContext());
String SColor = SP.getString("PrefColor", "#03A9F4");
......@@ -69,12 +67,10 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
if (a.isSelected()) {
holder.card_layout.setBackgroundColor(holder.card_layout.getContext().getColor(R.color.selected_album));
holder.picture.setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
holder.selectHolder.setVisibility(View.VISIBLE);
} else {
holder.card_layout.setBackgroundColor(holder.card_layout.getContext().getColor(R.color.unselected_album));
//holder.picture.setColorFilter(0x00000000, PorterDuff.Mode.SRC_ATOP);
holder.picture.clearColorFilter();
holder.selectHolder.setVisibility(View.INVISIBLE);
......@@ -112,6 +108,8 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
nPhotos = (TextView) itemView.findViewById(R.id.image_number_text);
}
}
}
......
......@@ -22,6 +22,7 @@ public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.ViewHolder
ArrayList<Photo> photos;
private int layout_ID;
private View.OnClickListener mOnClickListener;
private View.OnLongClickListener mOnLongClickListener;
......@@ -73,6 +74,11 @@ public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.ViewHolder
}
}
@Override
public int getItemCount() {
return photos.size();
}
public void setOnClickListener(View.OnClickListener lis) {
mOnClickListener = lis;
}
......@@ -81,10 +87,6 @@ public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.ViewHolder
mOnLongClickListener = lis;
}
@Override
public int getItemCount() {
return photos.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
......
package com.leafpic.app.Adapters;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.leafpic.app.Base.Album;
import com.leafpic.app.R;
import java.util.ArrayList;
public class SelectAlbumAdapter extends RecyclerView.Adapter<SelectAlbumAdapter.ViewHolder> {
ArrayList<Album> albums;
private int layout_ID;
private View.OnClickListener mOnClickListener;
public SelectAlbumAdapter(ArrayList<Album> ph, int id) {
albums = ph;
layout_ID = id;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(layout_ID, parent, false);
v.setOnClickListener(mOnClickListener);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(SelectAlbumAdapter.ViewHolder holder, int position) {
Album a = albums.get(position);
a.setPath();
Glide.clear(holder.picture);
Glide.with(holder.picture.getContext())
.load(a.getPathCoverAlbum())
.asBitmap()
.centerCrop()
.placeholder(R.drawable.ic_empty)
.into(holder.picture);
holder.name.setText(Html.fromHtml("<i><font>" + a.DisplayName + "</font></i>"));
SharedPreferences SP;
SP = PreferenceManager.getDefaultSharedPreferences(holder.picture.getContext());
String SColor = SP.getString("PrefColor", "#03A9F4");
holder.nPhotos.setText(Html.fromHtml("<b><font color='" + SColor + "'>" + a.getImagesCount() + "</font></b>" + "<font " +
"color='#FFFFFF'> Photos</font>"));
holder.name.setTag(a.Path);
}
public void setOnClickListener(View.OnClickListener lis) {
mOnClickListener = lis;
}
@Override
public int getItemCount() {
return albums.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
ImageView picture;
TextView name, nPhotos;
public ViewHolder(View itemView) {
super(itemView);
picture = (ImageView) itemView.findViewById(R.id.item_image_img);
name = (TextView) itemView.findViewById(R.id.album_name);
nPhotos = (TextView) itemView.findViewById(R.id.photoCount);
}
}
}
......@@ -456,20 +456,17 @@ public class AlbumsActivity extends AppCompatActivity implements FolderChooserDi
*/
albums.loadPreviewHiddenAlbums();
//dialog.dismiss();
}
else {
} else
albums.loadPreviewAlbums();
}
mRecyclerView = (RecyclerView) findViewById(R.id.gridAlbums);
adapt = new AlbumsAdapter(albums.dispAlbums, R.layout.album_card);
adapt.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
TextView a = (TextView) v.findViewById(R.id.picturetext);
String s = a.getTag().toString();
adapt.notifyItemChanged(albums.selectAlbum(s, true));
adapt.notifyItemChanged(albums.selectAlbum(a.getTag().toString(), true));
editmode = true;
invalidateOptionsMenu();
return true;
......@@ -480,16 +477,11 @@ public class AlbumsActivity extends AppCompatActivity implements FolderChooserDi
@Override
public void onClick(View v) {
TextView a = (TextView) v.findViewById(R.id.picturetext);
String s = a.getTag().toString();
Album album = albums.getAlbum(s);
int pos;
if (editmode) {
if (album.isSelected()) pos = albums.selectAlbum(s, false);
else pos = albums.selectAlbum(album, true);
adapt.notifyItemChanged(pos);
adapt.notifyItemChanged(albums.toggleSelectAlbum(a.getTag().toString()));
invalidateOptionsMenu();
} else {
Album album = albums.getAlbum(a.getTag().toString());
Intent intent = new Intent(AlbumsActivity.this, PhotosActivity.class);
Bundle b = new Bundle();
b.putParcelable("album", album);
......@@ -498,7 +490,6 @@ public class AlbumsActivity extends AppCompatActivity implements FolderChooserDi
}
}
});
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setAdapter(adapt);
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
......
......@@ -34,21 +34,22 @@ public class HandlingAlbums {
}
public int selectAlbum(String a, boolean val) {
Album x = getAlbum(a);
if (x != null) {
x.setSelcted(val);
if (val) selectedAlbums.add(x);
else selectedAlbums.remove(x);
public int toggleSelectAlbum(String path) {
Album s = getAlbum(path);
if (s != null) {
s.setSelcted(!s.isSelected());
if (s.isSelected()) selectedAlbums.add(s);
else selectedAlbums.remove(s);
}
return last_position_selecte;
}
public int selectAlbum(Album x, boolean val) {
public int selectAlbum(String path, boolean val) {
Album x = getAlbum(path);
if (x != null) {
x.setSelcted(val);
if (val) selectedAlbums.add(x);
else selectedAlbums.remove(x);
x.setSelcted(val);
}
return last_position_selecte;
}
......@@ -58,9 +59,9 @@ public class HandlingAlbums {
}
public void clearSelectedAlbums() {
for (Album dispAlbum : dispAlbums) {
for (Album dispAlbum : dispAlbums)
dispAlbum.setSelcted(false);
}
selectedAlbums.clear();
}
......@@ -114,7 +115,6 @@ public class HandlingAlbums {
@Override
public void onScanCompleted(String path, Uri uri) {
System.out.println("SCAN COMPLETED: " + path);
}
});
}
......
......@@ -6,6 +6,7 @@ import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.util.Log;
import com.leafpic.app.utils.StringUtils;
import java.io.File;
......@@ -83,6 +84,17 @@ public class HandlingPhotos implements Parcelable {
hidden = in.readByte() != 0x00;
}
public String getSelectedPhotosSerilized() {
String s = "";
if (selectedPhotos.size() > 0) {
for (Photo photo : selectedPhotos)
s += photo.Path + "^|/";
return s.substring(0, s.length() - 3);
}
return s;
}
public void sort() {
if (!hidden) {
......@@ -180,6 +192,12 @@ public class HandlingPhotos implements Parcelable {
return null;
}
public void LogSELECTED() {
for (Photo photo : selectedPhotos) {
Log.wtf("asdasdas", photo.Path);
}
}
public int selectPhoto(String path, boolean val) {
Photo x = getPhoto(path);
if (x != null) {
......@@ -190,6 +208,16 @@ public class HandlingPhotos implements Parcelable {
return last_position_selecte;
}
public int toggleSelectPhoto(String path) {
Photo x = getPhoto(path);
if (x != null) {
x.setSelected(!x.isSelected());
if (x.isSelected()) selectedPhotos.add(x);
else selectedPhotos.remove(x);
}
return last_position_selecte;
}
public void deleteSelectedPhotos() {
for (Photo photo : selectedPhotos)
deletePhoto(photo);
......
......@@ -31,6 +31,7 @@ import java.text.SimpleDateFormat;
/**
* Created by dnld on 12/12/15.
*/
public class PhotoActivity extends AppCompatActivity {
PhotosPagerAdapter mCustomPagerAdapter;
......@@ -120,6 +121,7 @@ public class PhotoActivity extends AppCompatActivity {
}
})
.show();
return true;
case R.id.useAsIntent:
......
......@@ -18,6 +18,7 @@ import android.support.v7.widget.*;
import android.text.Html;
import android.text.InputType;
import android.transition.Slide;
import android.util.Log;
import android.view.*;
import android.widget.ImageView;
import android.widget.TextView;
......@@ -97,16 +98,11 @@ public class PhotosActivity extends AppCompatActivity {
@Override
public void onClick(View v) {
TextView is = (TextView) v.findViewById(R.id.path);
Photo f = photos.getPhoto(is.getTag().toString());
int pos;
if (editmode) {
if (f.isSelected()) pos = photos.selectPhoto(f.Path, false);
else pos = photos.selectPhoto(f.Path, true);
adapter.notifyItemChanged(pos);
adapter.notifyItemChanged(photos.toggleSelectPhoto(is.getTag().toString()));
invalidateOptionsMenu();
//updateSelectedPhotsCount();
} else {
photos.setCurrentPhoto(f.Path);
photos.setCurrentPhoto(is.getTag().toString());
Intent intent = new Intent(PhotosActivity.this, PhotoActivity.class);
Bundle b = new Bundle();
b.putParcelable("album", photos);
......@@ -122,11 +118,11 @@ public class PhotosActivity extends AppCompatActivity {
adapter.notifyItemChanged(photos.selectPhoto(is.getTag().toString(), true));
editmode = true;
invalidateOptionsMenu();
//intebdupdateSelectedPhotsCount();
return false;
return true;
}
});
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setAdapter(adapter);
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
......@@ -231,10 +227,48 @@ public class PhotosActivity extends AppCompatActivity {
adapter.notifyDataSetChanged();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
switch (requestCode) {
case SelectAlbumActivity.COPY_TO_ACTION:
if (resultCode == RESULT_OK) {
Bundle b = data.getExtras();
StringUtils.showToast(getApplicationContext(), b.getString("album_path"));
}
break;
case SelectAlbumActivity.MOVE_TO_ACTION:
if (resultCode == RESULT_OK) {
Bundle b = data.getExtras();
String newAlbumPath = b.getString("album_path");
String paths[] = b.getString("selected_photos").split("^|/");
for (String path : paths) {
Log.wtf("asdasd", path);
}
}
break;
default:
break;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.moveAction:
Intent int1 = new Intent(PhotosActivity.this, SelectAlbumActivity.class);
int1.putExtra("selected_photos", photos.getSelectedPhotosSerilized());
startActivityForResult(int1, SelectAlbumActivity.MOVE_TO_ACTION);
break;
case R.id.copyAction:
Intent int2 = new Intent(PhotosActivity.this, SelectAlbumActivity.class);
startActivityForResult(int2, SelectAlbumActivity.COPY_TO_ACTION);
break;
case R.id.endEditAlbumMode:
finishEditMode();
break;
......
package com.leafpic.app;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import com.leafpic.app.Adapters.SelectAlbumAdapter;
import com.leafpic.app.Base.Album;
import com.leafpic.app.Base.HandlingAlbums;
/**
* Created by dnld on 2/8/16.
*/
public class SelectAlbumActivity extends AppCompatActivity {
public static final int COPY_TO_ACTION = 23;
public static final int MOVE_TO_ACTION = 69;
HandlingAlbums albums = new HandlingAlbums(SelectAlbumActivity.this);
RecyclerView mRecyclerView;
SelectAlbumAdapter adapt;
String photoPaths;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_album_activity);
photoPaths = getIntent().getStringExtra("selected_photos");
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationIcon(getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
setSupportActionBar(toolbar);
getWindow().setStatusBarColor(getColor(R.color.toolbar));
albums.loadPreviewAlbums();
mRecyclerView = (RecyclerView) findViewById(R.id.gridAlbums);
adapt = new SelectAlbumAdapter(albums.dispAlbums, R.layout.select_album_card);
adapt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView a = (TextView) v.findViewById(R.id.album_name);
String s = a.getTag().toString();
Album album = albums.getAlbum(s);
Intent result = new Intent();
result.putExtra("album_path", album.Path);
result.putExtra("selected_photos", photoPaths);
setResult(Activity.RESULT_OK, result);
finish();
}
});
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setAdapter(adapt);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
adapt.notifyDataSetChanged();
}
}
......@@ -27,7 +27,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:elevation="10dp"
android:src="@mipmap/ic_done_white_48dp"
android:layout_gravity="center"
......@@ -41,7 +40,6 @@
android:scaleType="centerCrop"
/>
</RelativeLayout>
<!--VIEW divider DIVIDE IMMAGINE DALL TESTO SOTTO-->
<View
android:id="@+id/divider"
android:layout_width="match_parent"
......@@ -61,36 +59,28 @@
>
<TextView
android:id="@+id/picturetext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="20dp"
android:paddingTop="10dp"
android:maxLines="1"
android:textColor="@android:color/white"
android:textSize="16sp"
android:id="@+id/picturetext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingEnd="20dp"
android:paddingTop="10dp"
android:maxLines="1"
android:textColor="@android:color/white"
android:textSize="16sp"
/>
<TextView
android:id="@+id/image_number_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:maxLines="1"
android:textColor="@android:color/white"
android:textSize="14sp"
android:id="@+id/image_number_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:paddingBottom="10dp"
android:maxLines="1"
android:textColor="@android:color/white"
android:textSize="14sp"
/>
</LinearLayout>
<!-- <ImageView android:id="@+id/image_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_more_vert_white_24dp"
android:layout_below="@id/divider"
android:layout_alignBottom="@+id/linear_card_text"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
/>-->
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:background="@color/background_material_dark"
>
<include layout="@layout/toolbar"
android:id="@+id/toolbar"
android:background="@color/toolbar"
/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/gridAlbums"
/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_margin="8dp"
android:orientation="vertical"
tools:ignore="MissingPrefix">
<ImageView
android:id="@+id/item_image_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:scaleType="centerCrop"/>
<FrameLayout
android:id="@+id/item_image_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="?selectableItemBackgroundBorderless"
android:orientation="vertical">
<LinearLayout
android:id="@+id/item_text_container"
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_gravity="bottom"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/album_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="sans-serif-medium"
android:lines="1"
android:shadowColor="#AA000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="1"
android:textColor="#FFFFFF"
android:textSize="16sp"/>
<TextView
android:id="@+id/photoCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:lines="1"
android:shadowColor="#AA000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="1"
android:textColor="#FFFFFF"
android:textSize="15sp"/>
</LinearLayout>
</FrameLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
\ No newline at end of file
......@@ -29,6 +29,16 @@
android:title="@string/delete_album_action"
app:showAsAction="never"
/>
<item
android:id="@+id/copyAction"
android:title="Copy to"
app:showAsAction="never"
/>
<item