Skip to content

Commit 4dfa28c

Browse files
committed
adding an initial implementation of Create Document intent
1 parent ad87657 commit 4dfa28c

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@
5555
<category android:name="android.intent.category.DEFAULT" />
5656
</intent-filter>
5757

58+
<intent-filter>
59+
<action android:name="android.intent.action.CREATE_DOCUMENT" />
60+
<data android:mimeType="*/*" />
61+
62+
<category android:name="android.intent.category.OPENABLE" />
63+
<category android:name="android.intent.category.DEFAULT" />
64+
</intent-filter>
65+
5866
<intent-filter>
5967
<action android:name="android.intent.action.RINGTONE_PICKER" />
6068
<category android:name="android.intent.category.DEFAULT" />

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class MainActivity : SimpleActivity() {
147147

148148
fun refreshMenuItems() {
149149
val currentFragment = getCurrentFragment() ?: return
150+
val isCreateDocumentIntent = intent.action == Intent.ACTION_CREATE_DOCUMENT
150151
val currentViewType = config.getFolderViewType(currentFragment.currentPath)
151152
val favorites = config.favorites
152153

@@ -169,6 +170,9 @@ class MainActivity : SimpleActivity() {
169170
findItem(R.id.increase_column_count).isVisible =
170171
currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT && currentFragment !is StorageFragment
171172
findItem(R.id.reduce_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt > 1 && currentFragment !is StorageFragment
173+
174+
findItem(R.id.settings).isVisible = !isCreateDocumentIntent
175+
findItem(R.id.about).isVisible = !isCreateDocumentIntent
172176
}
173177
}
174178

@@ -373,6 +377,7 @@ class MainActivity : SimpleActivity() {
373377

374378
val isPickRingtoneIntent = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
375379
val isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT || intent.action == Intent.ACTION_PICK
380+
val isCreateDocumentIntent = intent.action == Intent.ACTION_CREATE_DOCUMENT
376381
val allowPickingMultipleIntent = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
377382
val getContentMimeType = if (isGetContentIntent) {
378383
intent.type ?: ""
@@ -385,6 +390,7 @@ class MainActivity : SimpleActivity() {
385390
it?.isPickMultipleIntent = allowPickingMultipleIntent
386391
it?.isGetContentIntent = isGetContentIntent
387392
it?.wantedMimeType = getContentMimeType
393+
it?.updateIsCreateDocumentIntent(isCreateDocumentIntent)
388394
}
389395

390396
if (refreshRecents) {
@@ -418,15 +424,20 @@ class MainActivity : SimpleActivity() {
418424

419425
private fun setupTabs() {
420426
main_tabs_holder.removeAllTabs()
421-
val isPickFileIntent =
422-
intent.action == RingtoneManager.ACTION_RINGTONE_PICKER || intent.action == Intent.ACTION_GET_CONTENT || intent.action == Intent.ACTION_PICK
427+
val action = intent.action
428+
val isPickFileIntent = action == RingtoneManager.ACTION_RINGTONE_PICKER || action == Intent.ACTION_GET_CONTENT || action == Intent.ACTION_PICK
429+
val isCreateDocumentIntent = action == Intent.ACTION_CREATE_DOCUMENT
430+
423431
if (isPickFileIntent) {
424432
mTabsToShow.remove(TAB_STORAGE_ANALYSIS)
425433
if (mTabsToShow.none { it and config.showTabs != 0 }) {
426434
config.showTabs = TAB_FILES
427435
mStoredShowTabs = TAB_FILES
428436
mTabsToShow = arrayListOf(TAB_FILES)
429437
}
438+
} else if (isCreateDocumentIntent) {
439+
mTabsToShow.clear()
440+
mTabsToShow = arrayListOf(TAB_FILES)
430441
}
431442

432443
mTabsToShow.forEachIndexed { index, value ->
@@ -698,6 +709,17 @@ class MainActivity : SimpleActivity() {
698709
finish()
699710
}
700711

712+
fun createDocumentConfirmed(path: String) {
713+
val resultIntent = Intent()
714+
val filename = intent.getStringExtra(Intent.EXTRA_TITLE) ?: ""
715+
val uri = getFilePublicUri(File(path, filename), BuildConfig.APPLICATION_ID)
716+
val type = path.getMimeType()
717+
resultIntent.setDataAndType(uri, type)
718+
resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
719+
setResult(Activity.RESULT_OK, resultIntent)
720+
finish()
721+
}
722+
701723
fun pickedRingtone(path: String) {
702724
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
703725
val type = path.getMimeType()

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
4242
override fun setupFragment(activity: SimpleActivity) {
4343
if (this.activity == null) {
4444
this.activity = activity
45-
items_swipe_refresh.setOnRefreshListener { refreshFragment() }
46-
items_fab.setOnClickListener { createNewItem() }
4745
breadcrumbs.listener = this@ItemsFragment
46+
items_swipe_refresh.setOnRefreshListener { refreshFragment() }
47+
items_fab.setOnClickListener {
48+
if (isCreateDocumentIntent) {
49+
(activity as MainActivity).createDocumentConfirmed(currentPath)
50+
} else {
51+
createNewItem()
52+
}
53+
}
4854
}
4955
}
5056

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ package com.simplemobiletools.filemanager.pro.fragments
33
import android.content.Context
44
import android.util.AttributeSet
55
import android.widget.RelativeLayout
6-
import com.simplemobiletools.commons.extensions.getMimeType
7-
import com.simplemobiletools.commons.extensions.isAudioFast
8-
import com.simplemobiletools.commons.extensions.toast
6+
import com.simplemobiletools.commons.extensions.*
97
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
108
import com.simplemobiletools.filemanager.pro.R
119
import com.simplemobiletools.filemanager.pro.activities.MainActivity
1210
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
1311
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
12+
import kotlinx.android.synthetic.main.items_fragment.view.*
1413

1514
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
1615
protected var activity: SimpleActivity? = null
@@ -21,9 +20,10 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
2120
var isGetRingtonePicker = false
2221
var isPickMultipleIntent = false
2322
var wantedMimeType = ""
23+
protected var isCreateDocumentIntent = false
2424

2525
protected fun clickedPath(path: String) {
26-
if (isGetContentIntent) {
26+
if (isGetContentIntent || isCreateDocumentIntent) {
2727
(activity as MainActivity).pickedPath(path)
2828
} else if (isGetRingtonePicker) {
2929
if (path.isAudioFast()) {
@@ -36,6 +36,18 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
3636
}
3737
}
3838

39+
fun updateIsCreateDocumentIntent(isCreateDocumentIntent: Boolean) {
40+
val iconId = if (isCreateDocumentIntent) {
41+
R.drawable.ic_check_vector
42+
} else {
43+
R.drawable.ic_plus_vector
44+
}
45+
46+
this.isCreateDocumentIntent = isCreateDocumentIntent
47+
val fabIcon = context.resources.getColoredDrawableWithColor(iconId, context.getProperPrimaryColor().getContrastColor())
48+
items_fab?.setImageDrawable(fabIcon)
49+
}
50+
3951
protected fun isProperMimeType(wantedMimeType: String, path: String, isDirectory: Boolean): Boolean {
4052
return if (wantedMimeType.isEmpty() || wantedMimeType == "*/*" || isDirectory) {
4153
true

0 commit comments

Comments
 (0)