From 4dfa28c4ff8628b8bb42cc194d855059071044c9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 17 Nov 2022 16:55:14 +0100 Subject: [PATCH] adding an initial implementation of Create Document intent --- app/src/main/AndroidManifest.xml | 8 ++++++ .../pro/activities/MainActivity.kt | 26 +++++++++++++++++-- .../pro/fragments/ItemsFragment.kt | 10 +++++-- .../pro/fragments/MyViewPagerFragment.kt | 20 +++++++++++--- 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 050b40ad..65db2b77 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -55,6 +55,14 @@ + + + + + + + + diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt index f87f94b0..0052b320 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt @@ -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() diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt index 9cc1e961..1da7e61d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt @@ -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() + } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt index 9fb4c21b..70095ab0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt @@ -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