diff --git a/composeApp/src/androidMain/AndroidManifest.xml b/composeApp/src/androidMain/AndroidManifest.xml index a613d69..1d1613e 100644 --- a/composeApp/src/androidMain/AndroidManifest.xml +++ b/composeApp/src/androidMain/AndroidManifest.xml @@ -233,14 +233,6 @@ - - - - - - diff --git a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/MainActivity.kt b/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/MainActivity.kt index dc6b271..684cdee 100644 --- a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/MainActivity.kt @@ -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 @@ -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() { @@ -109,7 +111,11 @@ class MainActivity : AppCompatActivity() { override fun onDestroy() { super.onDestroy() + val di = applicationContext.safeCast()?.di ?: (application as DIAware).di + val resolver by di.instanceOrNull() + DomainVerifier.verify(this) + resolver?.close() } override fun onStart() { diff --git a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/other/BurningSeriesReceiver.kt b/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/other/BurningSeriesReceiver.kt deleted file mode 100644 index f5e26f9..0000000 --- a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/other/BurningSeriesReceiver.kt +++ /dev/null @@ -1,17 +0,0 @@ -package dev.datlag.aniflow.other - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import dev.datlag.aniflow.model.ifValueOrNull - -open class BurningSeriesReceiver : BroadcastReceiver() { - override fun onReceive(context: Context?, intent: Intent?) { - intent?.let { i -> - val seriesHref = i.getStringExtra("href")?.ifBlank { null } ?: return@let - val watched = i.getIntExtra("watched", -1).ifValueOrNull(-1) { return@let } - - // ToDo("check connected href and set watched status") - } - } -} \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/other/BurningSeriesResolver.android.kt b/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/other/BurningSeriesResolver.android.kt index b0cb856..cf1e4b4 100644 --- a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/other/BurningSeriesResolver.android.kt +++ b/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/other/BurningSeriesResolver.android.kt @@ -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 { 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 { + private fun seriesBySelection(selection: String): ImmutableSet = scopeCatching { if (seriesClient == null) { - return persistentSetOf() + return@scopeCatching persistentSetOf() } val seriesCursor = seriesClient.query( @@ -146,13 +166,13 @@ actual class BurningSeriesResolver( selection, null, null - ) ?: return persistentSetOf() + ) ?: return@scopeCatching persistentSetOf() val series = mutableSetOf() if (seriesCursor.moveToFirst()) { while (!seriesCursor.isAfterLast) { - val titleIndex = seriesCursor.getColumnIndex("title") + val titleIndex = seriesCursor.getColumnIndex("fullTitle") val hrefIndex = seriesCursor.getColumnIndex("hrefPrimary") if (hrefIndex == -1) { @@ -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 {