adding the Recents tab

This commit is contained in:
tibbi
2021-05-19 19:25:17 +02:00
parent eb5e565739
commit a50977cb33
8 changed files with 102 additions and 30 deletions

View File

@ -26,12 +26,16 @@ import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
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.extensions.tryOpenPathIntent
import com.simplemobiletools.filemanager.pro.fragments.MyViewPagerFragment
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.helpers.TAB_FILES
import com.simplemobiletools.filemanager.pro.helpers.TAB_RECENTS
import com.stericson.RootTools.RootTools import com.stericson.RootTools.RootTools
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.items_fragment.* import kotlinx.android.synthetic.main.items_fragment.*
import kotlinx.android.synthetic.main.items_fragment.view.* import kotlinx.android.synthetic.main.items_fragment.view.*
import kotlinx.android.synthetic.main.recents_fragment.*
import java.io.File import java.io.File
import java.util.* import java.util.*
@ -59,6 +63,7 @@ class MainActivity : SimpleActivity() {
handleAppPasswordProtection { handleAppPasswordProtection {
mWasProtectionHandled = it mWasProtectionHandled = it
if (it) { if (it) {
initFragments()
mIsPasswordProtectionPending = false mIsPasswordProtectionPending = false
tryInitFileManager() tryInitFileManager()
checkWhatsNewDialog() checkWhatsNewDialog()
@ -80,13 +85,13 @@ class MainActivity : SimpleActivity() {
if (storedFontSize != config.fontSize) { if (storedFontSize != config.fontSize) {
getAllFragments().forEach { getAllFragments().forEach {
it.updateFontSize() it?.setupFontSize()
} }
} }
if (storedDateFormat != config.dateFormat || storedTimeFormat != getTimeFormat()) { if (storedDateFormat != config.dateFormat || storedTimeFormat != getTimeFormat()) {
getAllFragments().forEach { getAllFragments().forEach {
it.updateDateTimeFormat() it?.setupDateTimeFormat()
} }
} }
@ -97,6 +102,10 @@ class MainActivity : SimpleActivity() {
main_tabs_holder.background = ColorDrawable(config.backgroundColor) main_tabs_holder.background = ColorDrawable(config.backgroundColor)
main_tabs_holder.setSelectedTabIndicatorColor(getAdjustedPrimaryColor()) main_tabs_holder.setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
main_tabs_holder.getTabAt(main_view_pager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor()) main_tabs_holder.getTabAt(main_view_pager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
if (main_view_pager.adapter == null) {
initFragments()
}
} }
override fun onPause() { override fun onPause() {
@ -106,6 +115,7 @@ class MainActivity : SimpleActivity() {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
config.lastUsedViewPagerPage = main_view_pager.currentItem
config.temporarilyShowHidden = false config.temporarilyShowHidden = false
} }
@ -172,10 +182,10 @@ class MainActivity : SimpleActivity() {
val path = savedInstanceState.getString(PICKED_PATH) ?: internalStoragePath val path = savedInstanceState.getString(PICKED_PATH) ?: internalStoragePath
if (main_view_pager.adapter == null) { if (main_view_pager.adapter == null) {
initFragments()
main_view_pager.onGlobalLayout { main_view_pager.onGlobalLayout {
restorePath(path) restorePath(path)
} }
updateTabColors()
} else { } else {
restorePath(path) restorePath(path)
} }
@ -244,7 +254,7 @@ class MainActivity : SimpleActivity() {
checkOTGPath() checkOTGPath()
if (it) { if (it) {
if (main_view_pager.adapter == null) { if (main_view_pager.adapter == null) {
main_view_pager.adapter = ViewPagerAdapter(this) initFragments()
} }
main_view_pager.onGlobalLayout { main_view_pager.onGlobalLayout {
@ -287,6 +297,7 @@ class MainActivity : SimpleActivity() {
private fun initFragments() { private fun initFragments() {
main_view_pager.adapter = ViewPagerAdapter(this) main_view_pager.adapter = ViewPagerAdapter(this)
main_view_pager.currentItem = config.lastUsedViewPagerPage
main_view_pager.onPageChangeListener { main_view_pager.onPageChangeListener {
main_tabs_holder.getTabAt(it)?.select() main_tabs_holder.getTabAt(it)?.select()
invalidateOptionsMenu() invalidateOptionsMenu()
@ -322,6 +333,13 @@ class MainActivity : SimpleActivity() {
} }
} }
private fun updateTabColors() {
getInactiveTabIndexes(main_view_pager.currentItem).forEach {
main_tabs_holder.getTabAt(it)?.icon?.applyColorFilter(config.textColor)
}
main_tabs_holder.getTabAt(main_view_pager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
}
private fun checkOTGPath() { private fun checkOTGPath() {
ensureBackgroundThread { ensureBackgroundThread {
if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE) && hasOTGConnected() && config.OTGPath.isEmpty()) { if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE) && hasOTGConnected() && config.OTGPath.isEmpty()) {
@ -512,9 +530,9 @@ class MainActivity : SimpleActivity() {
} }
} }
private fun getInactiveTabIndexes(activeIndex: Int) = arrayListOf(0, 1).filter { it != activeIndex } private fun getInactiveTabIndexes(activeIndex: Int) = arrayListOf(TAB_FILES, TAB_RECENTS).filter { it != activeIndex }
private fun getAllFragments() = arrayListOf(items_fragment) private fun getAllFragments(): ArrayList<MyViewPagerFragment?> = arrayListOf(items_fragment, recents_fragment)
private fun getCurrentFragment() = items_fragment private fun getCurrentFragment() = items_fragment

View File

@ -7,7 +7,8 @@ import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.config
import com.simplemobiletools.filemanager.pro.fragments.ItemsFragment import com.simplemobiletools.filemanager.pro.fragments.MyViewPagerFragment
import com.simplemobiletools.filemanager.pro.helpers.TAB_FILES
class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() { class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
override fun instantiateItem(container: ViewGroup, position: Int): Any { override fun instantiateItem(container: ViewGroup, position: Int): Any {
@ -15,7 +16,7 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
val view = activity.layoutInflater.inflate(layout, container, false) val view = activity.layoutInflater.inflate(layout, container, false)
container.addView(view) container.addView(view)
(view as ItemsFragment).apply { (view as MyViewPagerFragment).apply {
setupFragment(activity) setupFragment(activity)
setupColors(activity.config.textColor, activity.getAdjustedPrimaryColor()) setupColors(activity.config.textColor, activity.getAdjustedPrimaryColor())
} }
@ -27,9 +28,12 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
container.removeView(item as View) container.removeView(item as View)
} }
override fun getCount() = 1 override fun getCount() = 2
override fun isViewFromObject(view: View, item: Any) = view == item override fun isViewFromObject(view: View, item: Any) = view == item
private fun getFragment(position: Int) = R.layout.items_fragment private fun getFragment(position: Int) = when (position) {
TAB_FILES -> R.layout.items_fragment
else -> R.layout.recents_fragment
}
} }

View File

@ -3,7 +3,6 @@ package com.simplemobiletools.filemanager.pro.fragments
import android.content.Context import android.content.Context
import android.os.Parcelable import android.os.Parcelable
import android.util.AttributeSet import android.util.AttributeSet
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.StoragePickerDialog import com.simplemobiletools.commons.dialogs.StoragePickerDialog
@ -30,7 +29,7 @@ import java.io.File
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
class ItemsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener { class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
var currentPath = "" var currentPath = ""
var isGetContentIntent = false var isGetContentIntent = false
var isGetRingtonePicker = false var isGetRingtonePicker = false
@ -47,7 +46,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorL
private var storedItems = ArrayList<ListItem>() private var storedItems = ArrayList<ListItem>()
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 { refreshItems() } items_swipe_refresh.setOnRefreshListener { refreshItems() }
@ -56,7 +55,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorL
} }
} }
fun setupColors(textColor: Int, adjustedPrimaryColor: Int) { override fun setupColors(textColor: Int, adjustedPrimaryColor: Int) {
context!!.updateTextColors(this) context!!.updateTextColors(this)
items_fastscroller.updatePrimaryColor() items_fastscroller.updatePrimaryColor()
storedItems = ArrayList() storedItems = ArrayList()
@ -69,12 +68,12 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorL
items_fastscroller.updateBubbleColors() items_fastscroller.updateBubbleColors()
} }
fun updateFontSize() { override fun setupFontSize() {
getRecyclerAdapter()?.updateFontSizes() getRecyclerAdapter()?.updateFontSizes()
breadcrumbs.updateFontSize(context!!.getTextSize()) breadcrumbs.updateFontSize(context!!.getTextSize())
} }
fun updateDateTimeFormat() { override fun setupDateTimeFormat() {
getRecyclerAdapter()?.updateDateTimeFormat() getRecyclerAdapter()?.updateDateTimeFormat()
} }

View File

@ -0,0 +1,16 @@
package com.simplemobiletools.filemanager.pro.fragments
import android.content.Context
import android.util.AttributeSet
import android.widget.RelativeLayout
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
abstract fun setupFragment(activity: SimpleActivity)
abstract fun setupColors(textColor: Int, adjustedPrimaryColor: Int)
abstract fun setupFontSize()
abstract fun setupDateTimeFormat()
}

View File

@ -1,17 +1,43 @@
package com.simplemobiletools.filemanager.pro.fragments package com.simplemobiletools.filemanager.pro.fragments
import android.os.Bundle import android.content.Context
import android.view.LayoutInflater import android.provider.MediaStore
import android.view.View import android.util.AttributeSet
import android.view.ViewGroup import com.simplemobiletools.commons.extensions.getIntValue
import androidx.fragment.app.Fragment import com.simplemobiletools.commons.extensions.getStringValue
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
import java.util.*
class RecentsFragment : Fragment() { class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener {
lateinit var mView: View override fun setupFragment(activity: SimpleActivity) {}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { override fun setupColors(textColor: Int, adjustedPrimaryColor: Int) {}
mView = inflater.inflate(R.layout.recents_fragment, container, false)!!
return mView private fun getRecents() {
val uri = MediaStore.Files.getContentUri("external")
val projection = arrayOf(MediaStore.Files.FileColumns.DATA, MediaStore.Files.FileColumns.DATE_MODIFIED)
val sortOrder = "${MediaStore.Files.FileColumns.DATE_MODIFIED} DESC LIMIT 20"
val cursor = context?.contentResolver?.query(uri, projection, null, null, sortOrder)
cursor?.use {
if (cursor.moveToFirst()) {
do {
val path = cursor.getStringValue(MediaStore.Files.FileColumns.DATA)
val modified = cursor.getIntValue(MediaStore.Files.FileColumns.DATE_MODIFIED)
} while (cursor.moveToNext())
}
}
} }
override fun refreshItems() {}
override fun deleteFiles(files: ArrayList<FileDirItem>) {}
override fun selectedPaths(paths: ArrayList<String>) {}
override fun setupFontSize() {}
override fun setupDateTimeFormat() {}
} }

View File

@ -24,3 +24,6 @@ const val OPEN_AS_IMAGE = 2
const val OPEN_AS_AUDIO = 3 const val OPEN_AS_AUDIO = 3
const val OPEN_AS_VIDEO = 4 const val OPEN_AS_VIDEO = 4
const val OPEN_AS_OTHER = 5 const val OPEN_AS_OTHER = 5
const val TAB_FILES = 0
const val TAB_RECENTS = 1

View File

@ -21,6 +21,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:icon="@drawable/ic_folder_vector" /> android:icon="@drawable/ic_folder_vector" />
<com.google.android.material.tabs.TabItem
android:id="@+id/tab_recents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/ic_clock_vector" />
</com.google.android.material.tabs.TabLayout> </com.google.android.material.tabs.TabLayout>
<com.simplemobiletools.commons.views.MyViewPager <com.simplemobiletools.commons.views.MyViewPager

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <com.simplemobiletools.filemanager.pro.fragments.RecentsFragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/recents_wrapper" android:id="@+id/recents_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -28,4 +28,4 @@
android:scrollbars="none" android:scrollbars="none"
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager" /> app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager" />
</RelativeLayout> </com.simplemobiletools.filemanager.pro.fragments.RecentsFragment>