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 04d8566ca..7a727ed3d 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 @@ -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 @@ -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 @@ -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) } } 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 ff60248c8..73b68093c 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,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) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt index 216a4c45b..0f0187b55 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt @@ -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 @@ -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 }