Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ import org.wikipedia.compose.components.error.WikiErrorClickEvents
import org.wikipedia.compose.extensions.shimmerEffect
import org.wikipedia.compose.theme.BaseTheme
import org.wikipedia.compose.theme.WikipediaTheme
import org.wikipedia.concurrency.AppEvent
import org.wikipedia.concurrency.AppEventBus
import org.wikipedia.concurrency.FlowEventBus
import org.wikipedia.dataclient.WikiSite
import org.wikipedia.dataclient.growthtasks.GrowthUserImpact
Expand Down Expand Up @@ -136,6 +138,31 @@ class ActivityTabFragment : Fragment() {
}
}
}

viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
AppEventBus.events.collectLatest { event ->
println("orange event $event")
when (event) {
AppEvent.ReadingHistoryChanged -> {
viewModel.loadReadingHistory()
viewModel.shouldRefreshTimelineSilently = true
viewModel.refreshTimeline()
}
AppEvent.DonationsChanged -> {
viewModel.loadDonationResults()
}
AppEvent.GamesChanged -> {
viewModel.loadWikiGamesStats()
}
AppEvent.ImpactChanged -> {
viewModel.loadImpact()
}
}
}
}
}

viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
viewModel.allDataLoaded.collectLatest {
Expand Down Expand Up @@ -177,7 +204,6 @@ class ActivityTabFragment : Fragment() {
override fun onResume() {
super.onResume()
requireActivity().addMenuProvider(menuProvider, viewLifecycleOwner)
viewModel.loadAll()
requireActivity().invalidateOptionsMenu()
}

Expand Down Expand Up @@ -545,7 +571,7 @@ class ActivityTabFragment : Fragment() {
val isRefreshing = timelineItems.loadState.refresh is LoadState.Loading
val isEmpty = timelineItems.itemCount == 0
when {
isRefreshing -> {
isRefreshing && !viewModel.shouldRefreshTimelineSilently -> {
item {
ActivityTabShimmerView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class ActivityTabViewModel() : ViewModel() {
else -> WikiSite.forLanguageCode(langCode)
}
}
var shouldRefreshTimelineSilently = false

val timelineFlow = Pager(
config = PagingConfig(
Expand Down Expand Up @@ -110,6 +111,10 @@ class ActivityTabViewModel() : ViewModel() {
impact !is UiState.Loading
}.stateIn(viewModelScope, SharingStarted.Lazily, false)

init {
loadAll()
}

fun loadAll() {
loadReadingHistory()
if (!AccountUtil.isLoggedIn) {
Expand All @@ -121,7 +126,7 @@ class ActivityTabViewModel() : ViewModel() {
refreshTimeline()
}

private fun refreshTimeline() {
fun refreshTimeline() {
currentTimelinePagingSource?.invalidate()
}

Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/org/wikipedia/concurrency/FlowEventBus.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,21 @@ object FlowEventBus {
}
}
}

object AppEventBus {
private val _events = MutableSharedFlow<AppEvent>(replay = 1, extraBufferCapacity = 8, onBufferOverflow = BufferOverflow.DROP_OLDEST)
val events = _events.asSharedFlow()

fun post(event: AppEvent) {
if (!_events.tryEmit(event)) {
_events.tryEmit(event)
}
}
}

sealed class AppEvent {
object ReadingHistoryChanged : AppEvent()
object ImpactChanged : AppEvent()
object DonationsChanged : AppEvent()
object GamesChanged : AppEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import org.wikipedia.auth.AccountUtil
import org.wikipedia.bridge.CommunicationBridge
import org.wikipedia.bridge.JavaScriptActionHandler
import org.wikipedia.categories.db.Category
import org.wikipedia.concurrency.AppEvent
import org.wikipedia.concurrency.AppEventBus
import org.wikipedia.database.AppDatabase
import org.wikipedia.dataclient.ServiceFactory
import org.wikipedia.dataclient.mwapi.MwQueryResponse
Expand Down Expand Up @@ -287,6 +289,7 @@ class PageFragmentLoadState(private var model: PageViewModel,
WikipediaApp.instance.appSessionEvent.pageViewed(entry)
ArticleLinkPreviewInteractionEvent(title.wikiSite.dbName(), pageSummary?.pageId ?: 0, entry.source).logNavigate()
ArticleLinkPreviewInteraction(fragment, entry.source).logNavigate()
AppEventBus.post(AppEvent.ReadingHistoryChanged)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import kotlinx.coroutines.withContext
import org.apache.commons.lang3.StringUtils
import org.wikipedia.Constants.InvokeSource
import org.wikipedia.R
import org.wikipedia.concurrency.AppEvent
import org.wikipedia.concurrency.AppEventBus
import org.wikipedia.database.AppDatabase
import org.wikipedia.dataclient.ServiceFactory
import org.wikipedia.extensions.isStarted
Expand Down Expand Up @@ -379,6 +381,7 @@ object ReadingListBehaviorsUtil {
} else {
FeedbackUtil.showMessage(activity, activity.getString(R.string.reading_list_article_already_exists_message, defaultList.title, title.displayText))
}
AppEventBus.post(AppEvent.ReadingHistoryChanged)
}
} else {
ExclusiveBottomSheetPresenter.show((activity as AppCompatActivity).supportFragmentManager,
Expand Down
Loading