diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java index acedf00a8..9509d19bf 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -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 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() { + + } } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index c73c387d0..b5d062661 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -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; diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/CopyTask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/CopyTask.kt index 0ea085f66..0309d7486 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/CopyTask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/CopyTask.kt @@ -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, File>, Void, Boolean>() { +class CopyTask(listener: CopyTask.CopyDoneListener, val context: Context) : AsyncTask, File>, Void, Boolean>() { private val TAG = CopyTask::class.java.simpleName - private var mListener: WeakReference? = null + private var mListener: WeakReference? = 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() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt index 24ca4a524..310817798 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt @@ -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, val copyListener: CopyTask.CopyListener, val listener: OnCopyListener) { +class CopyDialog(val activity: Activity, val files: List, val copyListener: CopyTask.CopyDoneListener, val listener: OnCopyListener) { init { val context = activity @@ -49,7 +49,7 @@ class CopyDialog(val activity: Activity, val files: List, 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 } diff --git a/app/src/main/res/menu/cab_media.xml b/app/src/main/res/menu/cab_media.xml index b742b423d..79fa17c9b 100644 --- a/app/src/main/res/menu/cab_media.xml +++ b/app/src/main/res/menu/cab_media.xml @@ -16,4 +16,8 @@ android:icon="@mipmap/delete" android:title="@string/delete" app:showAsAction="ifRoom"/> + diff --git a/app/src/main/res/menu/viewpager_menu.xml b/app/src/main/res/menu/viewpager_menu.xml index 9865b299c..e040e3659 100644 --- a/app/src/main/res/menu/viewpager_menu.xml +++ b/app/src/main/res/menu/viewpager_menu.xml @@ -1,14 +1,14 @@ - +