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:
@@ -1,8 +1,8 @@
|
|||||||
object Dependencies {
|
object Dependencies {
|
||||||
object Kotlin {
|
object Kotlin {
|
||||||
const val version = "1.4.10"
|
const val version = "1.4.20"
|
||||||
const val core = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${version}"
|
const val core = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${version}"
|
||||||
const val coroutinesCore = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"
|
const val coroutinesCore = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9-native-mt"
|
||||||
const val coroutinesAndroid = "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"
|
const val coroutinesAndroid = "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ object Dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object Ktor {
|
object Ktor {
|
||||||
private const val version = "1.4.1"
|
private const val version = "1.4.2"
|
||||||
const val ktorCore = "io.ktor:ktor-client-core:$version"
|
const val ktorCore = "io.ktor:ktor-client-core:$version"
|
||||||
const val ktorOkhttp = "io.ktor:ktor-client-okhttp:$version"
|
const val ktorOkhttp = "io.ktor:ktor-client-okhttp:$version"
|
||||||
const val ktorIos = "io.ktor:ktor-client-ios:$version"
|
const val ktorIos = "io.ktor:ktor-client-ios:$version"
|
||||||
|
|||||||
@@ -2,12 +2,15 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("multiplatform")
|
kotlin("multiplatform")
|
||||||
|
kotlin("native.cocoapods")
|
||||||
kotlin("plugin.serialization")
|
kotlin("plugin.serialization")
|
||||||
id("com.android.library")
|
id("com.android.library")
|
||||||
id("kotlin-android-extensions")
|
id("kotlin-android-extensions")
|
||||||
id("com.squareup.sqldelight")
|
id("com.squareup.sqldelight")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
google()
|
google()
|
||||||
@@ -24,27 +27,28 @@ kotlin {
|
|||||||
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
|
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
|
||||||
|
|
||||||
if (sdkName.startsWith("iphoneos")) {
|
if (sdkName.startsWith("iphoneos")) {
|
||||||
iosArm64("ios") {
|
iosArm64("ios")
|
||||||
binaries {
|
|
||||||
framework {
|
|
||||||
baseName = "Shared"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
iosX64("ios") {
|
iosX64("ios")
|
||||||
binaries {
|
|
||||||
framework {
|
|
||||||
baseName = "Shared"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cocoapods {
|
||||||
|
summary = "Shared module for Circolapp"
|
||||||
|
homepage = "Link to a Kotlin/Native module homepage"
|
||||||
|
|
||||||
|
frameworkName = "Shared"
|
||||||
|
|
||||||
|
pod ("HTMLKit", "~> 3.1.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
val commonMain by getting {
|
val commonMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(Dependencies.Kotlin.coroutinesCore)
|
implementation(Dependencies.Kotlin.coroutinesCore) {
|
||||||
|
version {
|
||||||
|
strictly("1.3.9-native-mt")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ktor
|
// Ktor
|
||||||
implementation(Dependencies.Ktor.ktorCore)
|
implementation(Dependencies.Ktor.ktorCore)
|
||||||
|
|||||||
@@ -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.toBoolean
|
||||||
import net.underdesk.circolapp.shared.utils.SqlUtils.toList
|
import net.underdesk.circolapp.shared.utils.SqlUtils.toList
|
||||||
import net.underdesk.circolapp.shared.utils.SqlUtils.toLong
|
import net.underdesk.circolapp.shared.utils.SqlUtils.toLong
|
||||||
|
import net.underdesk.circolapp.shared.utils.wrap
|
||||||
|
|
||||||
class CircularDao(
|
class CircularDao(
|
||||||
database: AppDatabase
|
database: AppDatabase
|
||||||
@@ -66,22 +67,28 @@ class CircularDao(
|
|||||||
|
|
||||||
fun getFlowCirculars(school: Int) =
|
fun getFlowCirculars(school: Int) =
|
||||||
appDatabaseQueries.getCirculars(school.toLong(), circularMapper).asFlow().mapToList()
|
appDatabaseQueries.getCirculars(school.toLong(), circularMapper).asFlow().mapToList()
|
||||||
|
fun getCFlowCirculars(school: Int) = getFlowCirculars(school).wrap()
|
||||||
|
|
||||||
fun searchCirculars(query: String, school: Int) =
|
fun searchCirculars(query: String, school: Int) =
|
||||||
appDatabaseQueries.searchCirculars(school.toLong(), query, circularMapper).asFlow()
|
appDatabaseQueries.searchCirculars(school.toLong(), query, circularMapper).asFlow()
|
||||||
.mapToList()
|
.mapToList()
|
||||||
|
fun searchCircularsC(query: String, school: Int) = searchCirculars(query, school).wrap()
|
||||||
|
|
||||||
fun getFavourites(school: Int) =
|
fun getFavourites(school: Int) =
|
||||||
appDatabaseQueries.getFavourites(school.toLong(), circularMapper).asFlow().mapToList()
|
appDatabaseQueries.getFavourites(school.toLong(), circularMapper).asFlow().mapToList()
|
||||||
|
fun getFavouritesC(school: Int) = getFavourites(school).wrap()
|
||||||
|
|
||||||
fun searchFavourites(query: String, school: Int) =
|
fun searchFavourites(query: String, school: Int) =
|
||||||
appDatabaseQueries.searchFavourites(school.toLong(), query, circularMapper).asFlow()
|
appDatabaseQueries.searchFavourites(school.toLong(), query, circularMapper).asFlow()
|
||||||
.mapToList()
|
.mapToList()
|
||||||
|
fun searchFavouritesC(query: String, school: Int) = searchFavourites(query, school).wrap()
|
||||||
|
|
||||||
fun getReminders(school: Int) =
|
fun getReminders(school: Int) =
|
||||||
appDatabaseQueries.getReminders(school.toLong(), circularMapper).asFlow().mapToList()
|
appDatabaseQueries.getReminders(school.toLong(), circularMapper).asFlow().mapToList()
|
||||||
|
fun getRemindersC(school: Int) = getReminders(school).wrap()
|
||||||
|
|
||||||
fun searchReminders(query: String, school: Int) =
|
fun searchReminders(query: String, school: Int) =
|
||||||
appDatabaseQueries.searchReminders(school.toLong(), query, circularMapper).asFlow()
|
appDatabaseQueries.searchReminders(school.toLong(), query, circularMapper).asFlow()
|
||||||
.mapToList()
|
.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
|
package net.underdesk.circolapp.shared.server.curie
|
||||||
|
|
||||||
|
import cocoapods.HTMLKit.HTMLElement
|
||||||
|
import cocoapods.HTMLKit.HTMLParser
|
||||||
import net.underdesk.circolapp.shared.data.Circular
|
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> {
|
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
|
package net.underdesk.circolapp.shared.server.porporato
|
||||||
|
|
||||||
|
import cocoapods.HTMLKit.HTMLElement
|
||||||
|
import cocoapods.HTMLKit.HTMLParser
|
||||||
import net.underdesk.circolapp.shared.data.Circular
|
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> {
|
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