fix: Checking if selfoss instance.
This commit is contained in:
parent
14ff4dbd05
commit
6e27d6d4e6
@ -140,20 +140,25 @@ class LoginActivity : AppCompatActivity(), DIAware {
|
|||||||
repository.refreshLoginInformation(url, login, password)
|
repository.refreshLoginInformation(url, login, password)
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
try {
|
||||||
repository.updateApiInformation()
|
repository.updateApiInformation()
|
||||||
val result = repository.login()
|
} catch (e: Exception) {
|
||||||
if (result) {
|
if (e.message?.startsWith("No transformation found") == true) {
|
||||||
val (errorFetching, displaySelfossOnly) = repository.shouldBeSelfossInstance()
|
|
||||||
if (!errorFetching && !displaySelfossOnly) {
|
|
||||||
goToMain()
|
|
||||||
} else {
|
|
||||||
if (displaySelfossOnly) {
|
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
applicationContext,
|
applicationContext,
|
||||||
R.string.application_selfoss_only,
|
R.string.application_selfoss_only,
|
||||||
Toast.LENGTH_LONG,
|
Toast.LENGTH_LONG,
|
||||||
).show()
|
).show()
|
||||||
|
preferenceError()
|
||||||
|
showProgress(false)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
val result = repository.login()
|
||||||
|
if (result) {
|
||||||
|
val errorFetching = repository.checkIfFetchFails()
|
||||||
|
if (!errorFetching) {
|
||||||
|
goToMain()
|
||||||
|
} else {
|
||||||
preferenceError()
|
preferenceError()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,7 +8,6 @@ import bou.amine.apps.readerforselfossv2.rest.SelfossApi
|
|||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
import bou.amine.apps.readerforselfossv2.utils.*
|
import bou.amine.apps.readerforselfossv2.utils.*
|
||||||
import io.github.aakira.napier.Napier
|
import io.github.aakira.napier.Napier
|
||||||
import io.ktor.client.call.*
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
@ -429,22 +428,19 @@ class Repository(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun shouldBeSelfossInstance(): Pair<Boolean, Boolean> {
|
suspend fun checkIfFetchFails(): Boolean {
|
||||||
var fetchFailed = true
|
var fetchFailed = true
|
||||||
var showSelfossOnlyModal = false
|
|
||||||
if (isNetworkAvailable()) {
|
if (isNetworkAvailable()) {
|
||||||
try {
|
try {
|
||||||
// Trying to fetch one item, and check someone is trying to use the app with
|
// Trying to fetch one item, and check someone is trying to use the app with
|
||||||
// a random rss feed, that would throw a NoTransformationFoundException
|
// a random rss feed, that would throw a NoTransformationFoundException
|
||||||
fetchFailed = !api.getItemsWithoutCatch().success
|
fetchFailed = !api.getItemsWithoutCatch().success
|
||||||
} catch (e: NoTransformationFoundException) {
|
|
||||||
showSelfossOnlyModal = true
|
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Napier.e(e.stackTraceToString(), tag = "RepositoryImpl.shouldBeSelfossInstance")
|
Napier.e(e.stackTraceToString(), tag = "RepositoryImpl.shouldBeSelfossInstance")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Pair(fetchFailed, showSelfossOnlyModal)
|
return fetchFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun logout() {
|
suspend fun logout() {
|
||||||
|
Loading…
Reference in New Issue
Block a user