From d0f649bb27ab3e7a3033eb5f66c8df5fb7181067 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 26 Jan 2023 14:07:12 +0100 Subject: [PATCH 1/8] Fetch remote selfoss configuration Fetch from /api/about the selfoss configuration to determine if we're using a public access instanceIf both authentication and public mode are enabled in the configuration and we're logging in without authentication, then we're using public access. --- .../android/LoginActivity.kt | 2 +- androidApp/src/test/kotlin/RepositoryTest.kt | 12 +++---- .../readerforselfossv2/model/SelfossModel.kt | 21 +++++++++++-- .../repository/RepositoryImpl.kt | 15 ++++++--- .../readerforselfossv2/rest/SelfossApi.kt | 2 +- .../service/AppSettingsService.kt | 31 ++++++++++++++++--- 6 files changed, 63 insertions(+), 20 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt index a47a1af..2a48ea7 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt @@ -128,7 +128,7 @@ class LoginActivity : AppCompatActivity(), DIAware { private fun goToMain() { CoroutineScope(Dispatchers.Main).launch { - repository.updateApiVersion() + repository.updateApiInformation() ACRA.errorReporter.putCustomData("SELFOSS_API_VERSION", appSettingsService.getApiVersion().toString()) } val intent = Intent(this, HomeActivity::class.java) diff --git a/androidApp/src/test/kotlin/RepositoryTest.kt b/androidApp/src/test/kotlin/RepositoryTest.kt index 38245b2..96ef289 100644 --- a/androidApp/src/test/kotlin/RepositoryTest.kt +++ b/androidApp/src/test/kotlin/RepositoryTest.kt @@ -49,7 +49,7 @@ class RepositoryTest { repository = Repository(api, appSettingsService, isConnectionAvailable, db) runBlocking { - repository.updateApiVersion() + repository.updateApiInformation() } } @@ -61,9 +61,9 @@ class RepositoryTest { every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false - coEvery { api.version() } returns StatusAndData( + coEvery { api.apiInformation() } returns StatusAndData( success = true, - data = SelfossModel.ApiVersion("2.19-ba1e8e3", "4.0.0") + data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0") ) coEvery { api.stats() } returns StatusAndData( success = true, @@ -81,7 +81,7 @@ class RepositoryTest { fun instantiate_repository() { initializeRepository() - coVerify(exactly = 1) { api.version() } + coVerify(exactly = 1) { api.apiInformation() } } @Test @@ -90,7 +90,7 @@ class RepositoryTest { initializeRepository(MutableStateFlow(false)) - coVerify(exactly = 0) { api.version() } + coVerify(exactly = 0) { api.apiInformation() } coVerify(exactly = 0) { api.stats() } } @@ -113,7 +113,7 @@ class RepositoryTest { @Test fun get_api_1_date_with_api_4_version_stored() { every { appSettingsService.getApiVersion() } returns 4 - coEvery { api.version() } returns StatusAndData(success = false, null) + coEvery { api.apiInformation() } returns StatusAndData(success = false, null) val itemParameters = FakeItemParameters() itemParameters.datetime = "2021-04-23 11:45:32" coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt index e5eec2a..87c495c 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt @@ -35,17 +35,32 @@ class SelfossModel { ) @Serializable - data class ApiVersion( + data class ApiInformation( val version: String?, - val apiversion: String? + val apiversion: String?, + val configuration: ApiConfiguration? ) { - fun getApiMajorVersion() : Int { + fun getApiMajorVersion(): Int { var versionNumber = 0 if (apiversion != null) { versionNumber = apiversion.substringBefore(".").toInt() } return versionNumber } + + fun getApiConfiguration() = configuration ?: ApiConfiguration(null, null) + } + + @kotlinx.serialization.Serializable + data class ApiConfiguration( + @Serializable(with = BooleanSerializer::class) + val publicMode: Boolean?, + @Serializable(with = BooleanSerializer::class) + val authEnabled: Boolean? + ) { + fun isAuthEnabled() = authEnabled ?: true + + fun isPublicModeEnabled() = publicMode ?: false } @Serializable 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 fb03172..5dacf72 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 @@ -439,13 +439,20 @@ class Repository( api.refreshLoginInformation() } - suspend fun updateApiVersion() { + suspend fun updateApiInformation() { val apiMajorVersion = appSettingsService.getApiVersion() if (isNetworkAvailable()) { - val fetchedVersion = api.version() - if (fetchedVersion.success && fetchedVersion.data != null && fetchedVersion.data.getApiMajorVersion() != apiMajorVersion) { - appSettingsService.updateApiVersion(fetchedVersion.data.getApiMajorVersion()) + val fetchedInformation = api.apiInformation() + if (fetchedInformation.success && fetchedInformation.data != null) { + if (fetchedInformation.data.getApiMajorVersion() != apiMajorVersion) { + appSettingsService.updateApiVersion(fetchedInformation.data.getApiMajorVersion()) + } + if (appSettingsService.getUserName().isEmpty() + && fetchedInformation.data.getApiConfiguration().isAuthEnabled() + && fetchedInformation.data.getApiConfiguration().isPublicModeEnabled()) { + appSettingsService.updatePublicAccess(true) + } } } } 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 c41e157..4d10b3b 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 @@ -191,7 +191,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) { } }) - suspend fun version(): StatusAndData = + suspend fun apiInformation(): StatusAndData = bodyOrFailure(client.tryToGet(url("/api/about"))) suspend fun markAsRead(id: String): SuccessResponse = diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/AppSettingsService.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/AppSettingsService.kt index d5b622d..35716a9 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/AppSettingsService.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/AppSettingsService.kt @@ -7,6 +7,7 @@ class AppSettingsService { // Api related private var _apiVersion: Int = -1 + private var _publicAccess: Boolean? = null private var _baseUrl: String = "" private var _userName: String = "" private var _password: String = "" @@ -48,10 +49,32 @@ class AppSettingsService { return _apiVersion } + + fun updateApiVersion(apiMajorVersion: Int) { + settings.putInt(API_VERSION_MAJOR, apiMajorVersion) + refreshApiVersion() + } + private fun refreshApiVersion() { _apiVersion = settings.getInt(API_VERSION_MAJOR, -1) } + fun getPublicAccess(): Boolean { + if (_publicAccess == null) { + refreshPublicAccess() + } + return _publicAccess!! + } + + fun updatePublicAccess(publicAccess: Boolean) { + settings.putBoolean(API_PUBLIC_ACCESS, publicAccess) + refreshPublicAccess() + } + + private fun refreshPublicAccess() { + _publicAccess = settings.getBoolean(API_PUBLIC_ACCESS, false) + } + fun getBaseUrl(): String { if (_baseUrl.isEmpty()) { refreshBaseUrl() @@ -333,6 +356,7 @@ class AppSettingsService { refreshUsername() refreshBaseUrl() refreshApiVersion() + refreshPublicAccess() } fun refreshUserSettings() { @@ -376,11 +400,6 @@ class AppSettingsService { refreshApiSettings() } - fun updateApiVersion(apiMajorVersion: Int) { - settings.putInt(API_VERSION_MAJOR, apiMajorVersion) - refreshApiVersion() - } - fun clearAll() { settings.clear() refreshApiSettings() @@ -409,6 +428,8 @@ class AppSettingsService { const val API_VERSION_MAJOR = "apiVersionMajor" + const val API_PUBLIC_ACCESS = "apiPublicAccess" + const val API_ITEMS_NUMBER = "prefer_api_items_number" const val API_TIMEOUT = "api_timeout" -- 2.34.1 From 529ada8882a66c5b15f9502d511b87aee6956f2e Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 26 Jan 2023 16:29:57 +0100 Subject: [PATCH 2/8] Fix broken tests --- androidApp/src/test/kotlin/RepositoryTest.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/androidApp/src/test/kotlin/RepositoryTest.kt b/androidApp/src/test/kotlin/RepositoryTest.kt index 96ef289..950b07e 100644 --- a/androidApp/src/test/kotlin/RepositoryTest.kt +++ b/androidApp/src/test/kotlin/RepositoryTest.kt @@ -20,6 +20,8 @@ import org.junit.Test private const val BASE_URL = "https://test.com/selfoss/" +private const val USERNAME = "username" + private const val SPOUT = "spouts\\rss\\fulltextrss" private const val IMAGE_URL = "b3aa8a664d08eb15d6ff1db2fa83e0d9.png" @@ -58,12 +60,13 @@ class RepositoryTest { clearAllMocks() every { appSettingsService.getApiVersion() } returns 4 every { appSettingsService.getBaseUrl() } returns BASE_URL + every { appSettingsService.getUserName() } returns USERNAME every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false coEvery { api.apiInformation() } returns StatusAndData( success = true, - data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0") + data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(false, true)) ) coEvery { api.stats() } returns StatusAndData( success = true, -- 2.34.1 From e3e8cc8a797c56f99c076c5c44259a3e4cb10c6a Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 26 Jan 2023 17:20:29 +0100 Subject: [PATCH 3/8] Add tests for the public access determination logic --- androidApp/src/test/kotlin/RepositoryTest.kt | 60 ++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/androidApp/src/test/kotlin/RepositoryTest.kt b/androidApp/src/test/kotlin/RepositoryTest.kt index 950b07e..ec307b9 100644 --- a/androidApp/src/test/kotlin/RepositoryTest.kt +++ b/androidApp/src/test/kotlin/RepositoryTest.kt @@ -113,6 +113,66 @@ class RepositoryTest { verify(exactly = 1) { appSettingsService.updateApiVersion(4) } } + @Test + fun get_public_access() { + every { appSettingsService.updatePublicAccess(any()) } returns Unit + coEvery { api.apiInformation() } returns StatusAndData( + success = true, + data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(true, true)) + ) + every { appSettingsService.getUserName() } returns "" + + initializeRepository() + + coVerify(exactly = 1) { api.apiInformation() } + coVerify(exactly = 1) { appSettingsService.updatePublicAccess(true) } + } + + @Test + fun get_public_access_username_not_empty() { + every { appSettingsService.updatePublicAccess(any()) } returns Unit + coEvery { api.apiInformation() } returns StatusAndData( + success = true, + data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(true, true)) + ) + every { appSettingsService.getUserName() } returns "username" + + initializeRepository() + + coVerify(exactly = 1) { api.apiInformation() } + coVerify(exactly = 0) { appSettingsService.updatePublicAccess(true) } + } + + @Test + fun get_public_access_no_auth() { + every { appSettingsService.updatePublicAccess(any()) } returns Unit + coEvery { api.apiInformation() } returns StatusAndData( + success = true, + data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(true, false)) + ) + every { appSettingsService.getUserName() } returns "" + + initializeRepository() + + coVerify(exactly = 1) { api.apiInformation() } + coVerify(exactly = 0) { appSettingsService.updatePublicAccess(true) } + } + + @Test + fun get_public_access_disabled() { + every { appSettingsService.updatePublicAccess(any()) } returns Unit + coEvery { api.apiInformation() } returns StatusAndData( + success = true, + data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(false, true)) + ) + every { appSettingsService.getUserName() } returns "" + + initializeRepository() + + coVerify(exactly = 1) { api.apiInformation() } + coVerify(exactly = 0) { appSettingsService.updatePublicAccess(true) } + } + @Test fun get_api_1_date_with_api_4_version_stored() { every { appSettingsService.getApiVersion() } returns 4 -- 2.34.1 From 04f3937095ff67c344d6b6dfd8d306bd380ba953 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 26 Jan 2023 15:13:49 +0100 Subject: [PATCH 4/8] Handle public access in the home screen In public access mode we can only read articles. Disable swiping articles in the listing to read them and remove the menu items to read all articles and to access sources settings. --- .../apps/readerforselfossv2/android/HomeActivity.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 64f9428..3b1ed43 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 @@ -114,10 +114,16 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar } } + val swipeDirs = if (appSettingsService.getPublicAccess()) { + 0 + } else { + ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT + } + val simpleItemTouchCallback = object : ItemTouchHelper.SimpleCallback( 0, - ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT + swipeDirs ) { override fun getSwipeDirs( recyclerView: RecyclerView, @@ -510,6 +516,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar override fun onCreateOptionsMenu(menu: Menu): Boolean { val inflater = menuInflater inflater.inflate(R.menu.home_menu, menu) + if (appSettingsService.getPublicAccess()) { + menu.removeItem(R.id.readAll) + menu.removeItem(R.id.action_sources) + } val searchItem = menu.findItem(R.id.action_search) val searchView = searchItem.getActionView() as SearchView -- 2.34.1 From eeea5b1e066c3e7cada7d517b88c84dc24fe96ff Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 26 Jan 2023 17:52:19 +0100 Subject: [PATCH 5/8] Hide the favourite button in card items when accessing a public instance --- .../android/adapters/ItemCardAdapter.kt | 4 ++ androidApp/src/main/res/layout/card_item.xml | 40 +++++++------------ 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt index d9b5f55..f21bd77 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt @@ -56,6 +56,10 @@ class ItemCardAdapter( val itm = items[position] binding.favButton.isSelected = itm.starred + if (appSettingsService.getPublicAccess()) { + binding.favButton.visibility = View.GONE + } + binding.title.text = itm.title.getHtmlDecoded() binding.title.setOnTouchListener(LinkOnTouchListener()) diff --git a/androidApp/src/main/res/layout/card_item.xml b/androidApp/src/main/res/layout/card_item.xml index 023be37..42e2b6e 100644 --- a/androidApp/src/main/res/layout/card_item.xml +++ b/androidApp/src/main/res/layout/card_item.xml @@ -47,7 +47,6 @@ android:id="@+id/sourceImage" android:layout_width="40dp" android:layout_height="40dp" - android:layout_marginLeft="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintLeft_toLeftOf="parent" @@ -85,41 +84,32 @@ app:layout_constraintTop_toBottomOf="@+id/title" tools:text="Google Actualité Il y a 5h" /> - + app:srcCompat="@drawable/ic_open_in_browser_black_24dp" + app:tint="?android:attr/textColorPrimary" /> + app:srcCompat="@drawable/ic_menu_heart_60dp" + app:tint="@color/ic_menu_heart_color" /> - + + + -- 2.34.1 From 0dc511ebe6a1e565dd43ebf9030d5a0d654c38c0 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 26 Jan 2023 15:48:54 +0100 Subject: [PATCH 6/8] Handle public access in the article reader screen Remove the favourite button from the article reader if accessing a public instance and don't mark articles as read when scrolling. --- .../android/ReaderActivity.kt | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt index 70ec25d..4b75c2f 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt @@ -84,7 +84,7 @@ class ReaderActivity : AppCompatActivity(), DIAware { } private fun readItem(item: SelfossModel.Item) { - if (appSettingsService.isMarkOnScrollEnabled()) { + if (appSettingsService.isMarkOnScrollEnabled() and !appSettingsService.getPublicAccess()) { CoroutineScope(Dispatchers.IO).launch { repository.markAsRead(item) } @@ -137,28 +137,34 @@ class ReaderActivity : AppCompatActivity(), DIAware { inflater.inflate(R.menu.reader_menu, menu) toolbarMenu = menu - if (allItems.isNotEmpty() && allItems[currentItem].starred) { - canRemoveFromFavorite() - } else { - canFavorite() - } alignmentMenu() - binding.pager.registerOnPageChangeCallback( - object : ViewPager2.OnPageChangeCallback() { - - override fun onPageSelected(position: Int) { - super.onPageSelected(position) - - if (allItems[position].starred) { - canRemoveFromFavorite() - } else { - canFavorite() - } - readItem(allItems[position]) - } + if (appSettingsService.getPublicAccess()) { + menu.removeItem(R.id.star) + } else { + if (allItems.isNotEmpty() && allItems[currentItem].starred) { + canRemoveFromFavorite() + } else { + canFavorite() } - ) + + + binding.pager.registerOnPageChangeCallback( + object : ViewPager2.OnPageChangeCallback() { + + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + + if (allItems[position].starred) { + canRemoveFromFavorite() + } else { + canFavorite() + } + readItem(allItems[position]) + } + } + ) + } return true } @@ -177,7 +183,7 @@ class ReaderActivity : AppCompatActivity(), DIAware { when (item.itemId) { android.R.id.home -> { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } R.id.star -> { -- 2.34.1 From c80177377cec57988a62b965c8df14841ba55af7 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 26 Jan 2023 16:22:42 +0100 Subject: [PATCH 7/8] Handle public access in the article fragment Remove the button to read/unread articles --- .../android/fragments/ArticleFragment.kt | 3 +++ .../src/main/res/layout/fragment_article.xml | 5 ++--- .../src/main/res/menu/reader_toolbar_no_read.xml | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 androidApp/src/main/res/menu/reader_toolbar_no_read.xml diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt index 3fb842c..4dd0221 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt @@ -195,6 +195,9 @@ class ArticleFragment : Fragment(), DIAware { private fun handleFloatingToolbar(): FloatingToolbar { val floatingToolbar: FloatingToolbar = binding.floatingToolbar + if (appSettingsService.getPublicAccess()) { + floatingToolbar.setMenu(R.menu.reader_toolbar_no_read) + } floatingToolbar.attachFab(fab) floatingToolbar.background = ColorDrawable(resources.getColor(R.color.colorAccent)) diff --git a/androidApp/src/main/res/layout/fragment_article.xml b/androidApp/src/main/res/layout/fragment_article.xml index 8e6db28..664015d 100644 --- a/androidApp/src/main/res/layout/fragment_article.xml +++ b/androidApp/src/main/res/layout/fragment_article.xml @@ -83,7 +83,7 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintLeft_toLeftOf="parent" - android:layout_gravity="end|bottom|right"> + android:layout_gravity="end|bottom|end"> + + + + + + \ No newline at end of file -- 2.34.1 From ec0fd2faee9f39ccab76aafbaa23d8e4ef874f4c Mon Sep 17 00:00:00 2001 From: davidoskky Date: Fri, 27 Jan 2023 00:25:27 +0100 Subject: [PATCH 8/8] Cleaning --- .../amine/apps/readerforselfossv2/android/ReaderActivity.kt | 2 +- .../bou/amine/apps/readerforselfossv2/model/SelfossModel.kt | 2 +- .../amine/apps/readerforselfossv2/repository/RepositoryImpl.kt | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt index 4b75c2f..8ca576d 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt @@ -84,7 +84,7 @@ class ReaderActivity : AppCompatActivity(), DIAware { } private fun readItem(item: SelfossModel.Item) { - if (appSettingsService.isMarkOnScrollEnabled() and !appSettingsService.getPublicAccess()) { + if (appSettingsService.isMarkOnScrollEnabled() && !appSettingsService.getPublicAccess()) { CoroutineScope(Dispatchers.IO).launch { repository.markAsRead(item) } diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt index 87c495c..8fdf5e8 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt @@ -51,7 +51,7 @@ class SelfossModel { fun getApiConfiguration() = configuration ?: ApiConfiguration(null, null) } - @kotlinx.serialization.Serializable + @Serializable data class ApiConfiguration( @Serializable(with = BooleanSerializer::class) val publicMode: Boolean?, 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 5dacf72..1bcf35e 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 @@ -448,6 +448,9 @@ class Repository( if (fetchedInformation.data.getApiMajorVersion() != apiMajorVersion) { appSettingsService.updateApiVersion(fetchedInformation.data.getApiMajorVersion()) } + // Check if we're accessing the instance in public mode + // This happens when auth and public mode are enabled but + // no credentials are provided to login if (appSettingsService.getUserName().isEmpty() && fetchedInformation.data.getApiConfiguration().isAuthEnabled() && fetchedInformation.data.getApiConfiguration().isPublicModeEnabled()) { -- 2.34.1