Skip to content

Commit 69db31a

Browse files
committed
improving the Create Document intent handling
1 parent 4dfa28c commit 69db31a

File tree

4 files changed

+110
-2
lines changed

4 files changed

+110
-2
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ android {
6464
}
6565

6666
dependencies {
67-
implementation 'com.github.SimpleMobileTools:Simple-Commons:2e9ca234a7'
67+
implementation 'com.github.SimpleMobileTools:Simple-Commons:f538687d6e'
6868
implementation 'com.github.tibbi:AndroidPdfViewer:da57ff410e'
6969
implementation 'com.github.Stericson:RootTools:df729dcb13'
7070
implementation 'com.github.Stericson:RootShell:1.6'

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.simplemobiletools.filemanager.pro.R
3232
import com.simplemobiletools.filemanager.pro.adapters.ViewPagerAdapter
3333
import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
3434
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
35+
import com.simplemobiletools.filemanager.pro.dialogs.InsertFilenameDialog
3536
import com.simplemobiletools.filemanager.pro.extensions.config
3637
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
3738
import com.simplemobiletools.filemanager.pro.fragments.ItemsFragment
@@ -709,9 +710,20 @@ class MainActivity : SimpleActivity() {
709710
finish()
710711
}
711712

713+
// 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
712714
fun createDocumentConfirmed(path: String) {
713-
val resultIntent = Intent()
714715
val filename = intent.getStringExtra(Intent.EXTRA_TITLE) ?: ""
716+
if (filename.isEmpty()) {
717+
InsertFilenameDialog(this, internalStoragePath) { newFilename ->
718+
finishCreateDocumentIntent(path, newFilename)
719+
}
720+
} else {
721+
finishCreateDocumentIntent(path, filename)
722+
}
723+
}
724+
725+
private fun finishCreateDocumentIntent(path: String, filename: String) {
726+
val resultIntent = Intent()
715727
val uri = getFilePublicUri(File(path, filename), BuildConfig.APPLICATION_ID)
716728
val type = path.getMimeType()
717729
resultIntent.setDataAndType(uri, type)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.simplemobiletools.filemanager.pro.dialogs
2+
3+
import androidx.appcompat.app.AlertDialog
4+
import com.simplemobiletools.commons.activities.BaseSimpleActivity
5+
import com.simplemobiletools.commons.extensions.*
6+
import com.simplemobiletools.filemanager.pro.R
7+
import kotlinx.android.synthetic.main.dialog_insert_filename.view.*
8+
9+
class InsertFilenameDialog(
10+
val activity: BaseSimpleActivity, var path: String, val callback: (filename: String) -> Unit
11+
) {
12+
init {
13+
val view = activity.layoutInflater.inflate(R.layout.dialog_insert_filename, null)
14+
15+
activity.getAlertDialogBuilder()
16+
.setPositiveButton(R.string.ok, null)
17+
.setNegativeButton(R.string.cancel, null)
18+
.apply {
19+
activity.setupDialogStuff(view, this, R.string.filename) { alertDialog ->
20+
alertDialog.showKeyboard(view.insert_filename_title)
21+
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
22+
val filename = view.insert_filename_title.value
23+
val extension = view.insert_filename_extension_title.value
24+
25+
if (filename.isEmpty()) {
26+
activity.toast(R.string.filename_cannot_be_empty)
27+
return@setOnClickListener
28+
}
29+
30+
var newFilename = filename
31+
if (extension.isNotEmpty()) {
32+
newFilename += ".$extension"
33+
}
34+
35+
val newPath = "$path/$newFilename"
36+
if (!newFilename.isAValidFilename()) {
37+
activity.toast(R.string.filename_invalid_characters)
38+
return@setOnClickListener
39+
}
40+
41+
if (activity.getDoesFilePathExist(newPath)) {
42+
val msg = String.format(activity.getString(R.string.file_already_exists), newFilename)
43+
activity.toast(msg)
44+
} else {
45+
callback(newFilename)
46+
alertDialog.dismiss()
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/insert_filename_holder"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:orientation="vertical"
7+
android:padding="@dimen/activity_margin">
8+
9+
<com.simplemobiletools.commons.views.MyTextInputLayout
10+
android:id="@+id/insert_filename_hint"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:layout_marginBottom="@dimen/activity_margin"
14+
android:hint="@string/filename">
15+
16+
<com.google.android.material.textfield.TextInputEditText
17+
android:id="@+id/insert_filename_title"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:inputType="textCapSentences"
21+
android:singleLine="true"
22+
android:textCursorDrawable="@null"
23+
android:textSize="@dimen/bigger_text_size" />
24+
25+
</com.simplemobiletools.commons.views.MyTextInputLayout>
26+
27+
<com.simplemobiletools.commons.views.MyTextInputLayout
28+
android:id="@+id/insert_filename_extension_hint"
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
android:layout_marginBottom="@dimen/activity_margin"
32+
android:hint="@string/extension">
33+
34+
<com.google.android.material.textfield.TextInputEditText
35+
android:id="@+id/insert_filename_extension_title"
36+
android:layout_width="match_parent"
37+
android:layout_height="wrap_content"
38+
android:inputType="textCapSentences"
39+
android:singleLine="true"
40+
android:textCursorDrawable="@null"
41+
android:textSize="@dimen/bigger_text_size" />
42+
43+
</com.simplemobiletools.commons.views.MyTextInputLayout>
44+
</LinearLayout>

0 commit comments

Comments
 (0)