@@ -12,10 +12,12 @@ import com.ismartcoding.lib.extensions.getParentPath
1212import com.ismartcoding.lib.extensions.scanFileByConnection
1313import com.ismartcoding.lib.helpers.CoroutinesHelper.withIO
1414import com.ismartcoding.plain.MainApp
15+ import com.ismartcoding.plain.R
1516import com.ismartcoding.plain.enums.FilesType
1617import com.ismartcoding.plain.features.file.DFile
1718import com.ismartcoding.plain.features.file.FileSortBy
1819import com.ismartcoding.plain.features.file.FileSystemHelper
20+ import com.ismartcoding.plain.features.locale.LocaleHelper
1921import com.ismartcoding.plain.features.media.FileMediaStoreHelper
2022import com.ismartcoding.plain.preference.FilePathData
2123import com.ismartcoding.plain.preference.LastFilePathPreference
@@ -60,7 +62,7 @@ class FilesViewModel : ISearchableViewModel<DFile>, ISelectableViewModel<DFile>,
6062 }
6163 }
6264
63- val breadcrumbs = mutableStateListOf( BreadcrumbItem ( FileSystemHelper .getInternalStorageName(), root) )
65+ val breadcrumbs = mutableStateListOf< BreadcrumbItem >( )
6466 val selectedBreadcrumbIndex = mutableIntStateOf(0 )
6567 var cutFiles = mutableListOf<DFile >()
6668 var copyFiles = mutableListOf<DFile >()
@@ -71,6 +73,11 @@ class FilesViewModel : ISearchableViewModel<DFile>, ISelectableViewModel<DFile>,
7173
7274 private val navigationHistory = Stack <String >()
7375
76+ init {
77+ // Initialize with default breadcrumb - will be updated when loadLastPathAsync is called
78+ breadcrumbs.add(BreadcrumbItem (getRootDisplayName(), root))
79+ }
80+
7481 val selectedFile = mutableStateOf<DFile ?>(null )
7582 val showRenameDialog = mutableStateOf(false )
7683
@@ -125,6 +132,8 @@ class FilesViewModel : ISearchableViewModel<DFile>, ISelectableViewModel<DFile>,
125132 val data = LastFilePathPreference .getValueAsync(context)
126133 if (data.selectedPath.isNotEmpty() && File (data.selectedPath).exists()) {
127134 root = data.rootPath
135+ // Infer the file system type from the root path
136+ type = inferFileTypeFromRoot(context, data.rootPath)
128137 // Restore complete breadcrumbs from fullPath
129138 rebuildBreadcrumbs(data.fullPath)
130139 _path = data.selectedPath
@@ -134,12 +143,31 @@ class FilesViewModel : ISearchableViewModel<DFile>, ISelectableViewModel<DFile>,
134143 selectedBreadcrumbIndex.value = breadcrumbs.size - 1
135144 }
136145 navigationHistory.clear()
146+ } else {
147+ // No saved path, but still infer the type based on current root
148+ type = inferFileTypeFromRoot(context, root)
149+ updateRootBreadcrumb()
150+ }
151+ }
152+
153+ private fun inferFileTypeFromRoot (context : Context , rootPath : String ): FilesType {
154+ val internalStoragePath = FileSystemHelper .getInternalStoragePath()
155+ val appDataPath = FileSystemHelper .getExternalFilesDirPath(context)
156+ val sdCardPath = FileSystemHelper .getSDCardPath(context)
157+ val usbPaths = FileSystemHelper .getUsbDiskPaths()
158+
159+ return when {
160+ rootPath == appDataPath -> FilesType .APP
161+ rootPath == sdCardPath -> FilesType .SDCARD
162+ usbPaths.contains(rootPath) -> FilesType .USB_STORAGE
163+ rootPath == internalStoragePath -> FilesType .INTERNAL_STORAGE
164+ else -> FilesType .INTERNAL_STORAGE // default fallback
137165 }
138166 }
139167
140168 private fun rebuildBreadcrumbs (targetPath : String ) {
141169 breadcrumbs.clear()
142- breadcrumbs.add(BreadcrumbItem (FileSystemHelper .getInternalStorageName (), root))
170+ breadcrumbs.add(BreadcrumbItem (getRootDisplayName (), root))
143171
144172 if (targetPath != root) {
145173 val relativePath = targetPath.removePrefix(root).trim(' /' )
@@ -155,6 +183,22 @@ class FilesViewModel : ISearchableViewModel<DFile>, ISelectableViewModel<DFile>,
155183 selectedBreadcrumbIndex.value = breadcrumbs.size - 1
156184 }
157185
186+ fun getRootDisplayName (): String {
187+ return when (type) {
188+ FilesType .INTERNAL_STORAGE -> FileSystemHelper .getInternalStorageName()
189+ FilesType .APP -> LocaleHelper .getString(R .string.app_data)
190+ FilesType .SDCARD -> LocaleHelper .getString(R .string.sdcard)
191+ FilesType .USB_STORAGE -> LocaleHelper .getString(R .string.usb_storage)
192+ FilesType .RECENTS -> LocaleHelper .getString(R .string.recents)
193+ }
194+ }
195+
196+ fun updateRootBreadcrumb () {
197+ if (breadcrumbs.isNotEmpty()) {
198+ breadcrumbs[0 ] = BreadcrumbItem (getRootDisplayName(), root)
199+ }
200+ }
201+
158202 // Check if we can navigate back
159203 fun canNavigateBack (): Boolean {
160204 return navigationHistory.isNotEmpty()
0 commit comments