adding an initial implementation of Search at Recents tab

This commit is contained in:
tibbi 2023-01-07 19:19:11 +01:00
parent 989e68227a
commit b12702848c
5 changed files with 198 additions and 54 deletions

View file

@ -144,16 +144,12 @@ class MainActivity : SimpleActivity() {
}
override fun onBackPressed() {
if (getCurrentFragment() is StorageFragment) {
super.onBackPressed()
return
}
val currentFragment = getCurrentFragment()
if (main_menu.isSearchOpen) {
main_menu.closeSearch()
} else if (getCurrentFragment() is RecentsFragment) {
} else if (currentFragment is RecentsFragment) {
super.onBackPressed()
} else if (getCurrentFragment()!!.breadcrumbs.getItemCount() <= 1) {
} else if (currentFragment != null && currentFragment.breadcrumbs.getItemCount() <= 1) {
if (!wasBackJustPressed && config.pressBackTwice) {
wasBackJustPressed = true
toast(R.string.press_back_again)
@ -164,8 +160,8 @@ class MainActivity : SimpleActivity() {
finish()
}
} else {
getCurrentFragment()!!.breadcrumbs.removeBreadcrumb()
openPath(getCurrentFragment()!!.breadcrumbs.getLastItem().path)
currentFragment?.breadcrumbs?.removeBreadcrumb() ?: return
openPath(currentFragment.breadcrumbs.getLastItem().path)
}
}

View file

@ -349,15 +349,6 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
mimetypes_placeholder.beVisibleIf(items.isEmpty())
}
private fun getListItemsFromFileDirItems(fileDirItems: ArrayList<FileDirItem>): ArrayList<ListItem> {
val listItems = ArrayList<ListItem>()
fileDirItems.forEach {
val listItem = ListItem(it.path, it.name, false, 0, it.size, it.modified, false, false)
listItems.add(listItem)
}
return listItems
}
private fun getRecyclerAdapter() = mimetypes_list.adapter as? ItemsAdapter
private fun showSortingDialog() {

View file

@ -4,26 +4,39 @@ import android.annotation.SuppressLint
import android.app.usage.StorageStatsManager
import android.content.Context
import android.content.Intent
import android.os.Handler
import android.os.storage.StorageManager
import android.provider.MediaStore
import android.provider.Settings
import android.util.AttributeSet
import androidx.appcompat.app.AppCompatActivity
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.LOWER_ALPHA
import com.simplemobiletools.commons.helpers.SHORT_ANIMATION_DURATION
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isOreoPlus
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.activities.MimeTypesActivity
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.formatSizeThousand
import com.simplemobiletools.filemanager.pro.helpers.*
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
import com.simplemobiletools.filemanager.pro.models.ListItem
import kotlinx.android.synthetic.main.storage_fragment.view.*
import java.util.*
class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener {
private val SIZE_DIVIDER = 100000
private var allDeviceListItems = ArrayList<ListItem>()
override fun setupFragment(activity: SimpleActivity) {
if (this.activity == null) {
this.activity = activity
}
total_space.text = String.format(context.getString(R.string.total_storage), "")
getSizes()
@ -42,41 +55,46 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
documents_holder.setOnClickListener { launchMimetypeActivity(DOCUMENTS) }
archives_holder.setOnClickListener { launchMimetypeActivity(ARCHIVES) }
others_holder.setOnClickListener { launchMimetypeActivity(OTHERS) }
}
override fun refreshFragment() {}
Handler().postDelayed({
val fileDirItems = getAllFiles()
allDeviceListItems = getListItemsFromFileDirItems(fileDirItems)
setupSearchResultsAdapter()
}, 2000)
}
override fun onResume(textColor: Int) {
getSizes()
context.updateTextColors(storage_fragment)
search_holder.setBackgroundColor(context.getProperBackgroundColor())
val properPrimaryColor = context.getProperPrimaryColor()
main_storage_usage_progressbar.setIndicatorColor(properPrimaryColor)
main_storage_usage_progressbar.trackColor = properPrimaryColor.adjustAlpha(0.3f)
main_storage_usage_progressbar.trackColor = properPrimaryColor.adjustAlpha(LOWER_ALPHA)
val redColor = context.resources.getColor(R.color.md_red_700)
images_progressbar.setIndicatorColor(redColor)
images_progressbar.trackColor = redColor.adjustAlpha(0.3f)
images_progressbar.trackColor = redColor.adjustAlpha(LOWER_ALPHA)
val greenColor = context.resources.getColor(R.color.md_green_700)
videos_progressbar.setIndicatorColor(greenColor)
videos_progressbar.trackColor = greenColor.adjustAlpha(0.3f)
videos_progressbar.trackColor = greenColor.adjustAlpha(LOWER_ALPHA)
val lightBlueColor = context.resources.getColor(R.color.md_light_blue_700)
audio_progressbar.setIndicatorColor(lightBlueColor)
audio_progressbar.trackColor = lightBlueColor.adjustAlpha(0.3f)
audio_progressbar.trackColor = lightBlueColor.adjustAlpha(LOWER_ALPHA)
val yellowColor = context.resources.getColor(R.color.md_yellow_700)
documents_progressbar.setIndicatorColor(yellowColor)
documents_progressbar.trackColor = yellowColor.adjustAlpha(0.3f)
documents_progressbar.trackColor = yellowColor.adjustAlpha(LOWER_ALPHA)
val tealColor = context.resources.getColor(R.color.md_teal_700)
archives_progressbar.setIndicatorColor(tealColor)
archives_progressbar.trackColor = tealColor.adjustAlpha(0.3f)
archives_progressbar.trackColor = tealColor.adjustAlpha(LOWER_ALPHA)
val pinkColor = context.resources.getColor(R.color.md_pink_700)
others_progressbar.setIndicatorColor(pinkColor)
others_progressbar.trackColor = pinkColor.adjustAlpha(0.3f)
others_progressbar.trackColor = pinkColor.adjustAlpha(LOWER_ALPHA)
}
private fun launchMimetypeActivity(mimetype: String) {
@ -223,6 +241,82 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}
override fun searchQueryChanged(text: String) {
if (text.isNotEmpty()) {
if (search_holder.alpha < 1f) {
search_holder.fadeIn()
}
} else {
search_holder.animate().alpha(0f).setDuration(SHORT_ANIMATION_DURATION).withEndAction {
search_holder.beGone()
(search_results_list.adapter as? ItemsAdapter)?.updateItems(allDeviceListItems, text)
}.start()
}
if (text.isNotEmpty()) {
val filtered = allDeviceListItems.filter { it.mName.contains(text, true) }.toMutableList() as ArrayList<ListItem>
(search_results_list.adapter as? ItemsAdapter)?.updateItems(filtered, text)
search_placeholder.beVisibleIf(filtered.isEmpty())
}
}
private fun setupSearchResultsAdapter() {
ItemsAdapter(context as SimpleActivity, allDeviceListItems, this, search_results_list, false, null, false) {
clickedPath((it as FileDirItem).path)
}.apply {
search_results_list.adapter = this
}
}
private fun getAllFiles(): ArrayList<FileDirItem> {
val fileDirItems = ArrayList<FileDirItem>()
val showHidden = context?.config?.shouldShowHidden ?: return fileDirItems
val uri = MediaStore.Files.getContentUri("external")
val projection = arrayOf(
MediaStore.Files.FileColumns.DATA,
MediaStore.Files.FileColumns.DISPLAY_NAME,
MediaStore.Files.FileColumns.SIZE,
MediaStore.Files.FileColumns.DATE_MODIFIED
)
try {
context?.queryCursor(uri, projection) { cursor ->
try {
val name = cursor.getStringValue(MediaStore.Files.FileColumns.DISPLAY_NAME)
if (!showHidden && name.startsWith(".")) {
return@queryCursor
}
val size = cursor.getLongValue(MediaStore.Files.FileColumns.SIZE)
if (size == 0L) {
return@queryCursor
}
val path = cursor.getStringValue(MediaStore.Files.FileColumns.DATA)
val lastModified = cursor.getLongValue(MediaStore.Files.FileColumns.DATE_MODIFIED) * 1000
fileDirItems.add(FileDirItem(path, name, false, 0, size, lastModified))
} catch (e: Exception) {
}
}
} catch (e: Exception) {
context?.showErrorToast(e)
}
return fileDirItems
}
override fun refreshFragment() {}
override fun deleteFiles(files: ArrayList<FileDirItem>) {}
override fun selectedPaths(paths: ArrayList<String>) {}
override fun setupDateTimeFormat() {}
override fun setupFontSize() {}
override fun toggleFilenameVisibility() {}
override fun columnCountChanged() {}
override fun finishActMode() {}
}

View file

@ -3,6 +3,8 @@ package com.simplemobiletools.filemanager.pro.helpers
import com.simplemobiletools.commons.helpers.TAB_FILES
import com.simplemobiletools.commons.helpers.TAB_RECENT_FILES
import com.simplemobiletools.commons.helpers.TAB_STORAGE_ANALYSIS
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.filemanager.pro.models.ListItem
const val PATH = "path"
const val MAX_COLUMN_COUNT = 15
@ -64,3 +66,12 @@ val archiveMimeTypes = arrayListOf(
"application/java-archive",
"multipart/x-zip"
)
fun getListItemsFromFileDirItems(fileDirItems: ArrayList<FileDirItem>): ArrayList<ListItem> {
val listItems = ArrayList<ListItem>()
fileDirItems.forEach {
val listItem = ListItem(it.path, it.name, false, 0, it.size, it.modified, false, false)
listItems.add(listItem)
}
return listItems
}

View file

@ -9,22 +9,24 @@
<androidx.core.widget.NestedScrollView
android:id="@+id/storage_nested_scrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/storage_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="HardcodedText,RelativeOverlap">
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardcodedText">
<RelativeLayout
android:id="@+id/free_space_holder"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin">
android:paddingEnd="@dimen/activity_margin"
app:layout_constraintTop_toTopOf="parent">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/free_space_value"
@ -69,19 +71,21 @@
<RelativeLayout
android:id="@+id/images_holder"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/free_space_holder"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/normal_margin"
android:paddingEnd="@dimen/activity_margin"
android:paddingBottom="@dimen/normal_margin">
android:paddingBottom="@dimen/normal_margin"
app:layout_constraintTop_toBottomOf="@+id/free_space_holder">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/images_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/images_size"
android:text="@string/images"
android:textSize="@dimen/bigger_text_size" />
@ -108,19 +112,21 @@
<RelativeLayout
android:id="@+id/videos_holder"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/images_holder"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/normal_margin"
android:paddingEnd="@dimen/activity_margin"
android:paddingBottom="@dimen/normal_margin">
android:paddingBottom="@dimen/normal_margin"
app:layout_constraintTop_toBottomOf="@+id/images_holder">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/videos_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/videos_size"
android:text="@string/videos"
android:textSize="@dimen/bigger_text_size" />
@ -147,19 +153,21 @@
<RelativeLayout
android:id="@+id/audio_holder"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/videos_holder"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/normal_margin"
android:paddingEnd="@dimen/activity_margin"
android:paddingBottom="@dimen/normal_margin">
android:paddingBottom="@dimen/normal_margin"
app:layout_constraintTop_toBottomOf="@+id/videos_holder">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/audio_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/audio_size"
android:text="@string/audio"
android:textSize="@dimen/bigger_text_size" />
@ -186,19 +194,21 @@
<RelativeLayout
android:id="@+id/documents_holder"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/audio_holder"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/normal_margin"
android:paddingEnd="@dimen/activity_margin"
android:paddingBottom="@dimen/normal_margin">
android:paddingBottom="@dimen/normal_margin"
app:layout_constraintTop_toBottomOf="@+id/audio_holder">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/documents_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/documents_size"
android:text="@string/documents"
android:textSize="@dimen/bigger_text_size" />
@ -225,19 +235,21 @@
<RelativeLayout
android:id="@+id/archives_holder"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/documents_holder"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/normal_margin"
android:paddingEnd="@dimen/activity_margin"
android:paddingBottom="@dimen/normal_margin">
android:paddingBottom="@dimen/normal_margin"
app:layout_constraintTop_toBottomOf="@+id/documents_holder">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/archives_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/archives_size"
android:text="@string/archives"
android:textSize="@dimen/bigger_text_size" />
@ -264,19 +276,21 @@
<RelativeLayout
android:id="@+id/others_holder"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/archives_holder"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/normal_margin"
android:paddingEnd="@dimen/activity_margin"
android:paddingBottom="@dimen/normal_margin">
android:paddingBottom="@dimen/normal_margin"
app:layout_constraintTop_toBottomOf="@+id/archives_holder">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/others_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/others_size"
android:text="@string/others"
android:textSize="@dimen/bigger_text_size" />
@ -300,6 +314,44 @@
android:max="100"
app:trackThickness="2dp" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/search_holder"
android:layout_width="match_parent"
android:layout_height="0dp"
android:alpha="0"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/search_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:alpha="0.8"
android:gravity="center"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin"
android:text="@string/no_items_found"
android:textSize="@dimen/bigger_text_size"
android:textStyle="italic"
android:visibility="gone" />
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/search_results_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:clipToPadding="false"
android:layoutAnimation="@anim/layout_animation"
android:paddingTop="@dimen/small_margin"
android:scrollbars="none"
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</com.simplemobiletools.filemanager.pro.fragments.StorageFragment>