Skip to content

Commit

Permalink
Merge branch 'release/4.0' of ssh://github.com/TeamAmaze/AmazeFileMan…
Browse files Browse the repository at this point in the history
…ager into release/3.10
  • Loading branch information
VishalNehra committed Feb 15, 2024
2 parents 711f18b + 8e91233 commit 193a4ba
Show file tree
Hide file tree
Showing 45 changed files with 2,654 additions and 1,723 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ We strongly recommend using apk signed by us (either Play Store version or from
### License:

Copyright (C) 2014-2018 Arpit Khurana <[email protected]>
Copyright (C) 2014-2021 Vishal Nehra <[email protected]>
Copyright (C) 2017-2021 Emmanuel Messulam <[email protected]>
Copyright (C) 2018-2021 Raymond Lai <airwave209gt at gmail.com>
Copyright (C) 2014-2023 Vishal Nehra <[email protected]>
Copyright (C) 2017-2023 Emmanuel Messulam <[email protected]>
Copyright (C) 2018-2023 Raymond Lai <airwave209gt at gmail.com>
Copyright (C) 2019-2023 Vishnu Sanal T <t.v.s10123 at gmail.com>
This file is part of Amaze File Manager.
Amaze File Manager is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ dependencies {
testImplementation "org.jsoup:jsoup:$jsoupVersion"
testImplementation "androidx.room:room-migration:$roomVersion"
testImplementation "io.mockk:mockk:$mockkVersion"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutineTestVersion"
testImplementation "androidx.arch.core:core-testing:$androidXArchCoreTestVersion"
kaptTest "com.google.auto.service:auto-service:1.0-rc4"

androidTestImplementation "junit:junit:$junitVersion"//tests the app logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
package com.amaze.filemanager.adapters

import android.content.Context
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -31,27 +34,30 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.amaze.filemanager.R
import com.amaze.filemanager.application.AppConfig
import com.amaze.filemanager.filesystem.HybridFileParcelable
import com.amaze.filemanager.asynchronous.asynctasks.searchfilesystem.SearchResult
import com.amaze.filemanager.ui.activities.MainActivity
import com.amaze.filemanager.ui.colors.ColorPreference
import java.util.Random

class SearchRecyclerViewAdapter :
ListAdapter<HybridFileParcelable, SearchRecyclerViewAdapter.ViewHolder>(
ListAdapter<SearchResult, SearchRecyclerViewAdapter.ViewHolder>(

object : DiffUtil.ItemCallback<HybridFileParcelable>() {
object : DiffUtil.ItemCallback<SearchResult>() {
override fun areItemsTheSame(
oldItem: HybridFileParcelable,
newItem: HybridFileParcelable
oldItem: SearchResult,
newItem: SearchResult
): Boolean {
return oldItem.path == newItem.path && oldItem.name == newItem.name
return oldItem.file.path == newItem.file.path &&
oldItem.file.name == newItem.file.name
}

override fun areContentsTheSame(
oldItem: HybridFileParcelable,
newItem: HybridFileParcelable
oldItem: SearchResult,
newItem: SearchResult
): Boolean {
return oldItem.path == newItem.path && oldItem.name == newItem.name
return oldItem.file.path == newItem.file.path &&
oldItem.file.name == newItem.file.name &&
oldItem.matchRange == newItem.matchRange
}
}
) {
Expand All @@ -62,17 +68,25 @@ class SearchRecyclerViewAdapter :
}

override fun onBindViewHolder(holder: SearchRecyclerViewAdapter.ViewHolder, position: Int) {
val item = getItem(position)

holder.fileNameTV.text = item.name
holder.filePathTV.text = item.path.substring(0, item.path.lastIndexOf("/"))

holder.colorView.setBackgroundColor(getRandomColor(holder.colorView.context))
val (file, matchResult) = getItem(position)

val colorPreference =
(AppConfig.getInstance().mainActivityContext as MainActivity).currentColorPreference

if (item.isDirectory) {
val fileName = SpannableString(file.name)
fileName.setSpan(
ForegroundColorSpan(colorPreference.accent),
matchResult.first,
matchResult.last + 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)

holder.fileNameTV.text = fileName
holder.filePathTV.text = file.path.substring(0, file.path.lastIndexOf("/"))

holder.colorView.setBackgroundColor(getRandomColor(holder.colorView.context))

if (file.isDirectory) {
holder.colorView.setBackgroundColor(colorPreference.primaryFirstTab)
} else {
holder.colorView.setBackgroundColor(colorPreference.accent)
Expand All @@ -93,16 +107,16 @@ class SearchRecyclerViewAdapter :

view.setOnClickListener {

val item = getItem(adapterPosition)
val (file, _) = getItem(adapterPosition)

if (!item.isDirectory) {
item.openFile(
if (!file.isDirectory) {
file.openFile(
AppConfig.getInstance().mainActivityContext as MainActivity?,
false
)
} else {
(AppConfig.getInstance().mainActivityContext as MainActivity?)
?.goToMain(item.path)
?.goToMain(file.path)
}

(AppConfig.getInstance().mainActivityContext as MainActivity?)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2014-2024 Arpit Khurana <[email protected]>, Vishal Nehra <[email protected]>,
* Emmanuel Messulam<[email protected]>, Raymond Lai <airwave209gt at gmail.com> and Contributors.
*
* This file is part of Amaze File Manager.
*
* Amaze File Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.amaze.filemanager.asynchronous.asynctasks.searchfilesystem

import android.content.Context
import com.amaze.filemanager.filesystem.HybridFileParcelable
import com.amaze.filemanager.filesystem.root.ListFilesCommand.listFiles

class BasicSearch(
query: String,
path: String,
searchParameters: SearchParameters,
context: Context
) : FileSearch(query, path, searchParameters) {
private val applicationContext = context.applicationContext

override suspend fun search(filter: SearchFilter) {
listFiles(
path,
SearchParameter.ROOT in searchParameters,
SearchParameter.SHOW_HIDDEN_FILES in searchParameters,
{ }
) { hybridFileParcelable: HybridFileParcelable ->
if (SearchParameter.SHOW_HIDDEN_FILES in searchParameters ||
!hybridFileParcelable.isHidden
) {
val resultRange =
filter.searchFilter(hybridFileParcelable.getName(applicationContext))
if (resultRange != null) {
publishProgress(hybridFileParcelable, resultRange)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2014-2024 Arpit Khurana <[email protected]>, Vishal Nehra <[email protected]>,
* Emmanuel Messulam<[email protected]>, Raymond Lai <airwave209gt at gmail.com> and Contributors.
*
* This file is part of Amaze File Manager.
*
* Amaze File Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.amaze.filemanager.asynchronous.asynctasks.searchfilesystem

import android.content.Context
import com.amaze.filemanager.fileoperations.filesystem.OpenMode
import com.amaze.filemanager.filesystem.HybridFile
import kotlinx.coroutines.isActive
import org.slf4j.LoggerFactory
import kotlin.coroutines.coroutineContext

class DeepSearch(
query: String,
path: String,
searchParameters: SearchParameters,
context: Context,
private val openMode: OpenMode
) : FileSearch(query, path, searchParameters) {
private val LOG = LoggerFactory.getLogger(DeepSearch::class.java)

private val applicationContext: Context

init {
applicationContext = context.applicationContext
}

/**
* Search for occurrences of a given text in file names and publish the result
*
* @param directory the current path
*/
override suspend fun search(filter: SearchFilter) {
val directory = HybridFile(openMode, path)
if (directory.isSmb) return

if (directory.isDirectory(applicationContext)) {
// you have permission to read this directory
val worklist = ArrayDeque<HybridFile>()
worklist.add(directory)
while (coroutineContext.isActive && worklist.isNotEmpty()) {
val nextFile = worklist.removeFirst()
nextFile.forEachChildrenFile(
applicationContext,
SearchParameter.ROOT in searchParameters
) { file ->
if (!file.isHidden || SearchParameter.SHOW_HIDDEN_FILES in searchParameters) {
val resultRange = filter.searchFilter(file.getName(applicationContext))
if (resultRange != null) {
publishProgress(file, resultRange)
}
if (file.isDirectory(applicationContext)) {
worklist.add(file)
}
}
}
}
} else {
LOG.warn("Cannot search " + directory.path + ": Permission Denied")
}
}
}
Loading

0 comments on commit 193a4ba

Please sign in to comment.