Commit 72b8e167 authored by Gilbert Ndresaj's avatar Gilbert Ndresaj

Merge pull request #4 from DNLDsht/master

Merge Donald
parents dc4aacc3 070908c6
......@@ -101,11 +101,11 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
public ViewHolder(View itemView) {
super(itemView);
picture = (ImageView) itemView.findViewById(R.id.picture);
selectHolder = (ImageView) itemView.findViewById(R.id.selectedPicIcon);
card_layout = (RelativeLayout) itemView.findViewById(R.id.layout_card_id);
name = (TextView) itemView.findViewById(R.id.picturetext);
nPhotos = (TextView) itemView.findViewById(R.id.image_number_text);
picture = (ImageView) itemView.findViewById(R.id.album_preview);
selectHolder = (ImageView) itemView.findViewById(R.id.selected_icon);
card_layout = (RelativeLayout) itemView.findViewById(R.id.album_card);
name = (TextView) itemView.findViewById(R.id.album_name);
nPhotos = (TextView) itemView.findViewById(R.id.album_photos_count);
}
}
......
......@@ -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 {
......@@ -96,10 +103,10 @@ public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.ViewHolder
public ViewHolder(View itemView) {
super(itemView);
imageView = (ImageView) itemView.findViewById(R.id.pic);
selectHolder = (ImageView) itemView.findViewById(R.id.selectedPicIcon);
gifIcon = (ImageView) itemView.findViewById(R.id.gifIcon);
path = (TextView) itemView.findViewById(R.id.path);
imageView = (ImageView) itemView.findViewById(R.id.photo_preview);
selectHolder = (ImageView) itemView.findViewById(R.id.selected_icon);
gifIcon = (ImageView) itemView.findViewById(R.id.type_icon);
path = (TextView) itemView.findViewById(R.id.photo_path);
}
}
}
......
......@@ -57,14 +57,14 @@ public class PhotosPagerAdapter extends android.support.v4.view.PagerAdapter {
if (f.MIME.equals("image/gif")) {
itemView = mLayoutInflater.inflate(R.layout.gif_pager_layout, container, false);
ImageView picture = (ImageView) itemView.findViewById(R.id.imageView);
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.imageView);
final SubsamplingScaleImageView picture = (SubsamplingScaleImageView) itemView.findViewById(R.id.media_view);
Glide.with(container.getContext())
.load(mResources.get(position).Path)
......
......@@ -75,9 +75,9 @@ public class SelectAlbumAdapter extends RecyclerView.Adapter<SelectAlbumAdapter.
public ViewHolder(View itemView) {
super(itemView);
picture = (ImageView) itemView.findViewById(R.id.item_image_img);
picture = (ImageView) itemView.findViewById(R.id.album_preview);
name = (TextView) itemView.findViewById(R.id.album_name);
nPhotos = (TextView) itemView.findViewById(R.id.photoCount);
nPhotos = (TextView) itemView.findViewById(R.id.album_photos_count);
}
}
}
......
......@@ -111,7 +111,7 @@ public class AlbumsActivity extends AppCompatActivity implements FolderChooserDi
getWindow().setNavigationBarColor(getColor(R.color.toolbar));
}
/**** ToolBar *****/
toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
/**** Status Bar */
//getWindow().setStatusBarColor(getColor(R.color.status_bar));
......@@ -185,7 +185,7 @@ public class AlbumsActivity extends AppCompatActivity implements FolderChooserDi
}
public void addHiddenFolder_FABEvent() {
FloatingActionButton btnAddFolder = (FloatingActionButton) findViewById(R.id.fabAddFolder);
FloatingActionButton btnAddFolder = (FloatingActionButton) findViewById(R.id.fab_add_folder);
if (hidden) {
btnAddFolder.setVisibility(View.VISIBLE);
......@@ -460,12 +460,12 @@ public class AlbumsActivity extends AppCompatActivity implements FolderChooserDi
albums.loadPreviewAlbums();
mRecyclerView = (RecyclerView) findViewById(R.id.gridAlbums);
mRecyclerView = (RecyclerView) findViewById(R.id.grid_albums);
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);
TextView a = (TextView) v.findViewById(R.id.album_name);
adapt.notifyItemChanged(albums.selectAlbum(a.getTag().toString(), true));
editmode = true;
invalidateOptionsMenu();
......@@ -476,7 +476,7 @@ public class AlbumsActivity extends AppCompatActivity implements FolderChooserDi
adapt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView a = (TextView) v.findViewById(R.id.picturetext);
TextView a = (TextView) v.findViewById(R.id.album_name);
if (editmode) {
adapt.notifyItemChanged(albums.toggleSelectAlbum(a.getTag().toString()));
invalidateOptionsMenu();
......
......@@ -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;
......
......@@ -16,7 +16,6 @@ import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.leafpic.app.Adapters.PhotosPagerAdapter;
......@@ -56,7 +55,7 @@ public class PhotoActivity extends AppCompatActivity {
toggleSystemUI();
}
});
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager = (ViewPager) findViewById(R.id.photos_pager);
mViewPager.setAdapter(mCustomPagerAdapter);
mViewPager.setCurrentItem(photos.getCurrentPhotoIndex());
......@@ -211,7 +210,7 @@ public class PhotoActivity extends AppCompatActivity {
public void initUiTweaks() {
/**** ToolBar ********/
toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setBackgroundColor(getColor(R.color.transparent_gray));
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
......
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();
}
});
......@@ -54,7 +61,7 @@ public class SelectAlbumActivity extends AppCompatActivity {
albums.loadPreviewAlbums();
mRecyclerView = (RecyclerView) findViewById(R.id.gridAlbums);
mRecyclerView = (RecyclerView) findViewById(R.id.grid_albums);
adapt = new SelectAlbumAdapter(albums.dispAlbums, R.layout.select_album_card);
......@@ -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();
......
......@@ -8,28 +8,27 @@
android:orientation="vertical"
tools:context=".MainActivity"
android:background="@color/background_material_dark">
<!--
android:background="@color/background_material_dark">
-->
<LinearLayout
android:layout_width="fill_parent"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:elevation="5dp">
<include layout="@layout/toolbar"
android:id="@+id/toolbar"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:elevation="5dp">
<include layout="@layout/toolbar"
android:id="@+id/my_awesome_toolbar"/>
android:id="@+id/grid_albums"
android:layout_gravity="center_horizontal"
android:numColumns="auto_fit"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/gridAlbums"
android:layout_gravity="center_horizontal"
android:numColumns="auto_fit"
/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabAddFolder"
android:onClick="addFolder"
android:id="@+id/fab_add_folder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:borderWidth="0dp"
......
......@@ -10,14 +10,14 @@
>
<include layout="@layout/toolbar"
android:id="@+id/my_awesome_toolbar"
android:id="@+id/toolbar"
android:background="@color/trasparent_toolbar"
android:windowActionBarOverlay="true"
/>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/photos_pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
</RelativeLayout>
\ No newline at end of file
......@@ -32,7 +32,7 @@
app:layout_collapseMode="parallax">
<ImageView
android:id="@+id/image"
android:id="@+id/header_image"
android:layout_width="match_parent"
android:layout_height="250dp"
android:scaleType="centerCrop"/>
......@@ -43,7 +43,7 @@
android:layout_height="wrap_content">
<TextView
android:id="@+id/AlbumName"
android:id="@+id/album_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
......@@ -53,14 +53,14 @@
android:textColor="@android:color/white"
android:textSize="30sp"/>
<View
android:id="@+id/divider"
android:id="@+id/album_card_divider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@android:color/white"
android:layout_marginStart="60dp"
android:layout_marginEnd="60dp"/>
<TextView
android:id="@+id/AlbumNPhotos"
android:id="@+id/album_photos_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
......@@ -93,15 +93,14 @@
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/gridPhotos"
android:id="@+id/grid_photos"
android:clipToPadding="false"
android:background="@color/md_dark_background"
/>
</android.support.v7.widget.CardView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:onClick="fabClick"
android:id="@+id/fab_camera"
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
......@@ -15,16 +15,16 @@
>
<RelativeLayout
android:id="@+id/layout_card_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/toolbar">
android:id="@+id/album_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/toolbar">
<RelativeLayout
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:id="@+id/header_album_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/selectedPicIcon"
android:id="@+id/selected_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
......@@ -35,32 +35,32 @@
android:layout_centerVertical="true"
/>
<ImageView
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="140dp"
android:scaleType="centerCrop"
android:id="@+id/album_preview"
android:layout_width="match_parent"
android:layout_height="140dp"
android:scaleType="centerCrop"
/>
</RelativeLayout>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@id/img"
android:background="@android:color/darker_gray"
android:id="@+id/album_card_divider"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@id/header_album_card"
android:background="@android:color/darker_gray"
/>
<LinearLayout
android:id="@+id/linear_card_text"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_below="@id/divider"
android:id="@+id/linear_card_text"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_below="@id/album_card_divider"
>
<TextView
android:id="@+id/picturetext"
android:id="@+id/album_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
......@@ -71,7 +71,7 @@
android:textSize="16sp"
/>
<TextView
android:id="@+id/image_number_text"
android:id="@+id/album_photos_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
......
......@@ -6,7 +6,7 @@
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageView"
android:id="@+id/media_view"
android:layout_width="match_parent"
android:layout_gravity="center_vertical"
android:layout_height="match_parent"/>
......
......@@ -12,7 +12,7 @@
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/AlbumName"
android:id="@+id/album_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
......@@ -24,7 +24,7 @@
android:text="Slide"
/>
<View
android:id="@+id/divider"
android:id="@+id/album_card_divider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@android:color/white"
......@@ -32,7 +32,7 @@
android:layout_marginEnd="30dp"
/>
<TextView
android:id="@+id/AlbumNPhotos"
android:id="@+id/album_photos_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
......
......@@ -6,7 +6,7 @@
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageView"
android:id="@+id/media_view"
android:layout_width="match_parent"
android:layout_gravity="center_vertical"
android:layout_height="match_parent"/>
......
......@@ -6,7 +6,7 @@
android:layout_margin="2dp"
>
<ImageView
android:id="@+id/selectedPicIcon"
android:id="@+id/selected_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
......@@ -16,7 +16,7 @@
android:layout_margin="10dp"
/>