forked from Louvorg/ReaderForSelfoss-multiplatform
Compare commits
16 Commits
v122123431
...
v122123521
Author | SHA1 | Date | |
---|---|---|---|
2cfaa9b285 | |||
f42ae97326 | |||
3b0028164b | |||
7420adeb5c | |||
316027ca3b | |||
9d58fba5c9 | |||
284c19ef89 | |||
7cfd17231a | |||
527830a5ae | |||
c4ed30f594 | |||
156c1681cf | |||
3593fbca78 | |||
430fc8e8cb | |||
4fce19bad4 | |||
49f5848e7b | |||
90452100a4 |
24
.drone.yml
24
.drone.yml
@ -3,27 +3,34 @@ type: docker
|
|||||||
name: test
|
name: test
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: AnylyseBuildTest
|
- name: BuildAndTest
|
||||||
image: mingc/android-build-box:latest
|
image: mingc/android-build-box:latest
|
||||||
commands:
|
commands:
|
||||||
- echo "---------------------------------------------------------"
|
- echo "---------------------------------------------------------"
|
||||||
- echo "Configure gradle..."
|
- echo "Configure gradle..."
|
||||||
- mkdir -p ~/.gradle && echo "org.gradle.daemon=false\nignoreGitVersion=true\npushCache=false\nsystemProp.org.gradle.internal.http.connectionTimeout=180000\nsystemProp.org.gradle.internal.http.socketTimeout=180000" >> ~/.gradle/gradle.properties
|
- mkdir -p ~/.gradle && echo "org.gradle.daemon=false\nignoreGitVersion=true\npushCache=false\nsystemProp.org.gradle.internal.http.connectionTimeout=180000\nsystemProp.org.gradle.internal.http.socketTimeout=180000" >> ~/.gradle/gradle.properties
|
||||||
- echo "---------------------------------------------------------"
|
- echo "---------------------------------------------------------"
|
||||||
- echo "Analysing..."
|
|
||||||
- ./gradlew sonarqube -Dsonar.projectKey=RFS2 -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_LOGIN
|
|
||||||
- echo "---------------------------------------------------------"
|
|
||||||
- echo "Building..."
|
- echo "Building..."
|
||||||
- ./gradlew build
|
- ./gradlew build -x test
|
||||||
- echo "---------------------------------------------------------"
|
- echo "---------------------------------------------------------"
|
||||||
- echo "Testing..."
|
- echo "Testing..."
|
||||||
- echo "---------------------------------------------------------"
|
- echo "---------------------------------------------------------"
|
||||||
- ./gradlew test
|
- ./gradlew koverMergedXmlReport
|
||||||
environment:
|
environment:
|
||||||
SONAR_HOST_URL:
|
SONAR_HOST_URL:
|
||||||
from_secret: sonarScannerHostUrl
|
from_secret: sonarScannerHostUrl
|
||||||
SONAR_LOGIN:
|
SONAR_LOGIN:
|
||||||
from_secret: sonarScannerLogin
|
from_secret: sonarScannerLogin
|
||||||
|
- name: Analyse
|
||||||
|
image: kytay/sonar-node-plugin
|
||||||
|
settings:
|
||||||
|
sonar_host:
|
||||||
|
from_secret: sonarScannerHostUrl
|
||||||
|
sonar_token:
|
||||||
|
from_secret: sonarScannerLogin
|
||||||
|
use_node_version: 16.18.1
|
||||||
|
sonar_debug: true
|
||||||
|
sonar_project_settings: ./sonar-project.properties
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
@ -88,9 +95,12 @@ steps:
|
|||||||
- name: build
|
- name: build
|
||||||
image: mingc/android-build-box:latest
|
image: mingc/android-build-box:latest
|
||||||
commands:
|
commands:
|
||||||
|
- echo "---------------------------------------------------------"
|
||||||
|
- echo "Fetch tags..."
|
||||||
|
- git fetch --tags
|
||||||
- echo "---------------------------------------------------------"
|
- echo "---------------------------------------------------------"
|
||||||
- echo "Configure gradle..."
|
- echo "Configure gradle..."
|
||||||
- mkdir -p ~/.gradle && echo "org.gradle.daemon=false\nignoreGitVersion=true\npushCache=false\nsystemProp.org.gradle.internal.http.connectionTimeout=180000\nsystemProp.org.gradle.internal.http.socketTimeout=180000" >> ~/.gradle/gradle.properties
|
- mkdir -p ~/.gradle && echo "org.gradle.daemon=false\nignoreGitVersion=false\npushCache=false\nsystemProp.org.gradle.internal.http.connectionTimeout=180000\nsystemProp.org.gradle.internal.http.socketTimeout=180000" >> ~/.gradle/gradle.properties
|
||||||
- echo "---------------------------------------------------------"
|
- echo "---------------------------------------------------------"
|
||||||
- echo "Generate APK"
|
- echo "Generate APK"
|
||||||
- ./gradlew :androidApp:assembleGithubConfigRelease -P pushCache=false
|
- ./gradlew :androidApp:assembleGithubConfigRelease -P pushCache=false
|
||||||
|
@ -8,6 +8,7 @@ plugins {
|
|||||||
kotlin("android")
|
kotlin("android")
|
||||||
kotlin("kapt")
|
kotlin("kapt")
|
||||||
id("com.mikepenz.aboutlibraries.plugin")
|
id("com.mikepenz.aboutlibraries.plugin")
|
||||||
|
id("org.jetbrains.kotlinx.kover") version "0.6.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Project.execWithOutput(cmd: String, ignore: Boolean = false): String {
|
fun Project.execWithOutput(cmd: String, ignore: Boolean = false): String {
|
||||||
@ -145,8 +146,8 @@ dependencies {
|
|||||||
implementation("com.amulyakhare:com.amulyakhare.textdrawable:1.0.1")
|
implementation("com.amulyakhare:com.amulyakhare.textdrawable:1.0.1")
|
||||||
|
|
||||||
// glide
|
// glide
|
||||||
kapt("com.github.bumptech.glide:compiler:4.11.0")
|
kapt("com.github.bumptech.glide:compiler:4.14.2")
|
||||||
implementation("com.github.bumptech.glide:okhttp3-integration:4.1.1")
|
implementation("com.github.bumptech.glide:okhttp3-integration:4.14.2")
|
||||||
|
|
||||||
// Themes
|
// Themes
|
||||||
implementation("com.github.rubensousa:floatingtoolbar:1.5.1")
|
implementation("com.github.rubensousa:floatingtoolbar:1.5.1")
|
||||||
|
@ -31,7 +31,6 @@ import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
|||||||
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 bou.amine.apps.readerforselfossv2.utils.ItemType
|
import bou.amine.apps.readerforselfossv2.utils.ItemType
|
||||||
import bou.amine.apps.readerforselfossv2.utils.longHash
|
|
||||||
import com.ashokvarma.bottomnavigation.BottomNavigationBar
|
import com.ashokvarma.bottomnavigation.BottomNavigationBar
|
||||||
import com.ashokvarma.bottomnavigation.BottomNavigationItem
|
import com.ashokvarma.bottomnavigation.BottomNavigationItem
|
||||||
import com.ashokvarma.bottomnavigation.TextBadgeItem
|
import com.ashokvarma.bottomnavigation.TextBadgeItem
|
||||||
@ -66,8 +65,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
|
|
||||||
private var fromTabShortcut: Boolean = false
|
private var fromTabShortcut: Boolean = false
|
||||||
|
|
||||||
private lateinit var tagsBadge: Map<Long, Int>
|
|
||||||
|
|
||||||
private val settingsLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
private val settingsLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||||
appSettingsService.refreshUserSettings()
|
appSettingsService.refreshUserSettings()
|
||||||
}
|
}
|
||||||
@ -156,15 +153,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
|
|
||||||
adapter.handleItemAtIndex(position)
|
adapter.handleItemAtIndex(position)
|
||||||
|
|
||||||
val tagHashes = i.tags.map { it.longHash() }
|
|
||||||
tagsBadge = tagsBadge.map {
|
|
||||||
if (tagHashes.contains(it.key)) {
|
|
||||||
(it.key to (it.value - 1))
|
|
||||||
} else {
|
|
||||||
(it.key to it.value)
|
|
||||||
}
|
|
||||||
}.toMap()
|
|
||||||
|
|
||||||
// Just load everythin
|
// Just load everythin
|
||||||
if (items.size <= 0) {
|
if (items.size <= 0) {
|
||||||
getElementsAccordingToTab()
|
getElementsAccordingToTab()
|
||||||
@ -612,9 +600,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
repository.logout()
|
repository.logout()
|
||||||
}
|
}
|
||||||
|
this@HomeActivity.finish()
|
||||||
val intent = Intent(this, LoginActivity::class.java)
|
val intent = Intent(this, LoginActivity::class.java)
|
||||||
this.startActivity(intent)
|
this.startActivity(intent)
|
||||||
this@HomeActivity.finish()
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_settings -> {
|
R.id.action_settings -> {
|
||||||
|
@ -11,6 +11,7 @@ import android.view.MenuItem
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
@ -48,7 +49,8 @@ class LoginActivity : AppCompatActivity(), DIAware {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
TrackHelper.track().download().identifier(DownloadTracker.Extra.ApkChecksum(applicationContext))
|
TrackHelper.track().download()
|
||||||
|
.identifier(DownloadTracker.Extra.ApkChecksum(applicationContext))
|
||||||
.with(tracker)
|
.with(tracker)
|
||||||
TrackHelper.track().screen("/login").with(tracker)
|
TrackHelper.track().screen("/login").with(tracker)
|
||||||
|
|
||||||
@ -64,7 +66,30 @@ class LoginActivity : AppCompatActivity(), DIAware {
|
|||||||
handleBaseUrlFail()
|
handleBaseUrlFail()
|
||||||
|
|
||||||
if (appSettingsService.getBaseUrl().isNotEmpty()) {
|
if (appSettingsService.getBaseUrl().isNotEmpty()) {
|
||||||
|
showProgress(true)
|
||||||
|
// This should be reverted when "old" users connected with a non-selfoss rss
|
||||||
|
// are handled. Revert to "simple" way.
|
||||||
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
try {
|
||||||
|
val (errorFetching, displaySelfossOnly) = repository.shouldBeSelfossInstance()
|
||||||
|
if (!errorFetching && !displaySelfossOnly) {
|
||||||
goToMain()
|
goToMain()
|
||||||
|
} else {
|
||||||
|
showProgress(false)
|
||||||
|
if (displaySelfossOnly) {
|
||||||
|
Toast.makeText(
|
||||||
|
applicationContext,
|
||||||
|
R.string.application_selfoss_only,
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
repository.logout()
|
||||||
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
repository.logout()
|
||||||
|
showProgress(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleActions()
|
handleActions()
|
||||||
@ -191,19 +216,29 @@ class LoginActivity : AppCompatActivity(), DIAware {
|
|||||||
|
|
||||||
repository.refreshLoginInformation(url, login, password)
|
repository.refreshLoginInformation(url, login, password)
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
val result = repository.login()
|
val result = repository.login()
|
||||||
if (result) {
|
if (result) {
|
||||||
|
val (errorFetching, displaySelfossOnly) = repository.shouldBeSelfossInstance()
|
||||||
|
if (!errorFetching && !displaySelfossOnly) {
|
||||||
goToMain()
|
goToMain()
|
||||||
} else {
|
} else {
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
if (displaySelfossOnly) {
|
||||||
|
Toast.makeText(
|
||||||
|
applicationContext,
|
||||||
|
R.string.application_selfoss_only,
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
preferenceError()
|
preferenceError()
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
preferenceError()
|
||||||
}
|
}
|
||||||
showProgress(false)
|
showProgress(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun showProgress(show: Boolean) {
|
private fun showProgress(show: Boolean) {
|
||||||
val shortAnimTime = resources.getInteger(android.R.integer.config_shortAnimTime)
|
val shortAnimTime = resources.getInteger(android.R.integer.config_shortAnimTime)
|
||||||
|
@ -36,10 +36,8 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
Snackbar.LENGTH_LONG
|
Snackbar.LENGTH_LONG
|
||||||
)
|
)
|
||||||
.setAction(R.string.undo_string) {
|
.setAction(R.string.undo_string) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
|
||||||
unreadItemAtIndex(item, position, false)
|
unreadItemAtIndex(item, position, false)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val view = s.view
|
val view = s.view
|
||||||
val tv: TextView = view.findViewById(com.google.android.material.R.id.snackbar_text)
|
val tv: TextView = view.findViewById(com.google.android.material.R.id.snackbar_text)
|
||||||
|
@ -16,7 +16,6 @@ import android.webkit.WebView
|
|||||||
import android.webkit.WebViewClient
|
import android.webkit.WebViewClient
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.content.res.ResourcesCompat
|
|
||||||
import androidx.core.widget.NestedScrollView
|
import androidx.core.widget.NestedScrollView
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import bou.amine.apps.readerforselfossv2.android.ImageActivity
|
import bou.amine.apps.readerforselfossv2.android.ImageActivity
|
||||||
@ -45,8 +44,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.acra.ktx.sendSilentlyWithAcra
|
|
||||||
import org.acra.ktx.sendWithAcra
|
|
||||||
import org.kodein.di.DI
|
import org.kodein.di.DI
|
||||||
import org.kodein.di.DIAware
|
import org.kodein.di.DIAware
|
||||||
import org.kodein.di.android.x.closestDI
|
import org.kodein.di.android.x.closestDI
|
||||||
@ -70,7 +67,7 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
private lateinit var fab: FloatingActionButton
|
private lateinit var fab: FloatingActionButton
|
||||||
private lateinit var textAlignment: String
|
private lateinit var textAlignment: String
|
||||||
private var _binding: FragmentArticleBinding? = null
|
private var _binding: FragmentArticleBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding
|
||||||
|
|
||||||
override val di : DI by closestDI()
|
override val di : DI by closestDI()
|
||||||
private val repository: Repository by instance()
|
private val repository: Repository by instance()
|
||||||
@ -113,13 +110,13 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
|
|
||||||
refreshAlignment()
|
refreshAlignment()
|
||||||
|
|
||||||
fab = binding.fab
|
fab = binding!!.fab
|
||||||
|
|
||||||
fab.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.colorAccent))
|
fab.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.colorAccent))
|
||||||
|
|
||||||
fab.rippleColor = resources.getColor(R.color.colorAccentDark)
|
fab.rippleColor = resources.getColor(R.color.colorAccentDark)
|
||||||
|
|
||||||
val floatingToolbar: FloatingToolbar = binding.floatingToolbar
|
val floatingToolbar: FloatingToolbar = binding!!.floatingToolbar
|
||||||
floatingToolbar.attachFab(fab)
|
floatingToolbar.attachFab(fab)
|
||||||
|
|
||||||
floatingToolbar.background = ColorDrawable(resources.getColor(R.color.colorAccent))
|
floatingToolbar.background = ColorDrawable(resources.getColor(R.color.colorAccent))
|
||||||
@ -167,35 +164,35 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
floatingToolbar.show()
|
floatingToolbar.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.source.text = contentSource
|
binding!!.source.text = contentSource
|
||||||
if (typeface != null) {
|
if (typeface != null) {
|
||||||
binding.source.typeface = typeface
|
binding!!.source.typeface = typeface
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contentText.isEmptyOrNullOrNullString()) {
|
if (contentText.isEmptyOrNullOrNullString()) {
|
||||||
getContentFromMercury()
|
getContentFromMercury()
|
||||||
} else {
|
} else {
|
||||||
binding.titleView.text = contentTitle
|
binding!!.titleView.text = contentTitle
|
||||||
if (typeface != null) {
|
if (typeface != null) {
|
||||||
binding.titleView.typeface = typeface
|
binding!!.titleView.typeface = typeface
|
||||||
}
|
}
|
||||||
|
|
||||||
htmlToWebview()
|
htmlToWebview()
|
||||||
|
|
||||||
if (!contentImage.isEmptyOrNullOrNullString() && context != null) {
|
if (!contentImage.isEmptyOrNullOrNullString() && context != null) {
|
||||||
binding.imageView.visibility = View.VISIBLE
|
binding!!.imageView.visibility = View.VISIBLE
|
||||||
Glide
|
Glide
|
||||||
.with(requireContext())
|
.with(requireContext())
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.load(contentImage)
|
.load(contentImage)
|
||||||
.apply(RequestOptions.fitCenterTransform())
|
.apply(RequestOptions.fitCenterTransform())
|
||||||
.into(binding.imageView)
|
.into(binding!!.imageView)
|
||||||
} else {
|
} else {
|
||||||
binding.imageView.visibility = View.GONE
|
binding!!.imageView.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.nestedScrollView.setOnScrollChangeListener(
|
binding!!.nestedScrollView.setOnScrollChangeListener(
|
||||||
NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
||||||
if (scrollY > oldScrollY) {
|
if (scrollY > oldScrollY) {
|
||||||
floatingToolbar.hide()
|
floatingToolbar.hide()
|
||||||
@ -224,7 +221,7 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
return binding.root
|
return binding!!.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@ -242,16 +239,16 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
|
|
||||||
private fun getContentFromMercury() {
|
private fun getContentFromMercury() {
|
||||||
if (repository.isNetworkAvailable()) {
|
if (repository.isNetworkAvailable()) {
|
||||||
binding.progressBar.visibility = View.VISIBLE
|
binding!!.progressBar.visibility = View.VISIBLE
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
try {
|
try {
|
||||||
val response = mercuryApi.query(url)
|
val response = mercuryApi.query(url)
|
||||||
if (response.success && response.data != null && !response.data?.content.isNullOrEmpty()) {
|
if (response.success && response.data != null && !response.data?.content.isNullOrEmpty()) {
|
||||||
binding.titleView.text = response.data!!.title.orEmpty()
|
binding!!.titleView.text = response.data!!.title.orEmpty()
|
||||||
try {
|
try {
|
||||||
if (typeface != null) {
|
if (typeface != null) {
|
||||||
binding.titleView.typeface = typeface
|
binding!!.titleView.typeface = typeface
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.sendSilentlyWithAcraWithName("getContentFromMercury > typeface")
|
e.sendSilentlyWithAcraWithName("getContentFromMercury > typeface")
|
||||||
@ -275,7 +272,7 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
|
|
||||||
if (!response.data?.lead_image_url.isNullOrEmpty() && context != null) {
|
if (!response.data?.lead_image_url.isNullOrEmpty() && context != null) {
|
||||||
try {
|
try {
|
||||||
binding.imageView.visibility = View.VISIBLE
|
binding!!.imageView.visibility = View.VISIBLE
|
||||||
try {
|
try {
|
||||||
Glide
|
Glide
|
||||||
.with(requireContext())
|
.with(requireContext())
|
||||||
@ -284,7 +281,7 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
response.data!!.lead_image_url.orEmpty()
|
response.data!!.lead_image_url.orEmpty()
|
||||||
)
|
)
|
||||||
.apply(RequestOptions.fitCenterTransform())
|
.apply(RequestOptions.fitCenterTransform())
|
||||||
.into(binding.imageView)
|
.into(binding!!.imageView)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.sendSilentlyWithAcraWithName("getContentFromMercury > glide lead image")
|
e.sendSilentlyWithAcraWithName("getContentFromMercury > glide lead image")
|
||||||
}
|
}
|
||||||
@ -292,12 +289,12 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
e.sendSilentlyWithAcraWithName("getContentFromMercury > outside glide lead image")
|
e.sendSilentlyWithAcraWithName("getContentFromMercury > outside glide lead image")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.imageView.visibility = View.GONE
|
binding!!.imageView.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
binding.nestedScrollView.scrollTo(0, 0)
|
binding!!.nestedScrollView.scrollTo(0, 0)
|
||||||
binding.progressBar.visibility = View.GONE
|
binding!!.progressBar.visibility = View.GONE
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.sendSilentlyWithAcraWithName("getContentFromMercury > scrollview")
|
e.sendSilentlyWithAcraWithName("getContentFromMercury > scrollview")
|
||||||
}
|
}
|
||||||
@ -320,8 +317,8 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
val a: TypedArray = requireContext().obtainStyledAttributes(resId, attrs)
|
val a: TypedArray = requireContext().obtainStyledAttributes(resId, attrs)
|
||||||
|
|
||||||
|
|
||||||
binding.webcontent.settings.standardFontFamily = a.getString(0)
|
binding!!.webcontent.settings.standardFontFamily = a.getString(0)
|
||||||
binding.webcontent.visibility = View.VISIBLE
|
binding!!.webcontent.visibility = View.VISIBLE
|
||||||
|
|
||||||
val colorOnSurface = TypedValue()
|
val colorOnSurface = TypedValue()
|
||||||
requireContext().theme.resolveAttribute(R.attr.colorOnSurface, colorOnSurface, true)
|
requireContext().theme.resolveAttribute(R.attr.colorOnSurface, colorOnSurface, true)
|
||||||
@ -329,21 +326,21 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
val colorSurface = TypedValue()
|
val colorSurface = TypedValue()
|
||||||
requireContext().theme.resolveAttribute(R.attr.colorSurface, colorSurface, true)
|
requireContext().theme.resolveAttribute(R.attr.colorSurface, colorSurface, true)
|
||||||
|
|
||||||
binding.webcontent.settings.useWideViewPort = true
|
binding!!.webcontent.settings.useWideViewPort = true
|
||||||
binding.webcontent.settings.loadWithOverviewMode = true
|
binding!!.webcontent.settings.loadWithOverviewMode = true
|
||||||
binding.webcontent.settings.javaScriptEnabled = false
|
binding!!.webcontent.settings.javaScriptEnabled = false
|
||||||
|
|
||||||
binding.webcontent.webViewClient = object : WebViewClient() {
|
binding!!.webcontent.webViewClient = object : WebViewClient() {
|
||||||
@Deprecated("Deprecated in Java")
|
@Deprecated("Deprecated in Java")
|
||||||
override fun shouldOverrideUrlLoading(view: WebView?, url : String): Boolean {
|
override fun shouldOverrideUrlLoading(view: WebView?, url : String): Boolean {
|
||||||
if (binding.webcontent.hitTestResult.type != WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
if (binding!!.webcontent.hitTestResult.type != WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
||||||
requireContext().startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
|
requireContext().startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Deprecated in Java")
|
@Deprecated("Deprecated in Java")
|
||||||
override fun shouldInterceptRequest(view: WebView?, url: String): WebResourceResponse? {
|
override fun shouldInterceptRequest(view: WebView, url: String): WebResourceResponse? {
|
||||||
val glideOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL)
|
val glideOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL)
|
||||||
if (url.lowercase(Locale.US).contains(".jpg") || url.lowercase(Locale.US).contains(".jpeg")) {
|
if (url.lowercase(Locale.US).contains(".jpg") || url.lowercase(Locale.US).contains(".jpeg")) {
|
||||||
try {
|
try {
|
||||||
@ -380,9 +377,9 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
binding.webcontent.setOnTouchListener { _, event -> gestureDetector.onTouchEvent(event)}
|
binding!!.webcontent.setOnTouchListener { _, event -> gestureDetector.onTouchEvent(event)}
|
||||||
|
|
||||||
binding.webcontent.settings.layoutAlgorithm =
|
binding!!.webcontent.settings.layoutAlgorithm =
|
||||||
WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING
|
WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING
|
||||||
|
|
||||||
var baseUrl: String? = null
|
var baseUrl: String? = null
|
||||||
@ -413,7 +410,7 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.webcontent.loadDataWithBaseURL(
|
binding!!.webcontent.loadDataWithBaseURL(
|
||||||
baseUrl,
|
baseUrl,
|
||||||
"""<html>
|
"""<html>
|
||||||
|<head>
|
|<head>
|
||||||
@ -466,17 +463,17 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun scrollDown() {
|
fun scrollDown() {
|
||||||
val height = binding.nestedScrollView.measuredHeight
|
val height = binding!!.nestedScrollView.measuredHeight
|
||||||
binding.nestedScrollView.smoothScrollBy(0, height/2)
|
binding!!.nestedScrollView.smoothScrollBy(0, height/2)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun scrollUp() {
|
fun scrollUp() {
|
||||||
val height = binding.nestedScrollView.measuredHeight
|
val height = binding!!.nestedScrollView.measuredHeight
|
||||||
binding.nestedScrollView.smoothScrollBy(0, -height/2)
|
binding!!.nestedScrollView.smoothScrollBy(0, -height/2)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openInBrowserAfterFailing() {
|
private fun openInBrowserAfterFailing() {
|
||||||
binding.progressBar.visibility = View.GONE
|
binding!!.progressBar.visibility = View.GONE
|
||||||
requireActivity().openInBrowserAsNewTask(this@ArticleFragment.item)
|
requireActivity().openInBrowserAsNewTask(this@ArticleFragment.item)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,10 +492,10 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun performClick(): Boolean {
|
fun performClick(): Boolean {
|
||||||
if (binding.webcontent.hitTestResult.type == WebView.HitTestResult.IMAGE_TYPE ||
|
if (binding!!.webcontent.hitTestResult.type == WebView.HitTestResult.IMAGE_TYPE ||
|
||||||
binding.webcontent.hitTestResult.type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
binding!!.webcontent.hitTestResult.type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
||||||
|
|
||||||
val position : Int = allImages.indexOf(binding.webcontent.hitTestResult.extra)
|
val position : Int = allImages.indexOf(binding!!.webcontent.hitTestResult.extra)
|
||||||
|
|
||||||
val intent = Intent(activity, ImageActivity::class.java)
|
val intent = Intent(activity, ImageActivity::class.java)
|
||||||
intent.putExtra("allImages", allImages)
|
intent.putExtra("allImages", allImages)
|
||||||
|
@ -28,7 +28,7 @@ class ImageFragment : Fragment() {
|
|||||||
val view = binding?.root
|
val view = binding?.root
|
||||||
|
|
||||||
binding!!.photoView.visibility = View.VISIBLE
|
binding!!.photoView.visibility = View.VISIBLE
|
||||||
Glide.with(activity)
|
Glide.with(requireActivity())
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.apply(glideOptions)
|
.apply(glideOptions)
|
||||||
.load(imageUrl)
|
.load(imageUrl)
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -6,4 +6,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">发生崩溃。请将细节发送给开发人员。</string>
|
<string name="crash_toast_text">发生崩溃。请将细节发送给开发人员。</string>
|
||||||
<string name="pref_switch_disable_acra">"禁用自动错误报告 "</string>
|
<string name="pref_switch_disable_acra">"禁用自动错误报告 "</string>
|
||||||
<string name="menu_home_filter">筛选器</string>
|
<string name="menu_home_filter">筛选器</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -126,4 +126,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -105,7 +105,7 @@
|
|||||||
<string name="new_items_notification_text">%1$d new items loaded.</string>
|
<string name="new_items_notification_text">%1$d new items loaded.</string>
|
||||||
<string name="pref_switch_notify_new_items">Notify on new items synced.</string>
|
<string name="pref_switch_notify_new_items">Notify on new items synced.</string>
|
||||||
<string name="shortcut_offline">Offline</string>
|
<string name="shortcut_offline">Offline</string>
|
||||||
<string name="pref_api_timeout">Api Timeout</string>
|
<string name="pref_api_timeout">Api Timeout (seconds)</string>
|
||||||
<string name="pref_header_experimental">Experimental</string>
|
<string name="pref_header_experimental">Experimental</string>
|
||||||
<string name="webview_dialog_issue_message">Webview not available. Disabling the article viewer to avoid any future crashes. Will load articles inside of your browser from now on.</string>
|
<string name="webview_dialog_issue_message">Webview not available. Disabling the article viewer to avoid any future crashes. Will load articles inside of your browser from now on.</string>
|
||||||
<string name="webview_dialog_issue_title">Webview issue</string>
|
<string name="webview_dialog_issue_title">Webview issue</string>
|
||||||
@ -129,4 +129,5 @@
|
|||||||
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
<string name="crash_toast_text">A crash occured. Sending the details to the developper.</string>
|
||||||
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
<string name="pref_switch_disable_acra">"Disable automatic bug reporting. "</string>
|
||||||
<string name="menu_home_filter">Filters</string>
|
<string name="menu_home_filter">Filters</string>
|
||||||
|
<string name="application_selfoss_only">This app only works with a Selfoss instance, and no other RSS feed.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -369,14 +369,7 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_tags() {
|
fun get_tags() {
|
||||||
val tags = listOf(
|
val (tags, tagsDB) = prepareTags()
|
||||||
SelfossModel.Tag("test", "red", 6),
|
|
||||||
SelfossModel.Tag("second", "yellow", 0)
|
|
||||||
)
|
|
||||||
val tagsDB = listOf(
|
|
||||||
TAG("test_DB", "red", 6),
|
|
||||||
TAG("second_DB", "yellow", 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
coEvery { api.tags() } returns StatusAndData(success = true, data = tags)
|
coEvery { api.tags() } returns StatusAndData(success = true, data = tags)
|
||||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
||||||
@ -396,17 +389,7 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_tags_with_sources_update_disabled() {
|
fun get_tags_with_sources_update_disabled() {
|
||||||
val tags = listOf(
|
val (tags, tagsDB) = prepareTags()
|
||||||
SelfossModel.Tag("test", "red", 6),
|
|
||||||
SelfossModel.Tag("second", "yellow", 0)
|
|
||||||
)
|
|
||||||
val tagsDB = listOf(
|
|
||||||
TAG("test_DB", "red", 6),
|
|
||||||
TAG("second_DB", "yellow", 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
coEvery { api.tags() } returns StatusAndData(success = true, data = tags)
|
|
||||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns true
|
every { appSettingsService.isItemCachingEnabled() } returns true
|
||||||
|
|
||||||
@ -426,17 +409,7 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_tags_with_items_caching_disabled() {
|
fun get_tags_with_items_caching_disabled() {
|
||||||
val tags = listOf(
|
val (tags, _) = prepareTags()
|
||||||
SelfossModel.Tag("test", "red", 6),
|
|
||||||
SelfossModel.Tag("second", "yellow", 0)
|
|
||||||
)
|
|
||||||
val tagsDB = listOf(
|
|
||||||
TAG("test_DB", "red", 6),
|
|
||||||
TAG("second_DB", "yellow", 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
coEvery { api.tags() } returns StatusAndData(success = true, data = tags)
|
|
||||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
|
|
||||||
@ -453,17 +426,7 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_tags_with_sources_update_and_items_caching_disabled() {
|
fun get_tags_with_sources_update_and_items_caching_disabled() {
|
||||||
val tags = listOf(
|
val (tags, tagsDB) = prepareTags()
|
||||||
SelfossModel.Tag("test", "red", 6),
|
|
||||||
SelfossModel.Tag("second", "yellow", 0)
|
|
||||||
)
|
|
||||||
val tagsDB = listOf(
|
|
||||||
TAG("test_DB", "red", 6),
|
|
||||||
TAG("second_DB", "yellow", 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
coEvery { api.tags() } returns StatusAndData(success = true, data = tags)
|
|
||||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
|
|
||||||
@ -482,17 +445,7 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_tags_without_connection() {
|
fun get_tags_without_connection() {
|
||||||
val tags = listOf(
|
val (tags, tagsDB) = prepareTags()
|
||||||
SelfossModel.Tag("test", "red", 6),
|
|
||||||
SelfossModel.Tag("second", "yellow", 0)
|
|
||||||
)
|
|
||||||
val tagsDB = listOf(
|
|
||||||
TAG("test_DB", "red", 6),
|
|
||||||
TAG("second_DB", "yellow", 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
coEvery { api.tags() } returns StatusAndData(success = true, data = tags)
|
|
||||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns true
|
every { appSettingsService.isItemCachingEnabled() } returns true
|
||||||
|
|
||||||
@ -510,17 +463,7 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_tags_without_connection_and_items_caching_disabled() {
|
fun get_tags_without_connection_and_items_caching_disabled() {
|
||||||
val tags = listOf(
|
prepareTags()
|
||||||
SelfossModel.Tag("test", "red", 6),
|
|
||||||
SelfossModel.Tag("second", "yellow", 0)
|
|
||||||
)
|
|
||||||
val tagsDB = listOf(
|
|
||||||
TAG("test_DB", "red", 6),
|
|
||||||
TAG("second_DB", "yellow", 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
coEvery { api.tags() } returns StatusAndData(success = true, data = tags)
|
|
||||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
||||||
|
|
||||||
@ -537,17 +480,7 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_tags_without_connection_and_sources_update_disabled() {
|
fun get_tags_without_connection_and_sources_update_disabled() {
|
||||||
val tags = listOf(
|
val (tags, tagsDB) = prepareTags()
|
||||||
SelfossModel.Tag("test", "red", 6),
|
|
||||||
SelfossModel.Tag("second", "yellow", 0)
|
|
||||||
)
|
|
||||||
val tagsDB = listOf(
|
|
||||||
TAG("test_DB", "red", 6),
|
|
||||||
TAG("second_DB", "yellow", 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
coEvery { api.tags() } returns StatusAndData(success = true, data = tags)
|
|
||||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns true
|
every { appSettingsService.isItemCachingEnabled() } returns true
|
||||||
|
|
||||||
@ -565,17 +498,7 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_tags_without_connection_and_sources_update_and_items_caching_disabled() {
|
fun get_tags_without_connection_and_sources_update_and_items_caching_disabled() {
|
||||||
val tags = listOf(
|
val (_, tagsDB) = prepareTags()
|
||||||
SelfossModel.Tag("test", "red", 6),
|
|
||||||
SelfossModel.Tag("second", "yellow", 0)
|
|
||||||
)
|
|
||||||
val tagsDB = listOf(
|
|
||||||
TAG("test_DB", "red", 6),
|
|
||||||
TAG("second_DB", "yellow", 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
coEvery { api.tags() } returns StatusAndData(success = true, data = tags)
|
|
||||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
|
|
||||||
@ -590,8 +513,36 @@ class RepositoryTest {
|
|||||||
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun prepareTags(): Pair<List<SelfossModel.Tag>, List<TAG>> {
|
||||||
|
val tags = listOf(
|
||||||
|
SelfossModel.Tag("test", "red", 6),
|
||||||
|
SelfossModel.Tag("second", "yellow", 0)
|
||||||
|
)
|
||||||
|
val tagsDB = listOf(
|
||||||
|
TAG("test_DB", "red", 6),
|
||||||
|
TAG("second_DB", "yellow", 0)
|
||||||
|
)
|
||||||
|
|
||||||
|
coEvery { api.tags() } returns StatusAndData(success = true, data = tags)
|
||||||
|
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
||||||
|
return Pair(tags, tagsDB)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_sources() {
|
fun get_sources() {
|
||||||
|
val (sources, sourcesDB) = prepareSources()
|
||||||
|
initializeRepository()
|
||||||
|
var testSources: List<SelfossModel.Source>?
|
||||||
|
runBlocking {
|
||||||
|
testSources = repository.getSources()
|
||||||
|
}
|
||||||
|
|
||||||
|
assertSame(sources, testSources)
|
||||||
|
assertNotEquals(sourcesDB.map { it.toView() }, testSources)
|
||||||
|
coVerify(exactly = 1) { api.sources() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun prepareSources(): Pair<ArrayList<SelfossModel.Source>, List<SOURCE>> {
|
||||||
val sources = arrayListOf(
|
val sources = arrayListOf(
|
||||||
SelfossModel.Source(
|
SelfossModel.Source(
|
||||||
1,
|
1,
|
||||||
@ -631,60 +582,15 @@ class RepositoryTest {
|
|||||||
|
|
||||||
coEvery { api.sources() } returns StatusAndData(success = true, data = sources)
|
coEvery { api.sources() } returns StatusAndData(success = true, data = sources)
|
||||||
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
||||||
initializeRepository()
|
return Pair(sources, sourcesDB)
|
||||||
var testSources: List<SelfossModel.Source>?
|
|
||||||
runBlocking {
|
|
||||||
testSources = repository.getSources()
|
|
||||||
}
|
|
||||||
|
|
||||||
assertSame(sources, testSources)
|
|
||||||
assertNotEquals(sourcesDB.map { it.toView() }, testSources)
|
|
||||||
coVerify(exactly = 1) { api.sources() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_sources_with_sources_update_disabled() {
|
fun get_sources_with_sources_update_disabled() {
|
||||||
val sources = arrayListOf(
|
val (sources, sourcesDB) = prepareSources()
|
||||||
SelfossModel.Source(
|
|
||||||
1,
|
|
||||||
"First source",
|
|
||||||
listOf("Test", "second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SelfossModel.Source(
|
|
||||||
2,
|
|
||||||
"Second DB source",
|
|
||||||
listOf("second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
val sourcesDB = listOf(
|
|
||||||
SOURCE(
|
|
||||||
"1",
|
|
||||||
"First source",
|
|
||||||
"Test,second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SOURCE(
|
|
||||||
"2",
|
|
||||||
"Second source",
|
|
||||||
"second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns true
|
every { appSettingsService.isItemCachingEnabled() } returns true
|
||||||
coEvery { api.sources() } returns StatusAndData(success = true, data = sources)
|
|
||||||
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
|
||||||
initializeRepository()
|
initializeRepository()
|
||||||
var testSources: List<SelfossModel.Source>?
|
var testSources: List<SelfossModel.Source>?
|
||||||
runBlocking {
|
runBlocking {
|
||||||
@ -701,47 +607,10 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_sources_with_items_caching_disabled() {
|
fun get_sources_with_items_caching_disabled() {
|
||||||
val sources = arrayListOf(
|
val (sources, _) = prepareSources()
|
||||||
SelfossModel.Source(
|
|
||||||
1,
|
|
||||||
"First source",
|
|
||||||
listOf("Test", "second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SelfossModel.Source(
|
|
||||||
2,
|
|
||||||
"Second source",
|
|
||||||
listOf("second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
val sourcesDB = listOf(
|
|
||||||
SOURCE(
|
|
||||||
"1",
|
|
||||||
"First source",
|
|
||||||
"Test,second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SOURCE(
|
|
||||||
"2",
|
|
||||||
"Second source",
|
|
||||||
"second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
coEvery { api.sources() } returns StatusAndData(success = true, data = sources)
|
|
||||||
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
|
||||||
initializeRepository()
|
initializeRepository()
|
||||||
var testSources: List<SelfossModel.Source>?
|
var testSources: List<SelfossModel.Source>?
|
||||||
runBlocking {
|
runBlocking {
|
||||||
@ -755,47 +624,10 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_sources_with_sources_update_and_items_caching_disabled() {
|
fun get_sources_with_sources_update_and_items_caching_disabled() {
|
||||||
val sources = arrayListOf(
|
val (sources, _) = prepareSources()
|
||||||
SelfossModel.Source(
|
|
||||||
1,
|
|
||||||
"First source",
|
|
||||||
listOf("Test", "second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SelfossModel.Source(
|
|
||||||
2,
|
|
||||||
"Second source",
|
|
||||||
listOf("second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
val sourcesDB = listOf(
|
|
||||||
SOURCE(
|
|
||||||
"1",
|
|
||||||
"First source",
|
|
||||||
"Test,second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SOURCE(
|
|
||||||
"2",
|
|
||||||
"Second source",
|
|
||||||
"second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
coEvery { api.sources() } returns StatusAndData(success = true, data = sources)
|
|
||||||
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
|
||||||
initializeRepository()
|
initializeRepository()
|
||||||
var testSources: List<SelfossModel.Source>?
|
var testSources: List<SelfossModel.Source>?
|
||||||
runBlocking {
|
runBlocking {
|
||||||
@ -809,45 +641,7 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_sources_without_connection() {
|
fun get_sources_without_connection() {
|
||||||
val sources = arrayListOf(
|
val (_, sourcesDB) = prepareSources()
|
||||||
SelfossModel.Source(
|
|
||||||
1,
|
|
||||||
"First source",
|
|
||||||
listOf("Test", "second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SelfossModel.Source(
|
|
||||||
2,
|
|
||||||
"Second source",
|
|
||||||
listOf("second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
val sourcesDB = listOf(
|
|
||||||
SOURCE(
|
|
||||||
"1",
|
|
||||||
"First DB source",
|
|
||||||
"Test,second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SOURCE(
|
|
||||||
"2",
|
|
||||||
"Second source",
|
|
||||||
"second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
coEvery { api.sources() } returns StatusAndData(success = true, data = sources)
|
|
||||||
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
|
||||||
initializeRepository(MutableStateFlow(false))
|
initializeRepository(MutableStateFlow(false))
|
||||||
var testSources: List<SelfossModel.Source>?
|
var testSources: List<SelfossModel.Source>?
|
||||||
runBlocking {
|
runBlocking {
|
||||||
@ -861,47 +655,10 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_sources_without_connection_and_items_caching_disabled() {
|
fun get_sources_without_connection_and_items_caching_disabled() {
|
||||||
val sources = arrayListOf(
|
prepareSources()
|
||||||
SelfossModel.Source(
|
|
||||||
1,
|
|
||||||
"First source",
|
|
||||||
listOf("Test", "second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SelfossModel.Source(
|
|
||||||
2,
|
|
||||||
"Second source",
|
|
||||||
listOf("second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
val sourcesDB = listOf(
|
|
||||||
SOURCE(
|
|
||||||
"1",
|
|
||||||
"First DB source",
|
|
||||||
"Test,second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SOURCE(
|
|
||||||
"2",
|
|
||||||
"Second source",
|
|
||||||
"second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
||||||
coEvery { api.sources() } returns StatusAndData(success = true, data = sources)
|
|
||||||
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
|
||||||
initializeRepository(MutableStateFlow(false))
|
initializeRepository(MutableStateFlow(false))
|
||||||
var testSources: List<SelfossModel.Source>?
|
var testSources: List<SelfossModel.Source>?
|
||||||
runBlocking {
|
runBlocking {
|
||||||
@ -915,47 +672,10 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_sources_without_connection_and_sources_update_disabled() {
|
fun get_sources_without_connection_and_sources_update_disabled() {
|
||||||
val sources = arrayListOf(
|
val (_, sourcesDB) = prepareSources()
|
||||||
SelfossModel.Source(
|
|
||||||
1,
|
|
||||||
"First source",
|
|
||||||
listOf("Test", "second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SelfossModel.Source(
|
|
||||||
2,
|
|
||||||
"Second source",
|
|
||||||
listOf("second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
val sourcesDB = listOf(
|
|
||||||
SOURCE(
|
|
||||||
"1",
|
|
||||||
"First DB source",
|
|
||||||
"Test,second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SOURCE(
|
|
||||||
"2",
|
|
||||||
"Second source",
|
|
||||||
"second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns true
|
every { appSettingsService.isItemCachingEnabled() } returns true
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||||
coEvery { api.sources() } returns StatusAndData(success = true, data = sources)
|
|
||||||
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
|
||||||
initializeRepository(MutableStateFlow(false))
|
initializeRepository(MutableStateFlow(false))
|
||||||
var testSources: List<SelfossModel.Source>?
|
var testSources: List<SelfossModel.Source>?
|
||||||
runBlocking {
|
runBlocking {
|
||||||
@ -969,47 +689,10 @@ class RepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_sources_without_connection_and_items_caching_and_sources_update_disabled() {
|
fun get_sources_without_connection_and_items_caching_and_sources_update_disabled() {
|
||||||
val sources = arrayListOf(
|
val (_, sourcesDB) = prepareSources()
|
||||||
SelfossModel.Source(
|
|
||||||
1,
|
|
||||||
"First source",
|
|
||||||
listOf("Test", "second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SelfossModel.Source(
|
|
||||||
2,
|
|
||||||
"Second source",
|
|
||||||
listOf("second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
val sourcesDB = listOf(
|
|
||||||
SOURCE(
|
|
||||||
"1",
|
|
||||||
"First DB source",
|
|
||||||
"Test,second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
),
|
|
||||||
SOURCE(
|
|
||||||
"2",
|
|
||||||
"Second source",
|
|
||||||
"second",
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||||
coEvery { api.sources() } returns StatusAndData(success = true, data = sources)
|
|
||||||
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
|
||||||
initializeRepository(MutableStateFlow(false))
|
initializeRepository(MutableStateFlow(false))
|
||||||
var testSources: List<SelfossModel.Source>?
|
var testSources: List<SelfossModel.Source>?
|
||||||
runBlocking {
|
runBlocking {
|
||||||
@ -1302,16 +985,7 @@ class RepositoryTest {
|
|||||||
)
|
)
|
||||||
|
|
||||||
initializeRepository()
|
initializeRepository()
|
||||||
repository.setTagFilter(SelfossModel.Tag("Tag", "read", 0))
|
prepareSearch()
|
||||||
repository.setSourceFilter(SelfossModel.Source(
|
|
||||||
1,
|
|
||||||
"First source",
|
|
||||||
listOf("Test", "second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
))
|
|
||||||
repository.searchFilter = "search"
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
repository.tryToCacheItemsAndGetNewOnes()
|
repository.tryToCacheItemsAndGetNewOnes()
|
||||||
}
|
}
|
||||||
@ -1325,16 +999,7 @@ class RepositoryTest {
|
|||||||
StatusAndData(success = false, data = generateTestApiItem())
|
StatusAndData(success = false, data = generateTestApiItem())
|
||||||
|
|
||||||
initializeRepository()
|
initializeRepository()
|
||||||
repository.setTagFilter(SelfossModel.Tag("Tag", "read", 0))
|
prepareSearch()
|
||||||
repository.setSourceFilter(SelfossModel.Source(
|
|
||||||
1,
|
|
||||||
"First source",
|
|
||||||
listOf("Test", "second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
))
|
|
||||||
repository.searchFilter = "search"
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
repository.tryToCacheItemsAndGetNewOnes()
|
repository.tryToCacheItemsAndGetNewOnes()
|
||||||
}
|
}
|
||||||
@ -1348,20 +1013,26 @@ class RepositoryTest {
|
|||||||
StatusAndData(success = false, data = generateTestApiItem())
|
StatusAndData(success = false, data = generateTestApiItem())
|
||||||
|
|
||||||
initializeRepository(MutableStateFlow(false))
|
initializeRepository(MutableStateFlow(false))
|
||||||
repository.setTagFilter(SelfossModel.Tag("Tag", "read", 0))
|
prepareSearch()
|
||||||
repository.setSourceFilter(SelfossModel.Source(
|
|
||||||
1,
|
|
||||||
"First source",
|
|
||||||
listOf("Test", "second"),
|
|
||||||
"spouts\\rss\\fulltextrss",
|
|
||||||
"",
|
|
||||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
|
||||||
))
|
|
||||||
repository.searchFilter = "search"
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
repository.tryToCacheItemsAndGetNewOnes()
|
repository.tryToCacheItemsAndGetNewOnes()
|
||||||
}
|
}
|
||||||
|
|
||||||
coVerify(exactly = 0) { api.getItems(any(), 0, null, null, null, null, 200) }
|
coVerify(exactly = 0) { api.getItems(any(), 0, null, null, null, null, 200) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun prepareSearch() {
|
||||||
|
repository.setTagFilter(SelfossModel.Tag("Tag", "read", 0))
|
||||||
|
repository.setSourceFilter(
|
||||||
|
SelfossModel.Source(
|
||||||
|
1,
|
||||||
|
"First source",
|
||||||
|
listOf("Test", "second"),
|
||||||
|
"spouts\\rss\\fulltextrss",
|
||||||
|
"",
|
||||||
|
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
repository.searchFilter = "search"
|
||||||
|
}
|
||||||
}
|
}
|
@ -11,12 +11,10 @@ plugins {
|
|||||||
id("com.android.library").version("7.3.1").apply(false)
|
id("com.android.library").version("7.3.1").apply(false)
|
||||||
kotlin("android").version("1.7.20").apply(false)
|
kotlin("android").version("1.7.20").apply(false)
|
||||||
kotlin("multiplatform").version("1.7.20").apply(false)
|
kotlin("multiplatform").version("1.7.20").apply(false)
|
||||||
id("org.sonarqube").version("3.4.0.2513").apply(false)
|
|
||||||
id("com.mikepenz.aboutlibraries.plugin").version("10.5.1").apply(false)
|
id("com.mikepenz.aboutlibraries.plugin").version("10.5.1").apply(false)
|
||||||
|
id("org.jetbrains.kotlinx.kover") version "0.6.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
apply(plugin = "org.sonarqube")
|
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
@ -30,3 +28,7 @@ allprojects {
|
|||||||
tasks.register("clean", Delete::class) {
|
tasks.register("clean", Delete::class) {
|
||||||
delete(rootProject.buildDir)
|
delete(rootProject.buildDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
koverMerged {
|
||||||
|
enable()
|
||||||
|
}
|
@ -10,6 +10,7 @@ plugins {
|
|||||||
id("com.android.library")
|
id("com.android.library")
|
||||||
id("com.squareup.sqldelight")
|
id("com.squareup.sqldelight")
|
||||||
kotlin("plugin.serialization") version "1.4.10"
|
kotlin("plugin.serialization") version "1.4.10"
|
||||||
|
id("org.jetbrains.kotlinx.kover") version "0.6.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.model
|
package bou.amine.apps.readerforselfossv2.model
|
||||||
|
|
||||||
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
|
||||||
import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded
|
|
||||||
import kotlinx.serialization.KSerializer
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.descriptors.PrimitiveKind
|
|
||||||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
|
||||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
|
||||||
import kotlinx.serialization.encoding.Decoder
|
|
||||||
import kotlinx.serialization.encoding.Encoder
|
|
||||||
import kotlinx.serialization.json.*
|
|
||||||
|
|
||||||
class MercuryModel {
|
class MercuryModel {
|
||||||
|
|
||||||
@ -20,138 +11,4 @@ class MercuryModel {
|
|||||||
val lead_image_url: String?,
|
val lead_image_url: String?,
|
||||||
val url: String
|
val url: String
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Tag(
|
|
||||||
val tag: String,
|
|
||||||
val color: String,
|
|
||||||
val unread: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
class Stats(
|
|
||||||
val total: Int,
|
|
||||||
val unread: Int,
|
|
||||||
val starred: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Spout(
|
|
||||||
val name: String,
|
|
||||||
val description: String
|
|
||||||
)
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class ApiVersion(
|
|
||||||
val version: String?,
|
|
||||||
val apiversion: String?
|
|
||||||
) {
|
|
||||||
fun getApiMajorVersion() : Int {
|
|
||||||
var versionNumber = 0
|
|
||||||
if (apiversion != null) {
|
|
||||||
versionNumber = apiversion.substringBefore(".").toInt()
|
|
||||||
}
|
|
||||||
return versionNumber
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Source(
|
|
||||||
val id: Int,
|
|
||||||
val title: String,
|
|
||||||
@Serializable(with = TagsListSerializer::class)
|
|
||||||
val tags: List<String>,
|
|
||||||
val spout: String,
|
|
||||||
val error: String,
|
|
||||||
val icon: String?
|
|
||||||
)
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Item(
|
|
||||||
val id: Int,
|
|
||||||
val datetime: String,
|
|
||||||
val title: String,
|
|
||||||
val content: String,
|
|
||||||
@Serializable(with = BooleanSerializer::class)
|
|
||||||
var unread: Boolean,
|
|
||||||
@Serializable(with = BooleanSerializer::class)
|
|
||||||
var starred: Boolean,
|
|
||||||
val thumbnail: String?,
|
|
||||||
val icon: String?,
|
|
||||||
val link: String,
|
|
||||||
val sourcetitle: String,
|
|
||||||
@Serializable(with = TagsListSerializer::class)
|
|
||||||
val tags: List<String>
|
|
||||||
) {
|
|
||||||
// TODO: maybe find a better way to handle these kind of urls
|
|
||||||
fun getLinkDecoded(): String {
|
|
||||||
var stringUrl: String
|
|
||||||
stringUrl =
|
|
||||||
if (link.startsWith("http://news.google.com/news/") || link.startsWith("https://news.google.com/news/")) {
|
|
||||||
if (link.contains("&url=")) {
|
|
||||||
link.substringAfter("&url=")
|
|
||||||
} else {
|
|
||||||
this.link.replace("&", "&")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.link.replace("&", "&")
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle :443 => https
|
|
||||||
if (stringUrl.contains(":443")) {
|
|
||||||
stringUrl = stringUrl.replace(":443", "").replace("http://", "https://")
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle url not starting with http
|
|
||||||
if (stringUrl.startsWith("//")) {
|
|
||||||
stringUrl = "http:$stringUrl"
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
fun sourceAndDateText(): String =
|
|
||||||
this.sourcetitle.getHtmlDecoded() + DateUtils.parseRelativeDate(this.datetime)
|
|
||||||
|
|
||||||
fun toggleStar(): Item {
|
|
||||||
this.starred = !this.starred
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: this seems to be super slow.
|
|
||||||
object TagsListSerializer : KSerializer<List<String>> {
|
|
||||||
override fun deserialize(decoder: Decoder): List<String> {
|
|
||||||
return when(val json = ((decoder as JsonDecoder).decodeJsonElement())) {
|
|
||||||
is JsonArray -> json.toList().map { it.toString() }
|
|
||||||
else -> json.toString().split(",")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override val descriptor: SerialDescriptor
|
|
||||||
get() = PrimitiveSerialDescriptor("tags", PrimitiveKind.STRING)
|
|
||||||
|
|
||||||
override fun serialize(encoder: Encoder, value: List<String>) {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object BooleanSerializer : KSerializer<Boolean> {
|
|
||||||
override fun deserialize(decoder: Decoder): Boolean {
|
|
||||||
val json = ((decoder as JsonDecoder).decodeJsonElement()).jsonPrimitive
|
|
||||||
return if (json.booleanOrNull != null) {
|
|
||||||
json.boolean
|
|
||||||
} else {
|
|
||||||
json.int == 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override val descriptor: SerialDescriptor
|
|
||||||
get() = PrimitiveSerialDescriptor("b", PrimitiveKind.BOOLEAN)
|
|
||||||
|
|
||||||
override fun serialize(encoder: Encoder, value: Boolean) {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.model
|
package bou.amine.apps.readerforselfossv2.model
|
||||||
|
|
||||||
import io.ktor.client.call.*
|
|
||||||
import io.ktor.client.statement.*
|
|
||||||
import io.ktor.http.*
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@ -22,27 +19,3 @@ class StatusAndData<T>(val success: Boolean, val data: T? = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun responseOrSuccessIf404(r: HttpResponse): SuccessResponse {
|
|
||||||
return if (r.status === HttpStatusCode.NotFound) {
|
|
||||||
SuccessResponse(true)
|
|
||||||
} else {
|
|
||||||
maybeResponse(r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun maybeResponse(r: HttpResponse): SuccessResponse {
|
|
||||||
return if (r.status.isSuccess()) {
|
|
||||||
r.body()
|
|
||||||
} else {
|
|
||||||
SuccessResponse(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend inline fun <reified T> bodyOrFailure(r: HttpResponse): StatusAndData<T> {
|
|
||||||
return if (r.status.isSuccess()) {
|
|
||||||
StatusAndData.succes(r.body())
|
|
||||||
} else {
|
|
||||||
StatusAndData.error()
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,13 +8,19 @@ 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
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class Repository(private val api: SelfossApi, private val appSettingsService: AppSettingsService, val isConnectionAvailable: MutableStateFlow<Boolean>, private val db: ReaderForSelfossDB) {
|
class Repository(
|
||||||
|
private val api: SelfossApi,
|
||||||
|
private val appSettingsService: AppSettingsService,
|
||||||
|
val isConnectionAvailable: MutableStateFlow<Boolean>,
|
||||||
|
private val db: ReaderForSelfossDB
|
||||||
|
) {
|
||||||
|
|
||||||
var items = ArrayList<SelfossModel.Item>()
|
var items = ArrayList<SelfossModel.Item>()
|
||||||
var connectionMonitored = false
|
var connectionMonitored = false
|
||||||
@ -146,7 +152,8 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getTags(): List<SelfossModel.Tag> {
|
suspend fun getTags(): List<SelfossModel.Tag> {
|
||||||
val isDatabaseEnabled = appSettingsService.isItemCachingEnabled() || !appSettingsService.isUpdateSourcesEnabled()
|
val isDatabaseEnabled =
|
||||||
|
appSettingsService.isItemCachingEnabled() || !appSettingsService.isUpdateSourcesEnabled()
|
||||||
return if (isNetworkAvailable() && !fetchedTags) {
|
return if (isNetworkAvailable() && !fetchedTags) {
|
||||||
val apiTags = api.tags()
|
val apiTags = api.tags()
|
||||||
if (apiTags.success && apiTags.data != null && isDatabaseEnabled) {
|
if (apiTags.success && apiTags.data != null && isDatabaseEnabled) {
|
||||||
@ -178,7 +185,8 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getSources(): ArrayList<SelfossModel.Source> {
|
suspend fun getSources(): ArrayList<SelfossModel.Source> {
|
||||||
val isDatabaseEnabled = appSettingsService.isItemCachingEnabled() || !appSettingsService.isUpdateSourcesEnabled()
|
val isDatabaseEnabled =
|
||||||
|
appSettingsService.isItemCachingEnabled() || !appSettingsService.isUpdateSourcesEnabled()
|
||||||
return if (isNetworkAvailable() && !fetchedSources) {
|
return if (isNetworkAvailable() && !fetchedSources) {
|
||||||
val apiSources = api.sources()
|
val apiSources = api.sources()
|
||||||
if (apiSources.success && apiSources.data != null && isDatabaseEnabled) {
|
if (apiSources.success && apiSources.data != null && isDatabaseEnabled) {
|
||||||
@ -380,18 +388,35 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun shouldBeSelfossInstance(): Pair<Boolean, Boolean> {
|
||||||
|
var fetchFailed = true
|
||||||
|
var showSelfossOnlyModal = false
|
||||||
|
if (isNetworkAvailable()) {
|
||||||
|
try {
|
||||||
|
// Trying to fetch one item, and check someone is trying to use the app with
|
||||||
|
// a random rss feed, that would throw a NoTransformationFoundException
|
||||||
|
fetchFailed = !api.getItemsWithoutCatch().success
|
||||||
|
} catch (e: NoTransformationFoundException) {
|
||||||
|
showSelfossOnlyModal = true
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Napier.e(e.stackTraceToString(), tag = "RepositoryImpl.shouldBeSelfossInstance")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Pair(fetchFailed, showSelfossOnlyModal)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun logout() {
|
suspend fun logout() {
|
||||||
if (isNetworkAvailable()) {
|
if (isNetworkAvailable()) {
|
||||||
try {
|
try {
|
||||||
val response = api.logout()
|
val response = api.logout()
|
||||||
if (response.isSuccess) {
|
if (!response.isSuccess) {
|
||||||
Napier.e("Couldn't logout.", tag = "RepositoryImpl.logout")
|
Napier.e("Couldn't logout.", tag = "RepositoryImpl.logout")
|
||||||
}
|
}
|
||||||
} catch (cause: Throwable) {
|
} catch (cause: Throwable) {
|
||||||
Napier.e(cause.stackTraceToString(), tag = "RepositoryImpl.logout")
|
Napier.e(cause.stackTraceToString(), tag = "RepositoryImpl.logout")
|
||||||
} finally {
|
|
||||||
appSettingsService.clearAll()
|
|
||||||
}
|
}
|
||||||
|
appSettingsService.clearAll()
|
||||||
} else {
|
} else {
|
||||||
appSettingsService.clearAll()
|
appSettingsService.clearAll()
|
||||||
}
|
}
|
||||||
@ -456,11 +481,29 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
private fun getDBItems(): List<ITEM> = db.itemsQueries.items().executeAsList()
|
private fun getDBItems(): List<ITEM> = db.itemsQueries.items().executeAsList()
|
||||||
|
|
||||||
private fun insertDBAction(articleid: String, read: Boolean = false, unread: Boolean = false, starred: Boolean = false, unstarred: Boolean = false) =
|
private fun insertDBAction(
|
||||||
|
articleid: String,
|
||||||
|
read: Boolean = false,
|
||||||
|
unread: Boolean = false,
|
||||||
|
starred: Boolean = false,
|
||||||
|
unstarred: Boolean = false
|
||||||
|
) =
|
||||||
db.actionsQueries.insertAction(articleid, read, unread, starred, unstarred)
|
db.actionsQueries.insertAction(articleid, read, unread, starred, unstarred)
|
||||||
|
|
||||||
private fun updateDBItem(item: SelfossModel.Item) =
|
private fun updateDBItem(item: SelfossModel.Item) =
|
||||||
db.itemsQueries.updateItem(item.datetime, item.title.getHtmlDecoded(), item.content, item.unread, item.starred, item.thumbnail, item.icon, item.link, item.sourcetitle, item.tags.joinToString(","), item.id.toString())
|
db.itemsQueries.updateItem(
|
||||||
|
item.datetime,
|
||||||
|
item.title.getHtmlDecoded(),
|
||||||
|
item.content,
|
||||||
|
item.unread,
|
||||||
|
item.starred,
|
||||||
|
item.thumbnail,
|
||||||
|
item.icon,
|
||||||
|
item.link,
|
||||||
|
item.sourcetitle,
|
||||||
|
item.tags.joinToString(","),
|
||||||
|
item.id.toString()
|
||||||
|
)
|
||||||
|
|
||||||
suspend fun tryToCacheItemsAndGetNewOnes(): List<SelfossModel.Item> {
|
suspend fun tryToCacheItemsAndGetNewOnes(): List<SelfossModel.Item> {
|
||||||
try {
|
try {
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
package bou.amine.apps.readerforselfossv2.rest
|
||||||
|
|
||||||
|
import bou.amine.apps.readerforselfossv2.model.StatusAndData
|
||||||
|
import bou.amine.apps.readerforselfossv2.model.SuccessResponse
|
||||||
|
import io.github.aakira.napier.Napier
|
||||||
|
import io.ktor.client.*
|
||||||
|
import io.ktor.client.call.*
|
||||||
|
import io.ktor.client.request.*
|
||||||
|
import io.ktor.client.request.forms.*
|
||||||
|
import io.ktor.client.statement.*
|
||||||
|
import io.ktor.http.*
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun responseOrSuccessIf404(r: HttpResponse?): SuccessResponse {
|
||||||
|
return if (r != null && r.status === HttpStatusCode.NotFound) {
|
||||||
|
SuccessResponse(true)
|
||||||
|
} else {
|
||||||
|
maybeResponse(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun maybeResponse(r: HttpResponse?): SuccessResponse {
|
||||||
|
return if (r != null && r.status.isSuccess()) {
|
||||||
|
r.body()
|
||||||
|
} else {
|
||||||
|
SuccessResponse(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend inline fun <reified T> bodyOrFailure(r: HttpResponse?): StatusAndData<T> {
|
||||||
|
return if (r != null && r.status.isSuccess()) {
|
||||||
|
StatusAndData.succes(r.body())
|
||||||
|
} else {
|
||||||
|
StatusAndData.error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun tryToRequest(
|
||||||
|
requestType: String,
|
||||||
|
fn: () -> HttpResponse
|
||||||
|
): HttpResponse? {
|
||||||
|
var response: HttpResponse? = null
|
||||||
|
try {
|
||||||
|
response = fn()
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
Napier.e("Couldn't execute $requestType request", ex, "tryTo$requestType")
|
||||||
|
}
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend inline fun HttpClient.tryToGet(
|
||||||
|
urlString: String,
|
||||||
|
crossinline block: HttpRequestBuilder.() -> Unit = {}
|
||||||
|
): HttpResponse? = tryToRequest("Get") { return this.get { url(urlString); block() } }
|
||||||
|
|
||||||
|
|
||||||
|
suspend inline fun HttpClient.tryToPost(
|
||||||
|
urlString: String,
|
||||||
|
block: HttpRequestBuilder.() -> Unit = {}
|
||||||
|
): HttpResponse? = tryToRequest("Post") { return this.post { url(urlString); block() } }
|
||||||
|
|
||||||
|
suspend inline fun HttpClient.tryToDelete(
|
||||||
|
urlString: String,
|
||||||
|
block: HttpRequestBuilder.() -> Unit = {}
|
||||||
|
): HttpResponse? = tryToRequest("Delete") { return this.delete { url(urlString); block() } }
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun HttpClient.tryToSubmitForm(
|
||||||
|
url: String,
|
||||||
|
formParameters: Parameters = Parameters.Empty,
|
||||||
|
encodeInQuery: Boolean = false,
|
||||||
|
block: HttpRequestBuilder.() -> Unit = {}
|
||||||
|
): HttpResponse? =
|
||||||
|
tryToRequest("SubmitForm") {
|
||||||
|
return this.submitForm(formParameters, encodeInQuery) {
|
||||||
|
url(url)
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.rest
|
package bou.amine.apps.readerforselfossv2.rest
|
||||||
|
|
||||||
import bou.amine.apps.readerforselfossv2.model.*
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
|
import bou.amine.apps.readerforselfossv2.model.StatusAndData
|
||||||
|
import bou.amine.apps.readerforselfossv2.model.SuccessResponse
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
import io.github.aakira.napier.Napier
|
import io.github.aakira.napier.Napier
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
@ -10,7 +12,6 @@ import io.ktor.client.plugins.contentnegotiation.*
|
|||||||
import io.ktor.client.plugins.cookies.*
|
import io.ktor.client.plugins.cookies.*
|
||||||
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.statement.*
|
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.*
|
||||||
@ -46,11 +47,11 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
}
|
}
|
||||||
install(HttpCookies)
|
install(HttpCookies)
|
||||||
install(HttpRequestRetry) {
|
install(HttpRequestRetry) {
|
||||||
maxRetries = 2
|
maxRetries = 1
|
||||||
retryIf { _, response ->
|
retryIf { _, response ->
|
||||||
response.status == HttpStatusCode.Forbidden && shouldHavePostLogin() && hasLoginInfo()
|
response.status == HttpStatusCode.Forbidden && shouldHavePostLogin() && hasLoginInfo()
|
||||||
}
|
}
|
||||||
modifyRequest { _ ->
|
modifyRequest {
|
||||||
Napier.i("Will modify", tag = "HttpSend")
|
Napier.i("Will modify", tag = "HttpSend")
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
Napier.i("Will login", tag = "HttpSend")
|
Napier.i("Will login", tag = "HttpSend")
|
||||||
@ -75,7 +76,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
|
|
||||||
// Api version was introduces after the POST login, so when there is a version, it should be available
|
// Api version was introduces after the POST login, so when there is a version, it should be available
|
||||||
private fun shouldHavePostLogin() = appSettingsService.getApiVersion() != -1
|
private fun shouldHavePostLogin() = appSettingsService.getApiVersion() != -1
|
||||||
private fun hasLoginInfo() = appSettingsService.getUserName() != null && appSettingsService.getPassword() != null
|
private fun hasLoginInfo() = appSettingsService.getUserName().isNotEmpty() && appSettingsService.getPassword().isNotEmpty()
|
||||||
|
|
||||||
suspend fun login(): SuccessResponse =
|
suspend fun login(): SuccessResponse =
|
||||||
if (appSettingsService.getUserName().isNotEmpty() && appSettingsService.getPassword().isNotEmpty()) {
|
if (appSettingsService.getUserName().isNotEmpty() && appSettingsService.getPassword().isNotEmpty()) {
|
||||||
@ -88,12 +89,12 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
SuccessResponse(true)
|
SuccessResponse(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getLogin() = maybeResponse(client.get(url("/login")) {
|
private suspend fun getLogin() = maybeResponse(client.tryToGet(url("/login")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
})
|
||||||
|
|
||||||
private suspend fun postLogin() = maybeResponse(client.post(url("/login")) {
|
private suspend fun postLogin() = maybeResponse(client.tryToPost(url("/login")) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
})
|
})
|
||||||
@ -106,9 +107,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
maybeLogoutIfAvailable()
|
maybeLogoutIfAvailable()
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun maybeLogoutIfAvailable() = responseOrSuccessIf404(client.get(url("/logout")))
|
private suspend fun maybeLogoutIfAvailable() = responseOrSuccessIf404(client.tryToGet(url("/logout")))
|
||||||
|
|
||||||
private suspend fun doLogout() = maybeResponse(client.delete(url("/api/session/current")))
|
private suspend fun doLogout() = maybeResponse(client.tryToDelete(url("/api/session/current")))
|
||||||
|
|
||||||
suspend fun getItems(
|
suspend fun getItems(
|
||||||
type: String,
|
type: String,
|
||||||
@ -119,7 +120,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
updatedSince: String?,
|
updatedSince: String?,
|
||||||
items: Int? = null
|
items: Int? = null
|
||||||
): StatusAndData<List<SelfossModel.Item>> =
|
): StatusAndData<List<SelfossModel.Item>> =
|
||||||
bodyOrFailure(client.get(url("/items")) {
|
bodyOrFailure(client.tryToGet(url("/items")) {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
@ -133,8 +134,18 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
parameter("offset", offset)
|
parameter("offset", offset)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
suspend fun getItemsWithoutCatch(): StatusAndData<List<SelfossModel.Item>> =
|
||||||
|
bodyOrFailure(client.get(url("/items")) {
|
||||||
|
if (!shouldHavePostLogin()) {
|
||||||
|
parameter("username", appSettingsService.getUserName())
|
||||||
|
parameter("password", appSettingsService.getPassword())
|
||||||
|
}
|
||||||
|
parameter("type", "all")
|
||||||
|
parameter("items", 1)
|
||||||
|
})
|
||||||
|
|
||||||
suspend fun stats(): StatusAndData<SelfossModel.Stats> =
|
suspend fun stats(): StatusAndData<SelfossModel.Stats> =
|
||||||
bodyOrFailure(client.get(url("/stats")) {
|
bodyOrFailure(client.tryToGet(url("/stats")) {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
@ -142,7 +153,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
suspend fun tags(): StatusAndData<List<SelfossModel.Tag>> =
|
suspend fun tags(): StatusAndData<List<SelfossModel.Tag>> =
|
||||||
bodyOrFailure(client.get(url("/tags")) {
|
bodyOrFailure(client.tryToGet(url("/tags")) {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
@ -150,7 +161,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
suspend fun update(): StatusAndData<String> =
|
suspend fun update(): StatusAndData<String> =
|
||||||
bodyOrFailure(client.get(url("/update")) {
|
bodyOrFailure(client.tryToGet(url("/update")) {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
@ -158,7 +169,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
suspend fun spouts(): StatusAndData<Map<String, SelfossModel.Spout>> =
|
suspend fun spouts(): StatusAndData<Map<String, SelfossModel.Spout>> =
|
||||||
bodyOrFailure(client.get(url("/sources/spouts")) {
|
bodyOrFailure(client.tryToGet(url("/sources/spouts")) {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
@ -166,7 +177,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
suspend fun sources(): StatusAndData<ArrayList<SelfossModel.Source>> =
|
suspend fun sources(): StatusAndData<ArrayList<SelfossModel.Source>> =
|
||||||
bodyOrFailure(client.get(url("/sources/list")) {
|
bodyOrFailure(client.tryToGet(url("/sources/list")) {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
@ -174,10 +185,10 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
suspend fun version(): StatusAndData<SelfossModel.ApiVersion> =
|
suspend fun version(): StatusAndData<SelfossModel.ApiVersion> =
|
||||||
bodyOrFailure(client.get(url("/api/about")))
|
bodyOrFailure(client.tryToGet(url("/api/about")))
|
||||||
|
|
||||||
suspend fun markAsRead(id: String): SuccessResponse =
|
suspend fun markAsRead(id: String): SuccessResponse =
|
||||||
maybeResponse(client.post(url("/mark/$id")) {
|
maybeResponse(client.tryToPost(url("/mark/$id")) {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
@ -185,7 +196,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
suspend fun unmarkAsRead(id: String): SuccessResponse =
|
suspend fun unmarkAsRead(id: String): SuccessResponse =
|
||||||
maybeResponse(client.post(url("/unmark/$id")) {
|
maybeResponse(client.tryToPost(url("/unmark/$id")) {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
@ -193,7 +204,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
suspend fun starr(id: String): SuccessResponse =
|
suspend fun starr(id: String): SuccessResponse =
|
||||||
maybeResponse(client.post(url("/starr/$id")) {
|
maybeResponse(client.tryToPost(url("/starr/$id")) {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
@ -201,7 +212,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
suspend fun unstarr(id: String): SuccessResponse =
|
suspend fun unstarr(id: String): SuccessResponse =
|
||||||
maybeResponse(client.post(url("/unstarr/$id")) {
|
maybeResponse(client.tryToPost(url("/unstarr/$id")) {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
@ -209,7 +220,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
suspend fun markAllAsRead(ids: List<String>): SuccessResponse =
|
suspend fun markAllAsRead(ids: List<String>): SuccessResponse =
|
||||||
maybeResponse(client.submitForm(
|
maybeResponse(client.tryToSubmitForm(
|
||||||
url = url("/mark"),
|
url = url("/mark"),
|
||||||
formParameters = Parameters.build {
|
formParameters = Parameters.build {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
@ -229,43 +240,21 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
): SuccessResponse =
|
): SuccessResponse =
|
||||||
maybeResponse(
|
maybeResponse(
|
||||||
if (appSettingsService.getApiVersion() > 1) {
|
if (appSettingsService.getApiVersion() > 1) {
|
||||||
createSource2(title, url, spout, tags, filter)
|
createSource("tags[]", title, url, spout, tags, filter)
|
||||||
} else {
|
} else {
|
||||||
createSource(title, url, spout, tags, filter)
|
createSource("tags", title, url, spout, tags, filter)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
private suspend fun createSource(
|
private suspend fun createSource(
|
||||||
|
tagsParamName: String,
|
||||||
title: String,
|
title: String,
|
||||||
url: String,
|
url: String,
|
||||||
spout: String,
|
spout: String,
|
||||||
tags: String,
|
tags: String,
|
||||||
filter: String
|
filter: String
|
||||||
): HttpResponse =
|
): HttpResponse? =
|
||||||
client.submitForm(
|
client.tryToSubmitForm(
|
||||||
url = url("/source"),
|
|
||||||
formParameters = Parameters.build {
|
|
||||||
// TODO: test this
|
|
||||||
if (!shouldHavePostLogin()) {
|
|
||||||
append("username", appSettingsService.getUserName())
|
|
||||||
append("password", appSettingsService.getPassword())
|
|
||||||
}
|
|
||||||
append("title", title)
|
|
||||||
append("url", url)
|
|
||||||
append("spout", spout)
|
|
||||||
append("tags", tags)
|
|
||||||
append("filter", filter)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
private suspend fun createSource2(
|
|
||||||
title: String,
|
|
||||||
url: String,
|
|
||||||
spout: String,
|
|
||||||
tags: String,
|
|
||||||
filter: String
|
|
||||||
): HttpResponse =
|
|
||||||
client.submitForm(
|
|
||||||
url = url("/source"),
|
url = url("/source"),
|
||||||
formParameters = Parameters.build {
|
formParameters = Parameters.build {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
@ -275,13 +264,13 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
append("title", title)
|
append("title", title)
|
||||||
append("url", url)
|
append("url", url)
|
||||||
append("spout", spout)
|
append("spout", spout)
|
||||||
append("tags[]", tags)
|
append(tagsParamName, tags)
|
||||||
append("filter", filter)
|
append("filter", filter)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun deleteSource(id: Int): SuccessResponse =
|
suspend fun deleteSource(id: Int): SuccessResponse =
|
||||||
maybeResponse(client.delete(url("/source/$id")) {
|
maybeResponse(client.tryToDelete(url("/source/$id")) {
|
||||||
if (!shouldHavePostLogin()) {
|
if (!shouldHavePostLogin()) {
|
||||||
parameter("username", appSettingsService.getUserName())
|
parameter("username", appSettingsService.getUserName())
|
||||||
parameter("password", appSettingsService.getPassword())
|
parameter("password", appSettingsService.getPassword())
|
||||||
|
@ -84,7 +84,13 @@ class AppSettingsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshItemsNumber() {
|
private fun refreshItemsNumber() {
|
||||||
_itemsNumber = settings.getString(API_ITEMS_NUMBER, "20").toInt()
|
_itemsNumber = try {
|
||||||
|
settings.getString(API_ITEMS_NUMBER, "20").toInt()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
settings.remove(API_ITEMS_NUMBER)
|
||||||
|
20
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getApiTimeout(): Long {
|
fun getApiTimeout(): Long {
|
||||||
@ -94,9 +100,21 @@ class AppSettingsService {
|
|||||||
return _apiTimeout!!
|
return _apiTimeout!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun secToMs(n: Long) = n * 1000
|
||||||
|
|
||||||
private fun refreshApiTimeout() {
|
private fun refreshApiTimeout() {
|
||||||
val settingsTimeout = settings.getLong(API_TIMEOUT, HttpTimeout.INFINITE_TIMEOUT_MS)
|
_apiTimeout = secToMs(try {
|
||||||
_apiTimeout = if (settingsTimeout > 0) settingsTimeout else HttpTimeout.INFINITE_TIMEOUT_MS
|
val settingsTimeout = settings.getString(API_TIMEOUT, "60")
|
||||||
|
if (settingsTimeout.toLong() > 0) {
|
||||||
|
settingsTimeout.toLong()
|
||||||
|
} else {
|
||||||
|
settings.remove(API_TIMEOUT)
|
||||||
|
60
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
settings.remove(API_TIMEOUT)
|
||||||
|
60
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshBaseUrl() {
|
private fun refreshBaseUrl() {
|
||||||
|
5
sonar-project.properties
Normal file
5
sonar-project.properties
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
sonar.projectKey=RFS2
|
||||||
|
sonar.coverage.jacoco.xmlReportPaths=build/reports/kover/merged/xml/report.xml
|
||||||
|
sonar.sourceEncoding=UTF-8
|
||||||
|
sonar.sources=.
|
||||||
|
sonar.exclusions=shared/src/iosArm64Main/**, shared/src/iosX64Main/**, docs/**
|
Reference in New Issue
Block a user