Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b421fdebf | ||
|
|
f89a320636 |
No files matched your search
@@ -4,12 +4,14 @@ An Android app for browsing SMB2/3 shares on a local network. It has a dark inte
|
||||
|
||||
The app is under active development. See [PLAN.md](PLAN.md) for the planned file actions, video playback, and further performance work.
|
||||
|
||||
The launcher icon's editable source is [artwork/app-icon.svg](artwork/app-icon.svg); Android uses matching vector drawables for the adaptive and monochrome icon.
|
||||
|
||||
## What works now
|
||||
|
||||
- Save multiple SMB connections after testing them. Credentials are encrypted with a device-bound Android Keystore key; app backup is disabled.
|
||||
- Browse folders, use breadcrumbs, search the current folder, filter by file type, sort by name/date/size, and refresh a listing.
|
||||
- Browse folders, use breadcrumbs, search the current folder, filter by file type, sort by name in either direction, newest/oldest, largest/smallest, or file type, and refresh a listing.
|
||||
- Open images and animated GIFs, then swipe through images in the same folder. The viewer reads at most 64 MB per file.
|
||||
- Reuse an SMB session while browsing, keep up to 20 recent folder listings in memory, and preload the next image in the viewer.
|
||||
- Reuse an SMB session while browsing and viewing images, keep up to 20 recent folder listings in memory, and preload nearby images in the viewer. Still images are decoded ahead of swipes within a bounded memory cache.
|
||||
|
||||
Video playback, downloads, deletion, thumbnails, and offline files are not implemented yet. Other files currently show their details.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<application android:label="SMB Explorer" android:allowBackup="false" android:usesCleartextTraffic="false" android:theme="@android:style/Theme.Material.NoActionBar">
|
||||
<application android:label="SMB Explorer" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:usesCleartextTraffic="false" android:theme="@android:style/Theme.Material.NoActionBar">
|
||||
<activity android:name=".MainActivity" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
@@ -32,6 +32,12 @@ class BrowseRepository(private val target: SmbTarget) {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun read(path: String): ByteArray = withContext(Dispatchers.IO) {
|
||||
mutex.withLock {
|
||||
(session ?: SmbShareSession(target).also { session = it }).read(path)
|
||||
}
|
||||
}
|
||||
|
||||
fun close() {
|
||||
scope.launch {
|
||||
mutex.withLock { session?.close(); session = null }
|
||||
|
||||
@@ -44,7 +44,12 @@ import kotlinx.coroutines.withContext
|
||||
import java.text.DateFormat
|
||||
import java.util.Date
|
||||
|
||||
private enum class SortMode { Name, Date, Size }
|
||||
private enum class SortMode(val label: String) {
|
||||
NameAsc("Name A–Z"), NameDesc("Name Z–A"),
|
||||
Newest("Newest first"), Oldest("Oldest first"),
|
||||
Largest("Largest first"), Smallest("Smallest first"),
|
||||
FileType("File type"),
|
||||
}
|
||||
private enum class FileFilter { All, Images, Videos, Other, Folders }
|
||||
|
||||
private val imageExtensions = setOf("jpg", "jpeg", "png", "gif", "webp", "heic", "heif", "bmp", "avif")
|
||||
@@ -69,7 +74,7 @@ fun BrowseScreen(saved: SavedShare, onConnections: () -> Unit) {
|
||||
var path by remember(saved.id) { mutableStateOf(saved.folder.trim('/', '\\').replace('/', '\\')) }
|
||||
var refresh by remember { mutableIntStateOf(0) }
|
||||
var search by remember { mutableStateOf("") }
|
||||
var sort by remember { mutableStateOf(SortMode.Name) }
|
||||
var sort by remember { mutableStateOf(SortMode.NameAsc) }
|
||||
var filter by remember { mutableStateOf(FileFilter.All) }
|
||||
var result by remember { mutableStateOf<ProbeResult?>(null) }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
@@ -102,8 +107,8 @@ fun BrowseScreen(saved: SavedShare, onConnections: () -> Unit) {
|
||||
|
||||
selectedImage?.let { image ->
|
||||
val images = result?.entries.orEmpty().filter { it.isImage() }
|
||||
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name })
|
||||
if (images.isNotEmpty()) ImageViewer(saved, path, images, image) { selectedImage = null }
|
||||
.sortedWith(sort.comparator())
|
||||
if (images.isNotEmpty()) ImageViewer(saved, repository, path, images, image) { selectedImage = null }
|
||||
return
|
||||
}
|
||||
|
||||
@@ -122,13 +127,7 @@ fun BrowseScreen(saved: SavedShare, onConnections: () -> Unit) {
|
||||
entries.asSequence()
|
||||
.filter { it.name.contains(search, ignoreCase = true) }
|
||||
.filter { filter.matches(it) }
|
||||
.sortedWith(compareByDescending<RemoteEntry> { it.directory }.then(
|
||||
when (sort) {
|
||||
SortMode.Name -> compareBy(String.CASE_INSENSITIVE_ORDER) { it.name }
|
||||
SortMode.Date -> compareByDescending { it.modifiedAt }
|
||||
SortMode.Size -> compareByDescending { it.size }
|
||||
},
|
||||
))
|
||||
.sortedWith(compareByDescending<RemoteEntry> { it.directory }.then(sort.comparator()))
|
||||
.toList()
|
||||
}
|
||||
}
|
||||
@@ -162,10 +161,10 @@ fun BrowseScreen(saved: SavedShare, onConnections: () -> Unit) {
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
if (loading && result != null) CircularProgressIndicator(Modifier.size(18.dp), strokeWidth = 2.dp)
|
||||
TextButton(onClick = { sortOpen = true }) { Text("Sort: ${sort.name} ▾") }
|
||||
TextButton(onClick = { sortOpen = true }) { Text("Sort: ${sort.label} ▾") }
|
||||
DropdownMenu(expanded = sortOpen, onDismissRequest = { sortOpen = false }) {
|
||||
SortMode.entries.forEach { option ->
|
||||
DropdownMenuItem(text = { Text(option.name) }, onClick = { sort = option; sortOpen = false })
|
||||
DropdownMenuItem(text = { Text(option.label) }, onClick = { sort = option; sortOpen = false })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,6 +194,21 @@ fun BrowseScreen(saved: SavedShare, onConnections: () -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun SortMode.comparator(): Comparator<RemoteEntry> {
|
||||
val byName = compareBy(String.CASE_INSENSITIVE_ORDER) { entry: RemoteEntry -> entry.name }
|
||||
return when (this) {
|
||||
SortMode.NameAsc -> byName
|
||||
SortMode.NameDesc -> byName.reversed()
|
||||
SortMode.Newest -> compareByDescending<RemoteEntry> { it.modifiedAt }.then(byName)
|
||||
SortMode.Oldest -> compareBy<RemoteEntry> { it.modifiedAt }.then(byName)
|
||||
SortMode.Largest -> compareByDescending<RemoteEntry> { it.size }.then(byName)
|
||||
SortMode.Smallest -> compareBy<RemoteEntry> { it.size }.then(byName)
|
||||
SortMode.FileType -> compareBy(String.CASE_INSENSITIVE_ORDER) { entry: RemoteEntry ->
|
||||
entry.name.substringAfterLast('.', "")
|
||||
}.then(byName)
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatDate(timestamp: Long): String = if (timestamp <= 0) "Unknown" else DateFormat.getDateTimeInstance().format(Date(timestamp))
|
||||
private fun formatSize(bytes: Long): String = when {
|
||||
bytes >= 1_048_576 -> "%.1f MB".format(bytes / 1_048_576.0)
|
||||
|
||||
@@ -5,6 +5,8 @@ package dev.alvin.smbexplorer
|
||||
|
||||
import android.graphics.ImageDecoder
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.widget.ImageView
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
|
||||
@@ -43,8 +45,8 @@ import kotlinx.coroutines.sync.withLock
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
@Composable
|
||||
fun ImageViewer(saved: SavedShare, folder: String, images: List<RemoteEntry>, initial: RemoteEntry, onClose: () -> Unit) {
|
||||
val loader = remember(saved.id, folder) { ImageLoader(saved.target, folder) }
|
||||
fun ImageViewer(saved: SavedShare, repository: BrowseRepository, folder: String, images: List<RemoteEntry>, initial: RemoteEntry, onClose: () -> Unit) {
|
||||
val loader = remember(saved.id, folder) { ImageLoader(repository, folder) }
|
||||
DisposableEffect(loader) { onDispose { loader.close() } }
|
||||
var index by remember(folder, initial.name) { mutableStateOf(images.indexOfFirst { it.name == initial.name }.coerceAtLeast(0)) }
|
||||
val entry = images[index]
|
||||
@@ -58,14 +60,9 @@ fun ImageViewer(saved: SavedShare, folder: String, images: List<RemoteEntry>, in
|
||||
error = null
|
||||
loading = true
|
||||
try {
|
||||
val bytes = loader.load(entry.name)
|
||||
drawable = loader.load(entry.name)
|
||||
images.getOrNull(index + 1)?.let { loader.prefetch(it.name) }
|
||||
drawable = withContext(Dispatchers.Default) {
|
||||
ImageDecoder.decodeDrawable(ImageDecoder.createSource(ByteBuffer.wrap(bytes))) { decoder, info, _ ->
|
||||
val largestSide = maxOf(info.size.width, info.size.height)
|
||||
if (largestSide > 4096) decoder.setTargetSampleSize((largestSide + 4095) / 4096)
|
||||
}
|
||||
}
|
||||
images.getOrNull(index - 1)?.let { loader.prefetch(it.name) }
|
||||
} catch (e: CancellationException) {
|
||||
throw e
|
||||
} catch (e: Exception) {
|
||||
@@ -112,18 +109,20 @@ fun ImageViewer(saved: SavedShare, folder: String, images: List<RemoteEntry>, in
|
||||
}
|
||||
}
|
||||
|
||||
private class ImageLoader(private val target: SmbTarget, private val folder: String) {
|
||||
private class ImageLoader(private val repository: BrowseRepository, private val folder: String) {
|
||||
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val mutex = Mutex()
|
||||
private var session: SmbShareSession? = null
|
||||
private val decodeMutex = Mutex()
|
||||
private val cache = LinkedHashMap<String, ByteArray>(4, .75f, true)
|
||||
private var cacheBytes = 0L
|
||||
private val decoded = LinkedHashMap<String, BitmapDrawable>(3, .75f, true)
|
||||
private var decodedBytes = 0L
|
||||
|
||||
suspend fun load(name: String): ByteArray = withContext(Dispatchers.IO) {
|
||||
private suspend fun bytes(name: String): ByteArray = withContext(Dispatchers.IO) {
|
||||
mutex.withLock {
|
||||
cache[name]?.let { return@withLock it }
|
||||
val path = if (folder.isEmpty()) name else "$folder\\$name"
|
||||
val bytes = (session ?: SmbShareSession(target).also { session = it }).read(path)
|
||||
val bytes = repository.read(path)
|
||||
if (bytes.size <= 24 * 1024 * 1024) {
|
||||
while (cacheBytes + bytes.size > 24L * 1024 * 1024) {
|
||||
val oldest = cache.entries.first()
|
||||
@@ -137,13 +136,43 @@ private class ImageLoader(private val target: SmbTarget, private val folder: Str
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun load(name: String): Drawable = decodeMutex.withLock {
|
||||
synchronized(decoded) { decoded[name] }?.let { return@withLock it }
|
||||
val data = bytes(name)
|
||||
val drawable = withContext(Dispatchers.Default) {
|
||||
ImageDecoder.decodeDrawable(ImageDecoder.createSource(ByteBuffer.wrap(data))) { decoder, info, _ ->
|
||||
val largestSide = maxOf(info.size.width, info.size.height)
|
||||
if (largestSide > 4096) decoder.setTargetSampleSize((largestSide + 4095) / 4096)
|
||||
}
|
||||
}
|
||||
if (drawable is BitmapDrawable) {
|
||||
val size = drawable.bitmap.allocationByteCount.toLong()
|
||||
if (size <= 24L * 1024 * 1024) synchronized(decoded) {
|
||||
while (decodedBytes + size > 24L * 1024 * 1024) {
|
||||
val oldest = decoded.entries.first()
|
||||
decodedBytes -= oldest.value.bitmap.allocationByteCount
|
||||
decoded.remove(oldest.key)
|
||||
}
|
||||
decoded.put(name, drawable)?.let { decodedBytes -= it.bitmap.allocationByteCount }
|
||||
decodedBytes += size
|
||||
}
|
||||
}
|
||||
drawable
|
||||
}
|
||||
|
||||
fun prefetch(name: String) {
|
||||
scope.launch { runCatching { load(name) } }
|
||||
scope.launch {
|
||||
runCatching {
|
||||
if (name.endsWith(".gif", true) || name.endsWith(".webp", true)) bytes(name)
|
||||
else load(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun close() {
|
||||
scope.launch {
|
||||
mutex.withLock { session?.close(); session = null; cache.clear() }
|
||||
mutex.withLock { cache.clear() }
|
||||
synchronized(decoded) { decoded.clear() }
|
||||
scope.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp" android:height="108dp"
|
||||
android:viewportWidth="108" android:viewportHeight="108">
|
||||
<path
|
||||
android:pathData="M24,38 L24,33 C24,30 26,28 29,28 L44,28 C46,28 47,29 49,31 L53,35 L78,35 C81,35 84,38 84,41 L84,73 C84,77 81,80 77,80 L29,80 C25,80 22,77 22,73 L22,42 C22,40 23,39 24,38 Z"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#D3C2FF"
|
||||
android:strokeWidth="5"
|
||||
android:strokeLineJoin="round" />
|
||||
<path
|
||||
android:pathData="M36,52 L70,52 M64,46 L70,52 L64,58 M70,65 L34,65 M40,59 L34,65 L40,71"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#55D9D0"
|
||||
android:strokeWidth="4.5"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round" />
|
||||
</vector>
|
||||
@@ -0,0 +1,17 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp" android:height="108dp"
|
||||
android:viewportWidth="108" android:viewportHeight="108">
|
||||
<path
|
||||
android:pathData="M24,38 L24,33 C24,30 26,28 29,28 L44,28 C46,28 47,29 49,31 L53,35 L78,35 C81,35 84,38 84,41 L84,73 C84,77 81,80 77,80 L29,80 C25,80 22,77 22,73 L22,42 C22,40 23,39 24,38 Z"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#FFFFFFFF"
|
||||
android:strokeWidth="5"
|
||||
android:strokeLineJoin="round" />
|
||||
<path
|
||||
android:pathData="M36,52 L70,52 M64,46 L70,52 L64,58 M70,65 L34,65 M40,59 L34,65 L40,71"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#FFFFFFFF"
|
||||
android:strokeWidth="4.5"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round" />
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_monochrome" />
|
||||
</adaptive-icon>
|
||||
@@ -0,0 +1,5 @@
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_monochrome" />
|
||||
</adaptive-icon>
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#191624</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 108 108" role="img" aria-label="SMB Explorer app icon">
|
||||
<rect width="108" height="108" rx="24" fill="#191624"/>
|
||||
<path d="M24 38V33c0-3 2-5 5-5h15c2 0 3 1 5 3l4 4h25c3 0 6 3 6 6v32c0 4-3 7-7 7H29c-4 0-7-3-7-7V42c0-2 1-3 2-4Z"
|
||||
fill="none" stroke="#D3C2FF" stroke-width="5" stroke-linejoin="round"/>
|
||||
<path d="M36 52h34m-6-6 6 6-6 6M70 65H34m6-6-6 6 6 6"
|
||||
fill="none" stroke="#55D9D0" stroke-width="4.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 530 B |
Reference in new issue
Block a user