mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-06 07:29:10 +00:00
Add specific iOS code to shared module
This commit is contained in:
@@ -8,6 +8,7 @@ import net.underdesk.circolapp.shared.utils.SqlUtils.joinToString
|
||||
import net.underdesk.circolapp.shared.utils.SqlUtils.toBoolean
|
||||
import net.underdesk.circolapp.shared.utils.SqlUtils.toList
|
||||
import net.underdesk.circolapp.shared.utils.SqlUtils.toLong
|
||||
import net.underdesk.circolapp.shared.utils.wrap
|
||||
|
||||
class CircularDao(
|
||||
database: AppDatabase
|
||||
@@ -66,22 +67,28 @@ class CircularDao(
|
||||
|
||||
fun getFlowCirculars(school: Int) =
|
||||
appDatabaseQueries.getCirculars(school.toLong(), circularMapper).asFlow().mapToList()
|
||||
fun getCFlowCirculars(school: Int) = getFlowCirculars(school).wrap()
|
||||
|
||||
fun searchCirculars(query: String, school: Int) =
|
||||
appDatabaseQueries.searchCirculars(school.toLong(), query, circularMapper).asFlow()
|
||||
.mapToList()
|
||||
fun searchCircularsC(query: String, school: Int) = searchCirculars(query, school).wrap()
|
||||
|
||||
fun getFavourites(school: Int) =
|
||||
appDatabaseQueries.getFavourites(school.toLong(), circularMapper).asFlow().mapToList()
|
||||
fun getFavouritesC(school: Int) = getFavourites(school).wrap()
|
||||
|
||||
fun searchFavourites(query: String, school: Int) =
|
||||
appDatabaseQueries.searchFavourites(school.toLong(), query, circularMapper).asFlow()
|
||||
.mapToList()
|
||||
fun searchFavouritesC(query: String, school: Int) = searchFavourites(query, school).wrap()
|
||||
|
||||
fun getReminders(school: Int) =
|
||||
appDatabaseQueries.getReminders(school.toLong(), circularMapper).asFlow().mapToList()
|
||||
fun getRemindersC(school: Int) = getReminders(school).wrap()
|
||||
|
||||
fun searchReminders(query: String, school: Int) =
|
||||
appDatabaseQueries.searchReminders(school.toLong(), query, circularMapper).asFlow()
|
||||
.mapToList()
|
||||
fun searchRemindersC(query: String, school: Int) = searchReminders(query, school).wrap()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.underdesk.circolapp.shared.data
|
||||
|
||||
import com.squareup.sqldelight.db.SqlDriver
|
||||
|
||||
object DatabaseFactory {
|
||||
fun createDatabase(sqlDriver: SqlDriver) = AppDatabase(sqlDriver)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.underdesk.circolapp.shared.utils
|
||||
|
||||
import io.ktor.utils.io.core.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
fun <T> Flow<T>.wrap(): CFlow<T> = CFlow(this)
|
||||
|
||||
class CFlow<T>(private val origin: Flow<T>) : Flow<T> by origin {
|
||||
fun watch(block: (T) -> Unit): Closeable {
|
||||
val job = Job()
|
||||
|
||||
onEach {
|
||||
block(it)
|
||||
}.launchIn(CoroutineScope(Dispatchers.Main + job))
|
||||
|
||||
return object : Closeable {
|
||||
override fun close() {
|
||||
job.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,25 @@
|
||||
package net.underdesk.circolapp.shared.server.curie
|
||||
|
||||
import cocoapods.HTMLKit.HTMLElement
|
||||
import cocoapods.HTMLKit.HTMLParser
|
||||
import net.underdesk.circolapp.shared.data.Circular
|
||||
|
||||
actual class SpecificCurieServer actual constructor(val curieServer: CurieServer) {
|
||||
actual class SpecificCurieServer actual constructor(private val curieServer: CurieServer) {
|
||||
actual fun parseHtml(string: String): List<Circular> {
|
||||
TODO("Not yet implemented")
|
||||
val document = HTMLParser(string).parseDocument()
|
||||
val htmlList = document.querySelector("ul")?.querySelectorAll("a") as List<HTMLElement>?
|
||||
|
||||
val list = ArrayList<Circular>()
|
||||
|
||||
htmlList?.forEach { element ->
|
||||
if (element.parentElement?.parentElement?.parentElement?.tagName == "li") {
|
||||
list.last().attachmentsNames.add(element.textContent)
|
||||
list.last().attachmentsUrls.add(element.attributes.objectForKey("href").toString())
|
||||
} else {
|
||||
list.add(curieServer.generateFromString(element.textContent, element.attributes.objectForKey("href").toString()))
|
||||
}
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
package net.underdesk.circolapp.shared.server.porporato
|
||||
|
||||
import cocoapods.HTMLKit.HTMLElement
|
||||
import cocoapods.HTMLKit.HTMLParser
|
||||
import net.underdesk.circolapp.shared.data.Circular
|
||||
|
||||
actual class SpecificPorporatoServer actual constructor(porporatoServer: PorporatoServer) {
|
||||
actual class SpecificPorporatoServer actual constructor(private val porporatoServer: PorporatoServer) {
|
||||
actual fun parseHtml(string: String): List<Circular> {
|
||||
TODO("Not yet implemented")
|
||||
val document = HTMLParser(string).parseDocument()
|
||||
val table = document.querySelectorAll("table") as List<HTMLElement>?
|
||||
val td = table?.get(2)?.querySelectorAll("td") as List<HTMLElement>?
|
||||
val htmlList = td?.get(2)?.querySelectorAll("a") as List<HTMLElement>?
|
||||
|
||||
val list = ArrayList<Circular>()
|
||||
|
||||
if (htmlList == null)
|
||||
return list
|
||||
|
||||
for (i in htmlList.indices) {
|
||||
list.add(
|
||||
porporatoServer.generateFromString(
|
||||
htmlList[i].textContent,
|
||||
htmlList[i].attributes.objectForKey("href").toString(),
|
||||
i.toLong()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user