Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IA Reader add dedicated tracking for time spend in sub-filtered streams. #11325

Merged
merged 15 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -108,8 +108,6 @@
import org.wordpress.android.ui.reader.services.update.ReaderUpdateLogic.UpdateTask;
import org.wordpress.android.ui.reader.services.update.ReaderUpdateServiceStarter;
import org.wordpress.android.ui.reader.subfilter.SubfilterListItem.Site;
import org.wordpress.android.ui.reader.tracker.ReaderTracker;
import org.wordpress.android.ui.reader.tracker.ReaderTrackerType;
import org.wordpress.android.ui.reader.utils.ReaderUtils;
import org.wordpress.android.ui.reader.viewmodels.ReaderModeInfo;
import org.wordpress.android.ui.reader.viewmodels.ReaderPostListViewModel;
Expand Down Expand Up @@ -224,7 +222,6 @@ public class ReaderPostListFragment extends Fragment
@Inject ImageManager mImageManager;
@Inject QuickStartStore mQuickStartStore;
@Inject UiHelpers mUiHelpers;
@Inject ReaderTracker mReaderTracker;

private enum ActionableEmptyViewButtonType {
DISCOVER,
Expand Down Expand Up @@ -405,7 +402,7 @@ public void onCreate(Bundle savedInstanceState) {
BuildConfig.INFORMATION_ARCHITECTURE_AVAILABLE && mIsTopLevel,
mRecyclerView
) || ReaderUtils.isDefaultTag(mCurrentTag)) && getPostListType() != ReaderPostListType.SEARCH_RESULTS) {
mViewModel.onSubfilterChanged(subfilterListItem, true);
mViewModel.onSubfilterChanged(subfilterListItem);
}
});

Expand Down Expand Up @@ -522,23 +519,19 @@ private void changeReaderMode(ReaderModeInfo readerModeInfo, boolean onlyOnChang
@Override
public void onPause() {
super.onPause();
AppLog.d(T.READER, "TRACK READER ReaderPostListFragment > STOP Count [mIsTopLevel = " + mIsTopLevel + "]");
mReaderTracker.stop(
mIsTopLevel ? ReaderTrackerType.MAIN_READER : ReaderTrackerType.FILTERED_LIST
);

if (mBookmarksSavedLocallyDialog != null) {
mBookmarksSavedLocallyDialog.dismiss();
}
mWasPaused = true;

mViewModel.onFragmentPause(mIsTopLevel);
}

@Override
public void onResume() {
super.onResume();
AppLog.d(T.READER, "TRACK READER ReaderPostListFragment > START Count [mIsTopLevel = " + mIsTopLevel + "]");
mReaderTracker.start(
mIsTopLevel ? ReaderTrackerType.MAIN_READER : ReaderTrackerType.FILTERED_LIST
);

checkPostAdapter();

if (mWasPaused) {
Expand Down Expand Up @@ -580,6 +573,8 @@ public void onResume() {
AppLog.w(T.READER, "Discover tag not found; ReaderTagTable returned null");
}
}

mViewModel.onFragmentResume(mIsTopLevel, ReaderUtils.isFollowing(getCurrentTag(), mIsTopLevel, mRecyclerView));
}

/*
Expand Down Expand Up @@ -1094,7 +1089,7 @@ public boolean onMenuItemActionCollapse(MenuItem item) {
BuildConfig.INFORMATION_ARCHITECTURE_AVAILABLE && mIsTopLevel,
mRecyclerView)
) {
mViewModel.onSubfilterChanged(mViewModel.getCurrentSubfilterValue(), false);
mViewModel.manageSubfilter();
} else {
// return to the followed tag that was showing prior to searching
resetPostAdapter(ReaderPostListType.TAG_FOLLOWED);
Expand Down Expand Up @@ -2004,7 +1999,7 @@ && getPostAdapter().isCurrentTag(tag)) {

if (BuildConfig.INFORMATION_ARCHITECTURE_AVAILABLE && manageSubfilter) {
if (mCurrentTag.isFollowedSites()) {
mViewModel.onSubfilterChanged(mViewModel.getCurrentSubfilterValue(), false);
mViewModel.manageSubfilter();
} else {
changeReaderMode(new ReaderModeInfo(
tag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.wordpress.android.ui.utils.UiString
import org.wordpress.android.ui.utils.UiString.UiStringRes
import org.wordpress.android.ui.utils.UiString.UiStringText

sealed class SubfilterListItem(val type: ItemType) {
sealed class SubfilterListItem(val type: ItemType, val isTrackedItem: Boolean = false) {
open var isSelected: Boolean = false
open val onClickAction: ((filter: SubfilterListItem) -> Unit)? = null
open val label: UiString? = null
Expand Down Expand Up @@ -60,7 +60,7 @@ sealed class SubfilterListItem(val type: ItemType) {
override var isSelected: Boolean = false,
override val onClickAction: (filter: SubfilterListItem) -> Unit,
val blog: ReaderBlog
) : SubfilterListItem(SITE) {
) : SubfilterListItem(SITE, true) {
override val label: UiString = if (blog.name.isNotEmpty()) {
UiStringText(blog.name)
} else {
Expand All @@ -72,7 +72,7 @@ sealed class SubfilterListItem(val type: ItemType) {
override var isSelected: Boolean = false,
override val onClickAction: (filter: SubfilterListItem) -> Unit,
val tag: ReaderTag
) : SubfilterListItem(TAG) {
) : SubfilterListItem(TAG, true) {
override val label: UiString = UiStringText(tag.tagTitle)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import javax.inject.Singleton
@Singleton
@MainThread
class ReaderTracker @Inject constructor(private val dateProvider: DateProvider) {
// TODO: evaluate during IA extensions to use something like Dispatchers.Main.Immediate in the fun(s)
// TODO: evaluate to use something like Dispatchers.Main.Immediate in the fun(s)
// to sync the access to trackers; so to remove the @MainThread and make the
// usage of this class more transparent to its users
private val trackers = mutableMapOf<ReaderTrackerType, ReaderTrackerInfo>()
Expand Down Expand Up @@ -45,6 +45,12 @@ class ReaderTracker @Inject constructor(private val dateProvider: DateProvider)
}
}

fun isRunning(type: ReaderTrackerType): Boolean {
return trackers[type]?.let { trackerInto ->
trackerInto.startDate != null
} ?: false
renanferrari marked this conversation as resolved.
Show resolved Hide resolved
}

fun getAnalyticsData(): Map<String, Any> {
return trackers.entries.associate { it.key.propertyName to it.value.accumulatedTime }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ data class ReaderTrackerInfo(
enum class ReaderTrackerType constructor(val propertyName: String) {
MAIN_READER("time_in_main_reader"),
FILTERED_LIST("time_in_reader_filtered_list"),
PAGED_POST("time_in_reader_paged_post")
PAGED_POST("time_in_reader_paged_post"),
SUBFILTERED_LIST("time_in_subfiltered_list")
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import org.wordpress.android.ui.reader.subfilter.SubfilterListItem.Site
import org.wordpress.android.ui.reader.subfilter.SubfilterListItem.SiteAll
import org.wordpress.android.ui.reader.subfilter.SubfilterListItem.Tag
import org.wordpress.android.ui.reader.subfilter.SubfilterListItemMapper
import org.wordpress.android.ui.reader.tracker.ReaderTracker
import org.wordpress.android.ui.reader.tracker.ReaderTrackerType
import org.wordpress.android.ui.reader.utils.ReaderUtils
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.AppLog.T
Expand All @@ -46,7 +48,8 @@ class ReaderPostListViewModel @Inject constructor(
@Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher,
private val appPrefsWrapper: AppPrefsWrapper,
private val subfilterListItemMapper: SubfilterListItemMapper,
private val eventBusWrapper: EventBusWrapper
private val eventBusWrapper: EventBusWrapper,
private val readerTracker: ReaderTracker
) : ScopedViewModel(bgDispatcher) {
private val newsItemSource = newsManager.newsItemSource()
private val _newsItemSourceMediator = MediatorLiveData<NewsItem>()
Expand Down Expand Up @@ -104,7 +107,7 @@ class ReaderPostListViewModel @Inject constructor(
newsManager.pull()

updateSubfilter(getCurrentSubfilterValue())
_shouldShowSubFilters.value = shouldShowSubfilter
changeSubfiltersVisibility(shouldShowSubfilter)
}

_shouldCollapseToolbar.value = collapseToolbar
Expand Down Expand Up @@ -197,7 +200,24 @@ class ReaderPostListViewModel @Inject constructor(
updateSubfilter(filter)
}

fun changeSubfiltersVisibility(show: Boolean) = _shouldShowSubFilters.postValue(show)
fun changeSubfiltersVisibility(show: Boolean) {
if (show) {
if (getCurrentSubfilterValue().isTrackedItem &&
!readerTracker.isRunning(ReaderTrackerType.SUBFILTERED_LIST)) {
AppLog.d(T.READER, "TRACK READER ReaderPostListFragment > START Count SUBFILTERED_LIST")
readerTracker.start(ReaderTrackerType.SUBFILTERED_LIST)
} else if (!getCurrentSubfilterValue().isTrackedItem &&
readerTracker.isRunning(ReaderTrackerType.SUBFILTERED_LIST)) {
AppLog.d(T.READER, "TRACK READER ReaderPostListFragment > STOP Count SUBFILTERED_LIST")
readerTracker.stop(ReaderTrackerType.SUBFILTERED_LIST)
}
} else if (readerTracker.isRunning(ReaderTrackerType.SUBFILTERED_LIST)) {
AppLog.d(T.READER, "TRACK READER ReaderPostListFragment > STOP Count SUBFILTERED_LIST")
readerTracker.stop(ReaderTrackerType.SUBFILTERED_LIST)
}
renanferrari marked this conversation as resolved.
Show resolved Hide resolved

_shouldShowSubFilters.postValue(show)
}

fun getCurrentSubfilterValue(): SubfilterListItem {
return if (!BuildConfig.INFORMATION_ARCHITECTURE_AVAILABLE) {
Expand Down Expand Up @@ -244,10 +264,19 @@ class ReaderPostListViewModel @Inject constructor(
_changeBottomSheetVisibility.value = Event(false)
}

fun onSubfilterChanged(
private fun changeSubfilter(
subfilterListItem: SubfilterListItem,
requestNewerPosts: Boolean
) {
if (subfilterListItem.isTrackedItem &&
!readerTracker.isRunning(ReaderTrackerType.SUBFILTERED_LIST)) {
AppLog.d(T.READER, "TRACK READER ReaderPostListFragment > START Count SUBFILTERED_LIST")
readerTracker.start(ReaderTrackerType.SUBFILTERED_LIST)
} else if (!subfilterListItem.isTrackedItem && readerTracker.isRunning(ReaderTrackerType.SUBFILTERED_LIST)) {
AppLog.d(T.READER, "TRACK READER ReaderPostListFragment > STOP Count SUBFILTERED_LIST")
readerTracker.stop(ReaderTrackerType.SUBFILTERED_LIST)
}
renanferrari marked this conversation as resolved.
Show resolved Hide resolved

when (subfilterListItem.type) {
SubfilterListItem.ItemType.SECTION_TITLE,
SubfilterListItem.ItemType.DIVIDER -> {
Expand Down Expand Up @@ -295,6 +324,14 @@ class ReaderPostListViewModel @Inject constructor(
isFirstLoad = false
}

fun onSubfilterChanged(subfilterListItem: SubfilterListItem) {
changeSubfilter(subfilterListItem, true)
}

fun manageSubfilter() {
changeSubfilter(getCurrentSubfilterValue(), false)
}
renanferrari marked this conversation as resolved.
Show resolved Hide resolved

fun onSearchMenuCollapse(collapse: Boolean) {
_shouldCollapseToolbar.value = collapse
}
Expand All @@ -314,6 +351,39 @@ class ReaderPostListViewModel @Inject constructor(
_startSubsActivity.postValue(Event(selectedTabIndex))
}

fun onFragmentResume(isTopLevelFragment: Boolean, isFollowingTag: Boolean) {
AppLog.d(
T.READER,
"TRACK READER ReaderPostListFragment > START Count [mIsTopLevel = $isTopLevelFragment]"
)
readerTracker.start(
if (isTopLevelFragment) ReaderTrackerType.MAIN_READER else ReaderTrackerType.FILTERED_LIST
)

if (BuildConfig.INFORMATION_ARCHITECTURE_AVAILABLE && isTopLevelFragment) {
if (isFollowingTag && getCurrentSubfilterValue().isTrackedItem) {
AppLog.d(T.READER, "TRACK READER ReaderPostListFragment > START Count SUBFILTERED_LIST")
readerTracker.start(ReaderTrackerType.SUBFILTERED_LIST)
}
}
}

fun onFragmentPause(isTopLevelFragment: Boolean) {
AppLog.d(
T.READER,
"TRACK READER ReaderPostListFragment > STOP Count [mIsTopLevel = $isTopLevelFragment]"
)
readerTracker.stop(
if (isTopLevelFragment) ReaderTrackerType.MAIN_READER else ReaderTrackerType.FILTERED_LIST
)

if (BuildConfig.INFORMATION_ARCHITECTURE_AVAILABLE &&
isTopLevelFragment && readerTracker.isRunning(ReaderTrackerType.SUBFILTERED_LIST)) {
AppLog.d(T.READER, "TRACK READER ReaderPostListFragment > STOP Count SUBFILTERED_LIST")
readerTracker.stop(ReaderTrackerType.SUBFILTERED_LIST)
}
}

private fun updateSubfilter(filter: SubfilterListItem) {
_currentSubFilter.postValue(filter)
val json = subfilterListItemMapper.toJson(filter)
Expand Down
Loading