mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Add pin icon to sources list (closes #2862)
This commit is contained in:
		| @@ -22,26 +22,15 @@ class SourceAdapter(val controller: SourceController) : | ||||
|     /** | ||||
|      * Listener for browse item clicks. | ||||
|      */ | ||||
|     val browseClickListener: OnBrowseClickListener = controller | ||||
|  | ||||
|     /** | ||||
|      * Listener for latest item clicks. | ||||
|      */ | ||||
|     val latestClickListener: OnLatestClickListener = controller | ||||
|     val clickListener: OnSourceClickListener = controller | ||||
|  | ||||
|     /** | ||||
|      * Listener which should be called when user clicks browse. | ||||
|      * Note: Should only be handled by [SourceController] | ||||
|      */ | ||||
|     interface OnBrowseClickListener { | ||||
|     interface OnSourceClickListener { | ||||
|         fun onBrowseClick(position: Int) | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Listener which should be called when user clicks latest. | ||||
|      * Note: Should only be handled by [SourceController] | ||||
|      */ | ||||
|     interface OnLatestClickListener { | ||||
|         fun onLatestClick(position: Int) | ||||
|         fun onPinClick(position: Int) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -41,15 +41,14 @@ import uy.kohesive.injekt.api.get | ||||
| /** | ||||
|  * This controller shows and manages the different catalogues enabled by the user. | ||||
|  * This controller should only handle UI actions, IO actions should be done by [SourcePresenter] | ||||
|  * [SourceAdapter.OnBrowseClickListener] call function data on browse item click. | ||||
|  * [SourceAdapter.OnSourceClickListener] call function data on browse item click. | ||||
|  * [SourceAdapter.OnLatestClickListener] call function data on latest item click | ||||
|  */ | ||||
| class SourceController : | ||||
|     NucleusController<SourceMainControllerBinding, SourcePresenter>(), | ||||
|     FlexibleAdapter.OnItemClickListener, | ||||
|     FlexibleAdapter.OnItemLongClickListener, | ||||
|     SourceAdapter.OnBrowseClickListener, | ||||
|     SourceAdapter.OnLatestClickListener { | ||||
|     SourceAdapter.OnSourceClickListener { | ||||
|  | ||||
|     private val preferences: PreferencesHelper = Injekt.get() | ||||
|  | ||||
| @@ -134,7 +133,7 @@ class SourceController : | ||||
|         val items = mutableListOf( | ||||
|             Pair( | ||||
|                 activity.getString(if (isPinned) R.string.action_unpin else R.string.action_pin), | ||||
|                 { pinSource(item.source, isPinned) } | ||||
|                 { toggleSourcePin(item.source) } | ||||
|             ) | ||||
|         ) | ||||
|         if (item.source !is LocalSource) { | ||||
| @@ -159,12 +158,12 @@ class SourceController : | ||||
|         presenter.updateSources() | ||||
|     } | ||||
|  | ||||
|     private fun pinSource(source: Source, isPinned: Boolean) { | ||||
|         val current = preferences.pinnedSources().get() | ||||
|     private fun toggleSourcePin(source: Source) { | ||||
|         val isPinned = source.id.toString() in preferences.pinnedSources().get() | ||||
|         if (isPinned) { | ||||
|             preferences.pinnedSources().set(current - source.id.toString()) | ||||
|             preferences.pinnedSources() -= source.id.toString() | ||||
|         } else { | ||||
|             preferences.pinnedSources().set(current + source.id.toString()) | ||||
|             preferences.pinnedSources() += source.id.toString() | ||||
|         } | ||||
|  | ||||
|         presenter.updateSources() | ||||
| @@ -185,6 +184,14 @@ class SourceController : | ||||
|         openSource(item.source, LatestUpdatesController(item.source)) | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Called when pin icon is clicked in [SourceAdapter] | ||||
|      */ | ||||
|     override fun onPinClick(position: Int) { | ||||
|         val item = adapter?.getItem(position) as? SourceItem ?: return | ||||
|         toggleSourcePin(item.source) | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Opens a catalogue with the given controller. | ||||
|      */ | ||||
|   | ||||
| @@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder | ||||
| import io.github.mthli.slice.Slice | ||||
| import kotlinx.android.synthetic.main.source_main_controller_card_item.card | ||||
| import kotlinx.android.synthetic.main.source_main_controller_card_item.image | ||||
| import kotlinx.android.synthetic.main.source_main_controller_card_item.pin | ||||
| import kotlinx.android.synthetic.main.source_main_controller_card_item.source_browse | ||||
| import kotlinx.android.synthetic.main.source_main_controller_card_item.source_latest | ||||
| import kotlinx.android.synthetic.main.source_main_controller_card_item.title | ||||
| @@ -27,11 +28,15 @@ class SourceHolder(view: View, override val adapter: SourceAdapter) : | ||||
|  | ||||
|     init { | ||||
|         source_browse.setOnClickListener { | ||||
|             adapter.browseClickListener.onBrowseClick(bindingAdapterPosition) | ||||
|             adapter.clickListener.onBrowseClick(bindingAdapterPosition) | ||||
|         } | ||||
|  | ||||
|         source_latest.setOnClickListener { | ||||
|             adapter.latestClickListener.onLatestClick(bindingAdapterPosition) | ||||
|             adapter.clickListener.onLatestClick(bindingAdapterPosition) | ||||
|         } | ||||
|  | ||||
|         pin.setOnClickListener { | ||||
|             adapter.clickListener.onPinClick(bindingAdapterPosition) | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -53,5 +58,14 @@ class SourceHolder(view: View, override val adapter: SourceAdapter) : | ||||
|  | ||||
|         source_browse.setText(R.string.browse) | ||||
|         source_latest.isVisible = source.supportsLatest | ||||
|  | ||||
|         pin.isVisible = true | ||||
|         pin.setImageResource( | ||||
|             if (item.isPinned) { | ||||
|                 R.drawable.ic_push_pin_filled_24dp | ||||
|             } else { | ||||
|                 R.drawable.ic_push_pin_24dp | ||||
|             } | ||||
|         ) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -14,7 +14,11 @@ import eu.kanade.tachiyomi.source.CatalogueSource | ||||
|  * @param source Instance of [CatalogueSource] containing source information. | ||||
|  * @param header The header for this item. | ||||
|  */ | ||||
| data class SourceItem(val source: CatalogueSource, val header: LangItem? = null) : | ||||
| data class SourceItem( | ||||
|     val source: CatalogueSource, | ||||
|     val header: LangItem? = null, | ||||
|     val isPinned: Boolean = false | ||||
| ) : | ||||
|     AbstractSectionableItem<SourceHolder, LangItem>(header) { | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -72,11 +72,12 @@ class SourcePresenter( | ||||
|         var sourceItems = byLang.flatMap { | ||||
|             val langItem = LangItem(it.key) | ||||
|             it.value.map { source -> | ||||
|                 if (source.id.toString() in pinnedSourceIds) { | ||||
|                     pinnedSources.add(SourceItem(source, LangItem(PINNED_KEY))) | ||||
|                 val isPinned = source.id.toString() in pinnedSourceIds | ||||
|                 if (isPinned) { | ||||
|                     pinnedSources.add(SourceItem(source, LangItem(PINNED_KEY), isPinned)) | ||||
|                 } | ||||
|  | ||||
|                 SourceItem(source, langItem) | ||||
|                 SourceItem(source, langItem, isPinned) | ||||
|             } | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user