mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
allow selecting multiple items
This commit is contained in:
@ -7,7 +7,10 @@ import android.os.Bundle;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.view.ActionMode;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
@ -35,7 +38,7 @@ import butterknife.ButterKnife;
|
|||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
public class ItemsFragment extends android.support.v4.app.Fragment
|
public class ItemsFragment extends android.support.v4.app.Fragment
|
||||||
implements AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
|
implements AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener, ListView.MultiChoiceModeListener {
|
||||||
@BindView(R.id.items_list) ListView mListView;
|
@BindView(R.id.items_list) ListView mListView;
|
||||||
@BindView(R.id.items_swipe_refresh) SwipeRefreshLayout mSwipeRefreshLayout;
|
@BindView(R.id.items_swipe_refresh) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||||
|
|
||||||
@ -44,6 +47,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
|||||||
private String mPath;
|
private String mPath;
|
||||||
|
|
||||||
private boolean mShowHidden;
|
private boolean mShowHidden;
|
||||||
|
private int mSelectedItemsCnt;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
@ -84,6 +88,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
|||||||
final ItemsAdapter adapter = new ItemsAdapter(getContext(), mItems);
|
final ItemsAdapter adapter = new ItemsAdapter(getContext(), mItems);
|
||||||
mListView.setAdapter(adapter);
|
mListView.setAdapter(adapter);
|
||||||
mListView.setOnItemClickListener(this);
|
mListView.setOnItemClickListener(this);
|
||||||
|
mListView.setMultiChoiceModeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setListener(ItemInteractionListener listener) {
|
public void setListener(ItemInteractionListener listener) {
|
||||||
@ -216,6 +221,48 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
|||||||
return type + "/*";
|
return type + "/*";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
|
||||||
|
if (checked) {
|
||||||
|
mSelectedItemsCnt++;
|
||||||
|
} else {
|
||||||
|
mSelectedItemsCnt--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mSelectedItemsCnt > 0) {
|
||||||
|
mode.setTitle(String.valueOf(mSelectedItemsCnt));
|
||||||
|
}
|
||||||
|
|
||||||
|
mode.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
|
mode.getMenuInflater().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_delete:
|
||||||
|
mode.finish();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyActionMode(ActionMode mode) {
|
||||||
|
mSelectedItemsCnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
public interface ItemInteractionListener {
|
public interface ItemInteractionListener {
|
||||||
void itemClicked(String path);
|
void itemClicked(String path);
|
||||||
}
|
}
|
||||||
|
17
app/src/main/res/drawable-v21/selector.xml
Normal file
17
app/src/main/res/drawable-v21/selector.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item>
|
||||||
|
<selector>
|
||||||
|
<item
|
||||||
|
android:drawable="@color/activated_item_foreground"
|
||||||
|
android:state_activated="true"/>
|
||||||
|
</selector>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<ripple android:color="@color/pressed_item_foreground">
|
||||||
|
<item android:id="@android:id/mask">
|
||||||
|
<color android:color="@android:color/white"/>
|
||||||
|
</item>
|
||||||
|
</ripple>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
5
app/src/main/res/drawable/selector.xml
Normal file
5
app/src/main/res/drawable/selector.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:drawable="@color/pressed_item_foreground" android:state_pressed="true"/>
|
||||||
|
<item android:drawable="@color/activated_item_foreground" android:state_activated="true"/>
|
||||||
|
</selector>
|
@ -14,6 +14,7 @@
|
|||||||
android:id="@+id/items_list"
|
android:id="@+id/items_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:choiceMode="multipleChoiceModal"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:paddingLeft="@dimen/activity_margin"/>
|
android:paddingLeft="@dimen/activity_margin"/>
|
||||||
</android.support.v4.widget.SwipeRefreshLayout>
|
</android.support.v4.widget.SwipeRefreshLayout>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:foreground="@drawable/selector"
|
||||||
android:paddingRight="@dimen/activity_margin">
|
android:paddingRight="@dimen/activity_margin">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
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_delete"
|
||||||
|
android:icon="@mipmap/delete"
|
||||||
|
android:title="@string/delete"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
|
</menu>
|
BIN
app/src/main/res/mipmap-hdpi/delete.png
Normal file
BIN
app/src/main/res/mipmap-hdpi/delete.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 296 B |
BIN
app/src/main/res/mipmap-mdpi/delete.png
Normal file
BIN
app/src/main/res/mipmap-mdpi/delete.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 191 B |
BIN
app/src/main/res/mipmap-xhdpi/delete.png
Normal file
BIN
app/src/main/res/mipmap-xhdpi/delete.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 256 B |
BIN
app/src/main/res/mipmap-xxhdpi/delete.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/delete.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 447 B |
BIN
app/src/main/res/mipmap-xxxhdpi/delete.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/delete.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 243 B |
@ -5,4 +5,6 @@
|
|||||||
<color name="colorAccent">@color/colorPrimary</color>
|
<color name="colorAccent">@color/colorPrimary</color>
|
||||||
|
|
||||||
<color name="lightGrey">#33000000</color>
|
<color name="lightGrey">#33000000</color>
|
||||||
|
<color name="pressed_item_foreground">#08000000</color>
|
||||||
|
<color name="activated_item_foreground">#11000000</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
<string name="file">File</string>
|
<string name="file">File</string>
|
||||||
<string name="invalid_name">The name contains invalid characters</string>
|
<string name="invalid_name">The name contains invalid characters</string>
|
||||||
<string name="error_occurred">An unknown error occurred</string>
|
<string name="error_occurred">An unknown error occurred</string>
|
||||||
|
<string name="delete">Delete</string>
|
||||||
|
|
||||||
<!-- About -->
|
<!-- About -->
|
||||||
<string name="about">About</string>
|
<string name="about">About</string>
|
||||||
|
Reference in New Issue
Block a user