add a copy/move menu item to media activity
This commit is contained in:
parent
d7ffc35dd0
commit
8487ef44c4
|
@ -34,9 +34,13 @@ import com.simplemobiletools.gallery.Constants;
|
|||
import com.simplemobiletools.gallery.R;
|
||||
import com.simplemobiletools.gallery.Utils;
|
||||
import com.simplemobiletools.gallery.adapters.MediaAdapter;
|
||||
import com.simplemobiletools.gallery.asynctasks.CopyTask;
|
||||
import com.simplemobiletools.gallery.dialogs.ChangeSorting;
|
||||
import com.simplemobiletools.gallery.dialogs.CopyDialog;
|
||||
import com.simplemobiletools.gallery.models.Medium;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -49,7 +53,7 @@ import butterknife.ButterKnife;
|
|||
|
||||
public class MediaActivity extends SimpleActivity
|
||||
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener,
|
||||
SwipeRefreshLayout.OnRefreshListener, ChangeSorting.ChangeDialogListener {
|
||||
SwipeRefreshLayout.OnRefreshListener, ChangeSorting.ChangeDialogListener, CopyTask.CopyDoneListener {
|
||||
private static final String TAG = MediaActivity.class.getSimpleName();
|
||||
@BindView(R.id.media_grid) GridView mGridView;
|
||||
@BindView(R.id.media_holder) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
|
@ -409,6 +413,29 @@ public class MediaActivity extends SimpleActivity
|
|||
return getIntent().getBooleanExtra(Constants.SET_WALLPAPER_INTENT, false);
|
||||
}
|
||||
|
||||
private void displayCopyDialog() {
|
||||
if (Utils.Companion.isShowingWritePermissions(this, new File(mPath)))
|
||||
return;
|
||||
|
||||
final List<File> files = new ArrayList<>();
|
||||
|
||||
final SparseBooleanArray items = mGridView.getCheckedItemPositions();
|
||||
final int cnt = items.size();
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
if (items.valueAt(i)) {
|
||||
final int id = items.keyAt(i);
|
||||
files.add(new File(mMedia.get(id).getPath()));
|
||||
}
|
||||
}
|
||||
|
||||
new CopyDialog(this, files, this, new CopyDialog.OnCopyListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
final String curItemPath = mMedia.get(position).getPath();
|
||||
|
@ -486,6 +513,9 @@ public class MediaActivity extends SimpleActivity
|
|||
prepareForDeleting();
|
||||
mode.finish();
|
||||
return true;
|
||||
case R.id.cab_copy:
|
||||
displayCopyDialog();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -519,4 +549,14 @@ public class MediaActivity extends SimpleActivity
|
|||
public void sortingDialogClosed() {
|
||||
initializeGallery();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copySucceeded(@NotNull File destinationDir) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyFailed() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ import butterknife.OnClick;
|
|||
|
||||
public class ViewPagerActivity extends SimpleActivity
|
||||
implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, ViewPager.OnTouchListener,
|
||||
ViewPagerFragment.FragmentClickListener, CopyTask.CopyListener {
|
||||
ViewPagerFragment.FragmentClickListener, CopyTask.CopyDoneListener {
|
||||
@BindView(R.id.undo_delete) View mUndoBtn;
|
||||
@BindView(R.id.view_pager) MyViewPager mPager;
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ import com.simplemobiletools.gallery.Utils
|
|||
import java.io.*
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
class CopyTask(listener: CopyTask.CopyListener, val context: Context) : AsyncTask<Pair<List<File>, File>, Void, Boolean>() {
|
||||
class CopyTask(listener: CopyTask.CopyDoneListener, val context: Context) : AsyncTask<Pair<List<File>, File>, Void, Boolean>() {
|
||||
private val TAG = CopyTask::class.java.simpleName
|
||||
private var mListener: WeakReference<CopyListener>? = null
|
||||
private var mListener: WeakReference<CopyDoneListener>? = null
|
||||
private var destinationDir: File? = null
|
||||
|
||||
init {
|
||||
|
@ -111,7 +111,7 @@ class CopyTask(listener: CopyTask.CopyListener, val context: Context) : AsyncTas
|
|||
}
|
||||
}
|
||||
|
||||
interface CopyListener {
|
||||
interface CopyDoneListener {
|
||||
fun copySucceeded(destinationDir: File)
|
||||
|
||||
fun copyFailed()
|
||||
|
|
|
@ -16,7 +16,7 @@ import kotlinx.android.synthetic.main.copy_item.view.*
|
|||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class CopyDialog(val activity: Activity, val files: List<File>, val copyListener: CopyTask.CopyListener, val listener: OnCopyListener) {
|
||||
class CopyDialog(val activity: Activity, val files: List<File>, val copyListener: CopyTask.CopyDoneListener, val listener: OnCopyListener) {
|
||||
|
||||
init {
|
||||
val context = activity
|
||||
|
@ -49,7 +49,7 @@ class CopyDialog(val activity: Activity, val files: List<File>, val copyListener
|
|||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (view.source.text.trimEnd('/') == destinationPath.trimEnd('/')) {
|
||||
if (view.source.text.trimEnd('/') == view.destination.text.trimEnd('/')) {
|
||||
context.toast(R.string.source_and_destination_same)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
|
|
@ -16,4 +16,8 @@
|
|||
android:icon="@mipmap/delete"
|
||||
android:title="@string/delete"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/cab_copy"
|
||||
android:title="@string/copy_move"
|
||||
app:showAsAction="never"/>
|
||||
</menu>
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
<?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/menu_set_as_wallpaper"
|
||||
android:title="@string/set_as_wallpaper"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/menu_copy"
|
||||
android:title="@string/copy_move"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/menu_set_as_wallpaper"
|
||||
android:title="@string/set_as_wallpaper"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/menu_open_with"
|
||||
android:title="@string/open_with"
|
||||
|
|
Loading…
Reference in New Issue