From 4d343064c30664a7a7b9bb4e73551c9331969579 Mon Sep 17 00:00:00 2001 From: "Kevin T. Coughlin" <706967+KevinTCoughlin@users.noreply.github.com> Date: Thu, 28 Nov 2024 15:22:07 -0800 Subject: [PATCH] Refactor to use dummy data --- .../smodr/views/fragments/EpisodesFragment.kt | 64 +++++++++++++------ .../jamoka/fragment/BinderRecyclerFragment.kt | 58 ++--------------- 2 files changed, 49 insertions(+), 73 deletions(-) diff --git a/Smodr/src/main/java/com/kevintcoughlin/smodr/views/fragments/EpisodesFragment.kt b/Smodr/src/main/java/com/kevintcoughlin/smodr/views/fragments/EpisodesFragment.kt index 9cadba1c..be5aad2f 100644 --- a/Smodr/src/main/java/com/kevintcoughlin/smodr/views/fragments/EpisodesFragment.kt +++ b/Smodr/src/main/java/com/kevintcoughlin/smodr/views/fragments/EpisodesFragment.kt @@ -6,7 +6,6 @@ import android.os.Bundle import android.view.View import android.widget.Toast import androidx.fragment.app.Fragment -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.cascadiacollections.jamoka.fragment.BinderRecyclerFragment @@ -24,25 +23,18 @@ import retrofit2.Response import retrofit2.Retrofit class EpisodesFragment : BinderRecyclerFragment(), Callback { - private val feedService: FeedService by lazy { createFeedService() } - private val layoutManager: LinearLayoutManager by lazy { LinearLayoutManager(context) } private val adapter: BinderRecyclerAdapter by lazy { BinderRecyclerAdapter( binder = EpisodeView(), config = BinderRecyclerAdapterConfig( - enableDiffUtil = true, - adapterCallback = object : - BinderRecyclerAdapter.AdapterCallback { - override fun onItemBound(model: Item, viewHolder: RecyclerView.ViewHolder) { - println("Bound episode: ${model.title}") - } - } + enableDiffUtil = false ) ) } + override fun getAdapter(): RecyclerView.Adapter<*> = adapter - override fun getLayoutManager(): RecyclerView.LayoutManager = layoutManager + override fun getLayoutManager(): RecyclerView.LayoutManager = LinearLayoutManager(context) override fun onRefresh() { fetchEpisodes() @@ -50,22 +42,52 @@ class EpisodesFragment : BinderRecyclerFragment(), Call override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + recyclerView?.apply { - // @todo: fix in base - val linearLayoutManager = layoutManager as? LinearLayoutManager - linearLayoutManager?.let { - recyclerView?.addItemDecoration( - DividerItemDecoration(requireContext(), it.orientation) - ) - } - adapter = this@EpisodesFragment.adapter + setHasFixedSize(true) + layoutManager = this@EpisodesFragment.getLayoutManager() + adapter = this@EpisodesFragment.getAdapter() } - fetchEpisodes() + + val dummyData = listOf( + Item( + guid = "1", + title = "Episode 1", + pubDate = "2024-11-01", + description = "This is a description for Episode 1", + duration = "25:00", + summary = "Summary of Episode 1", + origEnclosureLink = "https://example.com/episode1.mp3", + completed = false + ), + Item( + guid = "2", + title = "Episode 2", + pubDate = "2024-11-02", + description = "This is a description for Episode 2", + duration = "30:00", + summary = "Summary of Episode 2", + origEnclosureLink = "https://example.com/episode2.mp3", + completed = false + ), + Item( + guid = "3", + title = "Episode 3", + pubDate = "2024-11-03", + description = "This is a description for Episode 3", + duration = "40:00", + summary = "Summary of Episode 3", + origEnclosureLink = "https://example.com/episode3.mp3", + completed = false + ) + ) + adapter.updateItems(dummyData) +// fetchEpisodes() } override fun onResponse(call: Call, response: Response) { response.body()?.channel?.items?.let { - adapter.updateItems(it) // Use the new `updateItems` method for efficient updates + adapter.updateItems(it) } } diff --git a/common-android/src/main/java/com/cascadiacollections/jamoka/fragment/BinderRecyclerFragment.kt b/common-android/src/main/java/com/cascadiacollections/jamoka/fragment/BinderRecyclerFragment.kt index f29670b7..a316c8a0 100644 --- a/common-android/src/main/java/com/cascadiacollections/jamoka/fragment/BinderRecyclerFragment.kt +++ b/common-android/src/main/java/com/cascadiacollections/jamoka/fragment/BinderRecyclerFragment.kt @@ -1,7 +1,6 @@ package com.cascadiacollections.jamoka.fragment import android.os.Bundle -import android.os.Parcelable import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -16,14 +15,12 @@ import com.cascadiacollections.jamoka.R * Supports binding adapters, layout managers, and item selection callbacks. */ abstract class BinderRecyclerFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener { + private lateinit var swipeRefreshLayout: SwipeRefreshLayout + lateinit var recyclerView: RecyclerView - private var swipeRefreshLayout: SwipeRefreshLayout? = null - var recyclerView: RecyclerView? = null + abstract fun getLayoutManager(): RecyclerView.LayoutManager - /** - * Provide the layout manager for the RecyclerView. - */ - protected abstract fun getLayoutManager(): RecyclerView.LayoutManager? + abstract fun getAdapter(): RecyclerView.Adapter<*> @LayoutRes protected open fun getLayoutResId(): Int = R.layout.fragment_recycler_layout @@ -38,52 +35,9 @@ abstract class BinderRecyclerFragment : Fragmen override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + swipeRefreshLayout = view.findViewById(R.id.swipeContainer) recyclerView = view.findViewById(R.id.list) - - setupRecyclerView() - setupSwipeRefresh() - } - - /** - * Save the RecyclerView's layout state. - */ - override fun onSaveInstanceState(outState: Bundle) { - super.onSaveInstanceState(outState) - getLayoutManager()?.onSaveInstanceState()?.let { - outState.putParcelable(VIEW_STATE_KEY, it) - } - } - - /** - * Restore the RecyclerView's layout state. - */ - override fun onViewStateRestored(savedInstanceState: Bundle?) { - super.onViewStateRestored(savedInstanceState) - savedInstanceState?.getParcelable(VIEW_STATE_KEY, Parcelable::class.java)?.let { layoutState -> - getLayoutManager()?.onRestoreInstanceState(layoutState) - } - } - - /** - * Configures the RecyclerView with the provided adapter and layout manager. - */ - private fun setupRecyclerView() { - recyclerView?.apply { - setHasFixedSize(true) - layoutManager = layoutManager - this.adapter = adapter - } - } - - /** - * Configures the SwipeRefreshLayout and its listener. - */ - private fun setupSwipeRefresh() { - swipeRefreshLayout?.setOnRefreshListener(this) - } - - companion object { - private const val VIEW_STATE_KEY = "BinderRecyclerFragment.ViewState" + swipeRefreshLayout.setOnRefreshListener(this) } } \ No newline at end of file