mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-02-07 23:48:46 +01:00
improving the Create Document intent handling
This commit is contained in:
parent
4dfa28c4ff
commit
69db31ae23
@ -64,7 +64,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:2e9ca234a7'
|
implementation 'com.github.SimpleMobileTools:Simple-Commons:f538687d6e'
|
||||||
implementation 'com.github.tibbi:AndroidPdfViewer:da57ff410e'
|
implementation 'com.github.tibbi:AndroidPdfViewer:da57ff410e'
|
||||||
implementation 'com.github.Stericson:RootTools:df729dcb13'
|
implementation 'com.github.Stericson:RootTools:df729dcb13'
|
||||||
implementation 'com.github.Stericson:RootShell:1.6'
|
implementation 'com.github.Stericson:RootShell:1.6'
|
||||||
|
@ -32,6 +32,7 @@ import com.simplemobiletools.filemanager.pro.R
|
|||||||
import com.simplemobiletools.filemanager.pro.adapters.ViewPagerAdapter
|
import com.simplemobiletools.filemanager.pro.adapters.ViewPagerAdapter
|
||||||
import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
|
import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
|
||||||
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
|
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
|
||||||
|
import com.simplemobiletools.filemanager.pro.dialogs.InsertFilenameDialog
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.config
|
import com.simplemobiletools.filemanager.pro.extensions.config
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
||||||
import com.simplemobiletools.filemanager.pro.fragments.ItemsFragment
|
import com.simplemobiletools.filemanager.pro.fragments.ItemsFragment
|
||||||
@ -709,9 +710,20 @@ class MainActivity : SimpleActivity() {
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// used at apps that have no file access at all, but need to work with files. For example Simple Calendar uses this at exporting events into a file
|
||||||
fun createDocumentConfirmed(path: String) {
|
fun createDocumentConfirmed(path: String) {
|
||||||
val resultIntent = Intent()
|
|
||||||
val filename = intent.getStringExtra(Intent.EXTRA_TITLE) ?: ""
|
val filename = intent.getStringExtra(Intent.EXTRA_TITLE) ?: ""
|
||||||
|
if (filename.isEmpty()) {
|
||||||
|
InsertFilenameDialog(this, internalStoragePath) { newFilename ->
|
||||||
|
finishCreateDocumentIntent(path, newFilename)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
finishCreateDocumentIntent(path, filename)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun finishCreateDocumentIntent(path: String, filename: String) {
|
||||||
|
val resultIntent = Intent()
|
||||||
val uri = getFilePublicUri(File(path, filename), BuildConfig.APPLICATION_ID)
|
val uri = getFilePublicUri(File(path, filename), BuildConfig.APPLICATION_ID)
|
||||||
val type = path.getMimeType()
|
val type = path.getMimeType()
|
||||||
resultIntent.setDataAndType(uri, type)
|
resultIntent.setDataAndType(uri, type)
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.simplemobiletools.filemanager.pro.dialogs
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.filemanager.pro.R
|
||||||
|
import kotlinx.android.synthetic.main.dialog_insert_filename.view.*
|
||||||
|
|
||||||
|
class InsertFilenameDialog(
|
||||||
|
val activity: BaseSimpleActivity, var path: String, val callback: (filename: String) -> Unit
|
||||||
|
) {
|
||||||
|
init {
|
||||||
|
val view = activity.layoutInflater.inflate(R.layout.dialog_insert_filename, null)
|
||||||
|
|
||||||
|
activity.getAlertDialogBuilder()
|
||||||
|
.setPositiveButton(R.string.ok, null)
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.apply {
|
||||||
|
activity.setupDialogStuff(view, this, R.string.filename) { alertDialog ->
|
||||||
|
alertDialog.showKeyboard(view.insert_filename_title)
|
||||||
|
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||||
|
val filename = view.insert_filename_title.value
|
||||||
|
val extension = view.insert_filename_extension_title.value
|
||||||
|
|
||||||
|
if (filename.isEmpty()) {
|
||||||
|
activity.toast(R.string.filename_cannot_be_empty)
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
|
||||||
|
var newFilename = filename
|
||||||
|
if (extension.isNotEmpty()) {
|
||||||
|
newFilename += ".$extension"
|
||||||
|
}
|
||||||
|
|
||||||
|
val newPath = "$path/$newFilename"
|
||||||
|
if (!newFilename.isAValidFilename()) {
|
||||||
|
activity.toast(R.string.filename_invalid_characters)
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activity.getDoesFilePathExist(newPath)) {
|
||||||
|
val msg = String.format(activity.getString(R.string.file_already_exists), newFilename)
|
||||||
|
activity.toast(msg)
|
||||||
|
} else {
|
||||||
|
callback(newFilename)
|
||||||
|
alertDialog.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
44
app/src/main/res/layout/dialog_insert_filename.xml
Normal file
44
app/src/main/res/layout/dialog_insert_filename.xml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/insert_filename_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="@dimen/activity_margin">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextInputLayout
|
||||||
|
android:id="@+id/insert_filename_hint"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="@dimen/activity_margin"
|
||||||
|
android:hint="@string/filename">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/insert_filename_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="textCapSentences"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textCursorDrawable="@null"
|
||||||
|
android:textSize="@dimen/bigger_text_size" />
|
||||||
|
|
||||||
|
</com.simplemobiletools.commons.views.MyTextInputLayout>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextInputLayout
|
||||||
|
android:id="@+id/insert_filename_extension_hint"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="@dimen/activity_margin"
|
||||||
|
android:hint="@string/extension">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/insert_filename_extension_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="textCapSentences"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textCursorDrawable="@null"
|
||||||
|
android:textSize="@dimen/bigger_text_size" />
|
||||||
|
|
||||||
|
</com.simplemobiletools.commons.views.MyTextInputLayout>
|
||||||
|
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user