Skip to content

Commit

Permalink
Revert "Update sandwich to 2.0.0"
Browse files Browse the repository at this point in the history
This reverts commit e815b94.
  • Loading branch information
nonproto committed Nov 8, 2023
1 parent 7392d56 commit c9bec34
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 43 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ dependencies {
implementation(libs.versioncompare)
implementation(libs.tokenbucket)
implementation(libs.bundles.kahelpers)
implementation(libs.bundles.sandwich)
implementation(libs.sandwich)
implementation(libs.aboutLibraries.compose)
debugImplementation(libs.leakcanary)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ class V5MigrationService(
actualMigrated++
}

is ApiResponse.Failure.Error, is ApiResponse.Failure.Exception,
is ApiResponse.Failure.Error<*>, is ApiResponse.Failure.Exception<*>,
-> {
responseDto.log(" trying to map legacy id")
if (responseDto is ApiResponse.Failure.Exception) {
if (responseDto is ApiResponse.Failure.Exception<*>) {
failedUpdatesMangaList[manga] = "error processing"
failedUpdatesErrors.add(manga.title + ": error processing")
} else {
Expand Down Expand Up @@ -140,7 +140,7 @@ class V5MigrationService(
}
}

is ApiResponse.Failure.Error, is ApiResponse.Failure.Exception,
is ApiResponse.Failure.Error<*>, is ApiResponse.Failure.Exception<*>,
-> {
legacyIds.forEach {
val failedChapter = chapterMap[it]!!
Expand Down Expand Up @@ -174,7 +174,7 @@ class V5MigrationService(
private fun finishUpdates(
context: Context,
errorNotification: (List<String>, Uri?) -> Unit,
completeNotification: (Int) -> Unit,
completeNotificaton: (Int) -> Unit,
) {
if (failedUpdatesMangaList.isNotEmpty() || failedUpdatesChapters.isNotEmpty()) {
val errorFile = writeErrorFile(context, failedUpdatesErrors)
Expand All @@ -184,7 +184,7 @@ class V5MigrationService(
errorFile.getUriCompat(context),
)
}
completeNotification(actualMigrated)
completeNotificaton(actualMigrated)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class FollowsHandler {
val response =
authService.updateReadingStatusForManga(mangaId, readingStatusDto)
) {
is ApiResponse.Failure.Error, is ApiResponse.Failure.Exception -> {
is ApiResponse.Failure.Error<*>, is ApiResponse.Failure.Exception<*> -> {
response.log("trying to update reading status for manga $mangaId")
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.skydoves.sandwich.getOrNull
import com.skydoves.sandwich.getOrThrow
import com.skydoves.sandwich.onError
import com.skydoves.sandwich.onFailure
import com.skydoves.sandwich.retrofit.statusCode
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.MangaSimilar
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
Expand All @@ -25,7 +24,6 @@ import eu.kanade.tachiyomi.util.manga.MangaMappings
import eu.kanade.tachiyomi.util.system.withIOContext
import eu.kanade.tachiyomi.util.throws
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.nekomanga.constants.MdConstants
import org.nekomanga.core.network.ProxyRetrofitQueryMap
import org.nekomanga.domain.manga.SourceManga
Expand All @@ -38,7 +36,6 @@ class SimilarHandler {
private val db: DatabaseHelper by injectLazy()
private val mappings: MangaMappings by injectLazy()
private val preferencesHelper: PreferencesHelper by injectLazy()
private val json: Json by injectLazy()

suspend fun fetchRelated(
dexId: String,
Expand Down Expand Up @@ -131,26 +128,12 @@ class SimilarHandler {
forceRefresh: Boolean,
): List<SourceManga> {
if (forceRefresh) {
val dto = networkServices.similarService.getSimilarManga(dexId)
.onFailure {
TimberKt.e { "trying to get similar manga, $this" }
}.getOrNull()
val response = networkServices.similarService.getSimilarManga(dexId)
.onFailure {
TimberKt.e { "trying to get similar manga, $this" }
}.getOrNull()

/* val response2 = networkServices.similarServiceUpdated.getSimilarMangaString(dexId.substring(0, 2), dexId.substring(0, 3)).onFailure {
TimberKt.e { "trying to get similar manga, $this" }
}.getOrNull()
val dto = response2?.split("\n")?.mapNotNull { line ->
val splitLine = line.split(":::||@!@||:::")
if (splitLine.isNotEmpty() && splitLine.size == 2 && splitLine[0] == dexId) {
json.decodeFromString<SimilarMangaDto>(splitLine[1])
} else {
null
}
}?.firstOrNull()
*/

similarMangaParse(dexId, dto)
similarMangaParse(dexId, response)
}

val mangaDb = db.getSimilar(dexId).executeAsBlocking()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import com.github.michaelbull.result.Result
import com.skydoves.sandwich.ApiResponse
import com.skydoves.sandwich.onFailure
import com.skydoves.sandwich.onSuccess
import com.skydoves.sandwich.retrofit.errorBody
import com.skydoves.sandwich.retrofit.statusCode
import eu.kanade.tachiyomi.source.online.models.dto.ErrorResponse
import kotlinx.serialization.json.Json
import org.jsoup.Jsoup
Expand All @@ -17,7 +15,7 @@ import org.nekomanga.logging.TimberKt
/**
* Maps the ApiResponse Error to a Result Error, trying to decode the json response if its a mangadex api error
*/
fun ApiResponse.Failure.Error.toResultError(errorType: String): ResultError {
fun ApiResponse.Failure.Error<*>.toResultError(errorType: String): ResultError {
val errorBody = this.errorBody?.string() ?: ""

TimberKt.e {
Expand Down Expand Up @@ -49,7 +47,7 @@ fun ApiResponse.Failure.Error.toResultError(errorType: String): ResultError {
return ResultError.HttpError(this.statusCode.code, error)
}

fun <T> ApiResponse.Failure<T>.toResultError(errorType: String): ResultError {
fun ApiResponse.Failure<*>.toResultError(errorType: String): ResultError {
return when (this) {
is ApiResponse.Failure.Error -> this.toResultError(errorType)
is ApiResponse.Failure.Exception -> this.toResultError(errorType)
Expand All @@ -69,16 +67,16 @@ fun <T> ApiResponse<T>.getOrResultError(errorType: String): Result<T, ResultErro
/**
* Maps the ApiResponse Exception to a Result Error
*/
fun ApiResponse.Failure.Exception.toResultError(errorType: String): ResultError {
TimberKt.e(this.throwable) { "Exception $errorType ${this.message}" }
fun ApiResponse.Failure.Exception<*>.toResultError(errorType: String): ResultError {
TimberKt.e(this.exception) { "Exception $errorType ${this.message}" }

return ResultError.Generic(errorString = "Unknown Error: '${this.message}'")
}

fun ApiResponse<*>.log(type: String) {
return when (this) {
is ApiResponse.Failure.Exception -> {
TimberKt.e(this.throwable) { "Exception $type ${this.message}" }
TimberKt.e(this.exception) { "Exception $type ${this.message}" }
}

is ApiResponse.Failure.Error -> {
Expand All @@ -104,7 +102,7 @@ fun ApiResponse<*>.throws(type: String) {
}

is ApiResponse.Failure.Exception -> {
throw Exception("Error $type ${this.message} ${this.throwable}")
throw Exception("Error $type ${this.message} ${this.exception}")
}

else -> {
Expand Down
7 changes: 1 addition & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ okhttp_version = "5.0.0-alpha.11"
retrofit_version = "2.9.0"
rxbinding_version = "1.0.1"
roboelectric_version = "4.8.1"
sandwich_version = "2.0.0"
kotlin_result = "1.1.18"


Expand Down Expand Up @@ -93,10 +92,7 @@ okhttp-logging-interceptor = { module = "com.squareup.okhttp3:logging-intercepto
okhttp-dnsoverhttps = { module = "com.squareup.okhttp3:okhttp-dnsoverhttps", version.ref = "okhttp_version" }
okio = "com.squareup.okio:okio:3.6.0"

sandwich = { module = "com.github.skydoves:sandwich", version.ref = "sandwich_version" }
sandwich-retrofit = { module = "com.github.skydoves:sandwich-retrofit", version.ref = "sandwich_version" }
sandwich-retrofit-serialization = { module = "com.github.skydoves:sandwich-retrofit-serialization", version.ref = "sandwich_version" }

sandwich = "com.github.skydoves:sandwich:1.3.9"
versioncompare = "io.github.g00fy2:versioncompare:1.5.0"

timber = "com.jakewharton.timber:timber:5.0.1"
Expand Down Expand Up @@ -134,7 +130,6 @@ iconics = ["iconics-core", "iconics-views", "iconics-compose"]
kahelpers = ["ka-helpers-kotlin-ext", "ka-helpers-activity", "ka-helpers-string", "ka-helpers-common"]
ok = ["okhttp", "okhttp-logging-interceptor", "okhttp-dnsoverhttps", "okio"]
nucleus = ["nucleus", "nucleus-support"]
sandwich = ["sandwich", "sandwich-retrofit", "sandwich-retrofit-serialization"]
tachiyomi = ["tachi-image-decoder", "tachi-source-api", "tachi-directional-view-pager", "tachi-unifile"]
tests = ["junit", "mockk", "kotest-assertions"]
retrofit = ["retrofit-core", "retrofit-serialization", "retrofit-scalars"]
Expand Down

0 comments on commit c9bec34

Please sign in to comment.