mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-01 00:25:26 +02:00
Merge branch 'advplyr:master' into master
This commit is contained in:
commit
f9be51184d
6 changed files with 102 additions and 4 deletions
|
@ -38,15 +38,12 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "com.anggrayudi:storage:0.13.0"
|
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
||||||
implementation project(':capacitor-android')
|
implementation project(':capacitor-android')
|
||||||
|
|
||||||
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
|
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
|
||||||
|
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.9.2'
|
|
||||||
|
|
||||||
testImplementation "junit:junit:$junitVersion"
|
testImplementation "junit:junit:$junitVersion"
|
||||||
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
||||||
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
||||||
|
@ -61,6 +58,7 @@ dependencies {
|
||||||
|
|
||||||
implementation "androidx.media:media:$androidx_media_version"
|
implementation "androidx.media:media:$androidx_media_version"
|
||||||
|
|
||||||
|
// Exo Player
|
||||||
if (findProject(':exoplayer-library-core') != null) {
|
if (findProject(':exoplayer-library-core') != null) {
|
||||||
implementation project(':exoplayer-library-core')
|
implementation project(':exoplayer-library-core')
|
||||||
implementation project(':exoplayer-library-ui')
|
implementation project(':exoplayer-library-ui')
|
||||||
|
@ -75,9 +73,18 @@ dependencies {
|
||||||
implementation "com.google.android.exoplayer:exoplayer-hls:$exoplayer_version"
|
implementation "com.google.android.exoplayer:exoplayer-hls:$exoplayer_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Glide for images
|
||||||
implementation "com.github.bumptech.glide:glide:$glide_version"
|
implementation "com.github.bumptech.glide:glide:$glide_version"
|
||||||
kapt "com.github.bumptech.glide:compiler:$glide_version"
|
kapt "com.github.bumptech.glide:compiler:$glide_version"
|
||||||
|
|
||||||
|
// Paper NoSQL Db
|
||||||
|
implementation 'io.github.pilgr:paperdb:2.7.2'
|
||||||
|
|
||||||
|
// Simple Storage
|
||||||
|
implementation "com.anggrayudi:storage:0.13.0"
|
||||||
|
|
||||||
|
// OK HTTP
|
||||||
|
implementation 'com.squareup.okhttp3:okhttp:4.9.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: 'capacitor.build.gradle'
|
apply from: 'capacitor.build.gradle'
|
||||||
|
|
|
@ -6,7 +6,9 @@ import android.os.*
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.anggrayudi.storage.SimpleStorage
|
import com.anggrayudi.storage.SimpleStorage
|
||||||
import com.anggrayudi.storage.SimpleStorageHelper
|
import com.anggrayudi.storage.SimpleStorageHelper
|
||||||
|
import com.audiobookshelf.app.data.DbManager
|
||||||
import com.getcapacitor.BridgeActivity
|
import com.getcapacitor.BridgeActivity
|
||||||
|
import io.paperdb.Paper
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : BridgeActivity() {
|
class MainActivity : BridgeActivity() {
|
||||||
|
@ -44,11 +46,14 @@ class MainActivity : BridgeActivity() {
|
||||||
registerPlugin(MyNativeAudio::class.java)
|
registerPlugin(MyNativeAudio::class.java)
|
||||||
registerPlugin(AudioDownloader::class.java)
|
registerPlugin(AudioDownloader::class.java)
|
||||||
registerPlugin(StorageManager::class.java)
|
registerPlugin(StorageManager::class.java)
|
||||||
|
registerPlugin(DbManager::class.java)
|
||||||
|
|
||||||
var filter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE).apply {
|
var filter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE).apply {
|
||||||
addAction(DownloadManager.ACTION_NOTIFICATION_CLICKED)
|
addAction(DownloadManager.ACTION_NOTIFICATION_CLICKED)
|
||||||
}
|
}
|
||||||
registerReceiver(broadcastReceiver, filter)
|
registerReceiver(broadcastReceiver, filter)
|
||||||
|
|
||||||
|
Paper.init(applicationContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import androidx.documentfile.provider.DocumentFile
|
||||||
import androidx.media.MediaBrowserServiceCompat
|
import androidx.media.MediaBrowserServiceCompat
|
||||||
import androidx.media.utils.MediaConstants
|
import androidx.media.utils.MediaConstants
|
||||||
import com.anggrayudi.storage.file.isExternalStorageDocument
|
import com.anggrayudi.storage.file.isExternalStorageDocument
|
||||||
|
import com.audiobookshelf.app.data.DbManager
|
||||||
import com.getcapacitor.Bridge
|
import com.getcapacitor.Bridge
|
||||||
import com.getcapacitor.JSObject
|
import com.getcapacitor.JSObject
|
||||||
import com.google.android.exoplayer2.*
|
import com.google.android.exoplayer2.*
|
||||||
|
@ -39,6 +40,7 @@ import com.google.android.gms.cast.*
|
||||||
import com.google.android.gms.cast.framework.*
|
import com.google.android.gms.cast.framework.*
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
|
import org.json.JSONObject
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.concurrent.schedule
|
import kotlin.concurrent.schedule
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.audiobookshelf.app.data
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import com.getcapacitor.JSObject
|
||||||
|
import com.getcapacitor.Plugin
|
||||||
|
import com.getcapacitor.PluginCall
|
||||||
|
import com.getcapacitor.PluginMethod
|
||||||
|
import com.getcapacitor.annotation.CapacitorPlugin
|
||||||
|
import io.paperdb.Paper
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
@CapacitorPlugin(name = "DbManager")
|
||||||
|
class DbManager : Plugin() {
|
||||||
|
val tag = "DbManager"
|
||||||
|
|
||||||
|
fun saveObject(db:String, key:String, value:JSONObject) {
|
||||||
|
Log.d(tag, "Saving Object $key ${value.toString()}")
|
||||||
|
Paper.book(db).write(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadObject(db:String, key:String):JSONObject? {
|
||||||
|
var json: JSONObject? = Paper.book(db).read(key)
|
||||||
|
Log.d(tag, "Loaded Object $key $json")
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
|
||||||
|
@PluginMethod
|
||||||
|
fun saveFromWebview(call: PluginCall) {
|
||||||
|
var db = call.getString("db", "").toString()
|
||||||
|
var key = call.getString("key", "").toString()
|
||||||
|
var value = call.getObject("value")
|
||||||
|
if (db == "" || key == "" || value == null) {
|
||||||
|
Log.d(tag, "saveFromWebview Invalid key/value")
|
||||||
|
} else {
|
||||||
|
var json = value as JSONObject
|
||||||
|
saveObject(db, key, json)
|
||||||
|
}
|
||||||
|
call.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
|
@PluginMethod
|
||||||
|
fun loadFromWebview(call:PluginCall) {
|
||||||
|
var db = call.getString("db", "").toString()
|
||||||
|
var key = call.getString("key", "").toString()
|
||||||
|
if (db == "" || key == "") {
|
||||||
|
Log.d(tag, "loadFromWebview Invalid Key")
|
||||||
|
call.resolve()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var json = loadObject(db, key)
|
||||||
|
var jsobj = JSObject.fromJSONObject(json)
|
||||||
|
call.resolve(jsobj)
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,6 +37,7 @@ export default {
|
||||||
plugins: [
|
plugins: [
|
||||||
'@/plugins/server.js',
|
'@/plugins/server.js',
|
||||||
'@/plugins/sqlStore.js',
|
'@/plugins/sqlStore.js',
|
||||||
|
'@/plugins/db.js',
|
||||||
'@/plugins/localStore.js',
|
'@/plugins/localStore.js',
|
||||||
'@/plugins/init.client.js',
|
'@/plugins/init.client.js',
|
||||||
'@/plugins/axios.js',
|
'@/plugins/axios.js',
|
||||||
|
|
29
plugins/db.js
Normal file
29
plugins/db.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import { registerPlugin } from '@capacitor/core';
|
||||||
|
|
||||||
|
const DbManager = registerPlugin('DbManager');
|
||||||
|
|
||||||
|
class DbService {
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
save(db, key, value) {
|
||||||
|
return DbManager.saveFromWebview({ db, key, value }).then(() => {
|
||||||
|
console.log('Saved data', db, key, JSON.stringify(value))
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error('Failed to save data', error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
load(db, key) {
|
||||||
|
return DbManager.loadFromWebview({ db, key }).then((data) => {
|
||||||
|
console.log('Loaded data', db, key, JSON.stringify(data))
|
||||||
|
return data
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error('Failed to load', error)
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ({ app, store }, inject) => {
|
||||||
|
inject('db', new DbService())
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue