Compare commits
No commits in common. "270d959ee05a8b9e03ee4f145667a5ebc81d02fd" and "4c12c9d570be64ae9a68db70fd68b6b4c14537f7" have entirely different histories.
270d959ee0
...
4c12c9d570
@ -101,7 +101,6 @@ android {
|
|||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = "1.8"
|
jvmTarget = "1.8"
|
||||||
}
|
}
|
||||||
namespace = "bou.amine.apps.readerforselfossv2.android"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
package="bou.amine.apps.readerforselfossv2.android">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
@ -9,7 +9,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
|
|||||||
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityAddSourceBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityAddSourceBinding
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.Toppings
|
import bou.amine.apps.readerforselfossv2.android.themes.Toppings
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlInvalid
|
import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlValid
|
||||||
import bou.amine.apps.readerforselfossv2.model.NetworkUnavailableException
|
import bou.amine.apps.readerforselfossv2.model.NetworkUnavailableException
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
@ -84,7 +84,7 @@ class AddSourceActivity : AppCompatActivity(), DIAware {
|
|||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
val baseUrl = appSettingsService.getBaseUrl()
|
val baseUrl = appSettingsService.getBaseUrl()
|
||||||
if (baseUrl.isEmpty() || baseUrl.isBaseUrlInvalid(this@AddSourceActivity)) {
|
if (baseUrl.isEmpty() || !baseUrl.isBaseUrlValid(this@AddSourceActivity)) {
|
||||||
mustLoginToAddSource()
|
mustLoginToAddSource()
|
||||||
} else {
|
} else {
|
||||||
handleSpoutsSpinner(binding.spoutsSpinner, binding.progress, binding.formContainer)
|
handleSpoutsSpinner(binding.spoutsSpinner, binding.progress, binding.formContainer)
|
||||||
|
@ -14,7 +14,7 @@ import androidx.appcompat.app.AlertDialog
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityLoginBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityLoginBinding
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlInvalid
|
import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlValid
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
import com.mikepenz.aboutlibraries.LibsBuilder
|
import com.mikepenz.aboutlibraries.LibsBuilder
|
||||||
@ -122,7 +122,7 @@ class LoginActivity : AppCompatActivity(), DIAware {
|
|||||||
var cancel = false
|
var cancel = false
|
||||||
var focusView: View? = null
|
var focusView: View? = null
|
||||||
|
|
||||||
if (url.isBaseUrlInvalid(this@LoginActivity)) {
|
if (!url.isBaseUrlValid(this@LoginActivity)) {
|
||||||
binding.urlView.error = getString(R.string.login_url_problem)
|
binding.urlView.error = getString(R.string.login_url_problem)
|
||||||
focusView = binding.urlView
|
focusView = binding.urlView
|
||||||
cancel = true
|
cancel = true
|
||||||
|
@ -268,8 +268,8 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
|
|
||||||
private fun getContentFromMercury(customTabsIntent: CustomTabsIntent) {
|
private fun getContentFromMercury(customTabsIntent: CustomTabsIntent) {
|
||||||
if (repository.isNetworkAvailable()) {
|
if (repository.isNetworkAvailable()) {
|
||||||
binding.progressBar.visibility = View.VISIBLE
|
binding.progressBar.visibility = View.VISIBLE
|
||||||
val parser = MercuryApi()
|
val parser = MercuryApi()
|
||||||
|
|
||||||
parser.parseUrl(url).enqueue(
|
parser.parseUrl(url).enqueue(
|
||||||
object : Callback<ParsedContent> {
|
object : Callback<ParsedContent> {
|
||||||
|
@ -163,7 +163,7 @@ private fun openInBrowser(linkDecoded: String, app: Activity) {
|
|||||||
fun String.isUrlValid(): Boolean =
|
fun String.isUrlValid(): Boolean =
|
||||||
this.toHttpUrlOrNull() != null && Patterns.WEB_URL.matcher(this).matches()
|
this.toHttpUrlOrNull() != null && Patterns.WEB_URL.matcher(this).matches()
|
||||||
|
|
||||||
fun String.isBaseUrlInvalid(ctx: Context): Boolean {
|
fun String.isBaseUrlValid(ctx: Context): Boolean {
|
||||||
val baseUrl = this.toHttpUrlOrNull()
|
val baseUrl = this.toHttpUrlOrNull()
|
||||||
var existsAndEndsWithSlash = false
|
var existsAndEndsWithSlash = false
|
||||||
if (baseUrl != null) {
|
if (baseUrl != null) {
|
||||||
@ -171,7 +171,7 @@ fun String.isBaseUrlInvalid(ctx: Context): Boolean {
|
|||||||
existsAndEndsWithSlash = "" == pathSegments[pathSegments.size - 1]
|
existsAndEndsWithSlash = "" == pathSegments[pathSegments.size - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
return !(Patterns.WEB_URL.matcher(this).matches() && existsAndEndsWithSlash)
|
return Patterns.WEB_URL.matcher(this).matches() && existsAndEndsWithSlash
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.openInBrowserAsNewTask(i: SelfossModel.Item) {
|
fun Context.openInBrowserAsNewTask(i: SelfossModel.Item) {
|
||||||
|
@ -6,7 +6,7 @@ buildscript {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
|
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
|
||||||
classpath("com.android.tools.build:gradle:7.3.0")
|
classpath("com.android.tools.build:gradle:7.2.2")
|
||||||
|
|
||||||
// sonarquve
|
// sonarquve
|
||||||
classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.4.0.2513")
|
classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.4.0.2513")
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
|||||||
#Wed Feb 09 17:05:19 CET 2022
|
#Wed Feb 09 17:05:19 CET 2022
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
@ -112,7 +112,6 @@ android {
|
|||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
namespace = "bou.amine.apps.readerforselfossv2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sqldelight {
|
sqldelight {
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest />
|
<manifest package="bou.amine.apps.readerforselfossv2" />
|
@ -105,16 +105,4 @@ class SelfossModel {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StatusAndData<T>(val success: Boolean, val data: T? = null) {
|
|
||||||
companion object {
|
|
||||||
fun <T> succes(d: T): StatusAndData<T> {
|
|
||||||
return StatusAndData(true, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> error(): StatusAndData<T> {
|
|
||||||
return StatusAndData(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -47,7 +47,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
|
suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
|
||||||
// TODO: Use the updatedSince parameter
|
// TODO: Use the updatedSince parameter
|
||||||
var fetchedItems: SelfossModel.StatusAndData<List<SelfossModel.Item>> = SelfossModel.StatusAndData.error()
|
var fetchedItems: List<SelfossModel.Item>? = null
|
||||||
if (isNetworkAvailable()) {
|
if (isNetworkAvailable()) {
|
||||||
fetchedItems = api.getItems(
|
fetchedItems = api.getItems(
|
||||||
displayedItems.type,
|
displayedItems.type,
|
||||||
@ -59,25 +59,23 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
if (appSettingsService.isItemCachingEnabled()) {
|
if (appSettingsService.isItemCachingEnabled()) {
|
||||||
fetchedItems = SelfossModel.StatusAndData.succes(
|
fetchedItems = getDBItems().filter {
|
||||||
getDBItems().filter {
|
displayedItems == ItemType.ALL ||
|
||||||
displayedItems == ItemType.ALL ||
|
(it.unread && displayedItems == ItemType.UNREAD) ||
|
||||||
(it.unread && displayedItems == ItemType.UNREAD) ||
|
(it.starred && displayedItems == ItemType.STARRED)
|
||||||
(it.starred && displayedItems == ItemType.STARRED)
|
}.map { it.toView() }
|
||||||
}.map { it.toView() }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fetchedItems.success && fetchedItems.data != null) {
|
if (fetchedItems != null) {
|
||||||
items = ArrayList(fetchedItems.data!!)
|
items = ArrayList(fetchedItems)
|
||||||
sortItems()
|
sortItems()
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getOlderItems(): ArrayList<SelfossModel.Item> {
|
suspend fun getOlderItems(): ArrayList<SelfossModel.Item> {
|
||||||
var fetchedItems: SelfossModel.StatusAndData<List<SelfossModel.Item>> = SelfossModel.StatusAndData.error()
|
var fetchedItems: List<SelfossModel.Item>? = null
|
||||||
if (isNetworkAvailable()) {
|
if (isNetworkAvailable()) {
|
||||||
val offset = items.size
|
val offset = items.size
|
||||||
fetchedItems = api.getItems(
|
fetchedItems = api.getItems(
|
||||||
@ -90,16 +88,16 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
)
|
)
|
||||||
} // When using the db cache, we load everything the first time, so there should be nothing more to load.
|
} // When using the db cache, we load everything the first time, so there should be nothing more to load.
|
||||||
|
|
||||||
if (fetchedItems.success && fetchedItems.data != null) {
|
if (fetchedItems != null) {
|
||||||
items.addAll(fetchedItems.data!!)
|
items.addAll(fetchedItems)
|
||||||
sortItems()
|
sortItems()
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getMaxItemsForBackground(itemType: ItemType): List<SelfossModel.Item> {
|
private suspend fun getMaxItemsForBackground(itemType: ItemType): List<SelfossModel.Item>? {
|
||||||
return if (isNetworkAvailable()) {
|
return if (isNetworkAvailable()) {
|
||||||
val items = api.getItems(
|
api.getItems(
|
||||||
itemType.type,
|
itemType.type,
|
||||||
0,
|
0,
|
||||||
tagFilter?.tag,
|
tagFilter?.tag,
|
||||||
@ -108,11 +106,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
null,
|
null,
|
||||||
200
|
200
|
||||||
)
|
)
|
||||||
return if (items.success && items.data != null) {
|
|
||||||
items.data
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
@ -126,10 +119,10 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
var success = false
|
var success = false
|
||||||
if (isNetworkAvailable()) {
|
if (isNetworkAvailable()) {
|
||||||
val response = api.stats()
|
val response = api.stats()
|
||||||
if (response.success && response.data != null) {
|
if (response != null) {
|
||||||
badgeUnread = response.data.unread
|
badgeUnread = response.unread
|
||||||
badgeAll = response.data.total
|
badgeAll = response.total
|
||||||
badgeStarred = response.data.starred
|
badgeStarred = response.starred
|
||||||
success = true
|
success = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -145,10 +138,10 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
suspend fun getTags(): List<SelfossModel.Tag>? {
|
suspend fun getTags(): List<SelfossModel.Tag>? {
|
||||||
return if (isNetworkAvailable()) {
|
return if (isNetworkAvailable()) {
|
||||||
val apiTags = api.tags()
|
val apiTags = api.tags()
|
||||||
if (apiTags.success && apiTags.data != null && (appSettingsService.isItemCachingEnabled() || !appSettingsService.isUpdateSourcesEnabled())) {
|
if (apiTags != null && (appSettingsService.isItemCachingEnabled() || !appSettingsService.isUpdateSourcesEnabled())) {
|
||||||
resetDBTagsWithData(apiTags.data)
|
resetDBTagsWithData(apiTags)
|
||||||
}
|
}
|
||||||
apiTags.data
|
apiTags
|
||||||
} else {
|
} else {
|
||||||
getDBTags().map { it.toView() }
|
getDBTags().map { it.toView() }
|
||||||
}
|
}
|
||||||
@ -156,12 +149,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
suspend fun getSpouts(): Map<String, SelfossModel.Spout>? {
|
suspend fun getSpouts(): Map<String, SelfossModel.Spout>? {
|
||||||
return if (isNetworkAvailable()) {
|
return if (isNetworkAvailable()) {
|
||||||
val spouts = api.spouts()
|
api.spouts()
|
||||||
return if (spouts.success && spouts.data != null) {
|
|
||||||
spouts.data
|
|
||||||
} else {
|
|
||||||
emptyMap() // TODO: do something here
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw NetworkUnavailableException()
|
throw NetworkUnavailableException()
|
||||||
}
|
}
|
||||||
@ -170,10 +158,10 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
suspend fun getSources(): ArrayList<SelfossModel.Source>? {
|
suspend fun getSources(): ArrayList<SelfossModel.Source>? {
|
||||||
return if (isNetworkAvailable()) {
|
return if (isNetworkAvailable()) {
|
||||||
val apiSources = api.sources()
|
val apiSources = api.sources()
|
||||||
if (apiSources.success && apiSources.data != null && (appSettingsService.isItemCachingEnabled() || !appSettingsService.isUpdateSourcesEnabled())) {
|
if (apiSources != null && (appSettingsService.isItemCachingEnabled() || !appSettingsService.isUpdateSourcesEnabled())) {
|
||||||
resetDBSourcesWithData(apiSources.data)
|
resetDBSourcesWithData(apiSources)
|
||||||
}
|
}
|
||||||
apiSources.data
|
apiSources
|
||||||
} else {
|
} else {
|
||||||
ArrayList(getDBSources().map { it.toView() })
|
ArrayList(getDBSources().map { it.toView() })
|
||||||
}
|
}
|
||||||
@ -190,7 +178,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
private suspend fun markAsReadById(id: Int): Boolean {
|
private suspend fun markAsReadById(id: Int): Boolean {
|
||||||
return if (isNetworkAvailable()) {
|
return if (isNetworkAvailable()) {
|
||||||
api.markAsRead(id.toString())?.isSuccess
|
api.markAsRead(id.toString())?.isSuccess == true
|
||||||
} else {
|
} else {
|
||||||
insertDBAction(id.toString(), read = true)
|
insertDBAction(id.toString(), read = true)
|
||||||
true
|
true
|
||||||
@ -209,7 +197,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
private suspend fun unmarkAsReadById(id: Int): Boolean {
|
private suspend fun unmarkAsReadById(id: Int): Boolean {
|
||||||
return if (isNetworkAvailable()) {
|
return if (isNetworkAvailable()) {
|
||||||
api.unmarkAsRead(id.toString())?.isSuccess
|
api.unmarkAsRead(id.toString())?.isSuccess == true
|
||||||
} else {
|
} else {
|
||||||
insertDBAction(id.toString(), unread = true)
|
insertDBAction(id.toString(), unread = true)
|
||||||
true
|
true
|
||||||
@ -227,7 +215,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
private suspend fun starrById(id: Int): Boolean {
|
private suspend fun starrById(id: Int): Boolean {
|
||||||
return if (isNetworkAvailable()) {
|
return if (isNetworkAvailable()) {
|
||||||
api.starr(id.toString())?.isSuccess
|
api.starr(id.toString())?.isSuccess == true
|
||||||
} else {
|
} else {
|
||||||
insertDBAction(id.toString(), starred = true)
|
insertDBAction(id.toString(), starred = true)
|
||||||
true
|
true
|
||||||
@ -245,7 +233,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
private suspend fun unstarrById(id: Int): Boolean {
|
private suspend fun unstarrById(id: Int): Boolean {
|
||||||
return if (isNetworkAvailable()) {
|
return if (isNetworkAvailable()) {
|
||||||
api.unstarr(id.toString())?.isSuccess
|
api.unstarr(id.toString())?.isSuccess == true
|
||||||
} else {
|
} else {
|
||||||
insertDBAction(id.toString(), starred = true)
|
insertDBAction(id.toString(), starred = true)
|
||||||
true
|
true
|
||||||
@ -255,7 +243,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
suspend fun markAllAsRead(items: ArrayList<SelfossModel.Item>): Boolean {
|
suspend fun markAllAsRead(items: ArrayList<SelfossModel.Item>): Boolean {
|
||||||
var success = false
|
var success = false
|
||||||
|
|
||||||
if (isNetworkAvailable() && api.markAllAsRead(items.map { it.id.toString() })?.isSuccess) {
|
if (isNetworkAvailable() && api.markAllAsRead(items.map { it.id.toString() })?.isSuccess == true) {
|
||||||
success = true
|
success = true
|
||||||
for (item in items) {
|
for (item in items) {
|
||||||
markAsReadLocally(item)
|
markAsReadLocally(item)
|
||||||
@ -344,7 +332,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
suspend fun updateRemote(): Boolean {
|
suspend fun updateRemote(): Boolean {
|
||||||
return if (isNetworkAvailable()) {
|
return if (isNetworkAvailable()) {
|
||||||
api.update()?.equals("finished")
|
api.update()?.equals("finished") ?: false
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@ -377,8 +365,8 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
if (isNetworkAvailable()) {
|
if (isNetworkAvailable()) {
|
||||||
val fetchedVersion = api.version()
|
val fetchedVersion = api.version()
|
||||||
if (fetchedVersion.success && fetchedVersion.data != null && fetchedVersion.data.getApiMajorVersion() != apiMajorVersion) {
|
if (fetchedVersion != null && fetchedVersion.getApiMajorVersion() != apiMajorVersion) {
|
||||||
appSettingsService.updateApiVersion(fetchedVersion.data.getApiMajorVersion())
|
appSettingsService.updateApiVersion(fetchedVersion.getApiMajorVersion())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,7 +383,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
fun getDBSources(): List<SOURCE> = db.sourcesQueries.sources().executeAsList()
|
fun getDBSources(): List<SOURCE> = db.sourcesQueries.sources().executeAsList()
|
||||||
|
|
||||||
private fun resetDBTagsWithData(tagEntities: List<SelfossModel.Tag>) {
|
fun resetDBTagsWithData(tagEntities: List<SelfossModel.Tag>) {
|
||||||
db.tagsQueries.deleteAllTags()
|
db.tagsQueries.deleteAllTags()
|
||||||
|
|
||||||
db.tagsQueries.transaction {
|
db.tagsQueries.transaction {
|
||||||
@ -405,7 +393,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resetDBSourcesWithData(sources: List<SelfossModel.Source>) {
|
fun resetDBSourcesWithData(sources: List<SelfossModel.Source>) {
|
||||||
db.sourcesQueries.deleteAllSources()
|
db.sourcesQueries.deleteAllSources()
|
||||||
|
|
||||||
db.sourcesQueries.transaction {
|
db.sourcesQueries.transaction {
|
||||||
@ -437,7 +425,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
val newItems = getMaxItemsForBackground(ItemType.UNREAD)
|
val newItems = getMaxItemsForBackground(ItemType.UNREAD)
|
||||||
val allItems = getMaxItemsForBackground(ItemType.ALL)
|
val allItems = getMaxItemsForBackground(ItemType.ALL)
|
||||||
val starredItems = getMaxItemsForBackground(ItemType.STARRED)
|
val starredItems = getMaxItemsForBackground(ItemType.STARRED)
|
||||||
insertDBItems(newItems + allItems + starredItems)
|
insertDBItems(newItems.orEmpty() + allItems.orEmpty() + starredItems.orEmpty())
|
||||||
return newItems
|
return newItems
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
// We do nothing
|
// We do nothing
|
||||||
|
@ -10,7 +10,6 @@ import io.ktor.client.plugins.contentnegotiation.*
|
|||||||
import io.ktor.client.plugins.logging.*
|
import io.ktor.client.plugins.logging.*
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.request.forms.*
|
import io.ktor.client.request.forms.*
|
||||||
import io.ktor.client.statement.*
|
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.serialization.kotlinx.json.*
|
import io.ktor.serialization.kotlinx.json.*
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
@ -35,7 +34,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
appSettingsService.logApiCalls(message)
|
appSettingsService.logApiCalls(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
level = LogLevel.INFO
|
level = LogLevel.ALL
|
||||||
}
|
}
|
||||||
install(HttpTimeout) {
|
install(HttpTimeout) {
|
||||||
requestTimeoutMillis = appSettingsService.getApiTimeout()
|
requestTimeoutMillis = appSettingsService.getApiTimeout()
|
||||||
@ -66,11 +65,11 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
client = createHttpClient()
|
client = createHttpClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun login(): SelfossModel.SuccessResponse =
|
suspend fun login(): SelfossModel.SuccessResponse? =
|
||||||
maybeResponse(client.get(url("/login")) {
|
client.get(url("/login")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
}.body()
|
||||||
|
|
||||||
suspend fun getItems(
|
suspend fun getItems(
|
||||||
type: String,
|
type: String,
|
||||||
@ -80,8 +79,8 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
search: String?,
|
search: String?,
|
||||||
updatedSince: String?,
|
updatedSince: String?,
|
||||||
items: Int? = null
|
items: Int? = null
|
||||||
): SelfossModel.StatusAndData<List<SelfossModel.Item>> =
|
): List<SelfossModel.Item>? =
|
||||||
bodyOrFailure(client.get(url("/items")) {
|
client.get(url("/items")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
parameter("type", type)
|
parameter("type", type)
|
||||||
@ -91,74 +90,74 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
parameter("updatedsince", updatedSince)
|
parameter("updatedsince", updatedSince)
|
||||||
parameter("items", items ?: appSettingsService.getItemsNumber())
|
parameter("items", items ?: appSettingsService.getItemsNumber())
|
||||||
parameter("offset", offset)
|
parameter("offset", offset)
|
||||||
})
|
}.body()
|
||||||
|
|
||||||
suspend fun stats(): SelfossModel.StatusAndData<SelfossModel.Stats> =
|
suspend fun stats(): SelfossModel.Stats? =
|
||||||
bodyOrFailure(client.get(url("/stats")) {
|
client.get(url("/stats")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
}.body()
|
||||||
|
|
||||||
suspend fun tags(): SelfossModel.StatusAndData<List<SelfossModel.Tag>> =
|
suspend fun tags(): List<SelfossModel.Tag>? =
|
||||||
bodyOrFailure(client.get(url("/tags")) {
|
client.get(url("/tags")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
}.body()
|
||||||
|
|
||||||
suspend fun update(): SelfossModel.StatusAndData<String> =
|
suspend fun update(): String? =
|
||||||
bodyOrFailure(client.get(url("/update")) {
|
client.get(url("/update")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
}.body()
|
||||||
|
|
||||||
suspend fun spouts(): SelfossModel.StatusAndData<Map<String, SelfossModel.Spout>> =
|
suspend fun spouts(): Map<String, SelfossModel.Spout>? =
|
||||||
bodyOrFailure(client.get(url("/sources/spouts")) {
|
client.get(url("/sources/spouts")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
}.body()
|
||||||
|
|
||||||
suspend fun sources(): SelfossModel.StatusAndData<ArrayList<SelfossModel.Source>> =
|
suspend fun sources(): ArrayList<SelfossModel.Source>? =
|
||||||
bodyOrFailure(client.get(url("/sources/list")) {
|
client.get(url("/sources/list")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
}.body()
|
||||||
|
|
||||||
suspend fun version(): SelfossModel.StatusAndData<SelfossModel.ApiVersion> =
|
suspend fun version(): SelfossModel.ApiVersion? =
|
||||||
bodyOrFailure(client.get(url("/api/about")))
|
client.get(url("/api/about")).body()
|
||||||
|
|
||||||
suspend fun markAsRead(id: String): SelfossModel.SuccessResponse =
|
suspend fun markAsRead(id: String): SelfossModel.SuccessResponse? =
|
||||||
maybeResponse(client.post(url("/mark/$id")) {
|
client.post(url("/mark/$id")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
}.body()
|
||||||
|
|
||||||
suspend fun unmarkAsRead(id: String): SelfossModel.SuccessResponse =
|
suspend fun unmarkAsRead(id: String): SelfossModel.SuccessResponse? =
|
||||||
maybeResponse(client.post(url("/unmark/$id")) {
|
client.post(url("/unmark/$id")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
}.body()
|
||||||
|
|
||||||
suspend fun starr(id: String): SelfossModel.SuccessResponse =
|
suspend fun starr(id: String): SelfossModel.SuccessResponse? =
|
||||||
maybeResponse(client.post(url("/starr/$id")) {
|
client.post(url("/starr/$id")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
}.body()
|
||||||
|
|
||||||
suspend fun unstarr(id: String): SelfossModel.SuccessResponse =
|
suspend fun unstarr(id: String): SelfossModel.SuccessResponse? =
|
||||||
maybeResponse(client.post(url("/unstarr/$id")) {
|
client.post(url("/unstarr/$id")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
}.body()
|
||||||
|
|
||||||
suspend fun markAllAsRead(ids: List<String>): SelfossModel.SuccessResponse =
|
suspend fun markAllAsRead(ids: List<String>): SelfossModel.SuccessResponse? =
|
||||||
maybeResponse(client.submitForm(
|
client.submitForm(
|
||||||
url = url("/mark"),
|
url = url("/mark"),
|
||||||
formParameters = Parameters.build {
|
formParameters = Parameters.build {
|
||||||
append("username", appSettingsService.getUserName())
|
append("username", appSettingsService.getUserName())
|
||||||
append("password", appSettingsService.getPassword())
|
append("password", appSettingsService.getPassword())
|
||||||
ids.map { append("ids[]", it) }
|
ids.map { append("ids[]", it) }
|
||||||
}
|
}
|
||||||
))
|
).body()
|
||||||
|
|
||||||
suspend fun createSourceForVersion(
|
suspend fun createSourceForVersion(
|
||||||
title: String,
|
title: String,
|
||||||
@ -167,14 +166,12 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
tags: String,
|
tags: String,
|
||||||
filter: String,
|
filter: String,
|
||||||
version: Int
|
version: Int
|
||||||
): SelfossModel.SuccessResponse =
|
): SelfossModel.SuccessResponse? =
|
||||||
maybeResponse(
|
if (version > 1) {
|
||||||
if (version > 1) {
|
createSource2(title, url, spout, tags, filter)
|
||||||
createSource2(title, url, spout, tags, filter)
|
} else {
|
||||||
} else {
|
createSource(title, url, spout, tags, filter)
|
||||||
createSource(title, url, spout, tags, filter)
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
suspend fun createSource(
|
suspend fun createSource(
|
||||||
title: String,
|
title: String,
|
||||||
@ -182,7 +179,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
spout: String,
|
spout: String,
|
||||||
tags: String,
|
tags: String,
|
||||||
filter: String
|
filter: String
|
||||||
): HttpResponse =
|
): SelfossModel.SuccessResponse? =
|
||||||
client.submitForm(
|
client.submitForm(
|
||||||
url = url("/source?username=${appSettingsService.getUserName()}&password=${appSettingsService.getPassword()}"),
|
url = url("/source?username=${appSettingsService.getUserName()}&password=${appSettingsService.getPassword()}"),
|
||||||
formParameters = Parameters.build {
|
formParameters = Parameters.build {
|
||||||
@ -192,7 +189,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
append("tags", tags)
|
append("tags", tags)
|
||||||
append("filter", filter)
|
append("filter", filter)
|
||||||
}
|
}
|
||||||
)
|
).body()
|
||||||
|
|
||||||
suspend fun createSource2(
|
suspend fun createSource2(
|
||||||
title: String,
|
title: String,
|
||||||
@ -200,7 +197,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
spout: String,
|
spout: String,
|
||||||
tags: String,
|
tags: String,
|
||||||
filter: String
|
filter: String
|
||||||
): HttpResponse =
|
): SelfossModel.SuccessResponse? =
|
||||||
client.submitForm(
|
client.submitForm(
|
||||||
url = url("/source?username=${appSettingsService.getUserName()}&password=${appSettingsService.getPassword()}"),
|
url = url("/source?username=${appSettingsService.getUserName()}&password=${appSettingsService.getPassword()}"),
|
||||||
formParameters = Parameters.build {
|
formParameters = Parameters.build {
|
||||||
@ -210,27 +207,11 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
append("tags[]", tags)
|
append("tags[]", tags)
|
||||||
append("filter", filter)
|
append("filter", filter)
|
||||||
}
|
}
|
||||||
)
|
).body()
|
||||||
|
|
||||||
suspend fun deleteSource(id: Int): SelfossModel.SuccessResponse =
|
suspend fun deleteSource(id: Int): SelfossModel.SuccessResponse? =
|
||||||
maybeResponse(client.delete(url("/source/$id")) {
|
client.delete(url("/source/$id")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
}.body()
|
||||||
|
|
||||||
suspend fun maybeResponse(r: HttpResponse): SelfossModel.SuccessResponse {
|
|
||||||
return if (r.status.isSuccess()) {
|
|
||||||
r.body()
|
|
||||||
} else {
|
|
||||||
SelfossModel.SuccessResponse(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend inline fun <reified T> bodyOrFailure(r: HttpResponse): SelfossModel.StatusAndData<T> {
|
|
||||||
return if (r.status.isSuccess()) {
|
|
||||||
SelfossModel.StatusAndData.succes(r.body())
|
|
||||||
} else {
|
|
||||||
SelfossModel.StatusAndData.error()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user