mirror of https://github.com/readrops/Readrops.git
Improve error handling when adding a new feed in FeedTab
This commit is contained in:
parent
e176cdbdb1
commit
a3c9e0a89e
|
@ -21,6 +21,7 @@ import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.get
|
import org.koin.core.component.get
|
||||||
|
import java.net.UnknownHostException
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
class FeedViewModel(
|
class FeedViewModel(
|
||||||
|
@ -161,23 +162,30 @@ class FeedViewModel(
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> viewModelScope.launch(Dispatchers.IO) {
|
else -> viewModelScope.launch(Dispatchers.IO) {
|
||||||
if (localRSSDataSource.isUrlRSSResource(url)) {
|
try {
|
||||||
// TODO add support for all account types
|
if (localRSSDataSource.isUrlRSSResource(url)) {
|
||||||
repository?.insertNewFeeds(listOf(url))
|
|
||||||
|
|
||||||
closeDialog()
|
|
||||||
} else {
|
|
||||||
val rssUrls = HtmlParser.getFeedLink(url, get())
|
|
||||||
|
|
||||||
if (rssUrls.isEmpty()) {
|
|
||||||
_addFeedDialogState.update {
|
|
||||||
it.copy(error = TextFieldError.NoRSSFeed)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TODO add support for all account types
|
// TODO add support for all account types
|
||||||
repository?.insertNewFeeds(rssUrls.map { it.url })
|
repository?.insertNewFeeds(listOf(url))
|
||||||
|
|
||||||
closeDialog()
|
closeDialog()
|
||||||
|
} else {
|
||||||
|
val rssUrls = HtmlParser.getFeedLink(url, get())
|
||||||
|
|
||||||
|
if (rssUrls.isEmpty()) {
|
||||||
|
_addFeedDialogState.update {
|
||||||
|
it.copy(error = TextFieldError.NoRSSFeed)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO add support for all account types
|
||||||
|
repository?.insertNewFeeds(rssUrls.map { it.url })
|
||||||
|
|
||||||
|
closeDialog()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
when (e) {
|
||||||
|
is UnknownHostException -> _addFeedDialogState.update { it.copy(error = TextFieldError.UnreachableUrl) }
|
||||||
|
else -> _addFeedDialogState.update { it.copy(error = TextFieldError.NoRSSFeed) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,5 +311,4 @@ class FeedViewModel(
|
||||||
}
|
}
|
||||||
|
|
||||||
// add/update folder
|
// add/update folder
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue