Skip to content

Commit 193a4ba

Browse files
committed
Merge branch 'release/4.0' of ssh://github.com/TeamAmaze/AmazeFileManager into release/3.10
2 parents 711f18b + 8e91233 commit 193a4ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2654
-1723
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ We strongly recommend using apk signed by us (either Play Store version or from
8585
### License:
8686

8787
Copyright (C) 2014-2018 Arpit Khurana <arpitkh96@gmail.com>
88-
Copyright (C) 2014-2021 Vishal Nehra <vishalmeham2@gmail.com>
89-
Copyright (C) 2017-2021 Emmanuel Messulam <emmanuelbendavid@gmail.com>
90-
Copyright (C) 2018-2021 Raymond Lai <airwave209gt at gmail.com>
88+
Copyright (C) 2014-2023 Vishal Nehra <vishalmeham2@gmail.com>
89+
Copyright (C) 2017-2023 Emmanuel Messulam <emmanuelbendavid@gmail.com>
90+
Copyright (C) 2018-2023 Raymond Lai <airwave209gt at gmail.com>
91+
Copyright (C) 2019-2023 Vishnu Sanal T <t.v.s10123 at gmail.com>
9192
This file is part of Amaze File Manager.
9293
Amaze File Manager is free software: you can redistribute it and/or modify
9394
it under the terms of the GNU General Public License as published by

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ dependencies {
151151
testImplementation "org.jsoup:jsoup:$jsoupVersion"
152152
testImplementation "androidx.room:room-migration:$roomVersion"
153153
testImplementation "io.mockk:mockk:$mockkVersion"
154+
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutineTestVersion"
155+
testImplementation "androidx.arch.core:core-testing:$androidXArchCoreTestVersion"
154156
kaptTest "com.google.auto.service:auto-service:1.0-rc4"
155157

156158
androidTestImplementation "junit:junit:$junitVersion"//tests the app logic

app/src/main/java/com/amaze/filemanager/adapters/SearchRecyclerViewAdapter.kt

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
package com.amaze.filemanager.adapters
2222

2323
import android.content.Context
24+
import android.text.Spannable
25+
import android.text.SpannableString
26+
import android.text.style.ForegroundColorSpan
2427
import android.view.LayoutInflater
2528
import android.view.View
2629
import android.view.ViewGroup
@@ -31,27 +34,30 @@ import androidx.recyclerview.widget.ListAdapter
3134
import androidx.recyclerview.widget.RecyclerView
3235
import com.amaze.filemanager.R
3336
import com.amaze.filemanager.application.AppConfig
34-
import com.amaze.filemanager.filesystem.HybridFileParcelable
37+
import com.amaze.filemanager.asynchronous.asynctasks.searchfilesystem.SearchResult
3538
import com.amaze.filemanager.ui.activities.MainActivity
3639
import com.amaze.filemanager.ui.colors.ColorPreference
3740
import java.util.Random
3841

3942
class SearchRecyclerViewAdapter :
40-
ListAdapter<HybridFileParcelable, SearchRecyclerViewAdapter.ViewHolder>(
43+
ListAdapter<SearchResult, SearchRecyclerViewAdapter.ViewHolder>(
4144

42-
object : DiffUtil.ItemCallback<HybridFileParcelable>() {
45+
object : DiffUtil.ItemCallback<SearchResult>() {
4346
override fun areItemsTheSame(
44-
oldItem: HybridFileParcelable,
45-
newItem: HybridFileParcelable
47+
oldItem: SearchResult,
48+
newItem: SearchResult
4649
): Boolean {
47-
return oldItem.path == newItem.path && oldItem.name == newItem.name
50+
return oldItem.file.path == newItem.file.path &&
51+
oldItem.file.name == newItem.file.name
4852
}
4953

5054
override fun areContentsTheSame(
51-
oldItem: HybridFileParcelable,
52-
newItem: HybridFileParcelable
55+
oldItem: SearchResult,
56+
newItem: SearchResult
5357
): Boolean {
54-
return oldItem.path == newItem.path && oldItem.name == newItem.name
58+
return oldItem.file.path == newItem.file.path &&
59+
oldItem.file.name == newItem.file.name &&
60+
oldItem.matchRange == newItem.matchRange
5561
}
5662
}
5763
) {
@@ -62,17 +68,25 @@ class SearchRecyclerViewAdapter :
6268
}
6369

6470
override fun onBindViewHolder(holder: SearchRecyclerViewAdapter.ViewHolder, position: Int) {
65-
val item = getItem(position)
66-
67-
holder.fileNameTV.text = item.name
68-
holder.filePathTV.text = item.path.substring(0, item.path.lastIndexOf("/"))
69-
70-
holder.colorView.setBackgroundColor(getRandomColor(holder.colorView.context))
71+
val (file, matchResult) = getItem(position)
7172

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

75-
if (item.isDirectory) {
76+
val fileName = SpannableString(file.name)
77+
fileName.setSpan(
78+
ForegroundColorSpan(colorPreference.accent),
79+
matchResult.first,
80+
matchResult.last + 1,
81+
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
82+
)
83+
84+
holder.fileNameTV.text = fileName
85+
holder.filePathTV.text = file.path.substring(0, file.path.lastIndexOf("/"))
86+
87+
holder.colorView.setBackgroundColor(getRandomColor(holder.colorView.context))
88+
89+
if (file.isDirectory) {
7690
holder.colorView.setBackgroundColor(colorPreference.primaryFirstTab)
7791
} else {
7892
holder.colorView.setBackgroundColor(colorPreference.accent)
@@ -93,16 +107,16 @@ class SearchRecyclerViewAdapter :
93107

94108
view.setOnClickListener {
95109

96-
val item = getItem(adapterPosition)
110+
val (file, _) = getItem(adapterPosition)
97111

98-
if (!item.isDirectory) {
99-
item.openFile(
112+
if (!file.isDirectory) {
113+
file.openFile(
100114
AppConfig.getInstance().mainActivityContext as MainActivity?,
101115
false
102116
)
103117
} else {
104118
(AppConfig.getInstance().mainActivityContext as MainActivity?)
105-
?.goToMain(item.path)
119+
?.goToMain(file.path)
106120
}
107121

108122
(AppConfig.getInstance().mainActivityContext as MainActivity?)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (C) 2014-2024 Arpit Khurana <arpitkh96@gmail.com>, Vishal Nehra <vishalmeham2@gmail.com>,
3+
* Emmanuel Messulam<emmanuelbendavid@gmail.com>, Raymond Lai <airwave209gt at gmail.com> and Contributors.
4+
*
5+
* This file is part of Amaze File Manager.
6+
*
7+
* Amaze File Manager is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
package com.amaze.filemanager.asynchronous.asynctasks.searchfilesystem
22+
23+
import android.content.Context
24+
import com.amaze.filemanager.filesystem.HybridFileParcelable
25+
import com.amaze.filemanager.filesystem.root.ListFilesCommand.listFiles
26+
27+
class BasicSearch(
28+
query: String,
29+
path: String,
30+
searchParameters: SearchParameters,
31+
context: Context
32+
) : FileSearch(query, path, searchParameters) {
33+
private val applicationContext = context.applicationContext
34+
35+
override suspend fun search(filter: SearchFilter) {
36+
listFiles(
37+
path,
38+
SearchParameter.ROOT in searchParameters,
39+
SearchParameter.SHOW_HIDDEN_FILES in searchParameters,
40+
{ }
41+
) { hybridFileParcelable: HybridFileParcelable ->
42+
if (SearchParameter.SHOW_HIDDEN_FILES in searchParameters ||
43+
!hybridFileParcelable.isHidden
44+
) {
45+
val resultRange =
46+
filter.searchFilter(hybridFileParcelable.getName(applicationContext))
47+
if (resultRange != null) {
48+
publishProgress(hybridFileParcelable, resultRange)
49+
}
50+
}
51+
}
52+
}
53+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (C) 2014-2024 Arpit Khurana <arpitkh96@gmail.com>, Vishal Nehra <vishalmeham2@gmail.com>,
3+
* Emmanuel Messulam<emmanuelbendavid@gmail.com>, Raymond Lai <airwave209gt at gmail.com> and Contributors.
4+
*
5+
* This file is part of Amaze File Manager.
6+
*
7+
* Amaze File Manager is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
package com.amaze.filemanager.asynchronous.asynctasks.searchfilesystem
22+
23+
import android.content.Context
24+
import com.amaze.filemanager.fileoperations.filesystem.OpenMode
25+
import com.amaze.filemanager.filesystem.HybridFile
26+
import kotlinx.coroutines.isActive
27+
import org.slf4j.LoggerFactory
28+
import kotlin.coroutines.coroutineContext
29+
30+
class DeepSearch(
31+
query: String,
32+
path: String,
33+
searchParameters: SearchParameters,
34+
context: Context,
35+
private val openMode: OpenMode
36+
) : FileSearch(query, path, searchParameters) {
37+
private val LOG = LoggerFactory.getLogger(DeepSearch::class.java)
38+
39+
private val applicationContext: Context
40+
41+
init {
42+
applicationContext = context.applicationContext
43+
}
44+
45+
/**
46+
* Search for occurrences of a given text in file names and publish the result
47+
*
48+
* @param directory the current path
49+
*/
50+
override suspend fun search(filter: SearchFilter) {
51+
val directory = HybridFile(openMode, path)
52+
if (directory.isSmb) return
53+
54+
if (directory.isDirectory(applicationContext)) {
55+
// you have permission to read this directory
56+
val worklist = ArrayDeque<HybridFile>()
57+
worklist.add(directory)
58+
while (coroutineContext.isActive && worklist.isNotEmpty()) {
59+
val nextFile = worklist.removeFirst()
60+
nextFile.forEachChildrenFile(
61+
applicationContext,
62+
SearchParameter.ROOT in searchParameters
63+
) { file ->
64+
if (!file.isHidden || SearchParameter.SHOW_HIDDEN_FILES in searchParameters) {
65+
val resultRange = filter.searchFilter(file.getName(applicationContext))
66+
if (resultRange != null) {
67+
publishProgress(file, resultRange)
68+
}
69+
if (file.isDirectory(applicationContext)) {
70+
worklist.add(file)
71+
}
72+
}
73+
}
74+
}
75+
} else {
76+
LOG.warn("Cannot search " + directory.path + ": Permission Denied")
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)