Skip to content

Commit 91b4271

Browse files
v1.5.0
1 parent a2489a3 commit 91b4271

30 files changed

Lines changed: 765 additions & 801 deletions

README.md

Lines changed: 64 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,31 @@ This documentation guides you on how to integrate and use the `FileTree` library
2222

2323
**4. Customizing Icons**
2424

25-
**5. Asynchronous File System**
25+
**5. AttributeSet**
2626

27-
**6. Example (Android View-Based)**
27+
**6. Asynchronous File System**
2828

29-
**7. Frequently Asked Questions (FAQ)**
29+
**7. Example (Android View-Based)**
3030

3131
**8. License.**
3232

3333
## 1. Introduction
3434

35-
The `FileTree` library provides a robust and modular way to manage and display file trees within your IDEs and code editors. It offers the following key features:
35+
The `FileTree` library offers a comprehensive and modular solution for managing and displaying file trees within IDEs and code editors. It is designed to provide the following key features:
3636

37-
- **Hierarchical File Tree Representation:** Presents files and folders in a hierarchical tree structure.
37+
- **Hierarchical File Tree Representation:** Displays files and folders in an organized hierarchical tree structure.
3838

39-
- **Hover-Navigated Directory**: Highlights directories as users navigate through them by clicking. This feature enhances user experience by visually indicating the current directory and providing a clear, interactive method for exploring the directory tree.
39+
- **Hover-Navigated Directory:** Highlights directories as users navigate through them with clicks. This feature enhances user experience by visually indicating the current directory, offering a clear and interactive method for exploring the directory tree.
4040

41-
- **Lazy Loading:** Optimizes loading time by only loading child nodes when expanded.
41+
- **Lazy Loading:** Improves loading time by loading child nodes only when they are expanded.
4242

43-
- **Asynchronous File System:** Performs file functions like expanding, collapsing, loading files in `FileTree`, etc. in the background thread to avoid blocking the Main UI Thread.
43+
- **Asynchronous File System:** Executes file operations like expanding, collapsing, and loading files in the `FileTree` on a background thread, preventing the Main UI Thread from being blocked.
4444

45-
- **Customizable Icons:** Allows you to set custom icons for files and folders.
45+
- **Customizable Icons:** Enables the use of custom icons for files and folders.
4646

47-
- **Flexibility:** Integrates seamlessly with various IDE UI frameworks (Android Views, Swing, SWT, Jetpack Compose).
47+
- **Concurrent FileMap:** Maintains a record of recently accessed files and directories, facilitating quick access to previously expanded files and directories.
48+
49+
- **RecyclerItemView:** Utilizes the built-in RecycledViewPool of RecyclerView to reuse old views, reducing memory usage by avoiding the creation of new views.
4850

4951
### Overview
5052

@@ -72,37 +74,19 @@ The specific instructions for adding a dependency will depend on your IDE and bu
7274

7375
### 2.2. Initialization and Loading
7476

75-
**1. Create an Instance:** Instantiate a `FileTree` object, providing the root directory:
76-
77-
```kotlin
78-
val fileTree = FileTree(this, "/storage/emulated/0")
79-
```
80-
81-
**2. Load the FileTree:** Call the `loadFileTree()` method to load the initial file tree structure. This will load the root directory and its immediate children:
77+
**1. Initialize:** Instantiate a `FileTree` object, providing the root directory:
8278

8379
```kotlin
84-
fileTree.loadFileTree()
80+
fileTreeView.initializeFileTree(this, "/storage/emulated/0")
8581
```
8682
### 2.3. UI Integration
8783

88-
This step involves integrating the `FileTree` library with your IDE's UI framework. The specific implementation will vary depending on your chosen UI framework. Below are common frameworks with basic examples:
84+
This step involves integrating the `FileTree` Library within your project, here's a basic example using Android Views:
8985

9086
- **Android View-Based (Android/Kotlin/Java):** Define `FileTreeView` in your Layout (XML) to display your `FileTree` data.
9187

9288
Docs [Getting Sarted](docs/integration/Android.md)
9389

94-
- **Jetpack Compose (Android/Kotlin):** Define a composable that renders the file tree using your `FileTree` data.
95-
96-
Docs [Getting Sarted](docs/integration/Android-Jetpack-Compose.md)
97-
98-
- **Swing (Java):** Use a `JTree` component and create a custom TreeModel that uses the `FileTreeNode` data from your `FileTree` object.
99-
100-
Docs [Getting Sarted](docs/integration/Java-Swing.md)
101-
102-
- **SWT (Java):** Similar to Swing, use a `TreeViewer` and a custom `TreeContentProvider` to map your `FileTreeNode` data.
103-
104-
Docs [Getting Sarted](docs/integration/Java-SWT.md)
105-
10690
### 2.4. Event Handling
10791

10892
The `FileTree` library provides events that you can use to react to user actions within the file tree:
@@ -151,22 +135,29 @@ import java.io.File
151135

152136
class FileIconProvider : FileTreeIconProvider {
153137

154-
override fun getChevronExpandIcon(): Int {
155-
return R.drawable.ic_chevron_expand
156-
}
157-
158-
override fun getChevronCollapseIcon(): Int {
159-
return R.drawable.ic_chevron_collapse
138+
override fun getChevronIcon(): Int {
139+
return R.drawable.ic_chevron
160140
}
161141

162-
override fun getFolderIcon(): Int {
142+
override fun getDefaultFolderIcon(): Int {
163143
return R.drawable.ic_folder
164144
}
165145

166146
override fun getDefaultFileIcon(): Int {
167147
return R.drawable.ic_file
168148
}
169149

150+
override fun getIconForFolder(folder: File): Int {
151+
return when (folder.name) {
152+
"app" -> R.drawable.ic_folder
153+
"src" -> R.drawable.ic_folder
154+
"kotlin" -> R.drawable.ic_folder
155+
"java" -> R.drawable.ic_folder
156+
"res" -> R.drawable.ic_folder
157+
else -> getDefaultFolderIcon()
158+
}
159+
}
160+
170161
override fun getIconForFile(file: File): Int {
171162
return when (file.name) {
172163
"gradlew.bat" -> R.drawable.ic_gradlewbat
@@ -189,11 +180,43 @@ class FileIconProvider : FileTreeIconProvider {
189180
}
190181
```
191182

192-
## 5. Asynchronous File System
183+
## 5. AttributeSet
184+
185+
| Attribute Name | Description | Default Value | XML Attribute | Type |
186+
|---------------------------|-------------------------------------------------------------------------------------------------|---------------|---------------------------------|---------|
187+
| **recyclerItemViewCount** | Defines the maximum number of items the RecyclerView can hold in its recycled view pool. | 200 | `app:recyclerItemViewCount` | Integer |
188+
| **recyclerItemViewEnabled** | Enables or disables the use of a recycled view pool for the RecyclerView. | true | `app:recyclerItemViewEnabled` | Boolean |
189+
| **itemViewCacheSize** | Sets the maximum size for the view cache in the RecyclerView. | 100 | `app:itemViewCacheSize` | Integer |
190+
| **itemViewCachingEnabled** | Enables or disables caching of item views in the RecyclerView. | true | `app:itemViewCachingEnabled` | Boolean |
191+
| **fileMapMaxSize** | Specifies the maximum number of entries in the file map, which caches recently accessed files and directories. | 150 | `app:fileMapMaxSize` | Integer |
192+
| **fileMapEnabled** | Enables or disables the file map functionality. | true | `app:fileMapEnabled` | Boolean |
193+
| **fileTreeAnimation** | Sets the animation style for expanding and collapsing the file tree. | 4 | `app:fileTreeAnimation` | Integer |
194+
| **fileTreeAnimationEnabled** | Enables or disables animations for the file tree. | true | `app:fileTreeAnimationEnabled` | Boolean |
195+
196+
### Usage Example
197+
198+
To configure these attributes in your XML layout file, use the following syntax:
199+
200+
```xml
201+
<com.zyron.filetree.widget.FileTreeView
202+
android:layout_width="match_parent"
203+
android:layout_height="match_parent"
204+
app:recyclerItemViewCount="250"
205+
app:recyclerItemViewEnabled="true"
206+
app:itemViewCacheSize="120"
207+
app:itemViewCachingEnabled="true"
208+
app:fileMapMaxSize="180"
209+
app:fileMapEnabled="true"
210+
app:fileTreeAnimation="FallDown"
211+
app:fileTreeAnimationEnabled="false"/>
212+
```
213+
Adjust these values according to your application's needs to optimize performance and user experience.
214+
215+
## 6. Asynchronous File System
193216

194217
The `FileTree` library typically uses a built-in asynchronous system powered by Kotlin Coroutines to perform core file functions such as expanding, collapsing and loading files in `FileTree` on the background thread. This ensures that the UI thread remains responsive while the functions are executed.
195218

196-
## 6. Example (Android view-based)
219+
## 7. Example (Android view-based)
197220

198221
Here's a basic example of using the `FileTree` library with Android views:
199222

@@ -234,24 +257,6 @@ class MainActivity : AppCompatActivity() {
234257
}
235258
```
236259

237-
## 7. Frequently Asked Questions (FAQ)
238-
239-
**Q:** How do I get the selected file or folder in the file tree?
240-
241-
**A:** Use the event listener for node selection to retrieve the selected node. The selected node will likely represent the FileTreeNode object that you can use to access the underlying File object.
242-
243-
**Q:** How do I refresh the file tree after making changes to the file system?
244-
245-
**A:** Use the `loadFileTree()` method to reload the tree structure. If you only need to update a portion of the tree, you can refresh specific nodes or sections.
246-
247-
**Q:** Can I customize the appearance of the file tree?
248-
249-
**A:** Yes, you can customize the appearance by using custom renderers (Swing, SWT) or composables (Jetpack Compose) to control the display of nodes.
250-
251-
**Q:** Can I use the `FileTree` library for other purposes besides IDEs and Code Editors?
252-
253-
**A:** Yes, the library can be adapted for other applications that require file tree management, such as file explorers or project management tools.
254-
255260
## 8. License
256261
```
257262
Copyright 2024 Zyron Official.
@@ -267,4 +272,4 @@ distributed under the License is distributed on an "AS IS" BASIS,
267272
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
268273
See the License for the specific language governing permissions and
269274
limitations under the License.
270-
```
275+
```

app/build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ plugins {
66
android {
77
namespace 'com.zyron.filetree'
88
compileSdk 34
9-
9+
1010
defaultConfig {
1111
applicationId "com.zyron.filetree"
12-
minSdk 26
12+
minSdk 29
1313
targetSdk 34
14-
versionCode 1
15-
versionName "1.0.0"
16-
14+
versionCode 2
15+
versionName "1.5.0"
16+
1717
vectorDrawables {
1818
useSupportLibrary true
1919
}
@@ -33,7 +33,7 @@ android {
3333

3434
buildFeatures {
3535
viewBinding true
36-
36+
3737
}
3838
}
3939

@@ -45,4 +45,4 @@ dependencies {
4545
implementation 'androidx.core:core-ktx:1.13.1'
4646
implementation 'androidx.recyclerview:recyclerview:1.3.2'
4747
implementation 'androidx.preference:preference-ktx:1.2.1'
48-
}
48+
}

app/src/main/kotlin/com/zyron/filetree/executorservice/FileOperationExecutor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.zyron.filetree.executorservice
22

33
import android.content.Context
44
import android.widget.Toast
5-
import com.zyron.filetree.interfaces.FileTreeEventListener
5+
import com.zyron.filetree.events.FileTreeEventListener
66
import java.io.File
77

88
class FileOperationExecutor(private val context: Context) : FileTreeEventListener {

app/src/main/res/layout/activity_main.xml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.drawerlayout.widget.DrawerLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools"
56
android:id="@+id/drawer_layout"
@@ -39,17 +40,33 @@
3940

4041
<com.google.android.material.navigation.NavigationView
4142
android:id="@+id/navigation_view"
42-
android:layout_width="348dp"
43+
android:layout_width="300dp"
4344
android:layout_height="match_parent"
4445
app:drawerLayoutCornerSize="4dp"
4546
android:padding="8dp"
4647
android:layout_gravity="start"
4748
style="@style/Widget.Material3.NavigationView">
48-
49-
<com.zyron.filetree.widget.FileTreeView
50-
android:id="@+id/file_tree_view"
49+
50+
<HorizontalScrollView
5151
android:layout_width="match_parent"
52-
android:layout_height="match_parent"/>
52+
android:layout_height="match_parent"
53+
android:scrollbarSize="0dp"
54+
android:fillViewport="true">
55+
56+
<androidx.core.widget.NestedScrollView
57+
android:layout_width="match_parent"
58+
android:layout_height="match_parent"
59+
android:fillViewport="true">
60+
61+
<com.zyron.filetree.widget.FileTreeView
62+
android:id="@+id/file_tree_view"
63+
android:layout_width="match_parent"
64+
android:layout_height="wrap_content"
65+
app:fileTreeAnimation="FallDown"/>
66+
67+
</androidx.core.widget.NestedScrollView>
68+
69+
</HorizontalScrollView>
5370

5471
</com.google.android.material.navigation.NavigationView>
5572

docs/integration/Android-Jetpack-Compose.md

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)