properly handle third party intents in the Recents tab

This commit is contained in:
tibbi 2021-05-19 21:04:08 +02:00
parent 9143e07949
commit 39eb160f6b
3 changed files with 24 additions and 19 deletions

View File

@ -19,7 +19,6 @@ import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
import com.simplemobiletools.filemanager.pro.dialogs.CreateNewItemDialog import com.simplemobiletools.filemanager.pro.dialogs.CreateNewItemDialog
import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.config
import com.simplemobiletools.filemanager.pro.extensions.isPathOnRoot import com.simplemobiletools.filemanager.pro.extensions.isPathOnRoot
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
@ -30,7 +29,6 @@ import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener { class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
private var activity: SimpleActivity? = null
private var showHidden = false private var showHidden = false
private var skipItemUpdating = false private var skipItemUpdating = false
private var isSearchOpen = false private var isSearchOpen = false
@ -248,18 +246,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
if (item.isDirectory) { if (item.isDirectory) {
openDirectory(item.path) openDirectory(item.path)
} else { } else {
val path = item.path clickedPath(item.path)
if (isGetContentIntent) {
(activity as MainActivity).pickedPath(path)
} else if (isGetRingtonePicker) {
if (path.isAudioFast()) {
(activity as MainActivity).pickedRingtone(path)
} else {
activity?.toast(R.string.select_audio_file)
}
} else {
activity?.tryOpenPathIntent(path, false)
}
} }
} }

View File

@ -3,14 +3,35 @@ 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.isAudioFast
import com.simplemobiletools.commons.extensions.toast
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.activities.SimpleActivity
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
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
var currentPath = "" var currentPath = ""
var isGetContentIntent = false var isGetContentIntent = false
var isGetRingtonePicker = false var isGetRingtonePicker = false
var isPickMultipleIntent = false var isPickMultipleIntent = false
protected fun clickedPath(path: String) {
if (isGetContentIntent) {
(activity as MainActivity).pickedPath(path)
} else if (isGetRingtonePicker) {
if (path.isAudioFast()) {
(activity as MainActivity).pickedRingtone(path)
} else {
activity?.toast(R.string.select_audio_file)
}
} else {
activity?.tryOpenPathIntent(path, false)
}
}
abstract fun setupFragment(activity: SimpleActivity) abstract fun setupFragment(activity: SimpleActivity)
abstract fun setupColors(textColor: Int, adjustedPrimaryColor: Int) abstract fun setupColors(textColor: Int, adjustedPrimaryColor: Int)

View File

@ -11,15 +11,12 @@ import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.config
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
import com.simplemobiletools.filemanager.pro.models.ListItem import com.simplemobiletools.filemanager.pro.models.ListItem
import kotlinx.android.synthetic.main.recents_fragment.view.* import kotlinx.android.synthetic.main.recents_fragment.view.*
import java.util.* import java.util.*
class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener { class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener {
private var activity: SimpleActivity? = null
override fun setupFragment(activity: SimpleActivity) { override fun setupFragment(activity: SimpleActivity) {
if (this.activity == null) { if (this.activity == null) {
this.activity = activity this.activity = activity
@ -33,8 +30,8 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
ensureBackgroundThread { ensureBackgroundThread {
getRecents { recents -> getRecents { recents ->
recents_swipe_refresh?.isRefreshing = false recents_swipe_refresh?.isRefreshing = false
ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, false, null, recents_swipe_refresh) { ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, isPickMultipleIntent, null, recents_swipe_refresh) {
activity?.tryOpenPathIntent((it as FileDirItem).path, false) clickedPath((it as FileDirItem).path)
}.apply { }.apply {
recents_list.adapter = this recents_list.adapter = this
} }