WIP implementing multiple children (working, with some issues)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user