a few more Move adjustments
This commit is contained in:
parent
7b4a6b401d
commit
5569bd06b5
|
@ -7,6 +7,7 @@ import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.support.v4.content.ContextCompat
|
import android.support.v4.content.ContextCompat
|
||||||
import android.support.v4.provider.DocumentFile
|
import android.support.v4.provider.DocumentFile
|
||||||
|
import com.simplemobiletools.filemanager.extensions.isPathOnSD
|
||||||
import com.simplemobiletools.filepicker.extensions.getSDCardPath
|
import com.simplemobiletools.filepicker.extensions.getSDCardPath
|
||||||
import com.simplemobiletools.filepicker.extensions.toast
|
import com.simplemobiletools.filepicker.extensions.toast
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
@ -38,7 +39,7 @@ class Utils {
|
||||||
fun needsStupidWritePermissions(context: Context, path: String) = isPathOnSD(context, path) && isKitkat() && !context.getSDCardPath().isEmpty()
|
fun needsStupidWritePermissions(context: Context, path: String) = isPathOnSD(context, path) && isKitkat() && !context.getSDCardPath().isEmpty()
|
||||||
|
|
||||||
fun isPathOnSD(context: Context, path: String): Boolean {
|
fun isPathOnSD(context: Context, path: String): Boolean {
|
||||||
return path.startsWith(context.getSDCardPath())
|
return context.isPathOnSD(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isKitkat() = Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT
|
fun isKitkat() = Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT
|
||||||
|
|
|
@ -6,15 +6,19 @@ import android.support.v4.util.Pair
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.simplemobiletools.filemanager.Utils
|
import com.simplemobiletools.filemanager.Utils
|
||||||
import com.simplemobiletools.filemanager.extensions.rescanItem
|
import com.simplemobiletools.filemanager.extensions.rescanItem
|
||||||
|
import com.simplemobiletools.filemanager.fragments.ItemsFragment
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class CopyTask(listener: CopyTask.CopyListener, val context: Context) : AsyncTask<Pair<List<File>, File>, Void, Boolean>() {
|
class CopyTask(listener: CopyTask.CopyListener, val context: Context, val deleteAfterCopy: Boolean) : AsyncTask<Pair<List<File>, File>, Void, Boolean>() {
|
||||||
private val TAG = CopyTask::class.java.simpleName
|
private val TAG = CopyTask::class.java.simpleName
|
||||||
private var mListener: WeakReference<CopyListener>? = null
|
private var mListener: WeakReference<CopyListener>? = null
|
||||||
|
private var mMovedFiles: ArrayList<File>
|
||||||
|
|
||||||
init {
|
init {
|
||||||
mListener = WeakReference(listener)
|
mListener = WeakReference(listener)
|
||||||
|
mMovedFiles = arrayListOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doInBackground(vararg params: Pair<List<File>, File>): Boolean? {
|
override fun doInBackground(vararg params: Pair<List<File>, File>): Boolean? {
|
||||||
|
@ -32,6 +36,16 @@ class CopyTask(listener: CopyTask.CopyListener, val context: Context) : AsyncTas
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (deleteAfterCopy) {
|
||||||
|
for (file in mMovedFiles) {
|
||||||
|
if (Utils.needsStupidWritePermissions(context, file.absolutePath)) {
|
||||||
|
Utils.getFileDocument(context, file.absolutePath).delete()
|
||||||
|
} else {
|
||||||
|
file.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +82,7 @@ class CopyTask(listener: CopyTask.CopyListener, val context: Context) : AsyncTas
|
||||||
val out = context.contentResolver.openOutputStream(document.uri)
|
val out = context.contentResolver.openOutputStream(document.uri)
|
||||||
copyStream(inputStream, out)
|
copyStream(inputStream, out)
|
||||||
context.rescanItem(destination)
|
context.rescanItem(destination)
|
||||||
|
mMovedFiles.add(source)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
copy(newFile, File(destination, child))
|
copy(newFile, File(destination, child))
|
||||||
|
@ -93,6 +108,7 @@ class CopyTask(listener: CopyTask.CopyListener, val context: Context) : AsyncTas
|
||||||
|
|
||||||
copyStream(inputStream, out)
|
copyStream(inputStream, out)
|
||||||
context.rescanItem(destination)
|
context.rescanItem(destination)
|
||||||
|
mMovedFiles.add(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun copyStream(inputStream: InputStream, out: OutputStream?) {
|
private fun copyStream(inputStream: InputStream, out: OutputStream?) {
|
||||||
|
@ -110,14 +126,14 @@ class CopyTask(listener: CopyTask.CopyListener, val context: Context) : AsyncTas
|
||||||
val listener = mListener?.get() ?: return
|
val listener = mListener?.get() ?: return
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
listener.copySucceeded()
|
listener.copySucceeded(if (deleteAfterCopy) ItemsFragment.ACTION_MOVE else ItemsFragment.ACTION_COPY)
|
||||||
} else {
|
} else {
|
||||||
listener.copyFailed()
|
listener.copyFailed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CopyListener {
|
interface CopyListener {
|
||||||
fun copySucceeded()
|
fun copySucceeded(action: Int)
|
||||||
|
|
||||||
fun copyFailed()
|
fun copyFailed()
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,9 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
||||||
private boolean mShowHidden;
|
private boolean mShowHidden;
|
||||||
private int mSelectedItemsCnt;
|
private int mSelectedItemsCnt;
|
||||||
|
|
||||||
|
public static int ACTION_COPY = 1;
|
||||||
|
public static int ACTION_MOVE = 2;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
@ -492,9 +495,9 @@ public class ItemsFragment extends android.support.v4.app.Fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void copySucceeded() {
|
public void copySucceeded(int action) {
|
||||||
fillItems();
|
fillItems();
|
||||||
Utils.Companion.showToast(getContext(), R.string.copying_success);
|
Utils.Companion.showToast(getContext(), action == ACTION_COPY ? R.string.copying_success : R.string.moving_success);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,16 +6,15 @@ import android.support.v4.util.Pair
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.Toast
|
|
||||||
import com.simplemobiletools.filemanager.Config
|
import com.simplemobiletools.filemanager.Config
|
||||||
import com.simplemobiletools.filemanager.R
|
import com.simplemobiletools.filemanager.R
|
||||||
import com.simplemobiletools.filemanager.Utils
|
import com.simplemobiletools.filemanager.Utils
|
||||||
import com.simplemobiletools.filemanager.activities.MainActivity
|
import com.simplemobiletools.filemanager.activities.MainActivity
|
||||||
import com.simplemobiletools.filemanager.asynctasks.CopyTask
|
import com.simplemobiletools.filemanager.asynctasks.CopyTask
|
||||||
|
import com.simplemobiletools.filemanager.extensions.isPathOnSD
|
||||||
import com.simplemobiletools.filemanager.extensions.rescanItem
|
import com.simplemobiletools.filemanager.extensions.rescanItem
|
||||||
import com.simplemobiletools.filemanager.extensions.toast
|
import com.simplemobiletools.filemanager.extensions.toast
|
||||||
import com.simplemobiletools.filepicker.dialogs.FilePickerDialog
|
import com.simplemobiletools.filepicker.dialogs.FilePickerDialog
|
||||||
import com.simplemobiletools.filepicker.extensions.getBasePath
|
|
||||||
import com.simplemobiletools.filepicker.extensions.humanizePath
|
import com.simplemobiletools.filepicker.extensions.humanizePath
|
||||||
import kotlinx.android.synthetic.main.copy_item.view.*
|
import kotlinx.android.synthetic.main.copy_item.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -88,23 +87,23 @@ class CopyDialog(val activity: Activity, val files: List<File>, val copyListener
|
||||||
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_copy) {
|
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_copy) {
|
||||||
context.toast(R.string.copying)
|
context.toast(R.string.copying)
|
||||||
val pair = Pair<List<File>, File>(files, destinationDir)
|
val pair = Pair<List<File>, File>(files, destinationDir)
|
||||||
CopyTask(copyListener, context).execute(pair)
|
CopyTask(copyListener, context, false).execute(pair)
|
||||||
|
dismiss()
|
||||||
|
} else {
|
||||||
|
if (context.isPathOnSD(sourcePath) || context.isPathOnSD(destinationPath)) {
|
||||||
|
context.toast(R.string.moving)
|
||||||
|
val pair = Pair<List<File>, File>(files, destinationDir)
|
||||||
|
CopyTask(copyListener, context, true).execute(pair)
|
||||||
dismiss()
|
dismiss()
|
||||||
} else {
|
} else {
|
||||||
if (sourcePath.getBasePath(context) == destinationPath.getBasePath(context)) {
|
|
||||||
for (f in files) {
|
for (f in files) {
|
||||||
val destination = File(destinationDir, f.name)
|
val destination = File(destinationDir, f.name)
|
||||||
f.renameTo(destination)
|
|
||||||
context.rescanItem(destination)
|
context.rescanItem(destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.toast(R.string.moving_success)
|
||||||
dismiss()
|
dismiss()
|
||||||
listener.onSuccess()
|
listener.onSuccess()
|
||||||
} else {
|
|
||||||
context.toast(R.string.copying_no_delete, Toast.LENGTH_LONG)
|
|
||||||
val pair = Pair<List<File>, File>(files, destinationDir)
|
|
||||||
CopyTask(copyListener, context).execute(pair)
|
|
||||||
dismiss()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,9 +3,10 @@ package com.simplemobiletools.filemanager.extensions
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.media.MediaScannerConnection
|
import android.media.MediaScannerConnection
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import com.simplemobiletools.filepicker.extensions.getSDCardPath
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
fun Context.toast(id: Int, length: Int = Toast.LENGTH_SHORT) = Toast.makeText(this, resources.getString(id), length).show()
|
fun Context.toast(id: Int) = Toast.makeText(this, resources.getString(id), Toast.LENGTH_SHORT).show()
|
||||||
|
|
||||||
fun Context.rescanItem(item: File) {
|
fun Context.rescanItem(item: File) {
|
||||||
if (item.isDirectory) {
|
if (item.isDirectory) {
|
||||||
|
@ -16,3 +17,5 @@ fun Context.rescanItem(item: File) {
|
||||||
|
|
||||||
MediaScannerConnection.scanFile(this, arrayOf(item.absolutePath), null, null)
|
MediaScannerConnection.scanFile(this, arrayOf(item.absolutePath), null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.isPathOnSD(path: String) = path.startsWith(getSDCardPath())
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
<string name="copying">Kopiere</string>
|
<string name="copying">Kopiere</string>
|
||||||
<string name="copying_success">Files copied successfully</string>
|
<string name="copying_success">Files copied successfully</string>
|
||||||
<string name="copying_failed">Konnte die Datei nicht kopieren</string>
|
<string name="copying_failed">Konnte die Datei nicht kopieren</string>
|
||||||
<string name="copying_no_delete">Copying, please delete source files manually</string>
|
<string name="moving">Moving</string>
|
||||||
|
<string name="moving_success">Files moved successfully</string>
|
||||||
<string name="already_exists">A file with that name already exists</string>
|
<string name="already_exists">A file with that name already exists</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="cancel">Abbrechen</string>
|
<string name="cancel">Abbrechen</string>
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
<string name="copying">Copia in corso</string>
|
<string name="copying">Copia in corso</string>
|
||||||
<string name="copying_success">Files copied successfully</string>
|
<string name="copying_success">Files copied successfully</string>
|
||||||
<string name="copying_failed">Impossibile copiare i file</string>
|
<string name="copying_failed">Impossibile copiare i file</string>
|
||||||
<string name="copying_no_delete">Copying, please delete source files manually</string>
|
<string name="moving">Moving</string>
|
||||||
|
<string name="moving_success">Files moved successfully</string>
|
||||||
<string name="already_exists">A file with that name already exists</string>
|
<string name="already_exists">A file with that name already exists</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="cancel">Annulla</string>
|
<string name="cancel">Annulla</string>
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
<string name="copying">コピー中</string>
|
<string name="copying">コピー中</string>
|
||||||
<string name="copying_success">Files copied successfully</string>
|
<string name="copying_success">Files copied successfully</string>
|
||||||
<string name="copying_failed">ファイルをコピーできませんでした</string>
|
<string name="copying_failed">ファイルをコピーできませんでした</string>
|
||||||
<string name="copying_no_delete">Copying, please delete source files manually</string>
|
<string name="moving">Moving</string>
|
||||||
|
<string name="moving_success">Files moved successfully</string>
|
||||||
<string name="already_exists">A file with that name already exists</string>
|
<string name="already_exists">A file with that name already exists</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
<string name="copying">A copiar</string>
|
<string name="copying">A copiar</string>
|
||||||
<string name="copying_success">Files copied successfully</string>
|
<string name="copying_success">Files copied successfully</string>
|
||||||
<string name="copying_failed">Não foi possível copiar os ficheiros</string>
|
<string name="copying_failed">Não foi possível copiar os ficheiros</string>
|
||||||
<string name="copying_no_delete">A copiar, apague os ficheiros originais manualmente</string>
|
<string name="moving">Moving</string>
|
||||||
|
<string name="moving_success">Files moved successfully</string>
|
||||||
<string name="already_exists">Já existe um ficheiro com este nome/string>
|
<string name="already_exists">Já existe um ficheiro com este nome/string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="cancel">Cancelar</string>
|
<string name="cancel">Cancelar</string>
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
<string name="copying">Kopierar</string>
|
<string name="copying">Kopierar</string>
|
||||||
<string name="copying_success">Files copied successfully</string>
|
<string name="copying_success">Files copied successfully</string>
|
||||||
<string name="copying_failed">Kunde inte kopiera filen</string>
|
<string name="copying_failed">Kunde inte kopiera filen</string>
|
||||||
<string name="copying_no_delete">Copying, please delete source files manually</string>
|
<string name="moving">Moving</string>
|
||||||
|
<string name="moving_success">Files moved successfully</string>
|
||||||
<string name="already_exists">A file with that name already exists</string>
|
<string name="already_exists">A file with that name already exists</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
|
|
|
@ -32,8 +32,9 @@
|
||||||
<string name="source_and_destination_same">Source and destination cannot be the same</string>
|
<string name="source_and_destination_same">Source and destination cannot be the same</string>
|
||||||
<string name="copying">Copying</string>
|
<string name="copying">Copying</string>
|
||||||
<string name="copying_success">Files copied successfully</string>
|
<string name="copying_success">Files copied successfully</string>
|
||||||
<string name="copying_failed">An error occurred during the copy</string>
|
<string name="copying_failed">An error occurred</string>
|
||||||
<string name="copying_no_delete">Copying, please delete source files manually</string>
|
<string name="moving">Moving</string>
|
||||||
|
<string name="moving_success">Files moved successfully</string>
|
||||||
<string name="already_exists">A file with that name already exists</string>
|
<string name="already_exists">A file with that name already exists</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
|
|
Loading…
Reference in New Issue