Commit 3ba6201c authored by Gilbert Ndresaj's avatar Gilbert Ndresaj

Merge pull request #3 from DNLDsht/master

move to [working] not well but works
parents 9b540c9e 9c82d458
......@@ -65,6 +65,12 @@ public class HandlingPhotos implements Parcelable {
}
public HandlingPhotos(Context ctx) {
context = ctx;
as = new MadiaStoreHandler(context);
selectedPhotos = new ArrayList<Photo>();
}
protected HandlingPhotos(Parcel in) {
FolderPath = in.readString();
if (in.readByte() == 0x01) {
......@@ -88,9 +94,9 @@ public class HandlingPhotos implements Parcelable {
String s = "";
if (selectedPhotos.size() > 0) {
for (Photo photo : selectedPhotos)
s += photo.Path + "^|/";
s += photo.Path + "ç";
return s.substring(0, s.length() - 3);
return s.substring(0, s.length() - 1);
}
return s;
}
......@@ -125,7 +131,6 @@ public class HandlingPhotos implements Parcelable {
}
public String getPreviewAlbumImg() {
//Log.wtf("asdfsfd", settings.coverPath);
if (settings.coverPath != null) return settings.coverPath;
return photos.get(0).Path;
}
......@@ -275,6 +280,28 @@ public class HandlingPhotos implements Parcelable {
}
}
private int removePhoto(String path) {
for (int i = 0; i < photos.size(); i++)
if (photos.get(i).Path.equals(path)) {
photos.remove(i);
return i;
}
return -1;
}
public void movePhoto(String olderPath, String folderPath) {
try {
File from = new File(olderPath);
File to = new File(StringUtils.getPhotoPathMoved(olderPath, folderPath));
scanFile(new String[]{from.getAbsolutePath()});
from.renameTo(to);
scanFile(new String[]{to.getAbsolutePath()});
} catch (Exception e) {
e.printStackTrace();
}
}
public void scanFile(String[] path) {
MediaScannerConnection.scanFile(context, path, null, new MediaScannerConnection.OnScanCompletedListener() {
......
......@@ -18,7 +18,6 @@ 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;
......@@ -48,24 +47,6 @@ public class PhotosActivity extends AppCompatActivity {
boolean editmode = false;
PhotosAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initActivityTransitions();
setContentView(R.layout.activity_photos);
LoadPhotos();
initUiTweaks();
}
@Override
public void onResume() {
LoadPhotos();
updateHeaderContent();
super.onResume();
}
//PALETTE
//Bitmap bitmap = ((BitmapDrawable) image.getDrawable()).getBitmap();
// Drawable b = new Drawable.createFromPath(photos.getPreviewAlbumImg());
......@@ -82,7 +63,24 @@ public class PhotosActivity extends AppCompatActivity {
}
});
*/
RecyclerView mRecyclerView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initActivityTransitions();
setContentView(R.layout.activity_photos);
LoadPhotos();
initUiTweaks();
}
@Override
public void onResume() {
LoadPhotos();
updateHeaderContent();
super.onResume();
}
public void LoadPhotos() {
......@@ -91,7 +89,7 @@ public class PhotosActivity extends AppCompatActivity {
final Album album = data.getParcelable("album");
photos = new HandlingPhotos(PhotosActivity.this, album);
RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.gridPhotos);
mRecyclerView = (RecyclerView) findViewById(R.id.gridPhotos);
adapter = new PhotosAdapter(photos.photos, R.layout.photo_card);
adapter.setOnClickListener(new View.OnClickListener() {
......@@ -170,11 +168,8 @@ public class PhotosActivity extends AppCompatActivity {
if (photos.getSelectedCount() == 0) {
editmode = false;
opt = menu.findItem(R.id.endEditAlbumMode);
setOptionsAlbmuMenusItemsVisible(menu, true);
opt.setEnabled(false).setVisible(false);
opt = menu.findItem(R.id.setAsAlbumPreview);
opt.setEnabled(false).setVisible(false);
} else if (photos.getSelectedCount() == 1) {
opt = menu.findItem(R.id.setAsAlbumPreview);
opt.setEnabled(true).setVisible(true);
......@@ -209,15 +204,21 @@ public class PhotosActivity extends AppCompatActivity {
private void setOptionsAlbmuMenusItemsVisible(final Menu m, boolean val) {
MenuItem option = m.findItem(R.id.hideAlbumButton);
option.setEnabled(val).setVisible(val);
option = m.findItem(R.id.excludeAlbumButton);
option.setEnabled(val).setVisible(val);
option = m.findItem(R.id.renameAlbum);
option.setEnabled(val).setVisible(val);
option = m.findItem(R.id.sharePhotos);
option.setEnabled(!val).setVisible(!val);
option = m.findItem(R.id.moveAction);
option.setEnabled(!val).setVisible(!val);
option = m.findItem(R.id.copyAction);
option.setEnabled(!val).setVisible(!val);
option = m.findItem(R.id.endEditAlbumMode);
option.setEnabled(!val).setVisible(!val);
option = m.findItem(R.id.setAsAlbumPreview);
option.setEnabled(!val).setVisible(!val);
}
private void finishEditMode() {
......@@ -230,22 +231,45 @@ public class PhotosActivity extends AppCompatActivity {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
// Bundle b = data.getExtras();
switch (requestCode) {
case SelectAlbumActivity.COPY_TO_ACTION:
if (resultCode == RESULT_OK) {
Bundle b = data.getExtras();
StringUtils.showToast(getApplicationContext(), b.getString("album_path"));
// StringUtils.showToast(getApplicationContext(), b.getString("album_path"));
}
break;
case SelectAlbumActivity.MOVE_TO_ACTION:
onResume();
//LoadPhotos();
StringUtils.showToast(getApplicationContext(), "album_path");
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);
}
//LoadPhotos();
//StringUtils.showToast(getApplicationContext(),"album_path");
/*String newAlbumPath = b.getString("album_path");
String selected_photos_paths = b.getString("selected_photos");
if(selected_photos_paths != null) {
String paths[] = selected_photos_paths.split("ç");
Log.wtf("asdasd", selected_photos_paths);
for (String path : paths) {
int pos = photos.movePhoto(path,newAlbumPath);
//adapter.notifyDataSetChanged();
//mRecyclerView.removeViewAt(pos);
//recyc
Log.wtf("asdfdas",pos+"");
//adapter.notifyItemChanged(pos
// );
}
//adapter.notifyDataSetChanged();
photos.clearSelectedPhotos();
onResume();
invalidateOptionsMenu();
}*/
}
break;
......@@ -263,6 +287,7 @@ public class PhotosActivity extends AppCompatActivity {
Intent int1 = new Intent(PhotosActivity.this, SelectAlbumActivity.class);
int1.putExtra("selected_photos", photos.getSelectedPhotosSerilized());
int1.putExtra("request_code", SelectAlbumActivity.MOVE_TO_ACTION);
startActivityForResult(int1, SelectAlbumActivity.MOVE_TO_ACTION);
break;
case R.id.copyAction:
......
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;
import com.leafpic.app.Base.Album;
import com.leafpic.app.Base.HandlingAlbums;
import com.leafpic.app.Base.HandlingPhotos;
/**
* Created by dnld on 2/8/16.
......@@ -27,6 +27,8 @@ public class SelectAlbumActivity extends AppCompatActivity {
RecyclerView mRecyclerView;
SelectAlbumAdapter adapt;
String photoPaths;
int code;
HandlingPhotos p;//= new HandlingPhotos(SelectAlbumActivity.this);
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -34,6 +36,9 @@ public class SelectAlbumActivity extends AppCompatActivity {
setContentView(R.layout.select_album_activity);
photoPaths = getIntent().getStringExtra("selected_photos");
code = getIntent().getIntExtra("request_code", -1);
p = new HandlingPhotos(SelectAlbumActivity.this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationIcon(getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
......@@ -46,6 +51,7 @@ public class SelectAlbumActivity extends AppCompatActivity {
getWindow().setStatusBarColor(getColor(R.color.toolbar));
albums.loadPreviewAlbums();
mRecyclerView = (RecyclerView) findViewById(R.id.gridAlbums);
......@@ -56,12 +62,22 @@ public class SelectAlbumActivity extends AppCompatActivity {
@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);
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);
}
finish();
}
});
......
......@@ -65,6 +65,14 @@ public class StringUtils {
return olderPath.substring(0, olderPath.lastIndexOf('/')) + "/" + newName;
}
public static String getPhotoPathMoved(String olderPath, String folderPath) {
String b[] = olderPath.split("/");
String fi = b[b.length - 1];
String path = folderPath + "/";
path += fi;
return path;
}
public static String getPhotoPathRenamed(String olderPath, String newName) {
String c = "", b[] = olderPath.split("/");
for (int x = 0; x < b.length - 2; x++) c += b[x] + "/";
......
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