Skip to content

Commit

Permalink
improve bs resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Jul 10, 2024
1 parent 168949f commit 4d9f5b8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 deletions.
8 changes: 0 additions & 8 deletions composeApp/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,6 @@
<meta-data android:name="photopicker_activity:0:required" android:value="" />
</service>

<receiver android:name=".other.BurningSeriesReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="dev.datlag.aniflow.BS_BROADCAST" />
</intent-filter>
</receiver>

<meta-data
android:name="instantapps.clients.allowed"
android:value="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.android.play.core.appupdate.AppUpdateOptions
import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.ktx.requestAppUpdateInfo
import dev.datlag.aniflow.other.BurningSeriesResolver
import dev.datlag.aniflow.other.ConsentInfo
import dev.datlag.aniflow.other.DomainVerifier
import dev.datlag.aniflow.other.LocalConsentInfo
Expand All @@ -36,6 +37,7 @@ import dev.datlag.tooling.safeCast
import io.github.aakira.napier.Napier
import org.kodein.di.DIAware
import org.kodein.di.instance
import org.kodein.di.instanceOrNull

class MainActivity : AppCompatActivity() {

Expand Down Expand Up @@ -109,7 +111,11 @@ class MainActivity : AppCompatActivity() {
override fun onDestroy() {
super.onDestroy()

val di = applicationContext.safeCast<DIAware>()?.di ?: (application as DIAware).di
val resolver by di.instanceOrNull<BurningSeriesResolver>()

DomainVerifier.verify(this)
resolver?.close()
}

override fun onStart() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,49 @@ actual class BurningSeriesResolver(
}

val selection = if (englishTrimmed != null && romajiTrimmed != null) {
"title LIKE '%$englishTrimmed%' OR title LIKE '%$romajiTrimmed%'"
"fullTitle LIKE '%$englishTrimmed%' OR fullTitle LIKE '%$romajiTrimmed%'"
} else if (englishTrimmed != null) {
"title LIKE '%$englishTrimmed%'"
"fullTitle LIKE '%$englishTrimmed%'"
} else {
"title LIKE '%$romajiTrimmed%'"
"fullTitle LIKE '%$romajiTrimmed%'"
}

return seriesBySelection(selection)
return seriesBySelection(selection).ifEmpty {
val mainTitleSelection = if (englishTrimmed != null && romajiTrimmed != null) {
"mainTitle LIKE '%$englishTrimmed%' OR mainTitle LIKE '%$romajiTrimmed%'"
} else if (englishTrimmed != null) {
"mainTitle LIKE '%$englishTrimmed%'"
} else {
"mainTitle LIKE '%$romajiTrimmed%'"
}

seriesBySelection(mainTitleSelection).ifEmpty {
val subTitleSelection = if (englishTrimmed != null && romajiTrimmed != null) {
"subTitle LIKE '%$englishTrimmed%' OR subTitle LIKE '%$romajiTrimmed%'"
} else if (englishTrimmed != null) {
"subTitle LIKE '%$englishTrimmed%'"
} else {
"subTitle LIKE '%$romajiTrimmed%'"
}

seriesBySelection(subTitleSelection)
}
}
}

actual fun resolveByName(value: String): ImmutableSet<Series> {
val trimmed = value.trim().replace("'", "").trim()

return if (trimmed.length >= 3) {
seriesBySelection("title LIKE '%$trimmed%'")
seriesBySelection("fullTitle LIKE '%$trimmed%'")
} else {
persistentSetOf()
}
}

private fun seriesBySelection(selection: String): ImmutableSet<Series> {
private fun seriesBySelection(selection: String): ImmutableSet<Series> = scopeCatching {
if (seriesClient == null) {
return persistentSetOf()
return@scopeCatching persistentSetOf()
}

val seriesCursor = seriesClient.query(
Expand All @@ -146,13 +166,13 @@ actual class BurningSeriesResolver(
selection,
null,
null
) ?: return persistentSetOf()
) ?: return@scopeCatching persistentSetOf()

val series = mutableSetOf<Series>()

if (seriesCursor.moveToFirst()) {
while (!seriesCursor.isAfterLast) {
val titleIndex = seriesCursor.getColumnIndex("title")
val titleIndex = seriesCursor.getColumnIndex("fullTitle")
val hrefIndex = seriesCursor.getColumnIndex("hrefPrimary")

if (hrefIndex == -1) {
Expand All @@ -175,12 +195,14 @@ actual class BurningSeriesResolver(
}

seriesCursor.close()
return series.toImmutableSet()
}
return@scopeCatching series.toImmutableSet()
}.getOrNull() ?: persistentSetOf()

actual fun close() {
episodeClient?.close()
seriesClient?.close()
scopeCatching {
episodeClient?.close()
seriesClient?.close()
}
}

companion object {
Expand Down

0 comments on commit 4d9f5b8

Please sign in to comment.