Merge pull request 'chore/sonarqube-fixes' (#35) from chore/sonarqube-fixes into master
Reviewed-on: https://gitea.amine-louveau.fr/Louvorg/ReaderForSelfoss-multiplatform/pulls/35
This commit is contained in:
commit
9603860bae
@ -18,4 +18,4 @@ steps:
|
|||||||
- name: build
|
- name: build
|
||||||
image: mingc/android-build-box:latest
|
image: mingc/android-build-box:latest
|
||||||
commands:
|
commands:
|
||||||
- ./gradlew :androidApp:build -PignoreGitVersion=true -P appLoginUrl="\"URL\"" -P appLoginUsername="\"LOGIN\"" -P appLoginPassword="\"PASS\""
|
- ./gradlew :androidApp:build -PignoreGitVersion=true -P appLoginUrl="\"URL\"" -P appLoginUsername="\"LOGIN\"" -P appLoginPassword="\"PASS\"" -P pushCache=false
|
@ -318,7 +318,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
|
|
||||||
handleRecurringTask()
|
handleRecurringTask()
|
||||||
|
|
||||||
handleOfflineActions()
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
repository.handleDBActions()
|
||||||
|
}
|
||||||
|
|
||||||
getElementsAccordingToTab()
|
getElementsAccordingToTab()
|
||||||
}
|
}
|
||||||
@ -1082,26 +1084,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleOfflineActions() {
|
private fun handleOfflineActions() {
|
||||||
fun doAndReportOnFail(success: Boolean, action: ACTION) {
|
|
||||||
if (success) {
|
|
||||||
thread {
|
|
||||||
repository.deleteDBAction(action)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
|
||||||
val actions = repository.getDBActions()
|
|
||||||
|
|
||||||
actions.forEach { action ->
|
|
||||||
when {
|
|
||||||
action.read -> doAndReportOnFail(repository.markAsReadById(action.articleid.toInt()), action)
|
|
||||||
action.unread -> doAndReportOnFail(repository.unmarkAsReadById(action.articleid.toInt()), action)
|
|
||||||
action.starred -> doAndReportOnFail(repository.starrById(action.articleid.toInt()), action)
|
|
||||||
action.unstarred -> doAndReportOnFail(repository.unstarrById(action.articleid.toInt()), action)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,14 @@ class MyApp : MultiDexApplication(), DIAware {
|
|||||||
ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifeCycleObserver(connectivityStatus, repository))
|
ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifeCycleObserver(connectivityStatus, repository))
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
viewModel.toastMessageProvider.collect { toastMessage ->
|
viewModel.networkAvailableProvider.collect { networkAvailable ->
|
||||||
|
val toastMessage = if (networkAvailable) {
|
||||||
|
repository.handleDBActions()
|
||||||
|
R.string.network_connectivity_retrieved
|
||||||
|
} else {
|
||||||
|
R.string.network_connectivity_lost
|
||||||
|
}
|
||||||
|
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
applicationContext,
|
applicationContext,
|
||||||
toastMessage,
|
toastMessage,
|
||||||
|
@ -22,7 +22,7 @@ class MercuryApi() {
|
|||||||
val retrofit =
|
val retrofit =
|
||||||
Retrofit
|
Retrofit
|
||||||
.Builder()
|
.Builder()
|
||||||
.baseUrl("https://www.amine-bou.fr")
|
.baseUrl("https://www.amine-louveau.fr")
|
||||||
.client(client)
|
.client(client)
|
||||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
.addConverterFactory(GsonConverterFactory.create(gson))
|
||||||
.build()
|
.build()
|
||||||
|
@ -17,9 +17,8 @@ import bou.amine.apps.readerforselfossv2.android.model.preloadImages
|
|||||||
import bou.amine.apps.readerforselfossv2.android.utils.Config
|
import bou.amine.apps.readerforselfossv2.android.utils.Config
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAccessible
|
import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAccessible
|
||||||
import bou.amine.apps.readerforselfossv2.dao.ACTION
|
import bou.amine.apps.readerforselfossv2.dao.ACTION
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.utils.ItemType
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import com.russhwolf.settings.Settings
|
import com.russhwolf.settings.Settings
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -57,28 +56,7 @@ override fun doWork(): Result {
|
|||||||
|
|
||||||
val notifyNewItems = settings.getBoolean("notify_new_items", false)
|
val notifyNewItems = settings.getBoolean("notify_new_items", false)
|
||||||
|
|
||||||
val actions: List<ACTION> = repository.getDBActions()
|
repository.handleDBActions()
|
||||||
|
|
||||||
actions.forEach { action ->
|
|
||||||
when {
|
|
||||||
action.read -> doAndReportOnFail(
|
|
||||||
repository.markAsReadById(action.articleid.toInt()),
|
|
||||||
action
|
|
||||||
)
|
|
||||||
action.unread -> doAndReportOnFail(
|
|
||||||
repository.unmarkAsReadById(action.articleid.toInt()),
|
|
||||||
action
|
|
||||||
)
|
|
||||||
action.starred -> doAndReportOnFail(
|
|
||||||
repository.starrById(action.articleid.toInt()),
|
|
||||||
action
|
|
||||||
)
|
|
||||||
action.unstarred -> doAndReportOnFail(
|
|
||||||
repository.unstarrById(action.articleid.toInt()),
|
|
||||||
action
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
launch {
|
launch {
|
||||||
handleNewItemsNotification(repository.tryToCacheItemsAndGetNewOnes(), notifyNewItems, notificationManager)
|
handleNewItemsNotification(repository.tryToCacheItemsAndGetNewOnes(), notifyNewItems, notificationManager)
|
||||||
@ -135,12 +113,4 @@ override fun doWork(): Result {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doAndReportOnFail(result: Boolean, action: ACTION) {
|
|
||||||
if (result) {
|
|
||||||
thread {
|
|
||||||
repository.deleteDBAction(action)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -35,6 +35,7 @@ fun String.toTextDrawableString(): String {
|
|||||||
try {
|
try {
|
||||||
textDrawable.append(s[0])
|
textDrawable.append(s[0])
|
||||||
} catch (e: StringIndexOutOfBoundsException) {
|
} catch (e: StringIndexOutOfBoundsException) {
|
||||||
|
// We do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return textDrawable.toString()
|
return textDrawable.toString()
|
||||||
|
@ -9,19 +9,21 @@ import kotlinx.coroutines.flow.asSharedFlow
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class AppViewModel(private val repository: Repository) : ViewModel() {
|
class AppViewModel(private val repository: Repository) : ViewModel() {
|
||||||
private val _toastMessageProvider = MutableSharedFlow<Int>()
|
private val _networkAvailableProvider = MutableSharedFlow<Boolean>()
|
||||||
val toastMessageProvider = _toastMessageProvider.asSharedFlow()
|
val networkAvailableProvider = _networkAvailableProvider.asSharedFlow()
|
||||||
private var wasConnected = true
|
private var wasConnected = true
|
||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
repository.isConnectionAvailable.collect { isConnected ->
|
repository.isConnectionAvailable.collect { isConnected ->
|
||||||
if (isConnected && !wasConnected && repository.connectionMonitored) {
|
if (repository.connectionMonitored) {
|
||||||
_toastMessageProvider.emit(R.string.network_connectivity_retrieved)
|
if (isConnected && !wasConnected && repository.connectionMonitored) {
|
||||||
wasConnected = true
|
_networkAvailableProvider.emit(true)
|
||||||
} else if (!isConnected && wasConnected && repository.connectionMonitored){
|
wasConnected = true
|
||||||
_toastMessageProvider.emit(R.string.network_connectivity_lost)
|
} else if (!isConnected && wasConnected && repository.connectionMonitored){
|
||||||
wasConnected = false
|
_networkAvailableProvider.emit(false)
|
||||||
|
wasConnected = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,4 +19,6 @@ android.useAndroidX=true
|
|||||||
android.enableJetifier=true
|
android.enableJetifier=true
|
||||||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
|
org.gradle.caching=true
|
||||||
ignoreGitVersion=false
|
ignoreGitVersion=false
|
||||||
|
pushCache=true
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
val pushCache: String by settings
|
||||||
|
|
||||||
pluginManagement {
|
pluginManagement {
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
@ -6,6 +8,16 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildCache {
|
||||||
|
remote<HttpBuildCache> {
|
||||||
|
url = uri("http://18.0.0.7:3071/cache/")
|
||||||
|
isAllowInsecureProtocol = true
|
||||||
|
isAllowUntrustedServer = true
|
||||||
|
isUseExpectContinue = true
|
||||||
|
isPush = (pushCache == "true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rootProject.name = "ReaderForSelfossV2"
|
rootProject.name = "ReaderForSelfossV2"
|
||||||
include(":androidApp")
|
include(":androidApp")
|
||||||
include(":shared")
|
include(":shared")
|
@ -329,8 +329,13 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
|||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun updateRemote(): Boolean =
|
suspend fun updateRemote(): Boolean {
|
||||||
isNetworkAvailable() && api.update()?.isSuccess == true
|
return if (isNetworkAvailable()) {
|
||||||
|
api.update()?.equals("finished") ?: false
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun login(): Boolean {
|
suspend fun login(): Boolean {
|
||||||
var result = false
|
var result = false
|
||||||
@ -429,4 +434,36 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
|||||||
} catch (e: Throwable) {}
|
} catch (e: Throwable) {}
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun handleDBActions() {
|
||||||
|
|
||||||
|
val actions: List<ACTION> = getDBActions()
|
||||||
|
|
||||||
|
actions.forEach { action ->
|
||||||
|
when {
|
||||||
|
action.read -> doAndReportOnFail(
|
||||||
|
markAsReadById(action.articleid.toInt()),
|
||||||
|
action
|
||||||
|
)
|
||||||
|
action.unread -> doAndReportOnFail(
|
||||||
|
unmarkAsReadById(action.articleid.toInt()),
|
||||||
|
action
|
||||||
|
)
|
||||||
|
action.starred -> doAndReportOnFail(
|
||||||
|
starrById(action.articleid.toInt()),
|
||||||
|
action
|
||||||
|
)
|
||||||
|
action.unstarred -> doAndReportOnFail(
|
||||||
|
unstarrById(action.articleid.toInt()),
|
||||||
|
action
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun doAndReportOnFail(result: Boolean, action: ACTION) {
|
||||||
|
if (result) {
|
||||||
|
deleteDBAction(action)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -100,7 +100,7 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) {
|
|||||||
parameter("password", apiDetailsService.getPassword())
|
parameter("password", apiDetailsService.getPassword())
|
||||||
}.body()
|
}.body()
|
||||||
|
|
||||||
suspend fun update(): SelfossModel.SuccessResponse? =
|
suspend fun update(): String? =
|
||||||
client.get(url("/update")) {
|
client.get(url("/update")) {
|
||||||
parameter("username", apiDetailsService.getUserName())
|
parameter("username", apiDetailsService.getUserName())
|
||||||
parameter("password", apiDetailsService.getPassword())
|
parameter("password", apiDetailsService.getPassword())
|
||||||
|
Loading…
Reference in New Issue
Block a user