adding an initial implementation of Create Document intent

This commit is contained in:
tibbi 2022-11-17 16:55:14 +01:00
parent ad8765757b
commit 4dfa28c4ff
4 changed files with 56 additions and 8 deletions

View File

@ -55,6 +55,14 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CREATE_DOCUMENT" />
<data android:mimeType="*/*" />
<category android:name="android.intent.category.OPENABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.RINGTONE_PICKER" />
<category android:name="android.intent.category.DEFAULT" />

View File

@ -147,6 +147,7 @@ class MainActivity : SimpleActivity() {
fun refreshMenuItems() {
val currentFragment = getCurrentFragment() ?: return
val isCreateDocumentIntent = intent.action == Intent.ACTION_CREATE_DOCUMENT
val currentViewType = config.getFolderViewType(currentFragment.currentPath)
val favorites = config.favorites
@ -169,6 +170,9 @@ class MainActivity : SimpleActivity() {
findItem(R.id.increase_column_count).isVisible =
currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT && currentFragment !is StorageFragment
findItem(R.id.reduce_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt > 1 && currentFragment !is StorageFragment
findItem(R.id.settings).isVisible = !isCreateDocumentIntent
findItem(R.id.about).isVisible = !isCreateDocumentIntent
}
}
@ -373,6 +377,7 @@ class MainActivity : SimpleActivity() {
val isPickRingtoneIntent = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
val isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT || intent.action == Intent.ACTION_PICK
val isCreateDocumentIntent = intent.action == Intent.ACTION_CREATE_DOCUMENT
val allowPickingMultipleIntent = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
val getContentMimeType = if (isGetContentIntent) {
intent.type ?: ""
@ -385,6 +390,7 @@ class MainActivity : SimpleActivity() {
it?.isPickMultipleIntent = allowPickingMultipleIntent
it?.isGetContentIntent = isGetContentIntent
it?.wantedMimeType = getContentMimeType
it?.updateIsCreateDocumentIntent(isCreateDocumentIntent)
}
if (refreshRecents) {
@ -418,8 +424,10 @@ class MainActivity : SimpleActivity() {
private fun setupTabs() {
main_tabs_holder.removeAllTabs()
val isPickFileIntent =
intent.action == RingtoneManager.ACTION_RINGTONE_PICKER || intent.action == Intent.ACTION_GET_CONTENT || intent.action == Intent.ACTION_PICK
val action = intent.action
val isPickFileIntent = action == RingtoneManager.ACTION_RINGTONE_PICKER || action == Intent.ACTION_GET_CONTENT || action == Intent.ACTION_PICK
val isCreateDocumentIntent = action == Intent.ACTION_CREATE_DOCUMENT
if (isPickFileIntent) {
mTabsToShow.remove(TAB_STORAGE_ANALYSIS)
if (mTabsToShow.none { it and config.showTabs != 0 }) {
@ -427,6 +435,9 @@ class MainActivity : SimpleActivity() {
mStoredShowTabs = TAB_FILES
mTabsToShow = arrayListOf(TAB_FILES)
}
} else if (isCreateDocumentIntent) {
mTabsToShow.clear()
mTabsToShow = arrayListOf(TAB_FILES)
}
mTabsToShow.forEachIndexed { index, value ->
@ -698,6 +709,17 @@ class MainActivity : SimpleActivity() {
finish()
}
fun createDocumentConfirmed(path: String) {
val resultIntent = Intent()
val filename = intent.getStringExtra(Intent.EXTRA_TITLE) ?: ""
val uri = getFilePublicUri(File(path, filename), BuildConfig.APPLICATION_ID)
val type = path.getMimeType()
resultIntent.setDataAndType(uri, type)
resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
setResult(Activity.RESULT_OK, resultIntent)
finish()
}
fun pickedRingtone(path: String) {
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
val type = path.getMimeType()

View File

@ -42,9 +42,15 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
override fun setupFragment(activity: SimpleActivity) {
if (this.activity == null) {
this.activity = activity
items_swipe_refresh.setOnRefreshListener { refreshFragment() }
items_fab.setOnClickListener { createNewItem() }
breadcrumbs.listener = this@ItemsFragment
items_swipe_refresh.setOnRefreshListener { refreshFragment() }
items_fab.setOnClickListener {
if (isCreateDocumentIntent) {
(activity as MainActivity).createDocumentConfirmed(currentPath)
} else {
createNewItem()
}
}
}
}

View File

@ -3,14 +3,13 @@ package com.simplemobiletools.filemanager.pro.fragments
import android.content.Context
import android.util.AttributeSet
import android.widget.RelativeLayout
import com.simplemobiletools.commons.extensions.getMimeType
import com.simplemobiletools.commons.extensions.isAudioFast
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.activities.MainActivity
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
import kotlinx.android.synthetic.main.items_fragment.view.*
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
protected var activity: SimpleActivity? = null
@ -21,9 +20,10 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
var isGetRingtonePicker = false
var isPickMultipleIntent = false
var wantedMimeType = ""
protected var isCreateDocumentIntent = false
protected fun clickedPath(path: String) {
if (isGetContentIntent) {
if (isGetContentIntent || isCreateDocumentIntent) {
(activity as MainActivity).pickedPath(path)
} else if (isGetRingtonePicker) {
if (path.isAudioFast()) {
@ -36,6 +36,18 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
}
fun updateIsCreateDocumentIntent(isCreateDocumentIntent: Boolean) {
val iconId = if (isCreateDocumentIntent) {
R.drawable.ic_check_vector
} else {
R.drawable.ic_plus_vector
}
this.isCreateDocumentIntent = isCreateDocumentIntent
val fabIcon = context.resources.getColoredDrawableWithColor(iconId, context.getProperPrimaryColor().getContrastColor())
items_fab?.setImageDrawable(fabIcon)
}
protected fun isProperMimeType(wantedMimeType: String, path: String, isDirectory: Boolean): Boolean {
return if (wantedMimeType.isEmpty() || wantedMimeType == "*/*" || isDirectory) {
true