mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 12:38:00 +01:00
add a contextual actionbar for deleting images
This commit is contained in:
parent
732fa20cb5
commit
a68ad87b4b
4 changed files with 57 additions and 1 deletions
|
@ -6,6 +6,10 @@ import android.net.Uri;
|
|||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.ActionMode;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.GridView;
|
||||
|
@ -19,8 +23,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PhotosActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
|
||||
public class PhotosActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener {
|
||||
private List<String> photos;
|
||||
private int selectedItemsCnt;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -33,6 +38,7 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI
|
|||
final PhotosAdapter adapter = new PhotosAdapter(this, getPhotos(path));
|
||||
gridView.setAdapter(adapter);
|
||||
gridView.setOnItemClickListener(this);
|
||||
gridView.setMultiChoiceModeListener(this);
|
||||
|
||||
final String dirName = Helpers.getFilename(path);
|
||||
setTitle(dirName);
|
||||
|
@ -66,4 +72,43 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI
|
|||
intent.putExtra(Constants.PHOTO, photos.get(position));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
|
||||
if (checked)
|
||||
selectedItemsCnt++;
|
||||
else
|
||||
selectedItemsCnt--;
|
||||
|
||||
mode.setTitle(String.valueOf(selectedItemsCnt));
|
||||
mode.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
final MenuInflater inflater = mode.getMenuInflater();
|
||||
inflater.inflate(R.menu.cab, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.cab_remove:
|
||||
mode.finish();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
selectedItemsCnt = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,4 +9,5 @@
|
|||
android:horizontalSpacing="1dp"
|
||||
android:numColumns="auto_fit"
|
||||
android:stretchMode="columnWidth"
|
||||
android:choiceMode="multipleChoiceModal"
|
||||
android:verticalSpacing="1dp"/>
|
||||
|
|
9
app/src/main/res/menu/cab.xml
Normal file
9
app/src/main/res/menu/cab.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/cab_remove"
|
||||
android:icon="@android:drawable/ic_menu_delete"
|
||||
android:title="@string/remove"
|
||||
app:showAsAction="always"/>
|
||||
</menu>
|
|
@ -2,4 +2,5 @@
|
|||
<string name="app_name">Simple Gallery</string>
|
||||
<string name="share_via">Share via</string>
|
||||
<string name="no_permissions">Not much to do in a gallery without accessing your photos</string>
|
||||
<string name="remove">Remove</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue