Commit b7f7a90f authored by Donald's avatar Donald

+ copy to

 + fabCamera Fixed
 + improved selected photos in photos act
 + diocane il move to che non funzia ancora
parent bbf16b1b
......@@ -87,6 +87,13 @@ public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.ViewHolder
mOnLongClickListener = lis;
}
public void removeItemAt(int pos) {
//Log.wtf("asdasd",getItemCount()+"");
photos.remove(pos);
//notifyItemRemoved(pos);
//Log.wtf("asdasd",getItemCount()+"");
// notifyDataSetChanged();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
......
......@@ -9,7 +9,7 @@ import android.provider.MediaStore;
import android.util.Log;
import com.leafpic.app.utils.StringUtils;
import java.io.File;
import java.io.*;
import java.util.ArrayList;
/**
......@@ -40,8 +40,10 @@ public class HandlingPhotos implements Parcelable {
public AlbumSettings settings;
Context context;
MadiaStoreHandler as;
private ArrayList<Integer> selectedPhotosIndexs;
private int current;
private int last_position_selecte = -1;
private Integer last_position_selecte = -1;
public HandlingPhotos(Context ctx, Album album) {
context = ctx;
......@@ -50,6 +52,8 @@ public class HandlingPhotos implements Parcelable {
hidden = album.isHidden();
selectedPhotos = new ArrayList<Photo>();
selectedPhotosIndexs = new ArrayList<Integer>();
DisplayName = album.DisplayName;
if (!hidden) {
......@@ -90,6 +94,15 @@ public class HandlingPhotos implements Parcelable {
hidden = in.readByte() != 0x00;
}
public void updatePhotos() {
if (!hidden) {
photos = as.getAlbumPhotos(ID, getSortingMode());
} else {
HiddenPhotosHandler db = new HiddenPhotosHandler(context);
photos = db.getPhotosByAlbum(ID);
}
}
public String getSelectedPhotosSerilized() {
String s = "";
if (selectedPhotos.size() > 0) {
......@@ -101,6 +114,17 @@ public class HandlingPhotos implements Parcelable {
return s;
}
public String getSelectedPhotosIndexSerilized() {
String s = "";
if (selectedPhotosIndexs.size() > 0) {
for (Integer photo : selectedPhotosIndexs)
s += photo + "ç";
return s.substring(0, s.length() - 1);
}
return s;
}
public void sort() {
if (!hidden) {
......@@ -157,6 +181,7 @@ public class HandlingPhotos implements Parcelable {
photo.setSelected(false);
}
selectedPhotos.clear();
selectedPhotosIndexs.clear();
}
public int getSelectedCount() {
......@@ -193,7 +218,6 @@ public class HandlingPhotos implements Parcelable {
return photos.get(i);
}
}
return null;
}
......@@ -203,12 +227,21 @@ public class HandlingPhotos implements Parcelable {
}
}
public Integer getLastSelectedPhotoIndex() {
return selectedPhotosIndexs.get(selectedPhotosIndexs.size() - 1);
}
public int selectPhoto(String path, boolean val) {
Photo x = getPhoto(path);
if (x != null) {
x.setSelected(val);
if (val) selectedPhotos.add(x);
else selectedPhotos.remove(x);
if (val) {
selectedPhotos.add(x);
selectedPhotosIndexs.add(last_position_selecte);
} else {
selectedPhotos.remove(x);
selectedPhotosIndexs.remove(last_position_selecte);
}
}
return last_position_selecte;
}
......@@ -217,9 +250,15 @@ public class HandlingPhotos implements Parcelable {
Photo x = getPhoto(path);
if (x != null) {
x.setSelected(!x.isSelected());
if (x.isSelected()) selectedPhotos.add(x);
else selectedPhotos.remove(x);
if (x.isSelected()) {
selectedPhotos.add(x);
selectedPhotosIndexs.add(last_position_selecte);
} else {
selectedPhotos.remove(x);
selectedPhotosIndexs.remove(last_position_selecte);
}
}
return last_position_selecte;
}
......@@ -302,6 +341,38 @@ public class HandlingPhotos implements Parcelable {
}
}
public void copySelectedPhotos(String paths, String folderPath) {
for (String path : paths.split("ç"))
copyPhoto(path, folderPath);
}
public void moveSelectedPhotos(String paths, String folderPath) {
for (String path : paths.split("ç"))
movePhoto(path, folderPath);
}
public void copyPhoto(String olderPath, String folderPath) {
try {
File from = new File(olderPath);
File to = new File(StringUtils.getPhotoPathMoved(olderPath, folderPath));
InputStream in = new FileInputStream(from);
OutputStream out = new FileOutputStream(to);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
out.write(buf, 0, len);
in.close();
out.close();
scanFile(new String[]{to.getAbsolutePath()});
} catch (Exception e) {
e.printStackTrace();
}
}
public void scanFile(String[] path) {
MediaScannerConnection.scanFile(context, path, null, new MediaScannerConnection.OnScanCompletedListener() {
......
......@@ -131,6 +131,43 @@ public class MadiaStoreHandler {
return list;
}
public ArrayList<Photo> getAlbumPhotos(String id, String sort) {
ArrayList<Photo> list = new ArrayList<Photo>();
String[] projection = new String[]{
MediaStore.Images.Media.DATE_TAKEN,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.MIME_TYPE
};
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Cursor cur = context.getContentResolver().query(
images,
projection,
MediaStore.Images.Media.BUCKET_ID + " = ?",
new String[]{id}, " " + sort);
if (cur.moveToFirst()) {
int pathColumn = cur.getColumnIndex(
MediaStore.Images.Media.DATA);
int dateColumn = cur.getColumnIndex(
MediaStore.Images.Media.DATE_TAKEN);
int mimeColumn = cur.getColumnIndex(
MediaStore.Images.Media.MIME_TYPE);
do {
list.add(new Photo(
cur.getString(pathColumn),
cur.getString(dateColumn),
cur.getString(mimeColumn)
));
} while (cur.moveToNext());
}
cur.close();
return list;
}
public int getAlbumPhotosCount(String id) {
int c;
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
......
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.util.Log;
import android.view.View;
import android.widget.TextView;
import com.leafpic.app.Adapters.SelectAlbumAdapter;
......@@ -27,6 +27,7 @@ public class SelectAlbumActivity extends AppCompatActivity {
RecyclerView mRecyclerView;
SelectAlbumAdapter adapt;
String photoPaths;
String photosIndexes;
int code;
HandlingPhotos p;//= new HandlingPhotos(SelectAlbumActivity.this);
......@@ -37,13 +38,19 @@ public class SelectAlbumActivity extends AppCompatActivity {
photoPaths = getIntent().getStringExtra("selected_photos");
code = getIntent().getIntExtra("request_code", -1);
photosIndexes = getIntent().getStringExtra("photos_indexes");
p = new HandlingPhotos(SelectAlbumActivity.this);
if (code == 69) setTitle("Move to");
else if (code == 23) setTitle("Copy to");
setResult(Activity.RESULT_CANCELED);
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();
}
});
......@@ -63,19 +70,19 @@ public class SelectAlbumActivity extends AppCompatActivity {
public void onClick(View v) {
TextView a = (TextView) v.findViewById(R.id.album_name);
String newAlbumPath = a.getTag().toString();
// Album album = albums.getAlbum(s);
// Intent result = new Intent();
//result.putExtra("album_path", album.Path);
//result.putExtra("selected_photos", photoPaths);
if (code == 69) {
String paths[] = photoPaths.split("ç");
Log.wtf("asdasd", photoPaths);
for (String path : paths) {
p.movePhoto(path, newAlbumPath);
}
setResult(Activity.RESULT_OK);
if (code == MOVE_TO_ACTION) {
Intent result = new Intent();
result.putExtra("photos_indexes", photosIndexes);
p.moveSelectedPhotos(photoPaths, newAlbumPath);
setResult(Activity.RESULT_OK, result);
}
if (code == COPY_TO_ACTION) {
Intent result = new Intent();
p.copySelectedPhotos(photoPaths, newAlbumPath);
setResult(Activity.RESULT_OK, result);
}
finish();
......
......@@ -100,8 +100,7 @@
</android.support.v7.widget.CardView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:onClick="fabClick"
android:id="@+id/fabCamera"
style="@style/fab"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:borderWidth="0dp"
......@@ -109,5 +108,5 @@
android:layout_margin="16dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom|right"/>
android:layout_gravity="bottom|end"/>
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
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