Really big settings cleaning.
This commit is contained in:
@ -1,15 +1,15 @@
|
||||
package bou.amine.apps.readerforselfossv2.utils
|
||||
|
||||
import android.text.format.DateUtils
|
||||
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
|
||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||
import java.time.Instant
|
||||
import java.time.LocalDateTime
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.ZoneOffset
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
actual class DateUtils actual constructor(apiDetailsService: ApiDetailsService) {
|
||||
val ads: ApiDetailsService = apiDetailsService // TODO: why is this needed now ?
|
||||
actual class DateUtils actual constructor(appSettingsService: AppSettingsService) {
|
||||
val ads: AppSettingsService = appSettingsService // TODO: why is this needed now ?
|
||||
|
||||
actual fun parseDate(dateString: String): Long {
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
package bou.amine.apps.readerforselfossv2.DI
|
||||
|
||||
import bou.amine.apps.readerforselfossv2.rest.SelfossApi
|
||||
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
|
||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||
import org.kodein.di.DI
|
||||
import org.kodein.di.bind
|
||||
import org.kodein.di.instance
|
||||
import org.kodein.di.singleton
|
||||
|
||||
val networkModule by DI.Module {
|
||||
bind<ApiDetailsService>() with singleton { ApiDetailsService() }
|
||||
bind<AppSettingsService>() with singleton { AppSettingsService() }
|
||||
bind<SelfossApi>() with singleton { SelfossApi(instance()) }
|
||||
}
|
@ -4,7 +4,7 @@ import bou.amine.apps.readerforselfossv2.dao.*
|
||||
import bou.amine.apps.readerforselfossv2.model.NetworkUnavailableException
|
||||
import bou.amine.apps.readerforselfossv2.rest.SelfossApi
|
||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
|
||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||
import bou.amine.apps.readerforselfossv2.utils.*
|
||||
import com.github.ln_12.library.ConnectivityStatus
|
||||
import com.russhwolf.settings.Settings
|
||||
@ -13,14 +13,13 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class Repository(private val api: SelfossApi, private val apiDetails: ApiDetailsService, private val connectivityStatus: ConnectivityStatus, private val db: ReaderForSelfossDB) {
|
||||
val settings = Settings()
|
||||
class Repository(private val api: SelfossApi, private val appSettingsService: AppSettingsService, connectivityStatus: ConnectivityStatus, private val db: ReaderForSelfossDB) {
|
||||
|
||||
var items = ArrayList<SelfossModel.Item>()
|
||||
val isConnectionAvailable = connectivityStatus.isNetworkConnected
|
||||
var connectionMonitored = false
|
||||
|
||||
var baseUrl = apiDetails.getBaseUrl()
|
||||
var baseUrl = appSettingsService.getBaseUrl()
|
||||
lateinit var dateUtils: DateUtils
|
||||
|
||||
var displayedItems = ItemType.UNREAD
|
||||
@ -29,7 +28,6 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
var sourceFilter: SelfossModel.Source? = null
|
||||
var searchFilter: String? = null
|
||||
|
||||
var itemsCaching = settings.getBoolean("items_caching", false)
|
||||
var offlineOverride = false
|
||||
|
||||
var badgeUnread = 0
|
||||
@ -43,7 +41,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
// TODO: Dispatchers.IO not available in KMM, an alternative solution should be found
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
updateApiVersion()
|
||||
dateUtils = DateUtils(apiDetails)
|
||||
dateUtils = DateUtils(appSettingsService)
|
||||
reloadBadges()
|
||||
}
|
||||
}
|
||||
@ -61,7 +59,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
null
|
||||
)
|
||||
} else {
|
||||
if (itemsCaching) {
|
||||
if (appSettingsService.isItemCachingEnabled()) {
|
||||
fetchedItems = getDBItems().filter {
|
||||
displayedItems == ItemType.ALL ||
|
||||
(it.unread && displayedItems == ItemType.UNREAD) ||
|
||||
@ -98,7 +96,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
return items
|
||||
}
|
||||
|
||||
suspend fun getMaxItemsForBackground(itemType: ItemType): List<SelfossModel.Item>? {
|
||||
private suspend fun getMaxItemsForBackground(itemType: ItemType): List<SelfossModel.Item>? {
|
||||
return if (isNetworkAvailable()) {
|
||||
api.getItems(
|
||||
itemType.type,
|
||||
@ -172,7 +170,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
return success
|
||||
}
|
||||
|
||||
suspend fun markAsReadById(id: Int): Boolean {
|
||||
private suspend fun markAsReadById(id: Int): Boolean {
|
||||
return if (isNetworkAvailable()) {
|
||||
api.markAsRead(id.toString())?.isSuccess == true
|
||||
} else {
|
||||
@ -191,7 +189,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
return success
|
||||
}
|
||||
|
||||
suspend fun unmarkAsReadById(id: Int): Boolean {
|
||||
private suspend fun unmarkAsReadById(id: Int): Boolean {
|
||||
return if (isNetworkAvailable()) {
|
||||
api.unmarkAsRead(id.toString())?.isSuccess == true
|
||||
} else {
|
||||
@ -209,7 +207,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
return success
|
||||
}
|
||||
|
||||
suspend fun starrById(id: Int): Boolean {
|
||||
private suspend fun starrById(id: Int): Boolean {
|
||||
return if (isNetworkAvailable()) {
|
||||
api.starr(id.toString())?.isSuccess == true
|
||||
} else {
|
||||
@ -227,7 +225,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
return success
|
||||
}
|
||||
|
||||
suspend fun unstarrById(id: Int): Boolean {
|
||||
private suspend fun unstarrById(id: Int): Boolean {
|
||||
return if (isNetworkAvailable()) {
|
||||
api.unstarr(id.toString())?.isSuccess == true
|
||||
} else {
|
||||
@ -307,7 +305,7 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
spout,
|
||||
tags,
|
||||
filter,
|
||||
apiDetails.getApiVersion()
|
||||
appSettingsService.getApiVersion()
|
||||
)?.isSuccess == true
|
||||
}
|
||||
|
||||
@ -350,27 +348,19 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
return result
|
||||
}
|
||||
|
||||
fun refreshLoginInformation(url: String, login: String, password: String,
|
||||
httpLogin: String, httpPassword: String,
|
||||
isSelfSignedCert: Boolean) {
|
||||
settings.putString("url", url)
|
||||
settings.putString("login", login)
|
||||
settings.putString("httpUserName", httpLogin)
|
||||
settings.putString("password", password)
|
||||
settings.putString("httpPassword", httpPassword)
|
||||
settings.putBoolean("isSelfSignedCert", isSelfSignedCert)
|
||||
fun refreshLoginInformation(url: String, login: String, password: String, isSelfSignedCert: Boolean) {
|
||||
appSettingsService.refreshLoginInformation(url, login, password, isSelfSignedCert)
|
||||
baseUrl = url
|
||||
api.refreshLoginInformation()
|
||||
}
|
||||
|
||||
private suspend fun updateApiVersion() {
|
||||
val apiMajorVersion = apiDetails.getApiVersion()
|
||||
val apiMajorVersion = appSettingsService.getApiVersion()
|
||||
|
||||
if (isNetworkAvailable()) {
|
||||
val fetchedVersion = api.version()
|
||||
if (fetchedVersion != null && fetchedVersion.getApiMajorVersion() != apiMajorVersion) {
|
||||
settings.putInt("apiVersionMajor", fetchedVersion.getApiMajorVersion())
|
||||
apiDetails.refreshApiVersion()
|
||||
appSettingsService.updateApiVersion(fetchedVersion.getApiMajorVersion())
|
||||
}
|
||||
}
|
||||
dateUtils = DateUtils(apiMajorVersion)
|
||||
@ -378,10 +368,10 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
|
||||
fun isNetworkAvailable() = isConnectionAvailable.value && !offlineOverride
|
||||
|
||||
fun getDBActions(): List<ACTION> =
|
||||
private fun getDBActions(): List<ACTION> =
|
||||
db.actionsQueries.actions().executeAsList()
|
||||
|
||||
fun deleteDBAction(action: ACTION) =
|
||||
private fun deleteDBAction(action: ACTION) =
|
||||
db.actionsQueries.deleteAction(action.id)
|
||||
|
||||
fun getDBTags(): List<TAG> = db.tagsQueries.tags().executeAsList()
|
||||
@ -432,7 +422,9 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
val starredItems = getMaxItemsForBackground(ItemType.STARRED)
|
||||
insertDBItems(newItems.orEmpty() + allItems.orEmpty() + starredItems.orEmpty())
|
||||
return newItems
|
||||
} catch (e: Throwable) {}
|
||||
} catch (e: Throwable) {
|
||||
// We do nothing
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package bou.amine.apps.readerforselfossv2.rest
|
||||
|
||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
|
||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.plugins.*
|
||||
@ -14,7 +14,7 @@ import io.ktor.client.plugins.logging.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class SelfossApi(private val apiDetailsService: ApiDetailsService) {
|
||||
class SelfossApi(private val appSettingsService: AppSettingsService) {
|
||||
|
||||
var client = createHttpClient()
|
||||
|
||||
@ -31,13 +31,13 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) {
|
||||
install(Logging) {
|
||||
logger = object : Logger {
|
||||
override fun log(message: String) {
|
||||
apiDetailsService.logApiCalls(message)
|
||||
appSettingsService.logApiCalls(message)
|
||||
}
|
||||
}
|
||||
level = LogLevel.ALL
|
||||
}
|
||||
install(HttpTimeout) {
|
||||
requestTimeoutMillis = apiDetailsService.getApiTimeout()
|
||||
requestTimeoutMillis = appSettingsService.getApiTimeout()
|
||||
}
|
||||
/* TODO: Auth as basic
|
||||
if (apiDetailsService.getUserName().isNotEmpty() && apiDetailsService.getPassword().isNotEmpty()) {
|
||||
@ -58,17 +58,17 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) {
|
||||
}
|
||||
|
||||
fun url(path: String) =
|
||||
"${apiDetailsService.getBaseUrl()}$path"
|
||||
"${appSettingsService.getBaseUrl()}$path"
|
||||
|
||||
fun refreshLoginInformation() {
|
||||
apiDetailsService.refresh()
|
||||
appSettingsService.refreshApiSettings()
|
||||
client = createHttpClient()
|
||||
}
|
||||
|
||||
suspend fun login(): SelfossModel.SuccessResponse? =
|
||||
client.get(url("/login")) {
|
||||
parameter("username", apiDetailsService.getUserName())
|
||||
parameter("password", apiDetailsService.getPassword())
|
||||
parameter("username", appSettingsService.getUserName())
|
||||
parameter("password", appSettingsService.getPassword())
|
||||
}.body()
|
||||
|
||||
suspend fun getItems(
|
||||
@ -81,45 +81,45 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) {
|
||||
items: Int? = null
|
||||
): List<SelfossModel.Item>? =
|
||||
client.get(url("/items")) {
|
||||
parameter("username", apiDetailsService.getUserName())
|
||||
parameter("password", apiDetailsService.getPassword())
|
||||
parameter("username", appSettingsService.getUserName())
|
||||
parameter("password", appSettingsService.getPassword())
|
||||
parameter("type", type)
|
||||
parameter("tag", tag)
|
||||
parameter("source", source)
|
||||
parameter("search", search)
|
||||
parameter("updatedsince", updatedSince)
|
||||
parameter("items", items ?: apiDetailsService.getItemsNumber())
|
||||
parameter("items", items ?: appSettingsService.getItemsNumber())
|
||||
parameter("offset", offset)
|
||||
}.body()
|
||||
|
||||
suspend fun stats(): SelfossModel.Stats? =
|
||||
client.get(url("/stats")) {
|
||||
parameter("username", apiDetailsService.getUserName())
|
||||
parameter("password", apiDetailsService.getPassword())
|
||||
parameter("username", appSettingsService.getUserName())
|
||||
parameter("password", appSettingsService.getPassword())
|
||||
}.body()
|
||||
|
||||
suspend fun tags(): List<SelfossModel.Tag>? =
|
||||
client.get(url("/tags")) {
|
||||
parameter("username", apiDetailsService.getUserName())
|
||||
parameter("password", apiDetailsService.getPassword())
|
||||
parameter("username", appSettingsService.getUserName())
|
||||
parameter("password", appSettingsService.getPassword())
|
||||
}.body()
|
||||
|
||||
suspend fun update(): String? =
|
||||
client.get(url("/update")) {
|
||||
parameter("username", apiDetailsService.getUserName())
|
||||
parameter("password", apiDetailsService.getPassword())
|
||||
parameter("username", appSettingsService.getUserName())
|
||||
parameter("password", appSettingsService.getPassword())
|
||||
}.body()
|
||||
|
||||
suspend fun spouts(): Map<String, SelfossModel.Spout>? =
|
||||
client.get(url("/sources/spouts")) {
|
||||
parameter("username", apiDetailsService.getUserName())
|
||||
parameter("password", apiDetailsService.getPassword())
|
||||
parameter("username", appSettingsService.getUserName())
|
||||
parameter("password", appSettingsService.getPassword())
|
||||
}.body()
|
||||
|
||||
suspend fun sources(): ArrayList<SelfossModel.Source>? =
|
||||
client.get(url("/sources/list")) {
|
||||
parameter("username", apiDetailsService.getUserName())
|
||||
parameter("password", apiDetailsService.getPassword())
|
||||
parameter("username", appSettingsService.getUserName())
|
||||
parameter("password", appSettingsService.getPassword())
|
||||
}.body()
|
||||
|
||||
suspend fun version(): SelfossModel.ApiVersion? =
|
||||
@ -127,34 +127,34 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) {
|
||||
|
||||
suspend fun markAsRead(id: String): SelfossModel.SuccessResponse? =
|
||||
client.post(url("/mark/$id")) {
|
||||
parameter("username", apiDetailsService.getUserName())
|
||||
parameter("password", apiDetailsService.getPassword())
|
||||
parameter("username", appSettingsService.getUserName())
|
||||
parameter("password", appSettingsService.getPassword())
|
||||
}.body()
|
||||
|
||||
suspend fun unmarkAsRead(id: String): SelfossModel.SuccessResponse? =
|
||||
client.post(url("/unmark/$id")) {
|
||||
parameter("username", apiDetailsService.getUserName())
|
||||
parameter("password", apiDetailsService.getPassword())
|
||||
parameter("username", appSettingsService.getUserName())
|
||||
parameter("password", appSettingsService.getPassword())
|
||||
}.body()
|
||||
|
||||
suspend fun starr(id: String): SelfossModel.SuccessResponse? =
|
||||
client.post(url("/starr/$id")) {
|
||||
parameter("username", apiDetailsService.getUserName())
|
||||
parameter("password", apiDetailsService.getPassword())
|
||||
parameter("username", appSettingsService.getUserName())
|
||||
parameter("password", appSettingsService.getPassword())
|
||||
}.body()
|
||||
|
||||
suspend fun unstarr(id: String): SelfossModel.SuccessResponse? =
|
||||
client.post(url("/unstarr/$id")) {
|
||||
parameter("username", apiDetailsService.getUserName())
|
||||
parameter("password", apiDetailsService.getPassword())
|
||||
parameter("username", appSettingsService.getUserName())
|
||||
parameter("password", appSettingsService.getPassword())
|
||||
}.body()
|
||||
|
||||
suspend fun markAllAsRead(ids: List<String>): SelfossModel.SuccessResponse? =
|
||||
client.submitForm(
|
||||
url = url("/mark"),
|
||||
formParameters = Parameters.build {
|
||||
append("username", apiDetailsService.getUserName())
|
||||
append("password", apiDetailsService.getPassword())
|
||||
append("username", appSettingsService.getUserName())
|
||||
append("password", appSettingsService.getPassword())
|
||||
ids.map { append("ids[]", it) }
|
||||
}
|
||||
).body()
|
||||
@ -181,7 +181,7 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) {
|
||||
filter: String
|
||||
): SelfossModel.SuccessResponse? =
|
||||
client.submitForm(
|
||||
url = url("/source?username=${apiDetailsService.getUserName()}&password=${apiDetailsService.getPassword()}"),
|
||||
url = url("/source?username=${appSettingsService.getUserName()}&password=${appSettingsService.getPassword()}"),
|
||||
formParameters = Parameters.build {
|
||||
append("title", title)
|
||||
append("url", url)
|
||||
@ -199,7 +199,7 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) {
|
||||
filter: String
|
||||
): SelfossModel.SuccessResponse? =
|
||||
client.submitForm(
|
||||
url = url("/source?username=${apiDetailsService.getUserName()}&password=${apiDetailsService.getPassword()}"),
|
||||
url = url("/source?username=${appSettingsService.getUserName()}&password=${appSettingsService.getPassword()}"),
|
||||
formParameters = Parameters.build {
|
||||
append("title", title)
|
||||
append("url", url)
|
||||
@ -211,7 +211,7 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) {
|
||||
|
||||
suspend fun deleteSource(id: Int): SelfossModel.SuccessResponse? =
|
||||
client.delete(url("/source/$id")) {
|
||||
parameter("username", apiDetailsService.getUserName())
|
||||
parameter("password", apiDetailsService.getPassword())
|
||||
parameter("username", appSettingsService.getUserName())
|
||||
parameter("password", appSettingsService.getPassword())
|
||||
}.body()
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
package bou.amine.apps.readerforselfossv2.service
|
||||
|
||||
import com.russhwolf.settings.Settings
|
||||
import io.github.aakira.napier.Napier
|
||||
import io.ktor.client.plugins.*
|
||||
|
||||
class ApiDetailsService {
|
||||
val settings: Settings = Settings()
|
||||
private var _apiVersion: Int = -1
|
||||
private var _baseUrl: String = ""
|
||||
private var _userName: String = ""
|
||||
private var _password: String = ""
|
||||
private var _itemsNumber: Int? = null
|
||||
private var _apiTimeout: Long? = null
|
||||
|
||||
fun logApiCalls(message: String) {
|
||||
Napier.d(message, tag = "LogApiCalls")
|
||||
}
|
||||
|
||||
|
||||
fun getApiVersion(): Int {
|
||||
if (_apiVersion == -1) {
|
||||
refreshApiVersion()
|
||||
return _apiVersion
|
||||
}
|
||||
return _apiVersion
|
||||
}
|
||||
|
||||
fun refreshApiVersion() {
|
||||
_apiVersion = settings.getInt("apiVersionMajor", -1)
|
||||
}
|
||||
|
||||
fun getBaseUrl(): String {
|
||||
if (_baseUrl.isEmpty()) {
|
||||
_baseUrl = settings.getString("url", "")
|
||||
}
|
||||
return _baseUrl
|
||||
}
|
||||
|
||||
fun getUserName(): String {
|
||||
if (_userName.isEmpty()) {
|
||||
_userName = settings.getString("login", "")
|
||||
}
|
||||
return _userName
|
||||
}
|
||||
|
||||
fun getPassword(): String {
|
||||
if (_password.isEmpty()) {
|
||||
_password = settings.getString("password", "")
|
||||
}
|
||||
return _password
|
||||
}
|
||||
|
||||
fun getItemsNumber(): Int {
|
||||
if (_itemsNumber == null) {
|
||||
refreshItemsNumber()
|
||||
}
|
||||
return _itemsNumber!!
|
||||
}
|
||||
|
||||
fun refreshItemsNumber() {
|
||||
_itemsNumber = settings.getString("prefer_api_items_number", "200").toInt()
|
||||
}
|
||||
|
||||
fun getApiTimeout(): Long {
|
||||
if (_apiTimeout == null) {
|
||||
refreshApiTimeout()
|
||||
}
|
||||
return _apiTimeout!!
|
||||
}
|
||||
|
||||
fun refreshApiTimeout() {
|
||||
val settingsTimeout = settings.getLong("api_timeout", HttpTimeout.INFINITE_TIMEOUT_MS)
|
||||
_apiTimeout = if (settingsTimeout > 0) settingsTimeout else HttpTimeout.INFINITE_TIMEOUT_MS
|
||||
}
|
||||
|
||||
fun refresh() {
|
||||
_password = settings.getString("password", "")
|
||||
_userName = settings.getString("login", "")
|
||||
_baseUrl = settings.getString("url", "")
|
||||
refreshApiVersion()
|
||||
refreshItemsNumber()
|
||||
refreshApiTimeout()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val translationUrl = "https://crwd.in/readerforselfoss"
|
||||
|
||||
const val sourceUrl = "https://gitea.amine-louveau.fr/Louvorg/ReaderForSelfoss-multiplatform"
|
||||
|
||||
const val trackerUrl = "https://gitea.amine-louveau.fr/Louvorg/ReaderForSelfoss-multiplatform/issues"
|
||||
|
||||
const val syncChannelId = "sync-channel-id"
|
||||
|
||||
const val newItemsChannelId = "new-items-channel-id"
|
||||
}
|
||||
}
|
@ -0,0 +1,428 @@
|
||||
package bou.amine.apps.readerforselfossv2.service
|
||||
|
||||
import com.russhwolf.settings.Settings
|
||||
import io.github.aakira.napier.Napier
|
||||
import io.ktor.client.plugins.*
|
||||
|
||||
class AppSettingsService {
|
||||
val settings: Settings = Settings()
|
||||
|
||||
// Api related
|
||||
private var _apiVersion: Int = -1
|
||||
private var _baseUrl: String = ""
|
||||
private var _userName: String = ""
|
||||
private var _password: String = ""
|
||||
|
||||
// User settings related
|
||||
private var _itemsCaching: Boolean? = null
|
||||
private var _internalBrowser: Boolean? = null
|
||||
private var _articleViewer: Boolean? = null
|
||||
private var _shouldBeCardView: Boolean? = null
|
||||
private var _displayUnreadCount: Boolean? = null
|
||||
private var _displayAllCount: Boolean? = null
|
||||
private var _fullHeightCards: Boolean? = null
|
||||
private var _updateSources: Boolean? = null
|
||||
private var _periodicRefresh: Boolean? = null
|
||||
private var _refreshWhenChargingOnly: Boolean? = null
|
||||
private var _infiniteLoading: Boolean? = null
|
||||
private var _displayAccountHeader: Boolean? = null
|
||||
private var _notifyNewItems: Boolean? = null
|
||||
private var _itemsNumber: Int? = null
|
||||
private var _apiTimeout: Long? = null
|
||||
private var _hiddenTags: List<String>? = null
|
||||
private var _refreshMinutes: Long = 360
|
||||
private var _markOnScroll: Boolean? = null
|
||||
private var _activeAlignment: Int? = null
|
||||
|
||||
private var _fontSize: Int? = null // settings.getString("reader_font_size", "16").toInt()
|
||||
private var _staticBar: Boolean? = null // settings.getBoolean("reader_static_bar", false)
|
||||
private var _font: String = "" // settings.getString("reader_font", "")
|
||||
|
||||
|
||||
init {
|
||||
refreshApiSettings()
|
||||
refreshUserSettings()
|
||||
}
|
||||
|
||||
fun logApiCalls(message: String) {
|
||||
Napier.d(message, tag = "LogApiCalls")
|
||||
}
|
||||
|
||||
fun getApiVersion(): Int {
|
||||
if (_apiVersion == -1) {
|
||||
refreshApiVersion()
|
||||
return _apiVersion
|
||||
}
|
||||
return _apiVersion
|
||||
}
|
||||
|
||||
fun refreshApiVersion() {
|
||||
_apiVersion = settings.getInt("apiVersionMajor", -1)
|
||||
}
|
||||
|
||||
fun getBaseUrl(): String {
|
||||
if (_baseUrl.isEmpty()) {
|
||||
refreshBaseUrl()
|
||||
}
|
||||
return _baseUrl
|
||||
}
|
||||
|
||||
fun getUserName(): String {
|
||||
if (_userName.isEmpty()) {
|
||||
refrershUsername()
|
||||
}
|
||||
return _userName
|
||||
}
|
||||
|
||||
fun getPassword(): String {
|
||||
if (_password.isEmpty()) {
|
||||
refreshPassword()
|
||||
}
|
||||
return _password
|
||||
}
|
||||
|
||||
fun getItemsNumber(): Int {
|
||||
if (_itemsNumber == null) {
|
||||
refreshItemsNumber()
|
||||
}
|
||||
return _itemsNumber!!
|
||||
}
|
||||
|
||||
fun refreshItemsNumber() {
|
||||
_itemsNumber = settings.getString("prefer_api_items_number", "200").toInt()
|
||||
}
|
||||
|
||||
fun getApiTimeout(): Long {
|
||||
if (_apiTimeout == null) {
|
||||
refreshApiTimeout()
|
||||
}
|
||||
return _apiTimeout!!
|
||||
}
|
||||
|
||||
private fun refreshApiTimeout() {
|
||||
val settingsTimeout = settings.getLong("api_timeout", HttpTimeout.INFINITE_TIMEOUT_MS)
|
||||
_apiTimeout = if (settingsTimeout > 0) settingsTimeout else HttpTimeout.INFINITE_TIMEOUT_MS
|
||||
}
|
||||
|
||||
private fun refreshBaseUrl() {
|
||||
_baseUrl = settings.getString("url", "")
|
||||
}
|
||||
|
||||
private fun refrershUsername() {
|
||||
_userName = settings.getString("login", "")
|
||||
}
|
||||
|
||||
private fun refreshPassword() {
|
||||
_password = settings.getString("password", "")
|
||||
}
|
||||
|
||||
private fun refreshInternalBrowserEnabled() {
|
||||
_internalBrowser = settings.getBoolean("prefer_internal_browser", true)
|
||||
}
|
||||
|
||||
fun isInternalBrowserEnabled(): Boolean {
|
||||
if (_internalBrowser != null) {
|
||||
refreshInternalBrowserEnabled()
|
||||
}
|
||||
return _internalBrowser == true
|
||||
}
|
||||
|
||||
private fun refreshArticleViewerEnabled() {
|
||||
_articleViewer = settings.getBoolean("prefer_article_viewer", true)
|
||||
}
|
||||
|
||||
fun isArticleViewerEnabled(): Boolean {
|
||||
if (_articleViewer != null) {
|
||||
refreshArticleViewerEnabled()
|
||||
}
|
||||
return _articleViewer == true
|
||||
}
|
||||
private fun refreshShouldBeCardViewEnabled() {
|
||||
_shouldBeCardView = settings.getBoolean("card_view_active", false)
|
||||
}
|
||||
|
||||
fun isCardViewEnabled(): Boolean {
|
||||
if (_shouldBeCardView != null) {
|
||||
refreshShouldBeCardViewEnabled()
|
||||
}
|
||||
return _shouldBeCardView == true
|
||||
}
|
||||
private fun refreshDisplayUnreadCountEnabled() {
|
||||
_displayUnreadCount = settings.getBoolean("display_unread_count", true)
|
||||
}
|
||||
|
||||
fun isDisplayUnreadCountEnabled(): Boolean {
|
||||
if (_displayUnreadCount != null) {
|
||||
refreshDisplayUnreadCountEnabled()
|
||||
}
|
||||
return _displayUnreadCount == true
|
||||
}
|
||||
private fun refreshDisplayAllCountEnabled() {
|
||||
_displayAllCount = settings.getBoolean("display_other_count", false)
|
||||
}
|
||||
|
||||
fun isDisplayAllCountEnabled(): Boolean {
|
||||
if (_displayAllCount != null) {
|
||||
refreshDisplayAllCountEnabled()
|
||||
}
|
||||
return _displayAllCount == true
|
||||
}
|
||||
private fun refreshFullHeightCardsEnabled() {
|
||||
_fullHeightCards = settings.getBoolean("full_height_cards", false)
|
||||
}
|
||||
|
||||
fun isFullHeightCardsEnabled(): Boolean {
|
||||
if (_fullHeightCards != null) {
|
||||
refreshFullHeightCardsEnabled()
|
||||
}
|
||||
return _fullHeightCards == true
|
||||
}
|
||||
private fun refreshUpdateSourcesEnabled() {
|
||||
_updateSources = settings.getBoolean("update_sources", true)
|
||||
}
|
||||
|
||||
fun isUpdateSourcesEnabled(): Boolean {
|
||||
if (_updateSources != null) {
|
||||
refreshUpdateSourcesEnabled()
|
||||
}
|
||||
return _updateSources == true
|
||||
}
|
||||
private fun refreshPeriodicRefreshEnabled() {
|
||||
_periodicRefresh = settings.getBoolean("periodic_refresh", false)
|
||||
}
|
||||
|
||||
fun isPeriodicRefreshEnabled(): Boolean {
|
||||
if (_periodicRefresh != null) {
|
||||
refreshPeriodicRefreshEnabled()
|
||||
}
|
||||
return _periodicRefresh == true
|
||||
}
|
||||
|
||||
private fun refreshRefreshWhenChargingOnlyEnabled() {
|
||||
_refreshWhenChargingOnly = settings.getBoolean("refresh_when_charging", false)
|
||||
}
|
||||
|
||||
fun isRefreshWhenChargingOnlyEnabled(): Boolean {
|
||||
if (_refreshWhenChargingOnly != null) {
|
||||
refreshRefreshWhenChargingOnlyEnabled()
|
||||
}
|
||||
return _refreshWhenChargingOnly == true
|
||||
}
|
||||
|
||||
private fun refreshRefreshMinutes() {
|
||||
_refreshMinutes = settings.getString("periodic_refresh_minutes", "360").toLong()
|
||||
if (_refreshMinutes <= 15) {
|
||||
_refreshMinutes = 15
|
||||
}
|
||||
}
|
||||
|
||||
fun getRefreshMinutes(): Long {
|
||||
if (_refreshMinutes != null) {
|
||||
refreshRefreshMinutes()
|
||||
}
|
||||
return _refreshMinutes
|
||||
}
|
||||
|
||||
private fun refreshHiddenTags() {
|
||||
if (settings.getString("hidden_tags", "").isNotEmpty()) {
|
||||
_hiddenTags = settings.getString("hidden_tags", "").replace("\\s".toRegex(), "").split(",")
|
||||
}
|
||||
}
|
||||
|
||||
fun getHiddenTags(): List<String> {
|
||||
if (_hiddenTags != null) {
|
||||
refreshHiddenTags()
|
||||
}
|
||||
return _hiddenTags.orEmpty()
|
||||
}
|
||||
|
||||
private fun refreshInfiniteLoadingEnabled() {
|
||||
_infiniteLoading = settings.getBoolean("infinite_loading", false)
|
||||
}
|
||||
|
||||
fun isInfiniteLoadingEnabled(): Boolean {
|
||||
if (_infiniteLoading != null) {
|
||||
refreshInfiniteLoadingEnabled()
|
||||
}
|
||||
return _infiniteLoading == true
|
||||
}
|
||||
|
||||
private fun refreshDisplayAccountHeaderEnabled() {
|
||||
_displayAccountHeader = settings.getBoolean("account_header_displaying", false)
|
||||
}
|
||||
|
||||
fun isDisplayAccountHeaderEnabled(): Boolean {
|
||||
if (_displayAccountHeader != null) {
|
||||
refreshDisplayAccountHeaderEnabled()
|
||||
}
|
||||
return _displayAccountHeader == true
|
||||
}
|
||||
|
||||
private fun refreshItemCachingEnabled() {
|
||||
_itemsCaching = settings.getBoolean("items_caching", false)
|
||||
}
|
||||
|
||||
fun isItemCachingEnabled(): Boolean {
|
||||
if (_itemsCaching != null) {
|
||||
refreshItemCachingEnabled()
|
||||
}
|
||||
return _itemsCaching == true
|
||||
}
|
||||
|
||||
private fun refreshNotifyNewItemsEnabled() {
|
||||
_notifyNewItems = settings.getBoolean("notify_new_items", false)
|
||||
}
|
||||
|
||||
fun isNotifyNewItemsEnabled(): Boolean {
|
||||
if (_notifyNewItems != null) {
|
||||
refreshNotifyNewItemsEnabled()
|
||||
}
|
||||
return _notifyNewItems == true
|
||||
}
|
||||
|
||||
|
||||
private fun refreshMarkOnScrollEnabled() {
|
||||
_markOnScroll = settings.getBoolean("mark_on_scroll", false)
|
||||
}
|
||||
|
||||
fun isMarkOnScrollEnabled(): Boolean {
|
||||
if (_markOnScroll != null) {
|
||||
refreshMarkOnScrollEnabled()
|
||||
}
|
||||
return _markOnScroll == true
|
||||
}
|
||||
|
||||
|
||||
private fun refreshActiveAllignment() {
|
||||
_activeAlignment = settings.getInt("text_align", JUSTIFY)
|
||||
}
|
||||
|
||||
fun getActiveAllignment(): Int {
|
||||
if (_activeAlignment != null) {
|
||||
refreshActiveAllignment()
|
||||
}
|
||||
return _activeAlignment ?: JUSTIFY
|
||||
}
|
||||
|
||||
fun changeAllignment(allignment: Int) {
|
||||
settings.putInt("text_align", allignment)
|
||||
_activeAlignment = allignment
|
||||
}
|
||||
|
||||
private fun refreshFontSize() {
|
||||
_fontSize = settings.getString("reader_font_size", "16").toInt()
|
||||
}
|
||||
|
||||
fun getFontSize(): Int {
|
||||
if (_fontSize != null) {
|
||||
refreshFontSize()
|
||||
}
|
||||
return _fontSize ?: 16
|
||||
}
|
||||
|
||||
private fun refreshStaticBarEnabled() {
|
||||
_staticBar = settings.getBoolean("reader_static_bar", false)
|
||||
}
|
||||
|
||||
fun isStaticBarEnabled(): Boolean {
|
||||
if (_staticBar != null) {
|
||||
refreshStaticBarEnabled()
|
||||
}
|
||||
return _staticBar == true
|
||||
}
|
||||
|
||||
private fun refreshFont() {
|
||||
_font = settings.getString("reader_font", "")
|
||||
}
|
||||
|
||||
fun getFont(): String {
|
||||
if (_font != null) {
|
||||
refreshFont()
|
||||
}
|
||||
return _font
|
||||
}
|
||||
|
||||
fun refreshApiSettings() {
|
||||
refreshPassword()
|
||||
refrershUsername()
|
||||
refreshBaseUrl()
|
||||
refreshApiVersion()
|
||||
}
|
||||
|
||||
fun refreshUserSettings() {
|
||||
refreshItemsNumber()
|
||||
refreshApiTimeout()
|
||||
refreshInternalBrowserEnabled()
|
||||
refreshArticleViewerEnabled()
|
||||
refreshShouldBeCardViewEnabled()
|
||||
refreshDisplayUnreadCountEnabled()
|
||||
refreshDisplayAllCountEnabled()
|
||||
refreshFullHeightCardsEnabled()
|
||||
refreshUpdateSourcesEnabled()
|
||||
refreshPeriodicRefreshEnabled()
|
||||
refreshRefreshWhenChargingOnlyEnabled()
|
||||
refreshRefreshMinutes()
|
||||
refreshHiddenTags()
|
||||
refreshInfiniteLoadingEnabled()
|
||||
refreshDisplayAccountHeaderEnabled()
|
||||
refreshItemCachingEnabled()
|
||||
refreshNotifyNewItemsEnabled()
|
||||
refreshMarkOnScrollEnabled()
|
||||
refreshActiveAllignment()
|
||||
refreshFontSize()
|
||||
refreshFont()
|
||||
refreshStaticBarEnabled()
|
||||
}
|
||||
|
||||
fun refreshLoginInformation(
|
||||
url: String,
|
||||
login: String,
|
||||
password: String,
|
||||
selfSignedCert: Boolean
|
||||
) {
|
||||
settings.putString("url", url)
|
||||
settings.putString("login", login)
|
||||
settings.putString("password", password)
|
||||
settings.putBoolean("isSelfSignedCert", selfSignedCert)
|
||||
refreshApiSettings()
|
||||
}
|
||||
|
||||
fun resetLoginInformation() {
|
||||
settings.remove("url")
|
||||
settings.remove("login")
|
||||
settings.remove("password")
|
||||
refreshApiSettings()
|
||||
}
|
||||
|
||||
fun updateApiVersion(apiMajorVersion: Int) {
|
||||
settings.putInt("apiVersionMajor", apiMajorVersion)
|
||||
refreshApiVersion()
|
||||
}
|
||||
|
||||
fun clearAll() {
|
||||
settings.clear()
|
||||
refreshApiSettings()
|
||||
refreshUserSettings()
|
||||
}
|
||||
|
||||
fun disableArticleViewer() {
|
||||
settings.putBoolean("prefer_article_viewer", false)
|
||||
refreshArticleViewerEnabled()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val translationUrl = "https://crwd.in/readerforselfoss"
|
||||
|
||||
const val sourceUrl = "https://gitea.amine-louveau.fr/Louvorg/ReaderForSelfoss-multiplatform"
|
||||
|
||||
const val trackerUrl = "https://gitea.amine-louveau.fr/Louvorg/ReaderForSelfoss-multiplatform/issues"
|
||||
|
||||
const val syncChannelId = "sync-channel-id"
|
||||
|
||||
const val newItemsChannelId = "new-items-channel-id"
|
||||
|
||||
const val JUSTIFY = 1
|
||||
|
||||
const val ALIGN_LEFT = 2
|
||||
}
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package bou.amine.apps.readerforselfossv2.utils
|
||||
|
||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
|
||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||
|
||||
|
||||
fun SelfossModel.Item.parseDate(dateUtils: DateUtils): Long =
|
||||
dateUtils.parseDate(this.datetime)
|
||||
|
||||
expect class DateUtils(apiDetailsService: ApiDetailsService) {
|
||||
expect class DateUtils(appSettingsService: AppSettingsService) {
|
||||
fun parseDate(dateString: String): Long
|
||||
|
||||
fun parseRelativeDate(dateString: String): String
|
||||
|
@ -1,8 +1,8 @@
|
||||
package bou.amine.apps.readerforselfossv2.utils
|
||||
|
||||
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
|
||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||
|
||||
actual class DateUtils actual constructor(apiDetailsService: ApiDetailsService) {
|
||||
actual class DateUtils actual constructor(appSettingsService: AppSettingsService) {
|
||||
actual fun parseDate(dateString: String): Long {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package bou.amine.apps.readerforselfossv2.utils
|
||||
|
||||
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
|
||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||
|
||||
actual class DateUtils actual constructor(apiDetailsService: ApiDetailsService) {
|
||||
actual class DateUtils actual constructor(appSettingsService: AppSettingsService) {
|
||||
actual fun parseDate(dateString: String): Long {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
Reference in New Issue
Block a user