mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-03-16 11:30:12 +01:00
filling the Recents tab content
This commit is contained in:
parent
a50977cb33
commit
8226588d95
@ -125,7 +125,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
||||
breadcrumbs.updateFontSize(context!!.getTextSize())
|
||||
}
|
||||
|
||||
ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller,
|
||||
ItemsAdapter(activity as SimpleActivity, storedItems, this, items_list, isPickMultipleIntent, items_fastscroller,
|
||||
items_swipe_refresh) {
|
||||
if ((it as? ListItem)?.isSectionTitle == true) {
|
||||
openDirectory(it.mPath)
|
||||
|
@ -3,32 +3,65 @@ package com.simplemobiletools.filemanager.pro.fragments
|
||||
import android.content.Context
|
||||
import android.provider.MediaStore
|
||||
import android.util.AttributeSet
|
||||
import com.simplemobiletools.commons.extensions.getIntValue
|
||||
import com.simplemobiletools.commons.extensions.getLongValue
|
||||
import com.simplemobiletools.commons.extensions.getStringValue
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
|
||||
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 {
|
||||
override fun setupFragment(activity: SimpleActivity) {}
|
||||
private var activity: SimpleActivity? = null
|
||||
|
||||
override fun setupFragment(activity: SimpleActivity) {
|
||||
this.activity = activity
|
||||
ensureBackgroundThread {
|
||||
getRecents { recents ->
|
||||
ItemsAdapter(activity, recents, this, recents_list, false, null, recents_swipe_refresh) {
|
||||
activity.tryOpenPathIntent((it as FileDirItem).path, false)
|
||||
}.apply {
|
||||
recents_list.adapter = this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setupColors(textColor: Int, adjustedPrimaryColor: Int) {}
|
||||
|
||||
private fun getRecents() {
|
||||
private fun getRecents(callback: (recents: ArrayList<ListItem>) -> Unit) {
|
||||
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 projection = arrayOf(
|
||||
MediaStore.Files.FileColumns.DATA,
|
||||
MediaStore.Files.FileColumns.DISPLAY_NAME,
|
||||
MediaStore.Files.FileColumns.DATE_MODIFIED,
|
||||
MediaStore.Files.FileColumns.SIZE
|
||||
)
|
||||
|
||||
val sortOrder = "${MediaStore.Files.FileColumns.DATE_MODIFIED} DESC LIMIT 50"
|
||||
val cursor = context?.contentResolver?.query(uri, projection, null, null, sortOrder)
|
||||
val listItems = arrayListOf<ListItem>()
|
||||
|
||||
cursor?.use {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
val path = cursor.getStringValue(MediaStore.Files.FileColumns.DATA)
|
||||
val modified = cursor.getIntValue(MediaStore.Files.FileColumns.DATE_MODIFIED)
|
||||
val name = cursor.getStringValue(MediaStore.Files.FileColumns.DISPLAY_NAME)
|
||||
val size = cursor.getLongValue(MediaStore.Files.FileColumns.SIZE)
|
||||
val modified = cursor.getLongValue(MediaStore.Files.FileColumns.DATE_MODIFIED) * 1000
|
||||
val fileDirItem = ListItem(path, name, false, 0, size, modified, false)
|
||||
listItems.add(fileDirItem)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
}
|
||||
|
||||
activity?.runOnUiThread {
|
||||
callback(listItems)
|
||||
}
|
||||
}
|
||||
|
||||
override fun refreshItems() {}
|
||||
|
@ -19,13 +19,18 @@
|
||||
android:textStyle="italic"
|
||||
android:visibility="gone" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/recents_list"
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/recents_swipe_refresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:layoutAnimation="@anim/layout_animation"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager" />
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/recents_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:layoutAnimation="@anim/layout_animation"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager" />
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
</com.simplemobiletools.filemanager.pro.fragments.RecentsFragment>
|
||||
|
Loading…
x
Reference in New Issue
Block a user