Skip to content

Commit

Permalink
feat. added the ability to set custom file icon provider via TreeView
Browse files Browse the repository at this point in the history
  • Loading branch information
RohitKushvaha01 authored and Sheikh-Abdul-Aziz committed Aug 4, 2024
1 parent 288d062 commit 4296f44
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
7 changes: 7 additions & 0 deletions filetree/src/main/kotlin/com/zyron/filetree/FileTree.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.zyron.filetree

import android.content.Context
import android.util.Log
import kotlinx.coroutines.*
import kotlin.collections.*
import java.io.File
Expand All @@ -26,6 +27,12 @@ class FileTree(private val context: Context, private val rootDirectory: String)
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())

init {
val file = File(rootDirectory)
val rw = file.canRead() && file.canWrite()
if (!file.exists() || !rw){
Log.e("FileTree","Provided path : $rootDirectory is invalid or does not exist")
Log.d("FileTree","continuing anyways...")
}
scope.coroutineContext[Job]?.invokeOnCompletion {
if (it is CancellationException) {
}
Expand Down
25 changes: 19 additions & 6 deletions filetree/src/main/kotlin/com/zyron/filetree/TreeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.zyron.filetree.adapter.FileTreeAdapter
import com.zyron.filetree.adapter.FileTreeClickListener
import com.zyron.filetree.provider.FileTreeIconProvider
import com.zyron.filetree.utils.Utils.runOnUiThread

class TreeView : RecyclerView {
Expand All @@ -22,26 +23,38 @@ class TreeView : RecyclerView {
}

constructor(context: Context, attrs: AttributeSet?, defstyleAttrs: Int) : super(
context,
attrs,
defstyleAttrs
context, attrs, defstyleAttrs
) {
this.context = context
}


fun init(path: String) {
init(path, null)
init(path, null,null)
}

fun init(path: String, listener: FileTreeClickListener?) {
fun init(path: String,listener: FileTreeClickListener?){
init(path,listener,null)
}

fun init(
path: String,
listener: FileTreeClickListener?,
fileTreeIconProvider: FileTreeIconProvider?
) {
this.path = path
fileTree = FileTree(context, path)

val fileTreeAdapter = if (listener == null) {
FileTreeAdapter(context, fileTree!!)
} else {
FileTreeAdapter(context, fileTree!!, listener)
if (fileTreeIconProvider != null) {
FileTreeAdapter(context, fileTree!!,fileTreeIconProvider, listener)
}else{
FileTreeAdapter(context, fileTree!!, listener)
}
}

layoutManager = LinearLayoutManager(context)
adapter = fileTreeAdapter
fileTree!!.loadFileTree()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class FileTreeAdapter(private val context: Context, private val fileTree: FileTr
constructor(context: Context, fileTree: FileTree,listener: FileTreeClickListener? = null) : this(context,fileTree,
DefaultFileIconProvider(),listener)



private var selectedItemPosition: Int = RecyclerView.NO_POSITION
private var nodes: MutableList<FileTreeNode> = fileTree.getNodes().toMutableList()

Expand Down

0 comments on commit 4296f44

Please sign in to comment.