mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
adding an initial implementation of Create Document intent
This commit is contained in:
@ -55,6 +55,14 @@
|
|||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</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>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.RINGTONE_PICKER" />
|
<action android:name="android.intent.action.RINGTONE_PICKER" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
@ -147,6 +147,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
fun refreshMenuItems() {
|
fun refreshMenuItems() {
|
||||||
val currentFragment = getCurrentFragment() ?: return
|
val currentFragment = getCurrentFragment() ?: return
|
||||||
|
val isCreateDocumentIntent = intent.action == Intent.ACTION_CREATE_DOCUMENT
|
||||||
val currentViewType = config.getFolderViewType(currentFragment.currentPath)
|
val currentViewType = config.getFolderViewType(currentFragment.currentPath)
|
||||||
val favorites = config.favorites
|
val favorites = config.favorites
|
||||||
|
|
||||||
@ -169,6 +170,9 @@ class MainActivity : SimpleActivity() {
|
|||||||
findItem(R.id.increase_column_count).isVisible =
|
findItem(R.id.increase_column_count).isVisible =
|
||||||
currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT && currentFragment !is StorageFragment
|
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.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 isPickRingtoneIntent = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
|
||||||
val isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT || intent.action == Intent.ACTION_PICK
|
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 allowPickingMultipleIntent = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
|
||||||
val getContentMimeType = if (isGetContentIntent) {
|
val getContentMimeType = if (isGetContentIntent) {
|
||||||
intent.type ?: ""
|
intent.type ?: ""
|
||||||
@ -385,6 +390,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
it?.isPickMultipleIntent = allowPickingMultipleIntent
|
it?.isPickMultipleIntent = allowPickingMultipleIntent
|
||||||
it?.isGetContentIntent = isGetContentIntent
|
it?.isGetContentIntent = isGetContentIntent
|
||||||
it?.wantedMimeType = getContentMimeType
|
it?.wantedMimeType = getContentMimeType
|
||||||
|
it?.updateIsCreateDocumentIntent(isCreateDocumentIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refreshRecents) {
|
if (refreshRecents) {
|
||||||
@ -418,8 +424,10 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun setupTabs() {
|
private fun setupTabs() {
|
||||||
main_tabs_holder.removeAllTabs()
|
main_tabs_holder.removeAllTabs()
|
||||||
val isPickFileIntent =
|
val action = intent.action
|
||||||
intent.action == RingtoneManager.ACTION_RINGTONE_PICKER || intent.action == Intent.ACTION_GET_CONTENT || intent.action == Intent.ACTION_PICK
|
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) {
|
if (isPickFileIntent) {
|
||||||
mTabsToShow.remove(TAB_STORAGE_ANALYSIS)
|
mTabsToShow.remove(TAB_STORAGE_ANALYSIS)
|
||||||
if (mTabsToShow.none { it and config.showTabs != 0 }) {
|
if (mTabsToShow.none { it and config.showTabs != 0 }) {
|
||||||
@ -427,6 +435,9 @@ class MainActivity : SimpleActivity() {
|
|||||||
mStoredShowTabs = TAB_FILES
|
mStoredShowTabs = TAB_FILES
|
||||||
mTabsToShow = arrayListOf(TAB_FILES)
|
mTabsToShow = arrayListOf(TAB_FILES)
|
||||||
}
|
}
|
||||||
|
} else if (isCreateDocumentIntent) {
|
||||||
|
mTabsToShow.clear()
|
||||||
|
mTabsToShow = arrayListOf(TAB_FILES)
|
||||||
}
|
}
|
||||||
|
|
||||||
mTabsToShow.forEachIndexed { index, value ->
|
mTabsToShow.forEachIndexed { index, value ->
|
||||||
@ -698,6 +709,17 @@ class MainActivity : SimpleActivity() {
|
|||||||
finish()
|
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) {
|
fun pickedRingtone(path: String) {
|
||||||
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
|
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
|
||||||
val type = path.getMimeType()
|
val type = path.getMimeType()
|
||||||
|
@ -42,9 +42,15 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||||||
override fun setupFragment(activity: SimpleActivity) {
|
override fun setupFragment(activity: SimpleActivity) {
|
||||||
if (this.activity == null) {
|
if (this.activity == null) {
|
||||||
this.activity = activity
|
this.activity = activity
|
||||||
items_swipe_refresh.setOnRefreshListener { refreshFragment() }
|
|
||||||
items_fab.setOnClickListener { createNewItem() }
|
|
||||||
breadcrumbs.listener = this@ItemsFragment
|
breadcrumbs.listener = this@ItemsFragment
|
||||||
|
items_swipe_refresh.setOnRefreshListener { refreshFragment() }
|
||||||
|
items_fab.setOnClickListener {
|
||||||
|
if (isCreateDocumentIntent) {
|
||||||
|
(activity as MainActivity).createDocumentConfirmed(currentPath)
|
||||||
|
} else {
|
||||||
|
createNewItem()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,14 +3,13 @@ package com.simplemobiletools.filemanager.pro.fragments
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import com.simplemobiletools.commons.extensions.getMimeType
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.extensions.isAudioFast
|
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
|
||||||
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
|
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
|
||||||
import com.simplemobiletools.filemanager.pro.R
|
import com.simplemobiletools.filemanager.pro.R
|
||||||
import com.simplemobiletools.filemanager.pro.activities.MainActivity
|
import com.simplemobiletools.filemanager.pro.activities.MainActivity
|
||||||
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
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) {
|
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
|
||||||
protected var activity: SimpleActivity? = null
|
protected var activity: SimpleActivity? = null
|
||||||
@ -21,9 +20,10 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||||||
var isGetRingtonePicker = false
|
var isGetRingtonePicker = false
|
||||||
var isPickMultipleIntent = false
|
var isPickMultipleIntent = false
|
||||||
var wantedMimeType = ""
|
var wantedMimeType = ""
|
||||||
|
protected var isCreateDocumentIntent = false
|
||||||
|
|
||||||
protected fun clickedPath(path: String) {
|
protected fun clickedPath(path: String) {
|
||||||
if (isGetContentIntent) {
|
if (isGetContentIntent || isCreateDocumentIntent) {
|
||||||
(activity as MainActivity).pickedPath(path)
|
(activity as MainActivity).pickedPath(path)
|
||||||
} else if (isGetRingtonePicker) {
|
} else if (isGetRingtonePicker) {
|
||||||
if (path.isAudioFast()) {
|
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 {
|
protected fun isProperMimeType(wantedMimeType: String, path: String, isDirectory: Boolean): Boolean {
|
||||||
return if (wantedMimeType.isEmpty() || wantedMimeType == "*/*" || isDirectory) {
|
return if (wantedMimeType.isEmpty() || wantedMimeType == "*/*" || isDirectory) {
|
||||||
true
|
true
|
||||||
|
Reference in New Issue
Block a user