From 255fbcb12ffcf6b916204c1b8e3d3a73792cbf04 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Wed, 17 Aug 2022 22:27:55 +0200 Subject: [PATCH 1/8] Added build cache. --- gradle.properties | 1 + settings.gradle.kts | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/gradle.properties b/gradle.properties index 5322fc7..1a20457 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,4 +19,5 @@ android.useAndroidX=true android.enableJetifier=true kotlin.mpp.enableGranularSourceSetsMetadata=true org.gradle.parallel=true +org.gradle.caching=true ignoreGitVersion=false diff --git a/settings.gradle.kts b/settings.gradle.kts index 0b32ec1..5c9e875 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -6,6 +6,17 @@ pluginManagement { } } + + +buildCache { + remote { + url = uri("http://18.0.0.7:3071/cache/") + isAllowInsecureProtocol = true + isAllowUntrustedServer = true + isUseExpectContinue = true + } +} + rootProject.name = "ReaderForSelfossV2" include(":androidApp") include(":shared") \ No newline at end of file -- 2.34.1 From e60f3a9d913fdf5da037bd8845497141f00a4642 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Wed, 17 Aug 2022 22:53:07 +0200 Subject: [PATCH 2/8] Push everywhere ? --- settings.gradle.kts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 5c9e875..9c5b39a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,5 @@ +val pushCache = true + pluginManagement { repositories { google() @@ -6,14 +8,13 @@ pluginManagement { } } - - buildCache { remote { url = uri("http://18.0.0.7:3071/cache/") isAllowInsecureProtocol = true isAllowUntrustedServer = true isUseExpectContinue = true + isPush = pushCache } } -- 2.34.1 From de43abf019c5666c758618db0c71ee88f030dc70 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Fri, 19 Aug 2022 22:20:47 +0200 Subject: [PATCH 3/8] Fixed mercury issues. --- .../apps/readerforselfossv2/android/api/mercury/MercuryApi.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/api/mercury/MercuryApi.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/api/mercury/MercuryApi.kt index 46d32ff..dc2357e 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/api/mercury/MercuryApi.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/api/mercury/MercuryApi.kt @@ -22,7 +22,7 @@ class MercuryApi() { val retrofit = Retrofit .Builder() - .baseUrl("https://www.amine-bou.fr") + .baseUrl("https://www.amine-louveau.fr") .client(client) .addConverterFactory(GsonConverterFactory.create(gson)) .build() -- 2.34.1 From c87473e8f1acea78973cf1e160c2f2421c8e7650 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Fri, 19 Aug 2022 22:30:27 +0200 Subject: [PATCH 4/8] Cache from settings. --- .drone.yml | 2 +- gradle.properties | 1 + settings.gradle.kts | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index 22ee6bd..b401477 100644 --- a/.drone.yml +++ b/.drone.yml @@ -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\"" \ No newline at end of file + - ./gradlew :androidApp:build -PignoreGitVersion=true -P appLoginUrl="\"URL\"" -P appLoginUsername="\"LOGIN\"" -P appLoginPassword="\"PASS\"" -P pushCache=false \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 1a20457..1503398 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,3 +21,4 @@ kotlin.mpp.enableGranularSourceSetsMetadata=true org.gradle.parallel=true org.gradle.caching=true ignoreGitVersion=false +pushCache=true diff --git a/settings.gradle.kts b/settings.gradle.kts index 9c5b39a..4f3bcd9 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,4 @@ -val pushCache = true +val pushCache: String by settings pluginManagement { repositories { @@ -14,7 +14,7 @@ buildCache { isAllowInsecureProtocol = true isAllowUntrustedServer = true isUseExpectContinue = true - isPush = pushCache + isPush = (pushCache == "true") } } -- 2.34.1 From 44a0469b176df3dfddf93091914aef163085e6c3 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Fri, 19 Aug 2022 22:38:55 +0200 Subject: [PATCH 5/8] Fixes #25; --- .../apps/readerforselfossv2/repository/RepositoryImpl.kt | 9 +++++++-- .../bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt index e4e7d90..2344d20 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt @@ -329,8 +329,13 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails return success } - suspend fun updateRemote(): Boolean = - isNetworkAvailable() && api.update()?.isSuccess == true + suspend fun updateRemote(): Boolean { + return if (isNetworkAvailable()) { + api.update()?.equals("finished") ?: false + } else { + false + } + } suspend fun login(): Boolean { var result = false diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt index 0047453..084d987 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt @@ -100,7 +100,7 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) { parameter("password", apiDetailsService.getPassword()) }.body() - suspend fun update(): SelfossModel.SuccessResponse? = + suspend fun update(): String? = client.get(url("/update")) { parameter("username", apiDetailsService.getUserName()) parameter("password", apiDetailsService.getPassword()) -- 2.34.1 From 34028949d72259cae5ed373a9e72a8584d7aade9 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Tue, 23 Aug 2022 22:52:36 +0200 Subject: [PATCH 6/8] More code cleaning. --- .../apps/readerforselfossv2/android/background/background.kt | 3 +-- .../readerforselfossv2/android/model/AndroidIModelUtils.kt | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/background/background.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/background/background.kt index 93f16be..1cbba10 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/background/background.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/background/background.kt @@ -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.network.isNetworkAccessible 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.utils.ItemType +import bou.amine.apps.readerforselfossv2.repository.Repository import com.russhwolf.settings.Settings import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/model/AndroidIModelUtils.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/model/AndroidIModelUtils.kt index 85c9e73..4822eca 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/model/AndroidIModelUtils.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/model/AndroidIModelUtils.kt @@ -35,6 +35,7 @@ fun String.toTextDrawableString(): String { try { textDrawable.append(s[0]) } catch (e: StringIndexOutOfBoundsException) { + // We do nothing } } return textDrawable.toString() -- 2.34.1 From fb572dbb272e4e1d85aed3e31271bd1fa0b997e5 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Wed, 24 Aug 2022 13:34:05 +0200 Subject: [PATCH 7/8] Closes #36 --- .../android/HomeActivity.kt | 23 ++----------- .../android/background/background.kt | 31 +----------------- .../repository/RepositoryImpl.kt | 32 +++++++++++++++++++ 3 files changed, 36 insertions(+), 50 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt index 722a8e4..87b5b67 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt @@ -318,7 +318,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar handleRecurringTask() - handleOfflineActions() + CoroutineScope(Dispatchers.Main).launch { + repository.handleDBActions() + } getElementsAccordingToTab() } @@ -1082,26 +1084,7 @@ 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) - } - } - } } } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/background/background.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/background/background.kt index 1cbba10..907338d 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/background/background.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/background/background.kt @@ -56,28 +56,7 @@ override fun doWork(): Result { val notifyNewItems = settings.getBoolean("notify_new_items", false) - val actions: List = 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 - ) - } - } + repository.handleDBActions() launch { handleNewItemsNotification(repository.tryToCacheItemsAndGetNewOnes(), notifyNewItems, notificationManager) @@ -134,12 +113,4 @@ override fun doWork(): Result { } } } - - private fun doAndReportOnFail(result: Boolean, action: ACTION) { - if (result) { - thread { - repository.deleteDBAction(action) - } - } - } } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt index 2344d20..6b7c824 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt @@ -434,4 +434,36 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails } catch (e: Throwable) {} return emptyList() } + + suspend fun handleDBActions() { + + val actions: List = 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) + } + } } \ No newline at end of file -- 2.34.1 From 75b566a38dcfbf4c095838bd2c1371e277799ab2 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Wed, 24 Aug 2022 13:58:24 +0200 Subject: [PATCH 8/8] Some cleaning to handle actions on connection restore. --- .../apps/readerforselfossv2/android/MyApp.kt | 9 ++++++++- .../android/viewmodel/AppViewModel.kt | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt index 887fc5a..3345124 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt @@ -69,7 +69,14 @@ class MyApp : MultiDexApplication(), DIAware { ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifeCycleObserver(connectivityStatus, repository)) 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( applicationContext, toastMessage, diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/viewmodel/AppViewModel.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/viewmodel/AppViewModel.kt index 9320762..018900e 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/viewmodel/AppViewModel.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/viewmodel/AppViewModel.kt @@ -9,19 +9,21 @@ import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.launch class AppViewModel(private val repository: Repository) : ViewModel() { - private val _toastMessageProvider = MutableSharedFlow() - val toastMessageProvider = _toastMessageProvider.asSharedFlow() + private val _networkAvailableProvider = MutableSharedFlow() + val networkAvailableProvider = _networkAvailableProvider.asSharedFlow() private var wasConnected = true init { viewModelScope.launch { repository.isConnectionAvailable.collect { isConnected -> - 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 + if (repository.connectionMonitored) { + if (isConnected && !wasConnected && repository.connectionMonitored) { + _networkAvailableProvider.emit(true) + wasConnected = true + } else if (!isConnected && wasConnected && repository.connectionMonitored){ + _networkAvailableProvider.emit(false) + wasConnected = false + } } } } -- 2.34.1