Compare commits

..

No commits in common. "9603860baead4fdefd767c80c1e40f5eccc2742e" and "0caeb94e645c07592b9c888fb1d063e4b2fbc15a" have entirely different histories.

11 changed files with 66 additions and 80 deletions

View File

@ -18,4 +18,4 @@ steps:
- name: build
image: mingc/android-build-box:latest
commands:
- ./gradlew :androidApp:build -PignoreGitVersion=true -P appLoginUrl="\"URL\"" -P appLoginUsername="\"LOGIN\"" -P appLoginPassword="\"PASS\"" -P pushCache=false
- ./gradlew :androidApp:build -PignoreGitVersion=true -P appLoginUrl="\"URL\"" -P appLoginUsername="\"LOGIN\"" -P appLoginPassword="\"PASS\""

View File

@ -318,9 +318,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
handleRecurringTask()
CoroutineScope(Dispatchers.Main).launch {
repository.handleDBActions()
}
handleOfflineActions()
getElementsAccordingToTab()
}
@ -1084,7 +1082,26 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
}
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)
}
}
}
}
}

View File

@ -69,14 +69,7 @@ class MyApp : MultiDexApplication(), DIAware {
ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifeCycleObserver(connectivityStatus, repository))
CoroutineScope(Dispatchers.Main).launch {
viewModel.networkAvailableProvider.collect { networkAvailable ->
val toastMessage = if (networkAvailable) {
repository.handleDBActions()
R.string.network_connectivity_retrieved
} else {
R.string.network_connectivity_lost
}
viewModel.toastMessageProvider.collect { toastMessage ->
Toast.makeText(
applicationContext,
toastMessage,

View File

@ -22,7 +22,7 @@ class MercuryApi() {
val retrofit =
Retrofit
.Builder()
.baseUrl("https://www.amine-louveau.fr")
.baseUrl("https://www.amine-bou.fr")
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.build()

View File

@ -17,8 +17,9 @@ import bou.amine.apps.readerforselfossv2.android.model.preloadImages
import bou.amine.apps.readerforselfossv2.android.utils.Config
import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAccessible
import bou.amine.apps.readerforselfossv2.dao.ACTION
import bou.amine.apps.readerforselfossv2.model.SelfossModel
import bou.amine.apps.readerforselfossv2.repository.Repository
import bou.amine.apps.readerforselfossv2.model.SelfossModel
import bou.amine.apps.readerforselfossv2.utils.ItemType
import com.russhwolf.settings.Settings
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -56,7 +57,28 @@ override fun doWork(): Result {
val notifyNewItems = settings.getBoolean("notify_new_items", false)
repository.handleDBActions()
val actions: List<ACTION> = 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
)
}
}
launch {
handleNewItemsNotification(repository.tryToCacheItemsAndGetNewOnes(), notifyNewItems, notificationManager)
@ -113,4 +135,12 @@ override fun doWork(): Result {
}
}
}
private fun doAndReportOnFail(result: Boolean, action: ACTION) {
if (result) {
thread {
repository.deleteDBAction(action)
}
}
}
}

View File

@ -35,7 +35,6 @@ fun String.toTextDrawableString(): String {
try {
textDrawable.append(s[0])
} catch (e: StringIndexOutOfBoundsException) {
// We do nothing
}
}
return textDrawable.toString()

View File

@ -9,21 +9,19 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
class AppViewModel(private val repository: Repository) : ViewModel() {
private val _networkAvailableProvider = MutableSharedFlow<Boolean>()
val networkAvailableProvider = _networkAvailableProvider.asSharedFlow()
private val _toastMessageProvider = MutableSharedFlow<Int>()
val toastMessageProvider = _toastMessageProvider.asSharedFlow()
private var wasConnected = true
init {
viewModelScope.launch {
repository.isConnectionAvailable.collect { isConnected ->
if (repository.connectionMonitored) {
if (isConnected && !wasConnected && repository.connectionMonitored) {
_networkAvailableProvider.emit(true)
wasConnected = true
} else if (!isConnected && wasConnected && repository.connectionMonitored){
_networkAvailableProvider.emit(false)
wasConnected = false
}
if (isConnected && !wasConnected && repository.connectionMonitored) {
_toastMessageProvider.emit(R.string.network_connectivity_retrieved)
wasConnected = true
} else if (!isConnected && wasConnected && repository.connectionMonitored){
_toastMessageProvider.emit(R.string.network_connectivity_lost)
wasConnected = false
}
}
}

View File

@ -19,6 +19,4 @@ android.useAndroidX=true
android.enableJetifier=true
kotlin.mpp.enableGranularSourceSetsMetadata=true
org.gradle.parallel=true
org.gradle.caching=true
ignoreGitVersion=false
pushCache=true

View File

@ -1,5 +1,3 @@
val pushCache: String by settings
pluginManagement {
repositories {
google()
@ -8,16 +6,6 @@ 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"
include(":androidApp")
include(":shared")

View File

@ -329,13 +329,8 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
return success
}
suspend fun updateRemote(): Boolean {
return if (isNetworkAvailable()) {
api.update()?.equals("finished") ?: false
} else {
false
}
}
suspend fun updateRemote(): Boolean =
isNetworkAvailable() && api.update()?.isSuccess == true
suspend fun login(): Boolean {
var result = false
@ -434,36 +429,4 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
} catch (e: Throwable) {}
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)
}
}
}

View File

@ -100,7 +100,7 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) {
parameter("password", apiDetailsService.getPassword())
}.body()
suspend fun update(): String? =
suspend fun update(): SelfossModel.SuccessResponse? =
client.get(url("/update")) {
parameter("username", apiDetailsService.getUserName())
parameter("password", apiDetailsService.getPassword())