Improved media deleting.

parent a91bee71
......@@ -226,20 +226,19 @@ public class FolderActivity extends AppCompatActivity {
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if(resultCode!=0) {
// One or more images were deleted
ArrayList<Integer> position = data.getIntegerArrayListExtra("files");
for (int i = 0; i < position.size(); i++) {
list_of_paths.remove(list_of_paths.get(position.get(i)));
list_of_files.remove(list_of_files.get(position.get(i)));
}
if(resultCode == 1) {
// One image was deleted
int position = data.getIntExtra("file", 0);
list_of_paths.remove(list_of_paths.get(position));
list_of_files.remove(list_of_files.get(position));
gridAdapter.notifyDataSetChanged();
// Set result of activity to 0 -> One pic deleted
setResult(0);
}
// The only image of the folder was deleted
if(resultCode == 2) {
TextView text = findViewById(R.id.placeholderNoImages);
text.setText(R.string.no_images);
// Set result of activity to 1 -> Folder emptied
setResult(1);
}
......@@ -249,6 +248,16 @@ public class FolderActivity extends AppCompatActivity {
// Set result of activity to 2 -> Thumbnail needs change
setResult(2);
}
}else if (requestCode == 2){
if(resultCode == 1) {
// One video was deleted
int position = data.getIntExtra("file", 0);
list_of_paths.remove(list_of_paths.get(position));
list_of_files.remove(list_of_files.get(position));
gridAdapter.notifyDataSetChanged();
// Set result of activity to 0 -> One video deleted
setResult(0);
}
}
}
}
......@@ -40,7 +40,6 @@ import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOption
public class ImageActivity extends AppCompatActivity {
ArrayList<String> list_of_images = new ArrayList<>();
ArrayList<Integer> files_to_delete = new ArrayList<>();
PagerAdapter mPagerAdapter;
ViewPager mPager;
int positionArray;
......@@ -141,6 +140,16 @@ public class ImageActivity extends AppCompatActivity {
hide();
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 99) {
if(resultCode == 1) {
// Update UI
deleteVideo();
}
}
}
private void toggle() {
if (mVisible) {
hide();
......@@ -239,7 +248,7 @@ public class ImageActivity extends AppCompatActivity {
intent.putExtra("position", position);
intent.putExtra("videoPath", image.getAbsolutePath());
// Start activity
startActivityForResult(intent, 2);
startActivityForResult(intent, 99);
}
});
// Set up the user interaction to manually show or hide the system UI.
......@@ -259,14 +268,14 @@ public class ImageActivity extends AppCompatActivity {
}else {
// Set up the user interaction to manually show or hide the system UI.
layout.setOnClickListener(new View.OnClickListener() {
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggle();
}
});
}
// Full image display
// Full image display
}else{
// Get subSampling view
SubsamplingScaleImageView imageView = layout.findViewById(R.id.inside_imageview_sub);
......@@ -417,9 +426,9 @@ public class ImageActivity extends AppCompatActivity {
if (image.delete()) {
int move_to;
// Add deleted file position to ArrayList and send it as Extra
files_to_delete.add(positionArray);
int fileToDelete = positionArray;
Intent intent = new Intent();
intent.putIntegerArrayListExtra("files", files_to_delete);
intent.putExtra("file", fileToDelete);
// Set result of activity to 1 -> File deleted
setResult(1, intent);
//Remove image from MediaStore
......@@ -459,4 +468,37 @@ public class ImageActivity extends AppCompatActivity {
}
});
}
private void deleteVideo(){
runOnUiThread(new Runnable() {
public void run() {
int move_to;
// Add deleted file position to ArrayList and send it as Extra
int fileToDelete = positionArray;
Intent intent = new Intent();
intent.putExtra("file", fileToDelete);
// Set result of activity to 1 -> File deleted
setResult(1, intent);
// Remove image from arrayList
list_of_images.remove(positionArray);
// Notify data changed
mPagerAdapter.notifyDataSetChanged();
// Set adapter position
if(positionArray != 0){
move_to = positionArray - 1;
mPager.setCurrentItem(move_to, true);
}else{
if(list_of_images.size() == 0) {
// Set result of activity to 2 -> Last file of folder was deleted
setResult(2, intent);
finish();
}else{
// Set result of activity to 3 -> First file of folder was deleted -> Need to recalculate folder thumbnail
setResult(3, intent);
}
}
}
});
}
}
......@@ -358,7 +358,7 @@ public class MainActivity extends AppCompatActivity {
list_of_folders.remove(folder_position);
gridAdapter.notifyDataSetChanged();
}
if(resultCode == 2) {
if(resultCode == 0 || resultCode == 2) {
startRefresh();
}
}
......
......@@ -166,9 +166,9 @@ public class VideoActivity extends AppCompatActivity {
shareVideo(file);
return true;
//case R.id.action_delete:
// deleteImage(file);
// return true;
case R.id.action_delete:
deleteVideo(file);
return true;
case R.id.action_details:
showDetails(file);
......@@ -252,6 +252,47 @@ public class VideoActivity extends AppCompatActivity {
});
}
private void deleteVideo(final File video){
runOnUiThread(new Runnable() {
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(VideoActivity.this);
builder.setTitle(R.string.delete_title)
.setMessage(R.string.delete_message)
.setIcon(R.drawable.ic_warning_black_24dp)
.setPositiveButton(R.string.delete_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (video.exists()) {
// Remove file from device
if (video.delete()) {
// Add deleted file position and send it as Extra
int fileToDelete = position_intent;
Intent intent = new Intent();
intent.putExtra("file", fileToDelete);
// Set result of activity to 1 -> File deleted
setResult(1, intent);
// Remove image from MediaStore
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(videoPath))));
// Finish activity
finish();
}
}
}
})
.setNegativeButton(R.string.delete_no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
}
public void exoPlayer(){
// 1. Create a default TrackSelector
......
......@@ -12,9 +12,10 @@
<ImageView
android:id="@+id/inside_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:contentDescription="@string/desc_full_image"/>
<ImageView
......
......@@ -16,7 +16,7 @@
<string name="delete_ok"></string>
<string name="delete_no">No</string>
<string name="delete_title">Atención!</string>
<string name="delete_message">La imagen será borrada para siempre, quieres continuar?</string>
<string name="delete_message">El archivo será borrado para siempre, quieres continuar?</string>
<string name="action_about">Sobre la app</string>
<string name="title_activity_video">Video</string>
<string name="title_activity_about">Sobre la app</string>
......
......@@ -25,7 +25,7 @@
<string name="delete_ok">Yes</string>
<string name="delete_no">No</string>
<string name="delete_title">Warning!</string>
<string name="delete_message">This will delete the image forever, are you sure?</string>
<string name="delete_message">This will delete the file forever, are you sure?</string>
<string name="ok" translatable="false">OK</string>
<string name="details_image">Image details</string>
......
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