Skip to content

Commit

Permalink
properly handle third party intents in the Recents tab
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbi committed May 19, 2021
1 parent 9143e07 commit 39eb160
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
import com.simplemobiletools.filemanager.pro.dialogs.CreateNewItemDialog
import com.simplemobiletools.filemanager.pro.extensions.config
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.RootHelpers
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
Expand All @@ -30,7 +29,6 @@ import java.util.*
import kotlin.collections.ArrayList

class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
private var activity: SimpleActivity? = null
private var showHidden = false
private var skipItemUpdating = false
private var isSearchOpen = false
Expand Down Expand Up @@ -248,18 +246,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
if (item.isDirectory) {
openDirectory(item.path)
} else {
val path = 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)
}
clickedPath(item.path)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,35 @@ package com.simplemobiletools.filemanager.pro.fragments
import android.content.Context
import android.util.AttributeSet
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.extensions.tryOpenPathIntent

abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
protected var activity: SimpleActivity? = null

var currentPath = ""
var isGetContentIntent = false
var isGetRingtonePicker = 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 setupColors(textColor: Int, adjustedPrimaryColor: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
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.models.ListItem
import kotlinx.android.synthetic.main.recents_fragment.view.*
import java.util.*

class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener {
private var activity: SimpleActivity? = null

override fun setupFragment(activity: SimpleActivity) {
if (this.activity == null) {
this.activity = activity
Expand All @@ -33,8 +30,8 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
ensureBackgroundThread {
getRecents { recents ->
recents_swipe_refresh?.isRefreshing = false
ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, false, null, recents_swipe_refresh) {
activity?.tryOpenPathIntent((it as FileDirItem).path, false)
ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, isPickMultipleIntent, null, recents_swipe_refresh) {
clickedPath((it as FileDirItem).path)
}.apply {
recents_list.adapter = this
}
Expand Down

0 comments on commit 39eb160

Please sign in to comment.