WIP implementing multiple children (working, with some issues)

This commit is contained in:
2025-01-17 08:55:37 +01:00
parent 0b0fd8f5af
commit 32fbeac079
10 changed files with 168 additions and 20 deletions

View File

@@ -69,7 +69,7 @@ class FileLogbookRepository: LogbookRepository {
override fun listLogbooks(
context: Context,
listener: LogbookListObtainedListener
): ArrayList<String> {
) {
val logbooksFileNames = context.getFilesDir().list(object: FilenameFilter {
override fun accept(dir: File?, name: String?): Boolean {
if (name == null)
@@ -81,15 +81,15 @@ class FileLogbookRepository: LogbookRepository {
})
if (logbooksFileNames == null || logbooksFileNames.isEmpty())
return arrayListOf()
listener.onLogbookListObtained(arrayListOf())
val logbooksNames = arrayListOf<String>()
logbooksFileNames.forEach { it ->
logbooksNames.add(
it.replace(FILE_NAME_START, "").replace("${FILE_NAME_START}_", "").replace(FILE_NAME_END, "")
it.replace("${FILE_NAME_START}_", "").replace(FILE_NAME_START, "").replace(FILE_NAME_END, "")
)
}
return logbooksNames
listener.onLogbookListObtained(logbooksNames)
}
private fun getFileName(name: String): String {

View File

@@ -7,9 +7,12 @@ import okio.IOException
import org.json.JSONException
interface LogbookRepository {
companion object {
val DEFAULT_LOGBOOK_NAME = "" // For compatibility with older app versions
}
fun loadLogbook(context: Context, name: String = "", listener: LogbookLoadedListener)
fun saveLogbook(context: Context,logbook: Logbook, listener: LogbookSavedListener)
fun listLogbooks(context: Context, listener: LogbookListObtainedListener): ArrayList<String>
fun listLogbooks(context: Context, listener: LogbookListObtainedListener)
}
interface LogbookLoadedListener {
@@ -29,7 +32,7 @@ interface LogbookSavedListener {
}
interface LogbookListObtainedListener {
fun onLogbookListObtained()
fun onLogbookListObtained(logbooksNames: ArrayList<String>)
fun onIOError(error: IOException)
fun onWebDAVError(error: SardineException)
fun onError(error: Exception)

View File

@@ -101,16 +101,22 @@ class WebDAVLogbookRepository(val webDavURL: String, val username: String, val p
override fun listLogbooks(
context: Context,
listener: LogbookListObtainedListener
): ArrayList<String> {
val logbooksNames = arrayListOf<String>()
for (dr: DavResource in sardine.list(webDavURL)){
logbooksNames.add(
dr.name.replace(FileLogbookRepository.Companion.FILE_NAME_START, "")
.replace("${FileLogbookRepository.Companion.FILE_NAME_START}_", "")
.replace(FileLogbookRepository.Companion.FILE_NAME_END, "")
)
}
return logbooksNames
) {
Thread(Runnable {
val logbooksNames = arrayListOf<String>()
for (dr: DavResource in sardine.list(webDavURL)){
if(!dr.name.startsWith(FILE_NAME_START))
continue
if(!dr.name.endsWith(FILE_NAME_END))
continue
logbooksNames.add(
dr.name.replace("${FILE_NAME_START}_", "")
.replace(FILE_NAME_START, "")
.replace(FILE_NAME_END, "")
)
}
listener.onLogbookListObtained(logbooksNames)
}).start()
}
private fun saveLogbook(context: Context, logbook: Logbook) {