From 0dc511ebe6a1e565dd43ebf9030d5a0d654c38c0 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 26 Jan 2023 15:48:54 +0100 Subject: [PATCH] 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 -> {