diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/FeedView.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/FeedView.kt index 5f1b8df1..08094a1f 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/FeedView.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/FeedView.kt @@ -25,6 +25,7 @@ import com.futo.platformplayer.views.others.ProgressBar import com.futo.platformplayer.views.others.TagsView import com.futo.platformplayer.views.adapters.InsertedViewAdapterWithLoader import com.futo.platformplayer.views.adapters.InsertedViewHolder +import com.futo.platformplayer.views.announcements.AnnouncementView import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -37,6 +38,7 @@ abstract class FeedView : L private val _progressBar: ProgressBar; private val _spinnerSortBy: Spinner; private val _containerSortBy: LinearLayout; + private val _announcementView: AnnouncementView; private val _tagsView: TagsView; private val _textCentered: TextView; private val _emptyPagerContainer: FrameLayout; @@ -73,6 +75,7 @@ abstract class FeedView : L _textCentered = findViewById(R.id.text_centered); _emptyPagerContainer = findViewById(R.id.empty_pager_container); _progressBar = findViewById(R.id.progress_bar); + _announcementView = findViewById(R.id.announcement_view) _progressBar.inactiveColor = Color.TRANSPARENT; _swipeRefresh = findViewById(R.id.swipe_refresh); @@ -172,6 +175,10 @@ abstract class FeedView : L _recyclerResults.addOnScrollListener(_scrollListener); } + protected fun showAnnouncementView() { + _announcementView.visibility = View.VISIBLE + } + private fun ensureEnoughContentVisible(filteredResults: List) { val canScroll = if (recyclerData.results.isEmpty()) false else { val layoutManager = recyclerData.layoutManager diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/HomeFragment.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/HomeFragment.kt index 4ac4557b..26210bc8 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/HomeFragment.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/HomeFragment.kt @@ -94,20 +94,10 @@ class HomeFragment : MainFragment() { class HomeView : ContentFeedView { override val feedStyle: FeedStyle get() = Settings.instance.home.getHomeFeedStyle(); - private var _announcementsView: AnnouncementView = AnnouncementView(context, null).apply { - if(!this.isClosed()) { - recyclerData.adapter.viewsToPrepend.add(this) - this.onClose.subscribe { - recyclerData.adapter.viewsToPrepend.remove(this) - } - } - }; - private val _taskGetPager: TaskHandler>; override val shouldShowTimeBar: Boolean get() = Settings.instance.home.progressBar constructor(fragment: HomeFragment, inflater: LayoutInflater, cachedRecyclerData: RecyclerData, GridLayoutManager, IPager, IPlatformContent, IPlatformContent, InsertedViewHolder>? = null) : super(fragment, inflater, cachedRecyclerData) { - _taskGetPager = TaskHandler>({ fragment.lifecycleScope }, { StatePlatform.instance.getHomeRefresh(fragment.lifecycleScope) }) @@ -138,6 +128,7 @@ class HomeFragment : MainFragment() { }; setPreviewsEnabled(Settings.instance.home.previewFeedItems); + showAnnouncementView() } fun onShown() { diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/SubscriptionsFeedFragment.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/SubscriptionsFeedFragment.kt index b1d630e4..1dca7b88 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/SubscriptionsFeedFragment.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/SubscriptionsFeedFragment.kt @@ -35,7 +35,6 @@ import com.futo.platformplayer.views.ToastView import com.futo.platformplayer.views.adapters.ContentPreviewViewHolder import com.futo.platformplayer.views.adapters.InsertedViewAdapterWithLoader import com.futo.platformplayer.views.adapters.InsertedViewHolder -import com.futo.platformplayer.views.announcements.AnnouncementView import com.futo.platformplayer.views.buttons.BigButton import com.futo.platformplayer.views.subscriptions.SubscriptionBar import kotlinx.coroutines.CancellationException @@ -125,6 +124,7 @@ class SubscriptionsFeedFragment : MainFragment() { initializeToolbarContent(); setPreviewsEnabled(Settings.instance.subscriptions.previewFeedItems); + showAnnouncementView() } fun onShown() { @@ -145,26 +145,6 @@ class SubscriptionsFeedFragment : MainFragment() { } } - val announcementsView = _announcementsView; - val homeTab = Settings.instance.tabs.find { it.id == 0 }; - val isHomeEnabled = homeTab?.enabled == true; - if (announcementsView != null && isHomeEnabled) { - recyclerData.adapter.viewsToPrepend.remove(announcementsView) - _announcementsView = null - } - - if (announcementsView == null && !isHomeEnabled) { - val c = context; - if (c != null) { - _announcementsView = AnnouncementView(c, null).apply { - recyclerData.adapter.viewsToPrepend.add(this) - this.onClose.subscribe { - recyclerData.adapter.viewsToPrepend.remove(this) - } - } - } - } - if (!StateSubscriptions.instance.global.isGlobalUpdating) { finishRefreshLayoutLoader(); } @@ -192,8 +172,6 @@ class SubscriptionsFeedFragment : MainFragment() { private var _subscriptionBar: SubscriptionBar? = null; - private var _announcementsView: AnnouncementView? = null; - @Serializable class FeedFilterSettings: FragmentedStorageFileJson() { val allowContentTypes: MutableList = mutableListOf(ContentType.MEDIA, ContentType.POST); diff --git a/app/src/main/java/com/futo/platformplayer/views/announcements/AnnouncementView.kt b/app/src/main/java/com/futo/platformplayer/views/announcements/AnnouncementView.kt index 467f23c4..e3be3a7d 100644 --- a/app/src/main/java/com/futo/platformplayer/views/announcements/AnnouncementView.kt +++ b/app/src/main/java/com/futo/platformplayer/views/announcements/AnnouncementView.kt @@ -115,12 +115,12 @@ class AnnouncementView : LinearLayout { _currentAnnouncement = announcement; if (announcement == null) { - visibility = View.GONE + _root.visibility = View.GONE onClose.emit() return; } - visibility = View.VISIBLE + _root.visibility = View.VISIBLE _textTitle.text = announcement.title; _textBody.text = announcement.msg; diff --git a/app/src/main/res/layout/fragment_feed.xml b/app/src/main/res/layout/fragment_feed.xml index 60cb7313..7d8cf27a 100644 --- a/app/src/main/res/layout/fragment_feed.xml +++ b/app/src/main/res/layout/fragment_feed.xml @@ -35,6 +35,12 @@ android:layout_height="wrap_content" android:orientation="vertical"> + +