Remove old and slow simplePath from SAF, also autoformatted

This commit is contained in:
Nicholas Wallace
2026-07-20 18:59:19 -07:00
parent b3c3950c55
commit dc6184f41d
6 changed files with 247 additions and 205 deletions
@@ -11,53 +11,66 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo
import java.io.File import java.io.File
enum class LockOrientationSetting { enum class LockOrientationSetting {
NONE, PORTRAIT, LANDSCAPE NONE,
PORTRAIT,
LANDSCAPE
} }
enum class HapticFeedbackSetting { enum class HapticFeedbackSetting {
OFF, LIGHT, MEDIUM, HEAVY OFF,
LIGHT,
MEDIUM,
HEAVY
} }
enum class ShakeSensitivitySetting { enum class ShakeSensitivitySetting {
VERY_LOW, LOW, MEDIUM, HIGH, VERY_HIGH VERY_LOW,
LOW,
MEDIUM,
HIGH,
VERY_HIGH
} }
enum class DownloadUsingCellularSetting { enum class DownloadUsingCellularSetting {
ASK, ALWAYS, NEVER ASK,
ALWAYS,
NEVER
} }
enum class StreamingUsingCellularSetting { enum class StreamingUsingCellularSetting {
ASK, ALWAYS, NEVER ASK,
ALWAYS,
NEVER
} }
enum class AndroidAutoBrowseSeriesSequenceOrderSetting { enum class AndroidAutoBrowseSeriesSequenceOrderSetting {
ASC, DESC ASC,
DESC
} }
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
data class ServerConnectionConfig( data class ServerConnectionConfig(
var id:String, var id: String,
var index:Int, var index: Int,
var name:String, var name: String,
var address:String, var address: String,
// version added after 0.9.81-beta // version added after 0.9.81-beta
var version:String?, var version: String?,
var userId:String, var userId: String,
var username:String, var username: String,
var token:String, var token: String,
var customHeaders:Map<String, String>? var customHeaders: Map<String, String>?
) )
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
data class LocalFile( data class LocalFile(
var id:String, var id: String,
var filename:String?, var filename: String?,
var contentUrl:String, var contentUrl: String,
var basePath:String, var basePath: String,
var absolutePath:String, var absolutePath: String,
var simplePath:String, var mimeType: String?,
var mimeType:String?, var size: Long
var size:Long
) { ) {
@JsonIgnore @JsonIgnore
fun exists(ctx: Context): Boolean { fun exists(ctx: Context): Boolean {
@@ -73,17 +86,17 @@ data class LocalFile(
} }
@JsonIgnore @JsonIgnore
fun isAudioFile():Boolean { fun isAudioFile(): Boolean {
if (mimeType == "application/octet-stream") return true if (mimeType == "application/octet-stream") return true
if (mimeType == "video/mp4") return true if (mimeType == "video/mp4") return true
return mimeType?.startsWith("audio") == true return mimeType?.startsWith("audio") == true
} }
@JsonIgnore @JsonIgnore
fun isEBookFile():Boolean { fun isEBookFile(): Boolean {
return getEBookFormat() != null return getEBookFormat() != null
} }
@JsonIgnore @JsonIgnore
fun getEBookFormat():String? { fun getEBookFormat(): String? {
if (mimeType == "application/epub+zip") return "epub" if (mimeType == "application/epub+zip") return "epub"
if (mimeType == "application/pdf") return "pdf" if (mimeType == "application/pdf") return "pdf"
if (mimeType == "application/x-mobipocket-ebook") return "mobi" if (mimeType == "application/x-mobipocket-ebook") return "mobi"
@@ -96,52 +109,53 @@ data class LocalFile(
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
data class LocalFolder( data class LocalFolder(
var id:String, var id: String,
var name:String, var name: String,
var contentUrl:String, var contentUrl: String,
var basePath:String, var basePath: String,
var absolutePath:String, var absolutePath: String,
var simplePath:String, var storageType: String,
var storageType:String, var mediaType: String
var mediaType:String
) )
@JsonTypeInfo(use= JsonTypeInfo.Id.DEDUCTION) @JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
@JsonSubTypes( @JsonSubTypes(JsonSubTypes.Type(LibraryItem::class), JsonSubTypes.Type(LocalLibraryItem::class))
JsonSubTypes.Type(LibraryItem::class), open class LibraryItemWrapper(var id: String) {
JsonSubTypes.Type(LocalLibraryItem::class)
)
open class LibraryItemWrapper(var id:String) {
@JsonIgnore @JsonIgnore
open fun getMediaDescription(progress:MediaProgressWrapper?, ctx: Context): MediaDescriptionCompat { return MediaDescriptionCompat.Builder().build() } open fun getMediaDescription(
progress: MediaProgressWrapper?,
ctx: Context
): MediaDescriptionCompat {
return MediaDescriptionCompat.Builder().build()
}
} }
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
data class DeviceInfo( data class DeviceInfo(
var deviceId:String, var deviceId: String,
var manufacturer:String, var manufacturer: String,
var model:String, var model: String,
var sdkVersion:Int, var sdkVersion: Int,
var clientVersion: String var clientVersion: String
) )
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
data class PlayItemRequestPayload( data class PlayItemRequestPayload(
var mediaPlayer:String, var mediaPlayer: String,
var forceDirectPlay:Boolean, var forceDirectPlay: Boolean,
var forceTranscode:Boolean, var forceTranscode: Boolean,
var deviceInfo:DeviceInfo var deviceInfo: DeviceInfo
) )
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
data class DeviceSettings( data class DeviceSettings(
var disableAutoRewind:Boolean, var disableAutoRewind: Boolean,
var enableAltView:Boolean, var enableAltView: Boolean,
var allowSeekingOnMediaControls:Boolean, var allowSeekingOnMediaControls: Boolean,
var jumpBackwardsTime:Int, var jumpBackwardsTime: Int,
var jumpForwardTime:Int, var jumpForwardTime: Int,
var enableMp3IndexSeeking:Boolean, var enableMp3IndexSeeking: Boolean,
var disableShakeToResetSleepTimer:Boolean, var disableShakeToResetSleepTimer: Boolean,
var shakeSensitivity: ShakeSensitivitySetting, var shakeSensitivity: ShakeSensitivitySetting,
var lockOrientation: LockOrientationSetting, var lockOrientation: LockOrientationSetting,
var hapticFeedback: HapticFeedbackSetting, var hapticFeedback: HapticFeedbackSetting,
@@ -149,7 +163,7 @@ data class DeviceSettings(
var autoSleepTimerStartTime: String, var autoSleepTimerStartTime: String,
var autoSleepTimerEndTime: String, var autoSleepTimerEndTime: String,
var autoSleepTimerAutoRewind: Boolean, var autoSleepTimerAutoRewind: Boolean,
var autoSleepTimerAutoRewindTime: Long, //Time in milliseconds var autoSleepTimerAutoRewindTime: Long, // Time in milliseconds
var sleepTimerLength: Long, // Time in milliseconds var sleepTimerLength: Long, // Time in milliseconds
var disableSleepTimerFadeOut: Boolean, var disableSleepTimerFadeOut: Boolean,
var disableSleepTimerResetFeedback: Boolean, var disableSleepTimerResetFeedback: Boolean,
@@ -162,7 +176,7 @@ data class DeviceSettings(
) { ) {
companion object { companion object {
// Static method to get default device settings // Static method to get default device settings
fun default():DeviceSettings { fun default(): DeviceSettings {
return DeviceSettings( return DeviceSettings(
disableAutoRewind = false, disableAutoRewind = false,
enableAltView = true, enableAltView = true,
@@ -193,21 +207,26 @@ data class DeviceSettings(
} }
@get:JsonIgnore @get:JsonIgnore
val jumpBackwardsTimeMs get() = jumpBackwardsTime * 1000L val jumpBackwardsTimeMs
get() = jumpBackwardsTime * 1000L
@get:JsonIgnore @get:JsonIgnore
val jumpForwardTimeMs get() = jumpForwardTime * 1000L val jumpForwardTimeMs
get() = jumpForwardTime * 1000L
@get:JsonIgnore @get:JsonIgnore
val autoSleepTimerStartHour get() = autoSleepTimerStartTime.split(":")[0].toInt() val autoSleepTimerStartHour
get() = autoSleepTimerStartTime.split(":")[0].toInt()
@get:JsonIgnore @get:JsonIgnore
val autoSleepTimerStartMinute get() = autoSleepTimerStartTime.split(":")[1].toInt() val autoSleepTimerStartMinute
get() = autoSleepTimerStartTime.split(":")[1].toInt()
@get:JsonIgnore @get:JsonIgnore
val autoSleepTimerEndHour get() = autoSleepTimerEndTime.split(":")[0].toInt() val autoSleepTimerEndHour
get() = autoSleepTimerEndTime.split(":")[0].toInt()
@get:JsonIgnore @get:JsonIgnore
val autoSleepTimerEndMinute get() = autoSleepTimerEndTime.split(":")[1].toInt() val autoSleepTimerEndMinute
get() = autoSleepTimerEndTime.split(":")[1].toInt()
@JsonIgnore @JsonIgnore
fun getShakeThresholdGravity() : Float { // Used in ShakeDetector fun getShakeThresholdGravity(): Float { // Used in ShakeDetector
return if (shakeSensitivity == ShakeSensitivitySetting.VERY_HIGH) 1.1f return if (shakeSensitivity == ShakeSensitivitySetting.VERY_HIGH) 1.1f
else if (shakeSensitivity == ShakeSensitivitySetting.HIGH) 1.3f else if (shakeSensitivity == ShakeSensitivitySetting.HIGH) 1.3f
else if (shakeSensitivity == ShakeSensitivitySetting.MEDIUM) 1.5f else if (shakeSensitivity == ShakeSensitivitySetting.MEDIUM) 1.5f
@@ -221,8 +240,8 @@ data class DeviceSettings(
} }
data class DeviceData( data class DeviceData(
var serverConnectionConfigs:MutableList<ServerConnectionConfig>, var serverConnectionConfigs: MutableList<ServerConnectionConfig>,
var lastServerConnectionConfigId:String?, var lastServerConnectionConfigId: String?,
var deviceSettings: DeviceSettings?, var deviceSettings: DeviceSettings?,
var lastPlaybackSession: PlaybackSession? var lastPlaybackSession: PlaybackSession?
) { ) {
@@ -100,7 +100,7 @@ class LocalLibraryItem(
@JsonIgnore @JsonIgnore
private fun trackExists(ctx: Context, contentUrl: String?, path: String): Boolean { private fun trackExists(ctx: Context, contentUrl: String?, path: String): Boolean {
return LocalFile("", null, contentUrl ?: "", "", path, "", null, 0).exists(ctx) return LocalFile("", null, contentUrl ?: "", "", path, null, 0).exists(ctx)
} }
@JsonIgnore @JsonIgnore
@@ -14,7 +14,6 @@ data class LocalMediaItem(
var mediaType: String, var mediaType: String,
var folderId: String, var folderId: String,
var contentUrl: String, var contentUrl: String,
var simplePath: String,
var basePath: String, var basePath: String,
var absolutePath: String, var absolutePath: String,
var audioTracks: MutableList<AudioTrack>, var audioTracks: MutableList<AudioTrack>,
@@ -35,7 +35,6 @@ class FolderScanner(private val ctx: Context) {
Uri.fromFile(file).toString(), Uri.fromFile(file).toString(),
file.getBasePath(ctx), file.getBasePath(ctx),
file.absolutePath, file.absolutePath,
file.getSimplePath(ctx),
file.mimeType, file.mimeType,
file.length() file.length()
) )
@@ -61,7 +60,6 @@ class FolderScanner(private val ctx: Context) {
contentUrl, contentUrl,
part.localFolderName, part.localFolderName,
part.finalDestinationPath, part.finalDestinationPath,
part.finalDestinationPath,
mimeTypeFor(part), mimeTypeFor(part),
size size
) )
@@ -81,7 +79,6 @@ class FolderScanner(private val ctx: Context) {
document.uri.toString(), document.uri.toString(),
document.getBasePath(ctx), document.getBasePath(ctx),
document.getAbsolutePath(ctx), document.getAbsolutePath(ctx),
document.getSimplePath(ctx),
document.mimeType, document.mimeType,
document.length() document.length()
) )
@@ -23,14 +23,17 @@ import java.io.File
class AbsFileSystem : Plugin() { class AbsFileSystem : Plugin() {
private val TAG = "AbsFileSystem" private val TAG = "AbsFileSystem"
private val tag = "AbsFileSystem" private val tag = "AbsFileSystem"
private var jacksonMapper = jacksonObjectMapper().enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature()) private var jacksonMapper =
jacksonObjectMapper()
.enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature())
lateinit var mainActivity: MainActivity lateinit var mainActivity: MainActivity
override fun load() { override fun load() {
mainActivity = (activity as MainActivity) mainActivity = (activity as MainActivity)
mainActivity.storage.storageAccessCallback = object : StorageAccessCallback { mainActivity.storage.storageAccessCallback =
object : StorageAccessCallback {
override fun onRootPathNotSelected( override fun onRootPathNotSelected(
requestCode: Int, requestCode: Int,
rootPath: String, rootPath: String,
@@ -45,7 +48,13 @@ class AbsFileSystem : Plugin() {
Log.d(TAG, "STORAGE ACCESS CALLBACK") Log.d(TAG, "STORAGE ACCESS CALLBACK")
} }
override fun onExpectedStorageNotSelected(requestCode: Int, selectedFolder: DocumentFile, selectedStorageType: StorageType, expectedBasePath: String, expectedStorageType: StorageType) { override fun onExpectedStorageNotSelected(
requestCode: Int,
selectedFolder: DocumentFile,
selectedStorageType: StorageType,
expectedBasePath: String,
expectedStorageType: StorageType
) {
Log.d(TAG, "STORAGE ACCESS CALLBACK") Log.d(TAG, "STORAGE ACCESS CALLBACK")
} }
@@ -65,16 +74,29 @@ class AbsFileSystem : Plugin() {
val REQUEST_CODE_SELECT_FOLDER = 6 val REQUEST_CODE_SELECT_FOLDER = 6
val REQUEST_CODE_SDCARD_ACCESS = 7 val REQUEST_CODE_SDCARD_ACCESS = 7
mainActivity.storage.folderPickerCallback = object : FolderPickerCallback { mainActivity.storage.folderPickerCallback =
object : FolderPickerCallback {
override fun onFolderSelected(requestCode: Int, folder: DocumentFile) { override fun onFolderSelected(requestCode: Int, folder: DocumentFile) {
Log.d(TAG, "ON FOLDER SELECTED ${folder.uri} ${folder.name}") Log.d(TAG, "ON FOLDER SELECTED ${folder.uri} ${folder.name}")
val absolutePath = folder.getAbsolutePath(activity) val absolutePath = folder.getAbsolutePath(activity)
val storageType = folder.getStorageType(activity) val storageType = folder.getStorageType(activity)
val simplePath = folder.getSimplePath(activity)
val basePath = folder.getBasePath(activity) val basePath = folder.getBasePath(activity)
val folderId = android.util.Base64.encodeToString(folder.id.toByteArray(), android.util.Base64.DEFAULT) val folderId =
android.util.Base64.encodeToString(
folder.id.toByteArray(),
android.util.Base64.DEFAULT
)
val localFolder = LocalFolder(folderId, folder.name ?: "", folder.uri.toString(),basePath,absolutePath, simplePath, storageType.toString(), mediaType) val localFolder =
LocalFolder(
folderId,
folder.name ?: "",
folder.uri.toString(),
basePath,
absolutePath,
storageType.toString(),
mediaType
)
DeviceManager.dbManager.saveLocalFolder(localFolder) DeviceManager.dbManager.saveLocalFolder(localFolder)
call.resolve(JSObject(jacksonMapper.writeValueAsString(localFolder))) call.resolve(JSObject(jacksonMapper.writeValueAsString(localFolder)))
@@ -94,14 +116,20 @@ class AbsFileSystem : Plugin() {
val builder: AlertDialog.Builder = AlertDialog.Builder(mainActivity) val builder: AlertDialog.Builder = AlertDialog.Builder(mainActivity)
builder.setMessage( builder.setMessage(
"You have no write access to this storage, thus selecting this folder is useless." + "You have no write access to this storage, thus selecting this folder is useless." +
"\nWould you like to grant access to this folder?") "\nWould you like to grant access to this folder?"
)
builder.setNegativeButton("Dont Allow") { _, _ -> builder.setNegativeButton("Dont Allow") { _, _ ->
run { run {
jsobj.put("error", "User Canceled, Access Denied") jsobj.put("error", "User Canceled, Access Denied")
call.resolve(jsobj) call.resolve(jsobj)
} }
} }
builder.setPositiveButton("Allow.") { _, _ -> mainActivity.storageHelper.requestStorageAccess(REQUEST_CODE_SDCARD_ACCESS, initialPath = FileFullPath(mainActivity, storageId, "")) } builder.setPositiveButton("Allow.") { _, _ ->
mainActivity.storageHelper.requestStorageAccess(
REQUEST_CODE_SDCARD_ACCESS,
initialPath = FileFullPath(mainActivity, storageId, "")
)
}
builder.show() builder.show()
} else { } else {
Log.d(TAG, "STORAGE ACCESS DENIED $requestCode") Log.d(TAG, "STORAGE ACCESS DENIED $requestCode")
@@ -110,14 +138,12 @@ class AbsFileSystem : Plugin() {
} }
} }
override fun onStoragePermissionDenied(requestCode: Int) { override fun onStoragePermissionDenied(requestCode: Int) {
Log.d(TAG, "STORAGE PERMISSION DENIED $requestCode") Log.d(TAG, "STORAGE PERMISSION DENIED $requestCode")
val jsobj = JSObject() val jsobj = JSObject()
jsobj.put("error", "Permission Denied") jsobj.put("error", "Permission Denied")
call.resolve(jsobj) call.resolve(jsobj)
} }
} }
mainActivity.storage.openFolderPicker(REQUEST_CODE_SELECT_FOLDER) mainActivity.storage.openFolderPicker(REQUEST_CODE_SELECT_FOLDER)
@@ -152,7 +178,7 @@ class AbsFileSystem : Plugin() {
val folderUrl = call.data.getString("folderUrl", "").toString() val folderUrl = call.data.getString("folderUrl", "").toString()
Log.d(TAG, "Check Folder Permissions for $folderUrl") Log.d(TAG, "Check Folder Permissions for $folderUrl")
val hasAccess = SimpleStorage.hasStorageAccess(context,folderUrl,true) val hasAccess = SimpleStorage.hasStorageAccess(context, folderUrl, true)
val jsobj = JSObject() val jsobj = JSObject()
jsobj.put("value", hasAccess) jsobj.put("value", hasAccess)
@@ -196,7 +222,8 @@ class AbsFileSystem : Plugin() {
if (localLibraryItem?.folderId?.startsWith("internal-") == true) { if (localLibraryItem?.folderId?.startsWith("internal-") == true) {
Log.d(tag, "Deleting internal library item at absolutePath $absolutePath") Log.d(tag, "Deleting internal library item at absolutePath $absolutePath")
val file = File(absolutePath) val file = File(absolutePath)
success = if (file.exists()) { success =
if (file.exists()) {
file.deleteRecursively() file.deleteRecursively()
} else { } else {
true true
@@ -207,9 +234,11 @@ class AbsFileSystem : Plugin() {
val folder = DeviceManager.dbManager.getLocalFolder(folderId) val folder = DeviceManager.dbManager.getLocalFolder(folderId)
folder?.absolutePath?.let { folderPath -> folder?.absolutePath?.let { folderPath ->
val splitAbsolutePath = absolutePath.split("/") val splitAbsolutePath = absolutePath.split("/")
val fullSubDir = splitAbsolutePath.subList(0, splitAbsolutePath.size - 1).joinToString("/") val fullSubDir =
splitAbsolutePath.subList(0, splitAbsolutePath.size - 1).joinToString("/")
if (fullSubDir != folderPath) { if (fullSubDir != folderPath) {
val subdirHasAnItem = DeviceManager.dbManager.getLocalLibraryItems().any { _localLibraryItem -> val subdirHasAnItem =
DeviceManager.dbManager.getLocalLibraryItems().any { _localLibraryItem ->
if (_localLibraryItem.id == localLibraryItemId) { if (_localLibraryItem.id == localLibraryItemId) {
false false
} else { } else {
-2
View File
@@ -119,7 +119,6 @@ class AbsDatabaseWeb extends WebPlugin {
name: 'Audiobooks', name: 'Audiobooks',
contentUrl: 'test', contentUrl: 'test',
absolutePath: '/audiobooks', absolutePath: '/audiobooks',
simplePath: 'audiobooks',
storageType: 'primary', storageType: 'primary',
mediaType: 'book' mediaType: 'book'
} }
@@ -196,7 +195,6 @@ class AbsDatabaseWeb extends WebPlugin {
filename: 'lf1.mp3', filename: 'lf1.mp3',
contentUrl: 'test', contentUrl: 'test',
absolutePath: 'test', absolutePath: 'test',
simplePath: 'test',
mimeType: 'audio/mpeg', mimeType: 'audio/mpeg',
size: 39048290 size: 39048290
} }