diff --git a/app/build.gradle b/app/build.gradle index 1cebf1a0c..c37938e8d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.10.12' + compile 'com.simplemobiletools:commons:2.10.14' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 228484cde..c966cdfe7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -18,12 +18,12 @@ import android.view.View import com.simplemobiletools.commons.asynctasks.CopyMoveTask import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog +import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.MyPagerAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.dialogs.CopyDialog -import com.simplemobiletools.gallery.dialogs.RenameFileDialog import com.simplemobiletools.gallery.dialogs.SaveAsDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.fragments.PhotoFragment @@ -336,8 +336,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun renameFile() { - RenameFileDialog(this, getCurrentFile()) { - mMedia[mPos].path = it.absolutePath + RenameItemDialog(this, getCurrentFile().absolutePath) { + mMedia[mPos].path = it updateActionbarTitle() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index c61dbe85d..a1e399dc0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -15,7 +15,7 @@ import com.bumptech.glide.signature.StringSignature import com.simplemobiletools.commons.asynctasks.CopyMoveTask import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog -import com.simplemobiletools.commons.dialogs.RenameFolderDialog +import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity @@ -165,11 +165,10 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList, } private fun renameFile() { - RenameFileDialog(activity, getCurrentFile()) { + RenameItemDialog(activity, getCurrentFile().absolutePath) { listener?.refreshItems() activity.runOnUiThread { actMode?.finish() @@ -237,8 +237,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, medium: Medium, pos: Int): View { itemView.apply { play_outline.visibility = if (medium.isVideo) View.VISIBLE else View.GONE - file_name.beVisibleIf(displayFilenames) - file_name.text = medium.name + save_as_name.beVisibleIf(displayFilenames) + save_as_name.text = medium.name toggleItemSelection(this, markedItems.contains(pos), pos) val path = medium.path diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt deleted file mode 100644 index 23f23ccb2..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt +++ /dev/null @@ -1,88 +0,0 @@ -package com.simplemobiletools.gallery.dialogs - -import android.provider.DocumentsContract -import android.support.v7.app.AlertDialog -import android.view.LayoutInflater -import android.view.WindowManager -import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.activities.SimpleActivity -import com.simplemobiletools.gallery.extensions.config -import kotlinx.android.synthetic.main.rename_file.view.* -import java.io.File - -class RenameFileDialog(val activity: SimpleActivity, val file: File, val callback: (newFile: File) -> Unit) { - - init { - val view = LayoutInflater.from(activity).inflate(R.layout.rename_file, null) - val fullName = file.name - val dotAt = fullName.lastIndexOf(".") - var name = fullName - - if (dotAt > 0) { - name = fullName.substring(0, dotAt) - val extension = fullName.substring(dotAt + 1) - view.file_extension.setText(extension) - } - - view.file_name.setText(name) - view.file_path.text = activity.humanizePath(file.parent) + "/" - - AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - activity.setupDialogStuff(view, this, R.string.rename_file) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ - val filename = view.file_name.value - val extension = view.file_extension.value - - if (filename.isEmpty()) { - context.toast(R.string.filename_cannot_be_empty) - return@setOnClickListener - } - - if (extension.isEmpty()) { - context.toast(R.string.extension_cannot_be_empty) - return@setOnClickListener - } - - val newFile = File(file.parent, "$filename.$extension") - if (!newFile.name.isAValidFilename()) { - context.toast(R.string.invalid_name) - return@setOnClickListener - } - - if (context.needsStupidWritePermissions(file.absolutePath)) { - activity.handleSAFDialog(file) { - var document = context.getFastDocument(file) - if (document?.isFile == false) { - document = context.getFileDocument(file.absolutePath, context.config.treeUri) - } - - DocumentsContract.renameDocument(context.contentResolver, document!!.uri, newFile.name) - sendSuccess(file, newFile) - dismiss() - } - } else if (file.renameTo(newFile)) { - sendSuccess(file, newFile) - dismiss() - } else { - context.toast(R.string.rename_file_error) - } - }) - } - } - - private fun sendSuccess(oldFile: File, newFile: File) { - if (activity.updateInMediaStore(oldFile, newFile)) { - callback.invoke(newFile) - } else { - val changedFiles = arrayListOf(oldFile, newFile) - activity.scanFiles(changedFiles) { - callback.invoke(newFile) - } - } - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt index 7af2fcb1c..3406e3de8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt @@ -6,7 +6,7 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity -import kotlinx.android.synthetic.main.rename_file.view.* +import kotlinx.android.synthetic.main.dialog_save_as.view.* import java.io.File class SaveAsDialog(val activity: SimpleActivity, val path: String, val callback: (savePath: String) -> Unit) { @@ -14,7 +14,7 @@ class SaveAsDialog(val activity: SimpleActivity, val path: String, val callback: init { var realPath = File(path).parent.trimEnd('/') val view = LayoutInflater.from(activity).inflate(R.layout.dialog_save_as, null).apply { - file_path.text = activity.humanizePath(realPath) + save_as_path.text = activity.humanizePath(realPath) val fullName = path.getFilenameFromPath() val dotAt = fullName.lastIndexOf(".") @@ -23,13 +23,13 @@ class SaveAsDialog(val activity: SimpleActivity, val path: String, val callback: if (dotAt > 0) { name = fullName.substring(0, dotAt) val extension = fullName.substring(dotAt + 1) - file_extension.setText(extension) + save_as_extension.setText(extension) } - file_name.setText(name) - file_path.setOnClickListener { + save_as_name.setText(name) + save_as_path.setOnClickListener { FilePickerDialog(activity, realPath, false, false, true) { - file_path.text = activity.humanizePath(it) + save_as_path.text = activity.humanizePath(it) realPath = it } } @@ -41,8 +41,8 @@ class SaveAsDialog(val activity: SimpleActivity, val path: String, val callback: .create().apply { activity.setupDialogStuff(view, this, R.string.save_as) getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ - val filename = view.file_name.value - val extension = view.file_extension.value + val filename = view.save_as_name.value + val extension = view.save_as_extension.value if (filename.isEmpty()) { context.toast(R.string.filename_cannot_be_empty) diff --git a/app/src/main/res/layout/dialog_save_as.xml b/app/src/main/res/layout/dialog_save_as.xml index 828459a79..c40bd92ad 100644 --- a/app/src/main/res/layout/dialog_save_as.xml +++ b/app/src/main/res/layout/dialog_save_as.xml @@ -8,14 +8,14 @@ android:padding="@dimen/activity_margin"> - - - - - - - - - - -