From 9ed9bf07fce429208f79ce5e94ea734fbc1d5887 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Fri, 23 Dec 2022 22:53:16 +0100 Subject: [PATCH] Items in repository. --- .../readerforselfossv2/android/ReaderActivity.kt | 14 +++++++------- .../android/adapters/ItemCardAdapter.kt | 2 +- .../android/adapters/ItemListAdapter.kt | 2 +- .../readerforselfossv2/android/utils/LinksUtils.kt | 2 -- .../repository/RepositoryImpl.kt | 10 ++++++++++ 5 files changed, 19 insertions(+), 11 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 c30c43f..5a9035b 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 @@ -30,6 +30,8 @@ class ReaderActivity : AppCompatActivity(), DIAware { private lateinit var binding: ActivityReaderBinding + private var allItems: ArrayList = ArrayList() + override val di by closestDI() private val repository: Repository by instance() private val appSettingsService: AppSettingsService by instance() @@ -61,12 +63,14 @@ class ReaderActivity : AppCompatActivity(), DIAware { supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) - if (allItems.isEmpty()) { + currentItem = intent.getIntExtra("currentItem", 0) + + allItems = repository.getReaderItems() + + if (allItems.isEmpty() || currentItem > allItems.size) { finish() } - currentItem = intent.getIntExtra("currentItem", 0) - readItem(allItems[currentItem]) binding.pager.adapter = ScreenSlidePagerAdapter(this) @@ -214,8 +218,4 @@ class ReaderActivity : AppCompatActivity(), DIAware { startActivity(intent) overridePendingTransition(0, 0) } - - companion object { - var allItems: ArrayList = ArrayList() - } } 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 227977a..a5fd7d1 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 @@ -132,8 +132,8 @@ class ItemCardAdapter( private fun handleLinkOpening() { binding.root.setOnClickListener { + repository.setReaderItems(items) c.openItemUrl( - items, bindingAdapterPosition, items[bindingAdapterPosition].getLinkDecoded(), appSettingsService.isArticleViewerEnabled(), diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt index 116c1e5..560a38a 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt @@ -84,8 +84,8 @@ class ItemListAdapter( private fun handleLinkOpening() { binding.root.setOnClickListener { + repository.setReaderItems(items) c.openItemUrl( - items, bindingAdapterPosition, items[bindingAdapterPosition].getLinkDecoded(), appSettingsService.isArticleViewerEnabled(), diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt index aed1e3f..b5db28e 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt @@ -18,7 +18,6 @@ import bou.amine.apps.readerforselfossv2.utils.toStringUriWithHttp import okhttp3.HttpUrl.Companion.toHttpUrlOrNull fun Context.openItemUrl( - allItems: ArrayList, currentItem: Int, linkDecoded: String, articleViewer: Boolean, @@ -33,7 +32,6 @@ fun Context.openItemUrl( ).show() } else { if (articleViewer) { - ReaderActivity.allItems = allItems val intent = Intent(this, ReaderActivity::class.java) intent.putExtra("currentItem", currentItem) app.startActivity(intent) 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 c93d68b..ce3808b 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 @@ -47,6 +47,8 @@ class Repository( private var fetchedSources = false private var fetchedTags = false + private var _readerItems = ArrayList() + suspend fun getNewerItems(): ArrayList { // TODO: Use the updatedSince parameter var fetchedItems: StatusAndData> = StatusAndData.error() @@ -558,4 +560,12 @@ class Repository( fun setSourceFilter(source: SelfossModel.Source?) { _sourceFilter.value = source } + + fun setReaderItems(readerItems: ArrayList) { + _readerItems = readerItems + } + + fun getReaderItems(): ArrayList { + return _readerItems + } } \ No newline at end of file