From eee4ccb28143185d1046a1b167e9d2d35322e00a Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Tue, 15 Jan 2019 09:46:09 +0100 Subject: [PATCH 001/103] Update FluxC --- .../org/wordpress/android/ui/stats/refresh/StatsModule.kt | 6 +++--- .../android/ui/stats/refresh/lists/BaseListUseCase.kt | 6 +++--- .../ui/stats/refresh/lists/sections/BaseStatsUseCase.kt | 2 +- .../lists/sections/insights/usecases/AllTimeStatsUseCase.kt | 4 ++-- build.gradle | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt index ed7d592d6322..6a27bbdd0666 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt @@ -7,7 +7,7 @@ import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS import org.wordpress.android.fluxc.network.utils.StatsGranularity.MONTHS import org.wordpress.android.fluxc.network.utils.StatsGranularity.WEEKS import org.wordpress.android.fluxc.network.utils.StatsGranularity.YEARS -import org.wordpress.android.fluxc.store.StatsStore +import org.wordpress.android.fluxc.store.stats.StatsStore import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.BaseListUseCase @@ -120,8 +120,8 @@ class StatsModule { @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, @Named(INSIGHTS_USE_CASES) useCases: List<@JvmSuppressWildcards BaseStatsUseCase<*, *>> ): BaseListUseCase { - return BaseListUseCase(bgDispatcher, mainDispatcher, useCases) { - statsStore.getInsights() + return BaseListUseCase(bgDispatcher, mainDispatcher, useCases) { site -> + statsStore.getInsights(site) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt index 8174a0a9572e..ad063865703f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.StatsStore.StatsTypes +import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T @@ -19,7 +19,7 @@ constructor( private val bgDispatcher: CoroutineDispatcher, private val mainDispatcher: CoroutineDispatcher, private val useCases: List>, - private val getStatsTypes: suspend (() -> List) + private val getStatsTypes: suspend ((site: SiteModel) -> List) ) { private val blockListData = combineMap( useCases.associateBy { it.type }.mapValues { entry -> entry.value.liveData } @@ -52,7 +52,7 @@ constructor( throw RuntimeException("Duplicate stats type in a use case") } useCases.forEach { block -> launch { block.fetch(site, refresh, forced) } } - val items = getStatsTypes() + val items = getStatsTypes(site) withContext(mainDispatcher) { statsTypes.value = items } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt index 0f0ff0f0d03c..6333c9b07c67 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt @@ -5,7 +5,7 @@ import android.arch.lifecycle.MutableLiveData import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.StatsStore.StatsTypes +import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.Error import org.wordpress.android.ui.stats.refresh.lists.Loading diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt index 089e6bdcb8ec..53a65cb7223f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt @@ -4,8 +4,8 @@ import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.InsightsAllTimeModel -import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.ALL_TIME_STATS +import org.wordpress.android.fluxc.store.stats.InsightsStore +import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.ALL_TIME_STATS import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem diff --git a/build.gradle b/build.gradle index c142c1485e7f..6f2a43aea749 100644 --- a/build.gradle +++ b/build.gradle @@ -92,5 +92,5 @@ subprojects { } ext { - fluxCVersion = '0b78142d158b06f3017807d0395d39bbc65ed88e' + fluxCVersion = '9d330335b2f8b2eb909aa967450b523e29baa2b6' } From cf9f0878284d236abd3f8e9b7f6b522f33bff1fd Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Thu, 17 Jan 2019 09:30:52 +0100 Subject: [PATCH 002/103] Add overflow menu to title --- .../ic_ellipsis_vertical_grey_darken_48dp.xml | 15 +++++++++++++++ .../main/res/layout/stats_block_title_item.xml | 15 +++++++++++++-- WordPress/src/main/res/values/strings.xml | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 WordPress/src/main/res/drawable/ic_ellipsis_vertical_grey_darken_48dp.xml diff --git a/WordPress/src/main/res/drawable/ic_ellipsis_vertical_grey_darken_48dp.xml b/WordPress/src/main/res/drawable/ic_ellipsis_vertical_grey_darken_48dp.xml new file mode 100644 index 000000000000..047b3c616cc3 --- /dev/null +++ b/WordPress/src/main/res/drawable/ic_ellipsis_vertical_grey_darken_48dp.xml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/WordPress/src/main/res/layout/stats_block_title_item.xml b/WordPress/src/main/res/layout/stats_block_title_item.xml index 072e9b7a9aec..54bc3041a6bd 100644 --- a/WordPress/src/main/res/layout/stats_block_title_item.xml +++ b/WordPress/src/main/res/layout/stats_block_title_item.xml @@ -1,15 +1,26 @@ + + + + diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index b1e56319fb0e..80d044bc3430 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -812,6 +812,7 @@ Service Followers %1$s - %2$s + Stats item settings We cannot open the statistics at the moment. Please try again later From 5ae3d8da130b41e47273c65a5da7fb5293051eb5 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Thu, 17 Jan 2019 09:39:20 +0100 Subject: [PATCH 003/103] Add overflow menu resource and icons --- .../res/drawable/ic_arrow_down_grey_dark_24dp.xml | 13 +++++++++++++ .../res/drawable/ic_arrow_up_grey_dark_24dp.xml | 13 +++++++++++++ .../main/res/drawable/ic_trash_grey_dark_24dp.xml | 15 +++++++++++++++ WordPress/src/main/res/menu/menu_stats_item.xml | 15 +++++++++++++++ WordPress/src/main/res/values/strings.xml | 3 +++ 5 files changed, 59 insertions(+) create mode 100644 WordPress/src/main/res/drawable/ic_arrow_down_grey_dark_24dp.xml create mode 100644 WordPress/src/main/res/drawable/ic_arrow_up_grey_dark_24dp.xml create mode 100644 WordPress/src/main/res/drawable/ic_trash_grey_dark_24dp.xml create mode 100644 WordPress/src/main/res/menu/menu_stats_item.xml diff --git a/WordPress/src/main/res/drawable/ic_arrow_down_grey_dark_24dp.xml b/WordPress/src/main/res/drawable/ic_arrow_down_grey_dark_24dp.xml new file mode 100644 index 000000000000..11365e9c23b0 --- /dev/null +++ b/WordPress/src/main/res/drawable/ic_arrow_down_grey_dark_24dp.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/WordPress/src/main/res/drawable/ic_arrow_up_grey_dark_24dp.xml b/WordPress/src/main/res/drawable/ic_arrow_up_grey_dark_24dp.xml new file mode 100644 index 000000000000..c1cdf781c6a7 --- /dev/null +++ b/WordPress/src/main/res/drawable/ic_arrow_up_grey_dark_24dp.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/WordPress/src/main/res/drawable/ic_trash_grey_dark_24dp.xml b/WordPress/src/main/res/drawable/ic_trash_grey_dark_24dp.xml new file mode 100644 index 000000000000..a7d5e8e7e921 --- /dev/null +++ b/WordPress/src/main/res/drawable/ic_trash_grey_dark_24dp.xml @@ -0,0 +1,15 @@ + + + + + + diff --git a/WordPress/src/main/res/menu/menu_stats_item.xml b/WordPress/src/main/res/menu/menu_stats_item.xml new file mode 100644 index 000000000000..4c707d8be788 --- /dev/null +++ b/WordPress/src/main/res/menu/menu_stats_item.xml @@ -0,0 +1,15 @@ + + + + + + diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 80d044bc3430..6ad70d63a3cc 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -814,6 +814,9 @@ %1$s - %2$s Stats item settings We cannot open the statistics at the moment. Please try again later + Move up + Move down + Remove from insights Jetpack From 12b2fbb0246c3a8f44f4a170b3291ccbcc2fbe89 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Thu, 17 Jan 2019 11:14:05 +0100 Subject: [PATCH 004/103] Update imports to fix build --- .../ui/stats/refresh/lists/BaseListUseCase.kt | 9 +++++ .../ui/stats/refresh/lists/StatsBlock.kt | 2 +- .../stats/refresh/lists/StatsListFragment.kt | 34 +++++++++++++++++++ .../stats/refresh/lists/StatsListViewModel.kt | 16 +++++++++ .../lists/sections/BaseStatsUseCase.kt | 11 ++++++ .../refresh/lists/sections/BlockListItem.kt | 7 +++- .../lists/sections/BlockListItemViewHolder.kt | 9 +++++ .../granular/GranularStatefulUseCase.kt | 2 +- .../granular/GranularStatelessUseCase.kt | 2 +- .../granular/usecases/AuthorsUseCase.kt | 2 +- .../granular/usecases/ClicksUseCase.kt | 2 +- .../granular/usecases/CountryViewsUseCase.kt | 2 +- .../sections/granular/usecases/DateUseCase.kt | 2 +- .../granular/usecases/OverviewUseCase.kt | 2 +- .../granular/usecases/PostsAndPagesUseCase.kt | 2 +- .../granular/usecases/ReferrersUseCase.kt | 2 +- .../granular/usecases/SearchTermsUseCase.kt | 2 +- .../granular/usecases/VideoPlaysUseCase.kt | 2 +- .../insights/usecases/AllTimeStatsUseCase.kt | 2 +- .../insights/usecases/CommentsUseCase.kt | 6 ++-- .../insights/usecases/FollowersUseCase.kt | 6 ++-- .../usecases/LatestPostSummaryUseCase.kt | 6 ++-- .../usecases/MostPopularInsightsUseCase.kt | 6 ++-- .../insights/usecases/PublicizeUseCase.kt | 6 ++-- .../usecases/TagsAndCategoriesUseCase.kt | 6 ++-- .../insights/usecases/TodayStatsUseCase.kt | 6 ++-- .../lists/viewholders/BaseStatsViewHolder.kt | 6 ++-- .../lists/viewholders/BlockListViewHolder.kt | 2 +- .../res/layout/stats_block_title_item.xml | 1 + .../lists/sections/BaseStatsUseCaseTest.kt | 2 +- .../granular/usecases/AuthorsUseCaseTest.kt | 6 ++-- .../granular/usecases/ClicksUseCaseTest.kt | 6 ++-- .../usecases/CountryViewsUseCaseTest.kt | 6 ++-- .../granular/usecases/OverviewUseCaseTest.kt | 6 ++-- .../usecases/PostsAndPagesUseCaseTest.kt | 6 ++-- .../granular/usecases/ReferrersUseCaseTest.kt | 6 ++-- .../usecases/SearchTermsUseCaseTest.kt | 6 ++-- .../usecases/VideoPlaysUseCaseTest.kt | 6 ++-- .../usecases/AllTimeStatsUseCaseTest.kt | 6 ++-- .../insights/usecases/CommentsUseCaseTest.kt | 6 ++-- .../insights/usecases/FollowersUseCaseTest.kt | 6 ++-- .../usecases/LatestPostSummaryUseCaseTest.kt | 6 ++-- .../MostPopularInsightsUseCaseTest.kt | 6 ++-- .../insights/usecases/PublicizeUseCaseTest.kt | 6 ++-- .../usecases/TagsAndCategoriesUseCaseTest.kt | 6 ++-- .../usecases/TodayStatsUseCaseTest.kt | 6 ++-- 46 files changed, 173 insertions(+), 88 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt index ad063865703f..37422c189167 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt @@ -12,6 +12,7 @@ import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T import org.wordpress.android.util.PackageUtils import org.wordpress.android.util.combineMap +import org.wordpress.android.util.merge import org.wordpress.android.util.mergeNotNull class BaseListUseCase @@ -37,6 +38,14 @@ constructor( } val navigationTarget: LiveData = mergeNotNull(useCases.map { it.navigationTarget }) + val menuClick: LiveData = merge(mergeNotNull(useCases.map { it.menuClick }), data) { click, viewModel -> + if (click != null && viewModel != null) { + val indexOfBlock = viewModel.indexOfFirst { it.type == click.second } + MenuClick(click.first, click.second, indexOfBlock == 0, indexOfBlock == viewModel.size - 1) + } else { + null + } + } suspend fun loadData(site: SiteModel) { loadData(site, false, false) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt index 695b0d5a3bab..b930acee33a2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt @@ -1,6 +1,6 @@ package org.wordpress.android.ui.stats.refresh.lists -import org.wordpress.android.fluxc.store.StatsStore.StatsTypes +import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.BLOCK_LIST import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.EMPTY import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.ERROR diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index ad407cc5f15e..093ac4ac07f4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -8,6 +8,7 @@ import android.os.Bundle import android.os.Parcelable import android.support.v4.app.FragmentActivity import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.PopupMenu import android.support.v7.widget.RecyclerView.LayoutManager import android.support.v7.widget.StaggeredGridLayoutManager import android.view.LayoutInflater @@ -24,6 +25,7 @@ import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS import org.wordpress.android.fluxc.network.utils.StatsGranularity.MONTHS import org.wordpress.android.fluxc.network.utils.StatsGranularity.WEEKS import org.wordpress.android.fluxc.network.utils.StatsGranularity.YEARS +import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes import org.wordpress.android.ui.ActivityLauncher import org.wordpress.android.ui.WPWebViewActivity import org.wordpress.android.ui.stats.StatsConstants @@ -273,6 +275,36 @@ class StatsListFragment : DaggerFragment() { } true } + + viewModel.menuClick.observe(this, Observer { menuClick -> + if (menuClick != null) { + val popup = PopupMenu(activity, menuClick.view) + val popupMenu = popup.menu + popup.inflate(R.menu.menu_stats_item) + popupMenu.findItem(R.id.action_move_up).isEnabled = menuClick.showUpAction + popupMenu.findItem(R.id.action_move_down).isEnabled = menuClick.showDownAction + popup.setOnMenuItemClickListener { menuItem -> + when (menuItem.itemId) { + R.id.action_move_up -> { + viewModel.onMoveUpClick(menuClick.type) + true + } + R.id.action_move_down -> { + viewModel.onMoveDownClick(menuClick.type) + true + } + R.id.action_remove -> { + viewModel.onRemoveClick(menuClick.type) + true + } + else -> { + false + } + } + } + popup.show() + } + }) } private fun updateInsights(statsState: List) { @@ -326,3 +358,5 @@ fun StatsGranularity.toStatsTimeFrame(): StatsTimeframe { YEARS -> StatsTimeframe.YEAR } } + +data class MenuClick(val view: View, val type: StatsTypes, val showUpAction: Boolean, val showDownAction: Boolean) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index f6944bf079cf..422d0418e28d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -4,6 +4,8 @@ import android.arch.lifecycle.LiveData import android.support.annotation.StringRes import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R +import org.wordpress.android.fluxc.store.stats.StatsStore +import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes import org.wordpress.android.viewmodel.ScopedViewModel abstract class StatsListViewModel(defaultDispatcher: CoroutineDispatcher, private val statsUseCase: BaseListUseCase) : @@ -20,10 +22,24 @@ abstract class StatsListViewModel(defaultDispatcher: CoroutineDispatcher, privat val navigationTarget: LiveData = statsUseCase.navigationTarget + val menuClick: LiveData = statsUseCase.menuClick + val data: LiveData> = _data override fun onCleared() { statsUseCase.onCleared() super.onCleared() } + + fun onMoveDownClick(type: StatsTypes) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + fun onMoveUpClick(type: StatsTypes) { + TODO() + } + + fun onRemoveClick(type: StatsTypes) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt index 6333c9b07c67..f73c4fffecf1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt @@ -2,6 +2,7 @@ package org.wordpress.android.ui.stats.refresh.lists.sections import android.arch.lifecycle.LiveData import android.arch.lifecycle.MutableLiveData +import android.view.View import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext import org.wordpress.android.fluxc.model.SiteModel @@ -27,6 +28,7 @@ abstract class BaseStatsUseCase( ) { private val domainModel = MutableLiveData>() private val uiState = MutableLiveData() + val liveData: LiveData = merge(domainModel, uiState) { data, uiState -> try { when (data) { @@ -43,6 +45,8 @@ abstract class BaseStatsUseCase( private val mutableNavigationTarget = MutableLiveData() val navigationTarget: LiveData = mutableNavigationTarget + private val mutableMenuClick = MutableLiveData>() + val menuClick: LiveData> = mutableMenuClick /** * Fetches data either from a local cache or from remote API @@ -100,6 +104,13 @@ abstract class BaseStatsUseCase( uiState.value = newState ?: uiState.value } + /** + * Trigger this method when the item menu button is clicked + */ + fun onMenuClick(view: View) { + mutableMenuClick.value = view to type + } + /** * Trigger this method when updating only a part of UI state. * @param update function diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItem.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItem.kt index 6e9d73681f56..34858a7938c6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItem.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItem.kt @@ -2,6 +2,7 @@ package org.wordpress.android.ui.stats.refresh.lists.sections import android.support.annotation.DrawableRes import android.support.annotation.StringRes +import android.view.View import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Columns.Alignment.CENTER import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ListItemWithIcon.IconStyle.NORMAL import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.BACKGROUND_INFO @@ -47,7 +48,11 @@ sealed class BlockListItem(val type: Type) { DIVIDER } - data class Title(@StringRes val textResource: Int? = null, val text: String? = null) : BlockListItem(TITLE) + data class Title( + @StringRes val textResource: Int? = null, + val text: String? = null, + val menuAction: ((View) -> Unit)? = null + ) : BlockListItem(TITLE) data class ListItem( val text: String, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItemViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItemViewHolder.kt index 60d75f84417d..369f0d59ffe2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItemViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItemViewHolder.kt @@ -28,6 +28,7 @@ import android.webkit.WebSettings import android.webkit.WebView import android.webkit.WebViewClient import android.widget.FrameLayout +import android.widget.ImageButton import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView @@ -71,8 +72,16 @@ sealed class BlockListItemViewHolder( R.layout.stats_block_title_item ) { private val text = itemView.findViewById(R.id.text) + private val menu = itemView.findViewById(R.id.menu) fun bind(item: Title) { text.setTextOrHide(item.textResource, item.text) + if (item.menuAction != null) { + menu.visibility = View.VISIBLE + menu.setOnClickListener { item.menuAction.invoke(menu) } + } else { + menu.visibility = View.GONE + menu.setOnClickListener(null) + } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatefulUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatefulUseCase.kt index 6250ab7ea09f..f104b97fd1d0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatefulUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatefulUseCase.kt @@ -3,7 +3,7 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.granular import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.StatsStore.StatsTypes +import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatefulUseCase import java.util.Date diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatelessUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatelessUseCase.kt index 216388bdcde0..910d53d4ec14 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatelessUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatelessUseCase.kt @@ -3,7 +3,7 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.granular import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.StatsStore.StatsTypes +import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase import java.util.Date diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/AuthorsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/AuthorsUseCase.kt index f1f53e266a71..e80a1d684bd9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/AuthorsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/AuthorsUseCase.kt @@ -7,7 +7,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.AuthorsModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.AUTHORS +import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.AUTHORS import org.wordpress.android.fluxc.store.stats.time.AuthorsStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewAuthors diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ClicksUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ClicksUseCase.kt index 67e237109bd4..43a751097974 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ClicksUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ClicksUseCase.kt @@ -7,7 +7,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.ClicksModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.CLICKS +import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.CLICKS import org.wordpress.android.fluxc.store.stats.time.ClicksStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewClicks diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/CountryViewsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/CountryViewsUseCase.kt index b346d48efa0d..c6be6a204c28 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/CountryViewsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/CountryViewsUseCase.kt @@ -7,7 +7,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.CountryViewsModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.COUNTRIES +import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.COUNTRIES import org.wordpress.android.fluxc.store.stats.time.CountryViewsStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewCountries diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/DateUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/DateUseCase.kt index e05f05a11500..77783651b1e7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/DateUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/DateUseCase.kt @@ -4,7 +4,7 @@ import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R.string import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.DATE +import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.DATE import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.BackgroundInformation diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/OverviewUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/OverviewUseCase.kt index fdf5b06cb856..9e24d2ec9540 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/OverviewUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/OverviewUseCase.kt @@ -5,7 +5,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.VisitsAndViewsModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.OVERVIEW +import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.OVERVIEW import org.wordpress.android.fluxc.store.stats.time.VisitsAndViewsStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatefulUseCase diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/PostsAndPagesUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/PostsAndPagesUseCase.kt index 7f339d0cfa8c..f7901993aa35 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/PostsAndPagesUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/PostsAndPagesUseCase.kt @@ -10,7 +10,7 @@ import org.wordpress.android.fluxc.model.stats.time.PostAndPageViewsModel.ViewsT import org.wordpress.android.fluxc.model.stats.time.PostAndPageViewsModel.ViewsType.PAGE import org.wordpress.android.fluxc.model.stats.time.PostAndPageViewsModel.ViewsType.POST import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.POSTS_AND_PAGES +import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.POSTS_AND_PAGES import org.wordpress.android.fluxc.store.stats.time.PostAndPageViewsStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.StatsConstants.ITEM_TYPE_HOME_PAGE diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ReferrersUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ReferrersUseCase.kt index ac77ce2164d6..94358a38630e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ReferrersUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ReferrersUseCase.kt @@ -7,7 +7,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.ReferrersModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.REFERRERS +import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.REFERRERS import org.wordpress.android.fluxc.store.stats.time.ReferrersStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewReferrers diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/SearchTermsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/SearchTermsUseCase.kt index 8ddeb3dcdcdc..6b5741aeb80c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/SearchTermsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/SearchTermsUseCase.kt @@ -7,7 +7,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.SearchTermsModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.SEARCH_TERMS +import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.SEARCH_TERMS import org.wordpress.android.fluxc.store.stats.time.SearchTermsStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewSearchTerms diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/VideoPlaysUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/VideoPlaysUseCase.kt index 83e04b5a3680..4ff6b00b8c7a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/VideoPlaysUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/VideoPlaysUseCase.kt @@ -7,7 +7,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.VideoPlaysModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.VIDEOS +import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.VIDEOS import org.wordpress.android.fluxc.store.stats.time.VideoPlaysStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewUrl diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt index 53a65cb7223f..4202d7b14240 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt @@ -44,7 +44,7 @@ class AllTimeStatsUseCase override fun buildUiModel(domainModel: InsightsAllTimeModel): List { val items = mutableListOf() - items.add(Title(R.string.stats_insights_all_time_stats)) + items.add(Title(R.string.stats_insights_all_time_stats, menuAction = this::onMenuClick)) val hasPosts = domainModel.posts > 0 val hasViews = domainModel.views > 0 diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt index df74ed22cacb..9f4dd2a9e4bf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt @@ -6,8 +6,8 @@ import org.wordpress.android.R.string import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.CommentsModel -import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.COMMENTS +import org.wordpress.android.fluxc.store.stats.InsightsStore +import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.COMMENTS import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewCommentsStats import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatefulUseCase @@ -57,7 +57,7 @@ class CommentsUseCase override fun buildStatefulUiModel(model: CommentsModel, uiState: Int): List { val items = mutableListOf() - items.add(Title(string.stats_view_comments)) + items.add(Title(string.stats_view_comments, menuAction = this::onMenuClick)) if (model.authors.isNotEmpty() || model.posts.isNotEmpty()) { items.add( TabsItem( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCase.kt index 1d7c860c44c7..d189832c1fd0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCase.kt @@ -9,8 +9,8 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.FollowersModel import org.wordpress.android.fluxc.model.stats.FollowersModel.FollowerModel -import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.FOLLOWERS +import org.wordpress.android.fluxc.store.stats.InsightsStore +import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.FOLLOWERS import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.StatsUtilsWrapper import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewFollowersStats @@ -77,7 +77,7 @@ class FollowersUseCase val wpComModel = domainModel.first val emailModel = domainModel.second val items = mutableListOf() - items.add(Title(string.stats_view_followers)) + items.add(Title(string.stats_view_followers, menuAction = this::onMenuClick)) if (domainModel.first.followers.isNotEmpty() || domainModel.second.followers.isNotEmpty()) { items.add( TabsItem( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCase.kt index 0a305d221e28..d2009cd65674 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCase.kt @@ -9,8 +9,8 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_LATEST_POST_S import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_LATEST_POST_SUMMARY_VIEW_POST_DETAILS_TAPPED import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.InsightsLatestPostModel -import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.LATEST_POST_SUMMARY +import org.wordpress.android.fluxc.store.stats.InsightsStore +import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.LATEST_POST_SUMMARY import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.AddNewPost import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.SharePost @@ -55,7 +55,7 @@ class LatestPostSummaryUseCase override fun buildUiModel(domainModel: InsightsLatestPostModel): List { val items = mutableListOf() - items.add(Title(string.stats_insights_latest_post_summary)) + items.add(Title(string.stats_insights_latest_post_summary, menuAction = this::onMenuClick)) items.add(latestPostSummaryMapper.buildMessageItem(domainModel, this::onLinkClicked)) if (domainModel.hasData()) { items.add( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt index d9972c5b092d..9e93e1ee667f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt @@ -4,8 +4,8 @@ import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.InsightsMostPopularModel -import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.MOST_POPULAR_DAY_AND_HOUR +import org.wordpress.android.fluxc.store.stats.InsightsStore +import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.MOST_POPULAR_DAY_AND_HOUR import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem @@ -46,7 +46,7 @@ class MostPopularInsightsUseCase override fun buildUiModel(domainModel: InsightsMostPopularModel): List { val items = mutableListOf() - items.add(Title(R.string.stats_insights_popular)) + items.add(Title(R.string.stats_insights_popular, menuAction = this::onMenuClick)) items.add(Header( R.string.stats_insights_most_popular_day_and_hour_label, R.string.stats_insights_most_popular_views_label) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCase.kt index 1b5812400a5e..96e8e66f8a26 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCase.kt @@ -6,8 +6,8 @@ import org.wordpress.android.R.string import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.PublicizeModel -import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.PUBLICIZE +import org.wordpress.android.fluxc.store.stats.InsightsStore +import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.PUBLICIZE import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewPublicizeStats import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase @@ -59,7 +59,7 @@ class PublicizeUseCase override fun buildUiModel(domainModel: PublicizeModel): List { val items = mutableListOf() - items.add(Title(string.stats_view_publicize)) + items.add(Title(string.stats_view_publicize, menuAction = this::onMenuClick)) if (domainModel.services.isEmpty()) { items.add(Empty()) } else { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCase.kt index 594f27fbba35..fbd74d1d8e18 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCase.kt @@ -8,8 +8,8 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.TagsModel import org.wordpress.android.fluxc.model.stats.TagsModel.TagModel -import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.TAGS_AND_CATEGORIES +import org.wordpress.android.fluxc.store.stats.InsightsStore +import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.TAGS_AND_CATEGORIES import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewTag import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewTagsAndCategoriesStats @@ -64,7 +64,7 @@ class TagsAndCategoriesUseCase override fun buildStatefulUiModel(domainModel: TagsModel, uiState: TagsAndCategoriesUiState): List { val items = mutableListOf() - items.add(Title(R.string.stats_insights_tags_and_categories)) + items.add(Title(R.string.stats_insights_tags_and_categories, menuAction = this::onMenuClick)) if (domainModel.tags.isEmpty()) { items.add(Empty()) } else { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCase.kt index c3b32ead0455..2b3393834a46 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCase.kt @@ -4,8 +4,8 @@ import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.VisitsModel -import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.TODAY_STATS +import org.wordpress.android.fluxc.store.stats.InsightsStore +import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.TODAY_STATS import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem @@ -42,7 +42,7 @@ class TodayStatsUseCase override fun buildUiModel(domainModel: VisitsModel): List { val items = mutableListOf() - items.add(Title(R.string.stats_insights_today_stats)) + items.add(Title(R.string.stats_insights_today_stats, menuAction = this::onMenuClick)) val hasViews = domainModel.views > 0 val hasVisitors = domainModel.visitors > 0 diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt index af8effe951d0..731f78d57b11 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt @@ -6,9 +6,9 @@ import android.support.v7.widget.RecyclerView.ViewHolder import android.support.v7.widget.StaggeredGridLayoutManager import android.view.LayoutInflater import android.view.ViewGroup -import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.LATEST_POST_SUMMARY -import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.DATE -import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.OVERVIEW +import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.LATEST_POST_SUMMARY +import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.DATE +import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.OVERVIEW import org.wordpress.android.ui.stats.refresh.lists.StatsBlock abstract class BaseStatsViewHolder( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt index a5843c598467..fdacb332798c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt @@ -7,7 +7,7 @@ import android.support.v7.widget.RecyclerView import android.view.ViewGroup import org.wordpress.android.R import org.wordpress.android.R.layout -import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.DATE +import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.DATE import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListAdapter import org.wordpress.android.util.image.ImageManager diff --git a/WordPress/src/main/res/layout/stats_block_title_item.xml b/WordPress/src/main/res/layout/stats_block_title_item.xml index 54bc3041a6bd..b6c1634fed01 100644 --- a/WordPress/src/main/res/layout/stats_block_title_item.xml +++ b/WordPress/src/main/res/layout/stats_block_title_item.xml @@ -18,6 +18,7 @@ android:layout_weight="1"/> Date: Tue, 22 Jan 2019 16:10:02 +0100 Subject: [PATCH 005/103] Implement moving blocks up and down --- .../android/ui/stats/refresh/StatsModule.kt | 40 ++++++++---- .../ui/stats/refresh/lists/BaseListUseCase.kt | 35 ++++++++--- .../stats/refresh/lists/StatsListFragment.kt | 61 +++++++++++-------- .../stats/refresh/lists/StatsListViewModel.kt | 18 +++--- .../lists/sections/BaseStatsUseCase.kt | 7 ++- build.gradle | 2 +- 6 files changed, 105 insertions(+), 58 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt index 6a27bbdd0666..ff9b627bcda4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt @@ -8,6 +8,7 @@ import org.wordpress.android.fluxc.network.utils.StatsGranularity.MONTHS import org.wordpress.android.fluxc.network.utils.StatsGranularity.WEEKS import org.wordpress.android.fluxc.network.utils.StatsGranularity.YEARS import org.wordpress.android.fluxc.store.stats.StatsStore +import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.BaseListUseCase @@ -120,9 +121,26 @@ class StatsModule { @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, @Named(INSIGHTS_USE_CASES) useCases: List<@JvmSuppressWildcards BaseStatsUseCase<*, *>> ): BaseListUseCase { - return BaseListUseCase(bgDispatcher, mainDispatcher, useCases) { site -> - statsStore.getInsights(site) - } + return BaseListUseCase( + bgDispatcher, + mainDispatcher, + useCases, + statsStore::getInsights, + moveTypeUp = { site, type -> + if (type is InsightsTypes) { + statsStore.moveTypeUp(site, type) + } + }, + moveTypeDown = { site, type -> + if (type is InsightsTypes) { + statsStore.moveTypeDown(site, type) + } + }, + removeType = { site, type -> + if (type is InsightsTypes) { + statsStore.removeType(site, type) + } + }) } /** @@ -138,9 +156,9 @@ class StatsModule { @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, @Named(GRANULAR_USE_CASE_FACTORIES) useCasesFactories: List<@JvmSuppressWildcards UseCaseFactory> ): BaseListUseCase { - return BaseListUseCase(bgDispatcher, mainDispatcher, useCasesFactories.map { it.build(DAYS) }) { + return BaseListUseCase(bgDispatcher, mainDispatcher, useCasesFactories.map { it.build(DAYS) }, { statsStore.getTimeStatsTypes() - } + }) } /** @@ -156,9 +174,9 @@ class StatsModule { @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, @Named(GRANULAR_USE_CASE_FACTORIES) useCasesFactories: List<@JvmSuppressWildcards UseCaseFactory> ): BaseListUseCase { - return BaseListUseCase(bgDispatcher, mainDispatcher, useCasesFactories.map { it.build(WEEKS) }) { + return BaseListUseCase(bgDispatcher, mainDispatcher, useCasesFactories.map { it.build(WEEKS) }, { statsStore.getTimeStatsTypes() - } + }) } /** @@ -174,9 +192,9 @@ class StatsModule { @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, @Named(GRANULAR_USE_CASE_FACTORIES) useCasesFactories: List<@JvmSuppressWildcards UseCaseFactory> ): BaseListUseCase { - return BaseListUseCase(bgDispatcher, mainDispatcher, useCasesFactories.map { it.build(MONTHS) }) { + return BaseListUseCase(bgDispatcher, mainDispatcher, useCasesFactories.map { it.build(MONTHS) }, { statsStore.getTimeStatsTypes() - } + }) } /** @@ -192,8 +210,8 @@ class StatsModule { @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, @Named(GRANULAR_USE_CASE_FACTORIES) useCasesFactories: List<@JvmSuppressWildcards UseCaseFactory> ): BaseListUseCase { - return BaseListUseCase(bgDispatcher, mainDispatcher, useCasesFactories.map { it.build(YEARS) }) { + return BaseListUseCase(bgDispatcher, mainDispatcher, useCasesFactories.map { it.build(YEARS) }, { statsStore.getTimeStatsTypes() - } + }) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt index 37422c189167..39926d2b3a30 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt @@ -7,6 +7,10 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes +import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action +import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action.MOVE_DOWN +import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action.MOVE_UP +import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action.REMOVE import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T @@ -20,7 +24,10 @@ constructor( private val bgDispatcher: CoroutineDispatcher, private val mainDispatcher: CoroutineDispatcher, private val useCases: List>, - private val getStatsTypes: suspend ((site: SiteModel) -> List) + private val getStatsTypes: suspend ((site: SiteModel) -> List), + private val moveTypeUp: suspend ((site: SiteModel, type: StatsTypes) -> Unit) = { _, _ -> }, + private val moveTypeDown: suspend ((site: SiteModel, type: StatsTypes) -> Unit) = { _, _ -> }, + private val removeType: suspend ((site: SiteModel, type: StatsTypes) -> Unit) = { _, _ -> } ) { private val blockListData = combineMap( useCases.associateBy { it.type }.mapValues { entry -> entry.value.liveData } @@ -40,8 +47,10 @@ constructor( val navigationTarget: LiveData = mergeNotNull(useCases.map { it.navigationTarget }) val menuClick: LiveData = merge(mergeNotNull(useCases.map { it.menuClick }), data) { click, viewModel -> if (click != null && viewModel != null) { - val indexOfBlock = viewModel.indexOfFirst { it.type == click.second } - MenuClick(click.first, click.second, indexOfBlock == 0, indexOfBlock == viewModel.size - 1) + val indexOfBlock = viewModel.indexOfFirst { it.statsTypes == click.type } + click.showUpAction = indexOfBlock > 0 + click.showDownAction = indexOfBlock < viewModel.size - 1 + click } else { null } @@ -55,20 +64,32 @@ constructor( loadData(site, true, forced) } + suspend fun refreshTypes(site: SiteModel) { + val items = getStatsTypes(site) + withContext(mainDispatcher) { + statsTypes.value = items + } + } + private suspend fun loadData(site: SiteModel, refresh: Boolean, forced: Boolean) { withContext(bgDispatcher) { if (PackageUtils.isDebugBuild() && useCases.distinctBy { it.type }.size < useCases.size) { throw RuntimeException("Duplicate stats type in a use case") } useCases.forEach { block -> launch { block.fetch(site, refresh, forced) } } - val items = getStatsTypes(site) - withContext(mainDispatcher) { - statsTypes.value = items - } + refreshTypes(site) } } fun onCleared() { useCases.forEach { it.clear() } } + + suspend fun onAction(site: SiteModel, type: StatsTypes, action: Action) { + when (action) { + MOVE_UP -> moveTypeUp(site, type) + MOVE_DOWN -> moveTypeDown(site, type) + REMOVE -> removeType(site, type) + } + } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index 093ac4ac07f4..d08341ade036 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -14,6 +14,7 @@ import android.support.v7.widget.StaggeredGridLayoutManager import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Toast import dagger.android.support.DaggerFragment import kotlinx.android.synthetic.main.stats_list_fragment.* import org.wordpress.android.R @@ -50,6 +51,7 @@ import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewTag import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewTagsAndCategoriesStats import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewUrl import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewVideoPlays +import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection import org.wordpress.android.ui.stats.refresh.lists.sections.granular.DaysListViewModel import org.wordpress.android.ui.stats.refresh.lists.sections.granular.MonthsListViewModel @@ -276,35 +278,34 @@ class StatsListFragment : DaggerFragment() { true } - viewModel.menuClick.observe(this, Observer { menuClick -> - if (menuClick != null) { - val popup = PopupMenu(activity, menuClick.view) - val popupMenu = popup.menu - popup.inflate(R.menu.menu_stats_item) - popupMenu.findItem(R.id.action_move_up).isEnabled = menuClick.showUpAction - popupMenu.findItem(R.id.action_move_down).isEnabled = menuClick.showDownAction - popup.setOnMenuItemClickListener { menuItem -> - when (menuItem.itemId) { - R.id.action_move_up -> { - viewModel.onMoveUpClick(menuClick.type) - true - } - R.id.action_move_down -> { - viewModel.onMoveDownClick(menuClick.type) - true - } - R.id.action_remove -> { - viewModel.onRemoveClick(menuClick.type) - true - } - else -> { - false - } + viewModel.menuClick.observeEvent(this) { menuClick -> + val popup = PopupMenu(activity, menuClick.view) + val popupMenu = popup.menu + popup.inflate(R.menu.menu_stats_item) + popupMenu.findItem(R.id.action_move_up).isVisible = menuClick.showUpAction + popupMenu.findItem(R.id.action_move_down).isVisible = menuClick.showDownAction + popup.show() + popup.setOnMenuItemClickListener { menuItem -> + when (menuItem.itemId) { + R.id.action_move_up -> { + viewModel.onAction(site, menuClick.type, Action.MOVE_UP) + true + } + R.id.action_move_down -> { + viewModel.onAction(site, menuClick.type, Action.MOVE_DOWN) + true + } + R.id.action_remove -> { + viewModel.onAction(site, menuClick.type, Action.REMOVE) + true + } + else -> { + false } } - popup.show() } - }) + true + } } private fun updateInsights(statsState: List) { @@ -359,4 +360,10 @@ fun StatsGranularity.toStatsTimeFrame(): StatsTimeframe { } } -data class MenuClick(val view: View, val type: StatsTypes, val showUpAction: Boolean, val showDownAction: Boolean) +data class MenuClick( + val view: View, + val type: StatsTypes, + var showUpAction: Boolean = true, + var showDownAction: Boolean = true +) : + Event() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index 422d0418e28d..55b49316fd8b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -3,8 +3,9 @@ package org.wordpress.android.ui.stats.refresh.lists import android.arch.lifecycle.LiveData import android.support.annotation.StringRes import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.launch import org.wordpress.android.R -import org.wordpress.android.fluxc.store.stats.StatsStore +import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes import org.wordpress.android.viewmodel.ScopedViewModel @@ -31,15 +32,14 @@ abstract class StatsListViewModel(defaultDispatcher: CoroutineDispatcher, privat super.onCleared() } - fun onMoveDownClick(type: StatsTypes) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + fun onAction(site: SiteModel, type: StatsTypes, action: Action) { + launch { + statsUseCase.onAction(site, type, action) + statsUseCase.refreshTypes(site) + } } - fun onMoveUpClick(type: StatsTypes) { - TODO() - } - - fun onRemoveClick(type: StatsTypes) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + enum class Action { + MOVE_DOWN, MOVE_UP, REMOVE } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt index f73c4fffecf1..3b48056818ca 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt @@ -10,6 +10,7 @@ import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.Error import org.wordpress.android.ui.stats.refresh.lists.Loading +import org.wordpress.android.ui.stats.refresh.lists.MenuClick import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget import org.wordpress.android.ui.stats.refresh.lists.StatsBlock import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.State.Data @@ -45,8 +46,8 @@ abstract class BaseStatsUseCase( private val mutableNavigationTarget = MutableLiveData() val navigationTarget: LiveData = mutableNavigationTarget - private val mutableMenuClick = MutableLiveData>() - val menuClick: LiveData> = mutableMenuClick + private val mutableMenuClick = MutableLiveData() + val menuClick: LiveData = mutableMenuClick /** * Fetches data either from a local cache or from remote API @@ -108,7 +109,7 @@ abstract class BaseStatsUseCase( * Trigger this method when the item menu button is clicked */ fun onMenuClick(view: View) { - mutableMenuClick.value = view to type + mutableMenuClick.value = MenuClick(view, type) } /** diff --git a/build.gradle b/build.gradle index 6f2a43aea749..59dec8425d49 100644 --- a/build.gradle +++ b/build.gradle @@ -92,5 +92,5 @@ subprojects { } ext { - fluxCVersion = '9d330335b2f8b2eb909aa967450b523e29baa2b6' + fluxCVersion = 'd4978fd021f7cac8b70724916959e774f2af8b6c' } From fb0daee236625e08271dcbad2ca495d57090f829 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Tue, 22 Jan 2019 16:48:21 +0100 Subject: [PATCH 006/103] Update fluxc with the fix --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 59dec8425d49..8db0647389ef 100644 --- a/build.gradle +++ b/build.gradle @@ -92,5 +92,5 @@ subprojects { } ext { - fluxCVersion = 'd4978fd021f7cac8b70724916959e774f2af8b6c' + fluxCVersion = 'f62c5ff07d807affc9dd1b5f29d9161250e95c43' } From ac253ee7ab5a5689e61bfc13d575bbb645c29bd1 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Tue, 22 Jan 2019 17:09:40 +0100 Subject: [PATCH 007/103] Revert FluxC package changes --- .../org/wordpress/android/ui/stats/refresh/StatsModule.kt | 4 ++-- .../android/ui/stats/refresh/lists/BaseListUseCase.kt | 2 +- .../wordpress/android/ui/stats/refresh/lists/StatsBlock.kt | 2 +- .../android/ui/stats/refresh/lists/StatsListFragment.kt | 2 +- .../android/ui/stats/refresh/lists/StatsListViewModel.kt | 2 +- .../ui/stats/refresh/lists/sections/BaseStatsUseCase.kt | 2 +- .../lists/sections/granular/GranularStatefulUseCase.kt | 2 +- .../lists/sections/granular/GranularStatelessUseCase.kt | 2 +- .../lists/sections/granular/usecases/AuthorsUseCase.kt | 2 +- .../lists/sections/granular/usecases/ClicksUseCase.kt | 2 +- .../lists/sections/granular/usecases/CountryViewsUseCase.kt | 2 +- .../refresh/lists/sections/granular/usecases/DateUseCase.kt | 2 +- .../lists/sections/granular/usecases/OverviewUseCase.kt | 2 +- .../sections/granular/usecases/PostsAndPagesUseCase.kt | 2 +- .../lists/sections/granular/usecases/ReferrersUseCase.kt | 2 +- .../lists/sections/granular/usecases/SearchTermsUseCase.kt | 2 +- .../lists/sections/granular/usecases/VideoPlaysUseCase.kt | 2 +- .../lists/sections/insights/usecases/AllTimeStatsUseCase.kt | 4 ++-- .../lists/sections/insights/usecases/CommentsUseCase.kt | 4 ++-- .../lists/sections/insights/usecases/FollowersUseCase.kt | 4 ++-- .../sections/insights/usecases/LatestPostSummaryUseCase.kt | 4 ++-- .../insights/usecases/MostPopularInsightsUseCase.kt | 4 ++-- .../lists/sections/insights/usecases/PublicizeUseCase.kt | 4 ++-- .../sections/insights/usecases/TagsAndCategoriesUseCase.kt | 4 ++-- .../lists/sections/insights/usecases/TodayStatsUseCase.kt | 4 ++-- .../stats/refresh/lists/viewholders/BaseStatsViewHolder.kt | 6 +++--- .../stats/refresh/lists/viewholders/BlockListViewHolder.kt | 2 +- .../ui/stats/refresh/lists/sections/BaseStatsUseCaseTest.kt | 2 +- .../lists/sections/granular/usecases/AuthorsUseCaseTest.kt | 6 +++--- .../lists/sections/granular/usecases/ClicksUseCaseTest.kt | 6 +++--- .../sections/granular/usecases/CountryViewsUseCaseTest.kt | 6 +++--- .../lists/sections/granular/usecases/OverviewUseCaseTest.kt | 6 +++--- .../sections/granular/usecases/PostsAndPagesUseCaseTest.kt | 6 +++--- .../sections/granular/usecases/ReferrersUseCaseTest.kt | 6 +++--- .../sections/granular/usecases/SearchTermsUseCaseTest.kt | 6 +++--- .../sections/granular/usecases/VideoPlaysUseCaseTest.kt | 6 +++--- .../sections/insights/usecases/AllTimeStatsUseCaseTest.kt | 6 +++--- .../lists/sections/insights/usecases/CommentsUseCaseTest.kt | 6 +++--- .../sections/insights/usecases/FollowersUseCaseTest.kt | 6 +++--- .../insights/usecases/LatestPostSummaryUseCaseTest.kt | 6 +++--- .../insights/usecases/MostPopularInsightsUseCaseTest.kt | 6 +++--- .../sections/insights/usecases/PublicizeUseCaseTest.kt | 6 +++--- .../insights/usecases/TagsAndCategoriesUseCaseTest.kt | 6 +++--- .../sections/insights/usecases/TodayStatsUseCaseTest.kt | 6 +++--- build.gradle | 2 +- 45 files changed, 88 insertions(+), 88 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt index ff9b627bcda4..acfea8d03aa7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt @@ -7,8 +7,8 @@ import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS import org.wordpress.android.fluxc.network.utils.StatsGranularity.MONTHS import org.wordpress.android.fluxc.network.utils.StatsGranularity.WEEKS import org.wordpress.android.fluxc.network.utils.StatsGranularity.YEARS -import org.wordpress.android.fluxc.store.stats.StatsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes +import org.wordpress.android.fluxc.store.StatsStore +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.BaseListUseCase diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt index 39926d2b3a30..d4adfebbe95d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes +import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action.MOVE_DOWN import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action.MOVE_UP diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt index b930acee33a2..695b0d5a3bab 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt @@ -1,6 +1,6 @@ package org.wordpress.android.ui.stats.refresh.lists -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes +import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.BLOCK_LIST import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.EMPTY import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.ERROR diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index d08341ade036..3be935864a52 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -26,7 +26,7 @@ import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS import org.wordpress.android.fluxc.network.utils.StatsGranularity.MONTHS import org.wordpress.android.fluxc.network.utils.StatsGranularity.WEEKS import org.wordpress.android.fluxc.network.utils.StatsGranularity.YEARS -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes +import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.ActivityLauncher import org.wordpress.android.ui.WPWebViewActivity import org.wordpress.android.ui.stats.StatsConstants diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index 55b49316fd8b..0f5006b022c4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.launch import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes +import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.viewmodel.ScopedViewModel abstract class StatsListViewModel(defaultDispatcher: CoroutineDispatcher, private val statsUseCase: BaseListUseCase) : diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt index 3b48056818ca..2a402007b79d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt @@ -6,7 +6,7 @@ import android.view.View import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes +import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.Error import org.wordpress.android.ui.stats.refresh.lists.Loading diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatefulUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatefulUseCase.kt index f104b97fd1d0..6250ab7ea09f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatefulUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatefulUseCase.kt @@ -3,7 +3,7 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.granular import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes +import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatefulUseCase import java.util.Date diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatelessUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatelessUseCase.kt index 910d53d4ec14..216388bdcde0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatelessUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/GranularStatelessUseCase.kt @@ -3,7 +3,7 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.granular import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsTypes +import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase import java.util.Date diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/AuthorsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/AuthorsUseCase.kt index e80a1d684bd9..f1f53e266a71 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/AuthorsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/AuthorsUseCase.kt @@ -7,7 +7,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.AuthorsModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.AUTHORS +import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.AUTHORS import org.wordpress.android.fluxc.store.stats.time.AuthorsStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewAuthors diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ClicksUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ClicksUseCase.kt index 43a751097974..67e237109bd4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ClicksUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ClicksUseCase.kt @@ -7,7 +7,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.ClicksModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.CLICKS +import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.CLICKS import org.wordpress.android.fluxc.store.stats.time.ClicksStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewClicks diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/CountryViewsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/CountryViewsUseCase.kt index c6be6a204c28..b346d48efa0d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/CountryViewsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/CountryViewsUseCase.kt @@ -7,7 +7,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.CountryViewsModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.COUNTRIES +import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.COUNTRIES import org.wordpress.android.fluxc.store.stats.time.CountryViewsStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewCountries diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/DateUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/DateUseCase.kt index 77783651b1e7..e05f05a11500 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/DateUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/DateUseCase.kt @@ -4,7 +4,7 @@ import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R.string import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.DATE +import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.DATE import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.BackgroundInformation diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/OverviewUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/OverviewUseCase.kt index 9e24d2ec9540..fdf5b06cb856 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/OverviewUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/OverviewUseCase.kt @@ -5,7 +5,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.VisitsAndViewsModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.OVERVIEW +import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.OVERVIEW import org.wordpress.android.fluxc.store.stats.time.VisitsAndViewsStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatefulUseCase diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/PostsAndPagesUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/PostsAndPagesUseCase.kt index f7901993aa35..7f339d0cfa8c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/PostsAndPagesUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/PostsAndPagesUseCase.kt @@ -10,7 +10,7 @@ import org.wordpress.android.fluxc.model.stats.time.PostAndPageViewsModel.ViewsT import org.wordpress.android.fluxc.model.stats.time.PostAndPageViewsModel.ViewsType.PAGE import org.wordpress.android.fluxc.model.stats.time.PostAndPageViewsModel.ViewsType.POST import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.POSTS_AND_PAGES +import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.POSTS_AND_PAGES import org.wordpress.android.fluxc.store.stats.time.PostAndPageViewsStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.StatsConstants.ITEM_TYPE_HOME_PAGE diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ReferrersUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ReferrersUseCase.kt index 94358a38630e..ac77ce2164d6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ReferrersUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ReferrersUseCase.kt @@ -7,7 +7,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.ReferrersModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.REFERRERS +import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.REFERRERS import org.wordpress.android.fluxc.store.stats.time.ReferrersStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewReferrers diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/SearchTermsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/SearchTermsUseCase.kt index 6b5741aeb80c..8ddeb3dcdcdc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/SearchTermsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/SearchTermsUseCase.kt @@ -7,7 +7,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.SearchTermsModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.SEARCH_TERMS +import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.SEARCH_TERMS import org.wordpress.android.fluxc.store.stats.time.SearchTermsStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewSearchTerms diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/VideoPlaysUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/VideoPlaysUseCase.kt index 4ff6b00b8c7a..83e04b5a3680 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/VideoPlaysUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/VideoPlaysUseCase.kt @@ -7,7 +7,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.VideoPlaysModel import org.wordpress.android.fluxc.network.utils.StatsGranularity -import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.VIDEOS +import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.VIDEOS import org.wordpress.android.fluxc.store.stats.time.VideoPlaysStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewUrl diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt index 4202d7b14240..9c7f68f18730 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt @@ -4,8 +4,8 @@ import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.InsightsAllTimeModel -import org.wordpress.android.fluxc.store.stats.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.ALL_TIME_STATS +import org.wordpress.android.fluxc.store.InsightsStore +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.ALL_TIME_STATS import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt index 9f4dd2a9e4bf..0332639558cb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt @@ -6,8 +6,8 @@ import org.wordpress.android.R.string import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.CommentsModel -import org.wordpress.android.fluxc.store.stats.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.COMMENTS +import org.wordpress.android.fluxc.store.InsightsStore +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.COMMENTS import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewCommentsStats import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatefulUseCase diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCase.kt index d189832c1fd0..10709e6fd9f6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCase.kt @@ -9,8 +9,8 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.FollowersModel import org.wordpress.android.fluxc.model.stats.FollowersModel.FollowerModel -import org.wordpress.android.fluxc.store.stats.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.FOLLOWERS +import org.wordpress.android.fluxc.store.InsightsStore +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.FOLLOWERS import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.StatsUtilsWrapper import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewFollowersStats diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCase.kt index d2009cd65674..adcd21728f38 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCase.kt @@ -9,8 +9,8 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_LATEST_POST_S import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_LATEST_POST_SUMMARY_VIEW_POST_DETAILS_TAPPED import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.InsightsLatestPostModel -import org.wordpress.android.fluxc.store.stats.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.LATEST_POST_SUMMARY +import org.wordpress.android.fluxc.store.InsightsStore +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.LATEST_POST_SUMMARY import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.AddNewPost import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.SharePost diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt index 9e93e1ee667f..afa1ddef8e73 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt @@ -4,8 +4,8 @@ import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.InsightsMostPopularModel -import org.wordpress.android.fluxc.store.stats.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.MOST_POPULAR_DAY_AND_HOUR +import org.wordpress.android.fluxc.store.InsightsStore +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.MOST_POPULAR_DAY_AND_HOUR import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCase.kt index 96e8e66f8a26..2390d68b5047 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCase.kt @@ -6,8 +6,8 @@ import org.wordpress.android.R.string import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.PublicizeModel -import org.wordpress.android.fluxc.store.stats.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.PUBLICIZE +import org.wordpress.android.fluxc.store.InsightsStore +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.PUBLICIZE import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewPublicizeStats import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCase.kt index fbd74d1d8e18..8f44deb11233 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCase.kt @@ -8,8 +8,8 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.TagsModel import org.wordpress.android.fluxc.model.stats.TagsModel.TagModel -import org.wordpress.android.fluxc.store.stats.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.TAGS_AND_CATEGORIES +import org.wordpress.android.fluxc.store.InsightsStore +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.TAGS_AND_CATEGORIES import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewTag import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget.ViewTagsAndCategoriesStats diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCase.kt index 2b3393834a46..e793cf6ce404 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCase.kt @@ -4,8 +4,8 @@ import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.VisitsModel -import org.wordpress.android.fluxc.store.stats.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.TODAY_STATS +import org.wordpress.android.fluxc.store.InsightsStore +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.TODAY_STATS import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt index 731f78d57b11..af8effe951d0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt @@ -6,9 +6,9 @@ import android.support.v7.widget.RecyclerView.ViewHolder import android.support.v7.widget.StaggeredGridLayoutManager import android.view.LayoutInflater import android.view.ViewGroup -import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.LATEST_POST_SUMMARY -import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.DATE -import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.OVERVIEW +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.LATEST_POST_SUMMARY +import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.DATE +import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.OVERVIEW import org.wordpress.android.ui.stats.refresh.lists.StatsBlock abstract class BaseStatsViewHolder( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt index fdacb332798c..a5843c598467 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt @@ -7,7 +7,7 @@ import android.support.v7.widget.RecyclerView import android.view.ViewGroup import org.wordpress.android.R import org.wordpress.android.R.layout -import org.wordpress.android.fluxc.store.stats.StatsStore.TimeStatsTypes.DATE +import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.DATE import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListAdapter import org.wordpress.android.util.image.ImageManager diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCaseTest.kt index 11053c9c28d9..01c098e60144 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCaseTest.kt @@ -10,7 +10,7 @@ import org.mockito.Mock import org.wordpress.android.BaseUnitTest import org.wordpress.android.R.string import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.stats.StatsStore.InsightsTypes.ALL_TIME_STATS +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.ALL_TIME_STATS import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.Loading diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/AuthorsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/AuthorsUseCaseTest.kt index 4716026d41f4..2a3a014c3de3 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/AuthorsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/AuthorsUseCaseTest.kt @@ -13,9 +13,9 @@ import org.wordpress.android.fluxc.model.stats.time.AuthorsModel import org.wordpress.android.fluxc.model.stats.time.AuthorsModel.Author import org.wordpress.android.fluxc.model.stats.time.AuthorsModel.Post import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.fluxc.store.stats.time.AuthorsStore import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ClicksUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ClicksUseCaseTest.kt index b1a95107738a..7e3446e62694 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ClicksUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ClicksUseCaseTest.kt @@ -13,9 +13,9 @@ import org.wordpress.android.fluxc.model.stats.time.ClicksModel import org.wordpress.android.fluxc.model.stats.time.ClicksModel.Click import org.wordpress.android.fluxc.model.stats.time.ClicksModel.Group import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.fluxc.store.stats.time.ClicksStore import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/CountryViewsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/CountryViewsUseCaseTest.kt index 0d944a7cf1c7..5ce56c1ea372 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/CountryViewsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/CountryViewsUseCaseTest.kt @@ -13,9 +13,9 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.CountryViewsModel import org.wordpress.android.fluxc.model.stats.time.CountryViewsModel.Country import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.fluxc.store.stats.time.CountryViewsStore import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/OverviewUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/OverviewUseCaseTest.kt index 7e53cd57483a..cfc8e950901b 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/OverviewUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/OverviewUseCaseTest.kt @@ -13,9 +13,9 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.VisitsAndViewsModel import org.wordpress.android.fluxc.model.stats.time.VisitsAndViewsModel.PeriodData import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.fluxc.store.stats.time.VisitsAndViewsStore import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/PostsAndPagesUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/PostsAndPagesUseCaseTest.kt index 3c2cd8085c3e..f08b3314fc47 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/PostsAndPagesUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/PostsAndPagesUseCaseTest.kt @@ -15,9 +15,9 @@ import org.wordpress.android.fluxc.model.stats.time.PostAndPageViewsModel.ViewsT import org.wordpress.android.fluxc.model.stats.time.PostAndPageViewsModel.ViewsType.PAGE import org.wordpress.android.fluxc.model.stats.time.PostAndPageViewsModel.ViewsType.POST import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.fluxc.store.stats.time.PostAndPageViewsStore import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ReferrersUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ReferrersUseCaseTest.kt index fb4492f4a6d1..999655a839a7 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ReferrersUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/ReferrersUseCaseTest.kt @@ -13,9 +13,9 @@ import org.wordpress.android.fluxc.model.stats.time.ReferrersModel import org.wordpress.android.fluxc.model.stats.time.ReferrersModel.Group import org.wordpress.android.fluxc.model.stats.time.ReferrersModel.Referrer import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.fluxc.store.stats.time.ReferrersStore import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/SearchTermsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/SearchTermsUseCaseTest.kt index e44d18e66898..1b3252ff33bd 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/SearchTermsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/SearchTermsUseCaseTest.kt @@ -13,9 +13,9 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.SearchTermsModel import org.wordpress.android.fluxc.model.stats.time.SearchTermsModel.SearchTerm import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.fluxc.store.stats.time.SearchTermsStore import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/VideoPlaysUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/VideoPlaysUseCaseTest.kt index ec8ac8358449..96877d4f9d96 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/VideoPlaysUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/usecases/VideoPlaysUseCaseTest.kt @@ -12,9 +12,9 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.VideoPlaysModel import org.wordpress.android.fluxc.model.stats.time.VideoPlaysModel.VideoPlays import org.wordpress.android.fluxc.network.utils.StatsGranularity.DAYS -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.fluxc.store.stats.time.VideoPlaysStore import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt index 90ec4e9d1e0d..e8fce3d9e96e 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt @@ -12,9 +12,9 @@ import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.InsightsAllTimeModel import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.Error diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCaseTest.kt index afb0c0d35b40..5fc194cea2b6 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCaseTest.kt @@ -13,9 +13,9 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.CommentsModel import org.wordpress.android.fluxc.model.stats.CommentsModel.Post import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.Error diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCaseTest.kt index a277b15eb057..08925fb09361 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCaseTest.kt @@ -16,9 +16,9 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.FollowersModel import org.wordpress.android.fluxc.model.stats.FollowersModel.FollowerModel import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.test import org.wordpress.android.ui.stats.StatsUtilsWrapper import org.wordpress.android.ui.stats.refresh.lists.BlockList diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCaseTest.kt index 802bf2a1a8a9..d73ff2a22fe6 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCaseTest.kt @@ -14,9 +14,9 @@ import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.InsightsLatestPostModel import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.Error diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCaseTest.kt index 7e1ee9665293..88e9794cac07 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCaseTest.kt @@ -11,9 +11,9 @@ import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.InsightsMostPopularModel import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.Error diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCaseTest.kt index eb799e239a08..9a4f45b6f36f 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCaseTest.kt @@ -14,9 +14,9 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.PublicizeModel import org.wordpress.android.fluxc.model.stats.PublicizeModel.Service import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.Error diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCaseTest.kt index 5881a0044b08..727a13b6df1f 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCaseTest.kt @@ -14,9 +14,9 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.TagsModel import org.wordpress.android.fluxc.model.stats.TagsModel.TagModel import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.Error diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCaseTest.kt index c5f214174a9f..1facc8da95c9 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCaseTest.kt @@ -11,9 +11,9 @@ import org.wordpress.android.R import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.VisitsModel import org.wordpress.android.fluxc.store.InsightsStore -import org.wordpress.android.fluxc.store.stats.StatsStore.OnStatsFetched -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsError -import org.wordpress.android.fluxc.store.stats.StatsStore.StatsErrorType.GENERIC_ERROR +import org.wordpress.android.fluxc.store.StatsStore.OnStatsFetched +import org.wordpress.android.fluxc.store.StatsStore.StatsError +import org.wordpress.android.fluxc.store.StatsStore.StatsErrorType.GENERIC_ERROR import org.wordpress.android.test import org.wordpress.android.ui.stats.refresh.lists.BlockList import org.wordpress.android.ui.stats.refresh.lists.Error diff --git a/build.gradle b/build.gradle index 8db0647389ef..039f65f63dc3 100644 --- a/build.gradle +++ b/build.gradle @@ -92,5 +92,5 @@ subprojects { } ext { - fluxCVersion = 'f62c5ff07d807affc9dd1b5f29d9161250e95c43' + fluxCVersion = 'ef55aed59e8da89837c277654505a6c93282e5a3' } From 814af3fad53b3695f3e56cd07224e182061034f3 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Tue, 22 Jan 2019 17:16:12 +0100 Subject: [PATCH 008/103] Remove background from an imagebutton --- WordPress/src/main/res/layout/stats_block_title_item.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/res/layout/stats_block_title_item.xml b/WordPress/src/main/res/layout/stats_block_title_item.xml index b6c1634fed01..4ff1df73b702 100644 --- a/WordPress/src/main/res/layout/stats_block_title_item.xml +++ b/WordPress/src/main/res/layout/stats_block_title_item.xml @@ -21,6 +21,7 @@ android:id="@+id/menu" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:background="@color/transparent" android:src="@drawable/ic_ellipsis_vertical_grey_darken_48dp" android:contentDescription="@string/stats_item_settings"/> From 9f66dcc75097377bd9319c0d30c58633f1c9d186 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Wed, 23 Jan 2019 09:07:04 +0100 Subject: [PATCH 009/103] Remove unused import --- .../android/ui/stats/refresh/lists/StatsListFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index 3be935864a52..9cf15d3d2835 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -14,7 +14,6 @@ import android.support.v7.widget.StaggeredGridLayoutManager import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.Toast import dagger.android.support.DaggerFragment import kotlinx.android.synthetic.main.stats_list_fragment.* import org.wordpress.android.R From e3f45f65b3e31d3e1cf0c4a0bee7e47c13ace34a Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Wed, 20 Mar 2019 09:00:42 +0100 Subject: [PATCH 010/103] Update FluxC hash --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4c08624001e2..a042bc5516e3 100644 --- a/build.gradle +++ b/build.gradle @@ -104,5 +104,5 @@ buildScan { } ext { - fluxCVersion = 'b5f72ff5a2e6657ea6cd5301e07d9c3bd42100e2' + fluxCVersion = '1dfb0d15b16cf5c747287bcf580a22419f1ec7be' } From 3c06109c5f65bfb3dfa46b33d73e2800a6412d07 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Wed, 20 Mar 2019 09:47:17 +0100 Subject: [PATCH 011/103] Fixes after merge --- .../android/ui/stats/refresh/StatsModule.kt | 14 ++++++------- .../ui/stats/refresh/lists/BaseListUseCase.kt | 20 ++++++++++--------- .../stats/refresh/lists/StatsListFragment.kt | 13 +++++++----- .../stats/refresh/lists/StatsListViewModel.kt | 10 ++++------ .../lists/sections/BaseStatsUseCase.kt | 2 +- .../insights/usecases/CommentsUseCase.kt | 2 ++ .../usecases/PostingActivityUseCase.kt | 2 +- 7 files changed, 34 insertions(+), 29 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt index 3e2701af9d25..f126ccf256b5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt @@ -168,21 +168,21 @@ class StatsModule { mainDispatcher, statsSiteProvider, useCases, - { statsStore.getInsights() }, + { statsStore.getInsights(statsSiteProvider.siteModel) }, uiModelMapper::mapInsights, - moveTypeUp = { site, type -> + moveTypeUp = { type -> if (type is InsightsTypes) { - statsStore.moveTypeUp(site, type) + statsStore.moveTypeUp(statsSiteProvider.siteModel, type) } }, - moveTypeDown = { site, type -> + moveTypeDown = { type -> if (type is InsightsTypes) { - statsStore.moveTypeDown(site, type) + statsStore.moveTypeDown(statsSiteProvider.siteModel, type) } }, - removeType = { site, type -> + removeType = { type -> if (type is InsightsTypes) { - statsStore.removeType(site, type) + statsStore.removeType(statsSiteProvider.siteModel, type) } } ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt index 9c1578884376..464b6ea3867e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt @@ -7,7 +7,6 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.wordpress.android.R -import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.stats.refresh.NavigationTarget @@ -36,9 +35,9 @@ class BaseListUseCase( private val useCases: List>, private val getStatsTypes: suspend () -> List, private val mapUiModel: (useCaseModels: List, showError: (Int) -> Unit) -> UiModel, - private val moveTypeUp: suspend ((site: SiteModel, type: StatsTypes) -> Unit) = { _, _ -> }, - private val moveTypeDown: suspend ((site: SiteModel, type: StatsTypes) -> Unit) = { _, _ -> }, - private val removeType: suspend ((site: SiteModel, type: StatsTypes) -> Unit) = { _, _ -> } + private val moveTypeUp: suspend ((type: StatsTypes) -> Unit) = {}, + private val moveTypeDown: suspend ((type: StatsTypes) -> Unit) = {}, + private val removeType: suspend ((type: StatsTypes) -> Unit) = {} ) { private val blockListData = combineMap( useCases.associateBy { it.type }.mapValues { entry -> entry.value.liveData } @@ -62,7 +61,10 @@ class BaseListUseCase( useCases.map { it.navigationTarget }, distinct = false ) - val menuClick: LiveData = merge(mergeNotNull(useCases.map { it.menuClick }), data) { click, viewModel: UiModel? -> + val menuClick: LiveData = merge( + mergeNotNull(useCases.map { it.menuClick }), + data + ) { click, viewModel: UiModel? -> val success = viewModel as? Success if (click != null && success != null) { val indexOfBlock = success.data.indexOfFirst { it.statsTypes == click.type } @@ -127,11 +129,11 @@ class BaseListUseCase( mutableListSelected.call() } - suspend fun onAction(site: SiteModel, type: StatsTypes, action: Action) { + suspend fun onAction(type: StatsTypes, action: Action) { when (action) { - MOVE_UP -> moveTypeUp(site, type) - MOVE_DOWN -> moveTypeDown(site, type) - REMOVE -> removeType(site, type) + MOVE_UP -> moveTypeUp(type) + MOVE_DOWN -> moveTypeDown(type) + REMOVE -> removeType(type) } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index e5b02df935ce..717d10f94364 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -20,11 +20,14 @@ import kotlinx.android.synthetic.main.stats_error_view.* import kotlinx.android.synthetic.main.stats_list_fragment.* import org.wordpress.android.R import org.wordpress.android.R.dimen +import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.StatsListItemDecoration +import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.UiModel import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter import org.wordpress.android.ui.stats.refresh.utils.StatsNavigator +import org.wordpress.android.util.Event import org.wordpress.android.util.image.ImageManager import org.wordpress.android.util.observeEvent import javax.inject.Inject @@ -111,10 +114,10 @@ class StatsListFragment : DaggerFragment() { val nonNullActivity = checkNotNull(activity) initializeViews(savedInstanceState) - initializeViewModels(nonNullActivity, savedInstanceState) + initializeViewModels(nonNullActivity) } - private fun initializeViewModels(activity: FragmentActivity, savedInstanceState: Bundle?) { + private fun initializeViewModels(activity: FragmentActivity) { val statsSection = arguments?.getSerializable(typeKey) as StatsSection val viewModelClass = when (statsSection) { @@ -189,15 +192,15 @@ class StatsListFragment : DaggerFragment() { popup.setOnMenuItemClickListener { menuItem -> when (menuItem.itemId) { R.id.action_move_up -> { - viewModel.onAction(site, menuClick.type, Action.MOVE_UP) + viewModel.onAction(menuClick.type, Action.MOVE_UP) true } R.id.action_move_down -> { - viewModel.onAction(site, menuClick.type, Action.MOVE_DOWN) + viewModel.onAction(menuClick.type, Action.MOVE_DOWN) true } R.id.action_remove -> { - viewModel.onAction(site, menuClick.type, Action.REMOVE) + viewModel.onAction(menuClick.type, Action.REMOVE) true } else -> { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index 27c06638b799..afdceabdcf10 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -7,9 +7,9 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlinx.coroutines.launch import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker +import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.DAY_STATS_USE_CASE import org.wordpress.android.ui.stats.refresh.INSIGHTS_USE_CASE @@ -22,8 +22,6 @@ import org.wordpress.android.ui.stats.refresh.utils.StatsDateSelector import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.util.mapNullable import org.wordpress.android.util.throttle -import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.viewmodel.ScopedViewModel import javax.inject.Inject import javax.inject.Named @@ -119,10 +117,10 @@ abstract class StatsListViewModel( class Error(val message: Int = R.string.stats_loading_error) : UiModel() } - fun onAction(site: SiteModel, type: StatsTypes, action: Action) { + fun onAction(type: StatsTypes, action: Action) { launch { - statsUseCase.onAction(site, type, action) - statsUseCase.refreshTypes(site) + statsUseCase.onAction(type, action) + statsUseCase.refreshTypes() } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt index d4938e2feea6..9130631cefa0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt @@ -8,8 +8,8 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext import org.wordpress.android.R import org.wordpress.android.fluxc.store.StatsStore.StatsTypes +import org.wordpress.android.ui.stats.refresh.NavigationTarget import org.wordpress.android.ui.stats.refresh.lists.MenuClick -import org.wordpress.android.ui.stats.refresh.lists.NavigationTarget import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.State.Data import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.State.Empty import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.State.Error diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt index dff43c35c6b3..f9e2261b3e94 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt @@ -5,7 +5,9 @@ import org.wordpress.android.R import org.wordpress.android.R.string import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.stats.CommentsModel +import org.wordpress.android.fluxc.model.stats.LimitMode import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.COMMENTS +import org.wordpress.android.fluxc.store.stats.insights.CommentsStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewCommentsStats import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatefulUseCase diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PostingActivityUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PostingActivityUseCase.kt index e74598851d3b..54a908c3c1e5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PostingActivityUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PostingActivityUseCase.kt @@ -44,7 +44,7 @@ class PostingActivityUseCase override fun buildUiModel(domainModel: PostingActivityModel): List { val items = mutableListOf() - items.add(Title(R.string.stats_insights_posting_activity)) + items.add(Title(R.string.stats_insights_posting_activity, menuAction = this::onMenuClick)) val activityItem = postingActivityMapper.buildActivityItem(domainModel.months, domainModel.max) items.add(activityItem) return items From 72e49e85cb6afeb1546ed767750cd32120cc5315 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Thu, 21 Mar 2019 11:32:27 +0100 Subject: [PATCH 012/103] Extract popup handling into a separate class --- .../android/ui/stats/refresh/StatsModule.kt | 18 +---- .../ui/stats/refresh/lists/BaseListUseCase.kt | 33 +------- .../stats/refresh/lists/StatsListFragment.kt | 39 +--------- .../stats/refresh/lists/StatsListViewModel.kt | 15 ++-- .../lists/sections/BaseStatsUseCase.kt | 11 --- .../insights/usecases/AllTimeStatsUseCase.kt | 20 ++++- .../insights/usecases/CommentsUseCase.kt | 26 +++++-- .../insights/usecases/FollowersUseCase.kt | 17 +++- .../usecases/LatestPostSummaryUseCase.kt | 13 +++- .../usecases/MostPopularInsightsUseCase.kt | 19 ++++- .../usecases/PostingActivityUseCase.kt | 20 ++++- .../insights/usecases/PublicizeUseCase.kt | 19 ++++- .../usecases/TagsAndCategoriesUseCase.kt | 19 ++++- .../insights/usecases/TodayStatsUseCase.kt | 18 ++++- .../refresh/utils/ItemPopupMenuHandler.kt | 78 +++++++++++++++++++ .../usecases/AllTimeStatsUseCaseTest.kt | 5 +- .../insights/usecases/CommentsUseCaseTest.kt | 5 +- .../insights/usecases/FollowersUseCaseTest.kt | 22 +++--- .../usecases/LatestPostSummaryUseCaseTest.kt | 5 +- .../MostPopularInsightsUseCaseTest.kt | 5 +- .../insights/usecases/PublicizeUseCaseTest.kt | 3 + .../usecases/TagsAndCategoriesUseCaseTest.kt | 3 + .../usecases/TodayStatsUseCaseTest.kt | 5 +- 23 files changed, 274 insertions(+), 144 deletions(-) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt index f126ccf256b5..113637c53754 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsModule.kt @@ -11,7 +11,6 @@ import org.wordpress.android.fluxc.network.utils.StatsGranularity.MONTHS import org.wordpress.android.fluxc.network.utils.StatsGranularity.WEEKS import org.wordpress.android.fluxc.network.utils.StatsGranularity.YEARS import org.wordpress.android.fluxc.store.StatsStore -import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.BaseListUseCase @@ -169,22 +168,7 @@ class StatsModule { statsSiteProvider, useCases, { statsStore.getInsights(statsSiteProvider.siteModel) }, - uiModelMapper::mapInsights, - moveTypeUp = { type -> - if (type is InsightsTypes) { - statsStore.moveTypeUp(statsSiteProvider.siteModel, type) - } - }, - moveTypeDown = { type -> - if (type is InsightsTypes) { - statsStore.moveTypeDown(statsSiteProvider.siteModel, type) - } - }, - removeType = { type -> - if (type is InsightsTypes) { - statsStore.removeType(statsSiteProvider.siteModel, type) - } - } + uiModelMapper::mapInsights ) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt index 464b6ea3867e..29c43b9ea92b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt @@ -10,12 +10,7 @@ import org.wordpress.android.R import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.stats.refresh.NavigationTarget -import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action -import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action.MOVE_DOWN -import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action.MOVE_UP -import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action.REMOVE import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.UiModel -import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.UiModel.Success import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.UseCaseModel import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider @@ -24,7 +19,6 @@ import org.wordpress.android.util.PackageUtils import org.wordpress.android.util.combineMap import org.wordpress.android.util.distinct import org.wordpress.android.util.map -import org.wordpress.android.util.merge import org.wordpress.android.util.mergeNotNull import org.wordpress.android.viewmodel.SingleLiveEvent @@ -34,10 +28,7 @@ class BaseListUseCase( private val statsSiteProvider: StatsSiteProvider, private val useCases: List>, private val getStatsTypes: suspend () -> List, - private val mapUiModel: (useCaseModels: List, showError: (Int) -> Unit) -> UiModel, - private val moveTypeUp: suspend ((type: StatsTypes) -> Unit) = {}, - private val moveTypeDown: suspend ((type: StatsTypes) -> Unit) = {}, - private val removeType: suspend ((type: StatsTypes) -> Unit) = {} + private val mapUiModel: (useCaseModels: List, showError: (Int) -> Unit) -> UiModel ) { private val blockListData = combineMap( useCases.associateBy { it.type }.mapValues { entry -> entry.value.liveData } @@ -61,20 +52,6 @@ class BaseListUseCase( useCases.map { it.navigationTarget }, distinct = false ) - val menuClick: LiveData = merge( - mergeNotNull(useCases.map { it.menuClick }), - data - ) { click, viewModel: UiModel? -> - val success = viewModel as? Success - if (click != null && success != null) { - val indexOfBlock = success.data.indexOfFirst { it.statsTypes == click.type } - click.showUpAction = indexOfBlock > 0 - click.showDownAction = indexOfBlock < success.data.size - 1 - click - } else { - null - } - } private val mutableSnackbarMessage = MutableLiveData() val snackbarMessage: LiveData = mutableSnackbarMessage.map { @@ -128,12 +105,4 @@ class BaseListUseCase( fun onListSelected() { mutableListSelected.call() } - - suspend fun onAction(type: StatsTypes, action: Action) { - when (action) { - MOVE_UP -> moveTypeUp(type) - MOVE_DOWN -> moveTypeDown(type) - REMOVE -> removeType(type) - } - } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index 717d10f94364..df877d8d860c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -7,7 +7,6 @@ import android.os.Bundle import android.os.Parcelable import android.support.v4.app.FragmentActivity import android.support.v7.widget.LinearLayoutManager -import android.support.v7.widget.PopupMenu import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView.LayoutManager import android.support.v7.widget.StaggeredGridLayoutManager @@ -20,14 +19,11 @@ import kotlinx.android.synthetic.main.stats_error_view.* import kotlinx.android.synthetic.main.stats_list_fragment.* import org.wordpress.android.R import org.wordpress.android.R.dimen -import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.StatsListItemDecoration -import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.Action import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.UiModel import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter import org.wordpress.android.ui.stats.refresh.utils.StatsNavigator -import org.wordpress.android.util.Event import org.wordpress.android.util.image.ImageManager import org.wordpress.android.util.observeEvent import javax.inject.Inject @@ -182,32 +178,8 @@ class StatsListFragment : DaggerFragment() { viewModel.onListSelected() }) - viewModel.menuClick.observeEvent(this) { menuClick -> - val popup = PopupMenu(activity, menuClick.view) - val popupMenu = popup.menu - popup.inflate(R.menu.menu_stats_item) - popupMenu.findItem(R.id.action_move_up).isVisible = menuClick.showUpAction - popupMenu.findItem(R.id.action_move_down).isVisible = menuClick.showDownAction - popup.show() - popup.setOnMenuItemClickListener { menuItem -> - when (menuItem.itemId) { - R.id.action_move_up -> { - viewModel.onAction(menuClick.type, Action.MOVE_UP) - true - } - R.id.action_move_down -> { - viewModel.onAction(menuClick.type, Action.MOVE_DOWN) - true - } - R.id.action_remove -> { - viewModel.onAction(menuClick.type, Action.REMOVE) - true - } - else -> { - false - } - } - } + viewModel.typeMoved?.observeEvent(this) { + viewModel.onTypeMoved() true } } @@ -228,10 +200,3 @@ class StatsListFragment : DaggerFragment() { layoutManager?.onRestoreInstanceState(recyclerViewState) } } - -data class MenuClick( - val view: View, - val type: StatsTypes, - var showUpAction: Boolean = true, - var showDownAction: Boolean = true -) : Event() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index afdceabdcf10..00d20794df2d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -9,7 +9,6 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker -import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.DAY_STATS_USE_CASE import org.wordpress.android.ui.stats.refresh.INSIGHTS_USE_CASE @@ -18,6 +17,7 @@ import org.wordpress.android.ui.stats.refresh.NavigationTarget import org.wordpress.android.ui.stats.refresh.StatsViewModel.DateSelectorUiModel import org.wordpress.android.ui.stats.refresh.WEEK_STATS_USE_CASE import org.wordpress.android.ui.stats.refresh.YEAR_STATS_USE_CASE +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsDateSelector import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.util.mapNullable @@ -32,7 +32,8 @@ abstract class StatsListViewModel( defaultDispatcher: CoroutineDispatcher, private val statsUseCase: BaseListUseCase, private val analyticsTracker: AnalyticsTrackerWrapper, - private val dateSelector: StatsDateSelector + private val dateSelector: StatsDateSelector, + private val popupMenuHandler: ItemPopupMenuHandler? = null ) : ScopedViewModel(defaultDispatcher) { private var trackJob: Job? = null private var isInitialized = false @@ -57,7 +58,7 @@ abstract class StatsListViewModel( it ?: DateSelectorUiModel(false) } - val menuClick: LiveData = statsUseCase.menuClick + val typeMoved = popupMenuHandler?.typeMoved override fun onCleared() { statsUseCase.onCleared() @@ -117,9 +118,8 @@ abstract class StatsListViewModel( class Error(val message: Int = R.string.stats_loading_error) : UiModel() } - fun onAction(type: StatsTypes, action: Action) { + fun onTypeMoved() { launch { - statsUseCase.onAction(type, action) statsUseCase.refreshTypes() } } @@ -134,8 +134,9 @@ class InsightsListViewModel @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, @Named(INSIGHTS_USE_CASE) private val insightsUseCase: BaseListUseCase, analyticsTracker: AnalyticsTrackerWrapper, - dateSelector: StatsDateSelector -) : StatsListViewModel(mainDispatcher, insightsUseCase, analyticsTracker, dateSelector) + dateSelector: StatsDateSelector, + popupMenuHandler: ItemPopupMenuHandler +) : StatsListViewModel(mainDispatcher, insightsUseCase, analyticsTracker, dateSelector, popupMenuHandler) class YearsListViewModel @Inject constructor( @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt index 9130631cefa0..1fa35c58ec91 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BaseStatsUseCase.kt @@ -3,13 +3,11 @@ package org.wordpress.android.ui.stats.refresh.lists.sections import android.arch.lifecycle.LiveData import android.arch.lifecycle.MediatorLiveData import android.arch.lifecycle.MutableLiveData -import android.view.View import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext import org.wordpress.android.R import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.NavigationTarget -import org.wordpress.android.ui.stats.refresh.lists.MenuClick import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.State.Data import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.State.Empty import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.State.Error @@ -58,8 +56,6 @@ abstract class BaseStatsUseCase( private val mutableNavigationTarget = MutableLiveData() val navigationTarget: LiveData = mutableNavigationTarget - private val mutableMenuClick = MutableLiveData() - val menuClick: LiveData = mutableMenuClick /** * Fetches data either from a local cache or from remote API @@ -123,13 +119,6 @@ abstract class BaseStatsUseCase( uiState.value = newState ?: uiState.value } - /** - * Trigger this method when the item menu button is clicked - */ - fun onMenuClick(view: View) { - mutableMenuClick.value = MenuClick(view, type) - } - /** * Trigger this method when updating only a part of UI state. * @param update function diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt index b885b4a17757..a927d9f3d25e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCase.kt @@ -1,7 +1,9 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases +import android.view.View import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R +import org.wordpress.android.R.string import org.wordpress.android.fluxc.model.stats.InsightsAllTimeModel import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.ALL_TIME_STATS import org.wordpress.android.fluxc.store.stats.insights.AllTimeInsightsStore @@ -11,8 +13,9 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Empty import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ListItemWithIcon import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title -import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter +import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.ui.stats.refresh.utils.toFormattedString import javax.inject.Inject import javax.inject.Named @@ -22,10 +25,15 @@ class AllTimeStatsUseCase @Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher, private val allTimeStore: AllTimeInsightsStore, private val statsSiteProvider: StatsSiteProvider, - private val statsDateFormatter: StatsDateFormatter + private val statsDateFormatter: StatsDateFormatter, + private val popupMenuHandler: ItemPopupMenuHandler ) : StatelessUseCase(ALL_TIME_STATS, mainDispatcher) { override fun buildLoadingItem(): List = listOf(Title(R.string.stats_insights_all_time_stats)) + override fun buildEmptyItem(): List { + return listOf(buildTitle(), Empty()) + } + override suspend fun loadCachedData(): InsightsAllTimeModel? { return allTimeStore.getAllTimeInsights(statsSiteProvider.siteModel) } @@ -49,7 +57,7 @@ class AllTimeStatsUseCase override fun buildUiModel(domainModel: InsightsAllTimeModel): List { val items = mutableListOf() - items.add(Title(R.string.stats_insights_all_time_stats, menuAction = this::onMenuClick)) + items.add(buildTitle()) val hasPosts = domainModel.posts > 0 val hasViews = domainModel.views > 0 @@ -102,4 +110,10 @@ class AllTimeStatsUseCase } return items } + + private fun buildTitle() = Title(string.stats_insights_all_time_stats, menuAction = this::onMenuClick) + + private fun onMenuClick(view: View) { + popupMenuHandler.onMenuClick(view, type) + } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt index f9e2261b3e94..f0309244ba9f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt @@ -1,5 +1,6 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases +import android.view.View import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R import org.wordpress.android.R.string @@ -24,6 +25,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Navig import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.TabsItem import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightUseCaseFactory +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.ui.stats.refresh.utils.toFormattedString import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper @@ -40,7 +42,8 @@ class CommentsUseCase private val commentsStore: CommentsStore, private val statsSiteProvider: StatsSiteProvider, private val analyticsTracker: AnalyticsTrackerWrapper, - private val useCaseMode: UseCaseMode + private val useCaseMode: UseCaseMode, + private val popupMenuHandler: ItemPopupMenuHandler ) : StatefulUseCase(COMMENTS, mainDispatcher, 0) { override suspend fun fetchRemoteData(forced: Boolean): State { val fetchMode = if (useCaseMode == VIEW_ALL) LimitMode.All else LimitMode.Top(BLOCK_ITEM_COUNT) @@ -52,7 +55,8 @@ class CommentsUseCase error != null -> State.Error(error.message ?: error.type.name) model != null && (model.authors.isNotEmpty() || model.posts.isNotEmpty()) -> State.Data( model, - cached = response.cached) + cached = response.cached + ) else -> State.Empty() } } @@ -64,11 +68,15 @@ class CommentsUseCase override fun buildLoadingItem(): List = listOf(Title(R.string.stats_view_comments)) + override fun buildEmptyItem(): List { + return listOf(buildTitle(), Empty()) + } + override fun buildStatefulUiModel(model: CommentsModel, uiState: Int): List { val items = mutableListOf() if (useCaseMode == BLOCK) { - items.add(Title(string.stats_view_comments, menuAction = this::onMenuClick)) + items.add(buildTitle()) } if (model.authors.isNotEmpty() || model.posts.isNotEmpty()) { @@ -99,6 +107,8 @@ class CommentsUseCase return items } + private fun buildTitle() = Title(string.stats_view_comments, menuAction = this::onMenuClick) + private fun buildAuthorsTab(authors: List): List { val mutableItems = mutableListOf() if (authors.isNotEmpty()) { @@ -140,12 +150,17 @@ class CommentsUseCase navigateTo(ViewCommentsStats(selectedTab)) } + private fun onMenuClick(view: View) { + popupMenuHandler.onMenuClick(view, type) + } + class CommentsUseCaseFactory @Inject constructor( @Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher, private val commentsStore: CommentsStore, private val statsSiteProvider: StatsSiteProvider, - private val analyticsTracker: AnalyticsTrackerWrapper + private val analyticsTracker: AnalyticsTrackerWrapper, + private val popupMenuHandler: ItemPopupMenuHandler ) : InsightUseCaseFactory { override fun build(useCaseMode: UseCaseMode) = CommentsUseCase( @@ -153,7 +168,8 @@ class CommentsUseCase commentsStore, statsSiteProvider, analyticsTracker, - useCaseMode + useCaseMode, + popupMenuHandler ) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCase.kt index 6474e75f80e0..34d1ecc7897c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCase.kt @@ -1,5 +1,6 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases +import android.view.View import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.async @@ -34,6 +35,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.TabsI import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightUseCaseFactory import org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases.FollowersUseCase.FollowersUiState +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.viewmodel.ResourceProvider @@ -52,6 +54,7 @@ class FollowersUseCase private val statsUtilsWrapper: StatsUtilsWrapper, private val resourceProvider: ResourceProvider, private val analyticsTracker: AnalyticsTrackerWrapper, + private val popupMenuHandler: ItemPopupMenuHandler, private val useCaseMode: UseCaseMode ) : StatefulUseCase, FollowersUiState>( FOLLOWERS, @@ -119,6 +122,10 @@ class FollowersUseCase override fun buildLoadingItem(): List = listOf(Title(R.string.stats_view_followers)) + override fun buildEmptyItem(): List { + return listOf(buildTitle(), Empty()) + } + override fun buildStatefulUiModel( domainModel: Pair, uiState: FollowersUiState @@ -128,7 +135,7 @@ class FollowersUseCase val items = mutableListOf() if (useCaseMode == BLOCK) { - items.add(Title(string.stats_view_followers, menuAction = this::onMenuClick)) + items.add(buildTitle()) } if (domainModel.first.followers.isNotEmpty() || domainModel.second.followers.isNotEmpty()) { @@ -169,6 +176,8 @@ class FollowersUseCase return items } + private fun buildTitle() = Title(string.stats_view_followers, menuAction = this::onMenuClick) + private fun loadMore() { GlobalScope.launch(bgDispatcher) { val state = fetchData(true, PagedMode(itemsToLoad, true)) @@ -215,6 +224,10 @@ class FollowersUseCase data class FollowersUiState(val selectedTab: Int = 0, val isLoading: Boolean = false) + private fun onMenuClick(view: View) { + popupMenuHandler.onMenuClick(view, type) + } + class FollowersUseCaseFactory @Inject constructor( @Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher, @@ -223,6 +236,7 @@ class FollowersUseCase private val statsSiteProvider: StatsSiteProvider, private val statsUtilsWrapper: StatsUtilsWrapper, private val resourceProvider: ResourceProvider, + private val popupMenuHandler: ItemPopupMenuHandler, private val analyticsTracker: AnalyticsTrackerWrapper ) : InsightUseCaseFactory { override fun build(useCaseMode: UseCaseMode) = @@ -234,6 +248,7 @@ class FollowersUseCase statsUtilsWrapper, resourceProvider, analyticsTracker, + popupMenuHandler, useCaseMode ) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCase.kt index c986393fc760..fc9b7138a93d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCase.kt @@ -1,5 +1,6 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases +import android.view.View import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R import org.wordpress.android.R.string @@ -23,6 +24,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Navig import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ValueItem import org.wordpress.android.ui.stats.refresh.utils.HUNDRED_THOUSAND +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.ui.stats.refresh.utils.toFormattedString import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper @@ -35,7 +37,8 @@ class LatestPostSummaryUseCase private val latestPostStore: LatestPostInsightsStore, private val statsSiteProvider: StatsSiteProvider, private val latestPostSummaryMapper: LatestPostSummaryMapper, - private val analyticsTracker: AnalyticsTrackerWrapper + private val analyticsTracker: AnalyticsTrackerWrapper, + private val popupMenuHandler: ItemPopupMenuHandler ) : StatelessUseCase(LATEST_POST_SUMMARY, mainDispatcher) { override suspend fun loadCachedData(): InsightsLatestPostModel? { return latestPostStore.getLatestPostInsights(statsSiteProvider.siteModel) @@ -67,7 +70,7 @@ class LatestPostSummaryUseCase private fun buildNullableUiModel(domainModel: InsightsLatestPostModel?): MutableList { val items = mutableListOf() - items.add(Title(string.stats_insights_latest_post_summary, menuAction = this::onMenuClick)) + items.add(buildTitle()) items.add(latestPostSummaryMapper.buildMessageItem(domainModel, this::onLinkClicked)) if (domainModel != null && domainModel.hasData()) { items.add( @@ -100,6 +103,8 @@ class LatestPostSummaryUseCase return items } + private fun buildTitle() = Title(string.stats_insights_latest_post_summary, menuAction = this::onMenuClick) + private fun InsightsLatestPostModel.hasData() = this.postViewsCount > 0 || this.postCommentCount > 0 || this.postLikeCount > 0 @@ -154,6 +159,10 @@ class LatestPostSummaryUseCase navigateTo(ViewPost(params.postId, params.postUrl)) } + private fun onMenuClick(view: View) { + popupMenuHandler.onMenuClick(view, type) + } + data class LinkClickParams(val postId: Long, val postUrl: String) data class SharePostParams(val postUrl: String, val postTitle: String) data class ViewMoreParams(val postId: Long, val postTitle: String, val postUrl: String) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt index 6bd94723667e..c939ea1e9a79 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCase.kt @@ -1,16 +1,20 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases +import android.view.View import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R +import org.wordpress.android.R.string import org.wordpress.android.fluxc.model.stats.InsightsMostPopularModel import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.MOST_POPULAR_DAY_AND_HOUR import org.wordpress.android.fluxc.store.stats.insights.MostPopularInsightsStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Empty import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ListItemWithIcon import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title import org.wordpress.android.ui.stats.refresh.utils.DateUtils +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.viewmodel.ResourceProvider import javax.inject.Inject @@ -23,7 +27,8 @@ class MostPopularInsightsUseCase private val mostPopularStore: MostPopularInsightsStore, private val statsSiteProvider: StatsSiteProvider, private val dateUtils: DateUtils, - private val resourceProvider: ResourceProvider + private val resourceProvider: ResourceProvider, + private val popupMenuHandler: ItemPopupMenuHandler ) : StatelessUseCase(MOST_POPULAR_DAY_AND_HOUR, mainDispatcher) { override suspend fun loadCachedData(): InsightsMostPopularModel? { return mostPopularStore.getMostPopularInsights(statsSiteProvider.siteModel) @@ -43,9 +48,13 @@ class MostPopularInsightsUseCase override fun buildLoadingItem(): List = listOf(Title(R.string.stats_insights_popular)) + override fun buildEmptyItem(): List { + return listOf(buildTitle(), Empty()) + } + override fun buildUiModel(domainModel: InsightsMostPopularModel): List { val items = mutableListOf() - items.add(Title(R.string.stats_insights_popular, menuAction = this::onMenuClick)) + items.add(buildTitle()) items.add( ListItemWithIcon( icon = R.drawable.ic_calendar_white_24dp, @@ -70,4 +79,10 @@ class MostPopularInsightsUseCase ) return items } + + private fun buildTitle() = Title(string.stats_insights_popular, menuAction = this::onMenuClick) + + private fun onMenuClick(view: View) { + popupMenuHandler.onMenuClick(view, type) + } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PostingActivityUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PostingActivityUseCase.kt index 54a908c3c1e5..32ca6117dce7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PostingActivityUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PostingActivityUseCase.kt @@ -1,5 +1,6 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases +import android.view.View import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R import org.wordpress.android.fluxc.model.stats.insights.PostingActivityModel @@ -9,7 +10,9 @@ import org.wordpress.android.fluxc.store.stats.insights.PostingActivityStore import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.StatelessUseCase import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Empty import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import java.util.Calendar import javax.inject.Inject @@ -20,9 +23,14 @@ class PostingActivityUseCase @Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher, private val store: PostingActivityStore, private val statsSiteProvider: StatsSiteProvider, - private val postingActivityMapper: PostingActivityMapper + private val postingActivityMapper: PostingActivityMapper, + private val popupMenuHandler: ItemPopupMenuHandler ) : StatelessUseCase(POSTING_ACTIVITY, mainDispatcher) { - override fun buildLoadingItem(): List = listOf(Title(R.string.stats_insights_all_time_stats)) + override fun buildLoadingItem(): List = listOf(Title(R.string.stats_insights_posting_activity)) + + override fun buildEmptyItem(): List { + return listOf(buildTitle(), Empty()) + } override suspend fun loadCachedData(): PostingActivityModel? { return store.getPostingActivity(statsSiteProvider.siteModel, getStartDate(), getEndDate()) @@ -44,12 +52,14 @@ class PostingActivityUseCase override fun buildUiModel(domainModel: PostingActivityModel): List { val items = mutableListOf() - items.add(Title(R.string.stats_insights_posting_activity, menuAction = this::onMenuClick)) + items.add(buildTitle()) val activityItem = postingActivityMapper.buildActivityItem(domainModel.months, domainModel.max) items.add(activityItem) return items } + private fun buildTitle() = Title(R.string.stats_insights_posting_activity, menuAction = this::onMenuClick) + private fun getEndDate(): Day { val endDate = Calendar.getInstance() return Day( @@ -68,4 +78,8 @@ class PostingActivityUseCase startDate.getActualMinimum(Calendar.DAY_OF_MONTH) ) } + + private fun onMenuClick(view: View) { + popupMenuHandler.onMenuClick(view, type) + } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCase.kt index c3eb7196c648..5abaef887398 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCase.kt @@ -1,5 +1,6 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases +import android.view.View import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R import org.wordpress.android.R.string @@ -20,6 +21,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Link import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.NavigationAction import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightUseCaseFactory +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.ServiceMapper import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper @@ -36,6 +38,7 @@ class PublicizeUseCase private val statsSiteProvider: StatsSiteProvider, private val mapper: ServiceMapper, private val analyticsTracker: AnalyticsTrackerWrapper, + private val popupMenuHandler: ItemPopupMenuHandler, private val useCaseMode: UseCaseMode ) : StatelessUseCase(PUBLICIZE, mainDispatcher) { private val itemsToLoad = if (useCaseMode == VIEW_ALL) VIEW_ALL_ITEM_COUNT else BLOCK_ITEM_COUNT @@ -67,11 +70,15 @@ class PublicizeUseCase override fun buildLoadingItem(): List = listOf(Title(R.string.stats_view_publicize)) + override fun buildEmptyItem(): List { + return listOf(buildTitle(), Empty()) + } + override fun buildUiModel(domainModel: PublicizeModel): List { val items = mutableListOf() if (useCaseMode == BLOCK) { - items.add(Title(string.stats_view_publicize, menuAction = this::onMenuClick)) + items.add(buildTitle()) } if (domainModel.services.isEmpty()) { @@ -91,18 +98,25 @@ class PublicizeUseCase return items } + private fun buildTitle() = Title(R.string.stats_view_publicize, menuAction = this::onMenuClick) + private fun onLinkClick() { analyticsTracker.track(AnalyticsTracker.Stat.STATS_PUBLICIZE_VIEW_MORE_TAPPED) return navigateTo(ViewPublicizeStats()) } + private fun onMenuClick(view: View) { + popupMenuHandler.onMenuClick(view, type) + } + class PublicizeUseCaseFactory @Inject constructor( @Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher, private val publicizeStore: PublicizeStore, private val statsSiteProvider: StatsSiteProvider, private val mapper: ServiceMapper, - private val analyticsTracker: AnalyticsTrackerWrapper + private val analyticsTracker: AnalyticsTrackerWrapper, + private val popupMenuHandler: ItemPopupMenuHandler ) : InsightUseCaseFactory { override fun build(useCaseMode: UseCaseMode) = PublicizeUseCase( @@ -111,6 +125,7 @@ class PublicizeUseCase statsSiteProvider, mapper, analyticsTracker, + popupMenuHandler, useCaseMode ) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCase.kt index e1992f69c68e..c59eed254dcf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCase.kt @@ -1,5 +1,6 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases +import android.view.View import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R import org.wordpress.android.R.drawable @@ -28,6 +29,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Navig import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightUseCaseFactory import org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases.TagsAndCategoriesUseCase.TagsAndCategoriesUiState +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.ui.stats.refresh.utils.toFormattedString import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper @@ -45,6 +47,7 @@ class TagsAndCategoriesUseCase private val statsSiteProvider: StatsSiteProvider, private val resourceProvider: ResourceProvider, private val analyticsTracker: AnalyticsTrackerWrapper, + private val popupMenuHandler: ItemPopupMenuHandler, private val useCaseMode: UseCaseMode ) : StatefulUseCase( TAGS_AND_CATEGORIES, @@ -71,11 +74,15 @@ class TagsAndCategoriesUseCase override fun buildLoadingItem(): List = listOf(Title(R.string.stats_insights_tags_and_categories)) + override fun buildEmptyItem(): List { + return listOf(buildTitle(), Empty()) + } + override fun buildStatefulUiModel(domainModel: TagsModel, uiState: TagsAndCategoriesUiState): List { val items = mutableListOf() if (useCaseMode == BLOCK) { - items.add(Title(R.string.stats_insights_tags_and_categories, menuAction = this::onMenuClick)) + items.add(buildTitle()) } if (domainModel.tags.isEmpty()) { @@ -122,6 +129,8 @@ class TagsAndCategoriesUseCase return items } + private fun buildTitle() = Title(string.stats_insights_tags_and_categories, menuAction = this::onMenuClick) + private fun areTagsEqual(tagA: TagModel, tagB: TagModel?): Boolean { return tagA.items == tagB?.items && tagA.views == tagB.views } @@ -175,6 +184,10 @@ class TagsAndCategoriesUseCase navigateTo(ViewTag(link)) } + private fun onMenuClick(view: View) { + popupMenuHandler.onMenuClick(view, type) + } + data class TagsAndCategoriesUiState(val expandedTag: TagModel? = null) class TagsAndCategoriesUseCaseFactory @@ -183,7 +196,8 @@ class TagsAndCategoriesUseCase private val tagsStore: TagsStore, private val statsSiteProvider: StatsSiteProvider, private val resourceProvider: ResourceProvider, - private val analyticsTracker: AnalyticsTrackerWrapper + private val analyticsTracker: AnalyticsTrackerWrapper, + private val popupMenuHandler: ItemPopupMenuHandler ) : InsightUseCaseFactory { override fun build(useCaseMode: UseCaseMode) = TagsAndCategoriesUseCase( @@ -192,6 +206,7 @@ class TagsAndCategoriesUseCase statsSiteProvider, resourceProvider, analyticsTracker, + popupMenuHandler, useCaseMode ) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCase.kt index b89f326ad947..4268eb16c1eb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCase.kt @@ -1,7 +1,9 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases +import android.view.View import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.R +import org.wordpress.android.R.string import org.wordpress.android.fluxc.model.stats.VisitsModel import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.TODAY_STATS import org.wordpress.android.fluxc.store.stats.insights.TodayInsightsStore @@ -11,6 +13,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Empty import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ListItemWithIcon import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.ui.stats.refresh.utils.toFormattedString import javax.inject.Inject @@ -20,7 +23,8 @@ class TodayStatsUseCase @Inject constructor( @Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher, private val todayStore: TodayInsightsStore, - private val statsSiteProvider: StatsSiteProvider + private val statsSiteProvider: StatsSiteProvider, + private val popupMenuHandler: ItemPopupMenuHandler ) : StatelessUseCase(TODAY_STATS, mainDispatcher) { override suspend fun loadCachedData(): VisitsModel? { return todayStore.getTodayInsights(statsSiteProvider.siteModel) @@ -43,9 +47,13 @@ class TodayStatsUseCase override fun buildLoadingItem(): List = listOf(Title(R.string.stats_insights_today_stats)) + override fun buildEmptyItem(): List { + return listOf(buildTitle(), Empty()) + } + override fun buildUiModel(domainModel: VisitsModel): List { val items = mutableListOf() - items.add(Title(R.string.stats_insights_today_stats, menuAction = this::onMenuClick)) + items.add(buildTitle()) val hasViews = domainModel.views > 0 val hasVisitors = domainModel.visitors > 0 @@ -97,4 +105,10 @@ class TodayStatsUseCase } return items } + + private fun onMenuClick(view: View) { + popupMenuHandler.onMenuClick(view, type) + } + + private fun buildTitle() = Title(string.stats_insights_today_stats, menuAction = this::onMenuClick) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt new file mode 100644 index 000000000000..4cd6a7a70920 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt @@ -0,0 +1,78 @@ +package org.wordpress.android.ui.stats.refresh.utils + +import android.arch.lifecycle.LiveData +import android.arch.lifecycle.MutableLiveData +import android.support.v7.widget.PopupMenu +import android.view.View +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import org.wordpress.android.R +import org.wordpress.android.fluxc.store.StatsStore +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes +import org.wordpress.android.fluxc.store.StatsStore.StatsTypes +import org.wordpress.android.modules.BG_THREAD +import org.wordpress.android.modules.UI_THREAD +import org.wordpress.android.util.Event +import javax.inject.Inject +import javax.inject.Named +import javax.inject.Singleton + +@Singleton +class ItemPopupMenuHandler +@Inject constructor( + @Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher, + @Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher, + private val statsStore: StatsStore, + private val statsSiteProvider: StatsSiteProvider +) { + private val mutableTypeMoved = MutableLiveData() + val typeMoved: LiveData = mutableTypeMoved + fun onMenuClick(view: View, statsType: StatsTypes) { + GlobalScope.launch(bgDispatcher) { + val type = statsType as InsightsTypes + val insights = statsStore.getInsights(statsSiteProvider.siteModel) + + val indexOfBlock = insights.indexOfFirst { it == type } + val showUpAction = indexOfBlock > 0 + val showDownAction = indexOfBlock < insights.size - 1 + withContext(mainDispatcher) { + val popup = PopupMenu(view.context, view) + val popupMenu = popup.menu + popup.inflate(R.menu.menu_stats_item) + popupMenu.findItem(R.id.action_move_up).isVisible = showUpAction + popupMenu.findItem(R.id.action_move_down).isVisible = showDownAction + popup.show() + popup.setOnMenuItemClickListener { menuItem -> + when (menuItem.itemId) { + R.id.action_move_up -> { + GlobalScope.launch(bgDispatcher) { + statsStore.moveTypeUp(statsSiteProvider.siteModel, type) + mutableTypeMoved.postValue(TypeChangeEvent(type)) + } + true + } + R.id.action_move_down -> { + GlobalScope.launch(bgDispatcher) { + statsStore.moveTypeDown(statsSiteProvider.siteModel, type) + mutableTypeMoved.postValue(TypeChangeEvent(type)) + } + true + } + R.id.action_remove -> { + GlobalScope.launch(bgDispatcher) { + statsStore.removeType(statsSiteProvider.siteModel, type) + mutableTypeMoved.postValue(TypeChangeEvent(type)) + } + true + } + else -> false + } + } + } + } + } + + data class TypeChangeEvent(val types: StatsTypes) : Event() +} diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt index b4ca9fd06635..64276a608bc3 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/AllTimeStatsUseCaseTest.kt @@ -23,6 +23,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.Us import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Empty import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ListItemWithIcon import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider @@ -30,6 +31,7 @@ class AllTimeStatsUseCaseTest : BaseUnitTest() { @Mock lateinit var insightsStore: AllTimeInsightsStore @Mock lateinit var statsDateFormatter: StatsDateFormatter @Mock lateinit var statsSiteProvider: StatsSiteProvider + @Mock lateinit var popupMenuHandler: ItemPopupMenuHandler @Mock lateinit var site: SiteModel private lateinit var useCase: AllTimeStatsUseCase private val bestDay = "2018-11-25" @@ -40,7 +42,8 @@ class AllTimeStatsUseCaseTest : BaseUnitTest() { Dispatchers.Unconfined, insightsStore, statsSiteProvider, - statsDateFormatter + statsDateFormatter, + popupMenuHandler ) whenever(statsSiteProvider.siteModel).thenReturn(site) } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCaseTest.kt index 50626e03b46d..41420d60b7d7 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCaseTest.kt @@ -36,6 +36,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type. import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM_WITH_ICON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.TITLE +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper @@ -44,6 +45,7 @@ class CommentsUseCaseTest : BaseUnitTest() { @Mock lateinit var statsSiteProvider: StatsSiteProvider @Mock lateinit var site: SiteModel @Mock lateinit var tracker: AnalyticsTrackerWrapper + @Mock lateinit var popupMenuHandler: ItemPopupMenuHandler private lateinit var useCase: CommentsUseCase private val postId: Long = 10 private val postTitle = "Post" @@ -59,7 +61,8 @@ class CommentsUseCaseTest : BaseUnitTest() { insightsStore, statsSiteProvider, tracker, - BLOCK + BLOCK, + popupMenuHandler ) whenever(statsSiteProvider.siteModel).thenReturn(site) } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCaseTest.kt index 00782dc473a4..e37af56fb042 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/FollowersUseCaseTest.kt @@ -36,6 +36,8 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Loadi import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.TabsItem import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.TITLE +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.usecases.FollowersUseCase.FollowersUseCaseFactory +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.viewmodel.ResourceProvider @@ -48,6 +50,8 @@ class FollowersUseCaseTest : BaseUnitTest() { @Mock lateinit var statsSiteProvider: StatsSiteProvider @Mock lateinit var site: SiteModel @Mock lateinit var tracker: AnalyticsTrackerWrapper + @Mock lateinit var popupMenuHandler: ItemPopupMenuHandler + private lateinit var useCaseFactory: FollowersUseCaseFactory private lateinit var useCase: FollowersUseCase private val avatar = "avatar.jpg" private val user = "John Smith" @@ -64,16 +68,17 @@ class FollowersUseCaseTest : BaseUnitTest() { val message = "Total followers count is 50" @Before fun setUp() { - useCase = FollowersUseCase( + useCaseFactory = FollowersUseCaseFactory( Dispatchers.Unconfined, Dispatchers.Unconfined, insightsStore, statsSiteProvider, statsUtilsWrapper, resourceProvider, - tracker, - BLOCK + popupMenuHandler, + tracker ) + useCase = useCaseFactory.build(BLOCK) whenever(statsUtilsWrapper.getSinceLabelLowerCase(dateSubscribed)).thenReturn(sinceLabel) whenever(resourceProvider.getString(any())).thenReturn(wordPressLabel) whenever(resourceProvider.getString(eq(R.string.stats_followers_count_message), any(), any())).thenReturn( @@ -234,16 +239,7 @@ class FollowersUseCaseTest : BaseUnitTest() { @Test fun `maps email followers to UI model in the view all mode`() = test { - useCase = FollowersUseCase( - Dispatchers.Unconfined, - Dispatchers.Unconfined, - insightsStore, - statsSiteProvider, - statsUtilsWrapper, - resourceProvider, - tracker, - VIEW_ALL - ) + useCase = useCaseFactory.build(VIEW_ALL) val refresh = true val wpComModel = FollowersModel( diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCaseTest.kt index 2638e81f22d4..d1357e29057f 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/LatestPostSummaryUseCaseTest.kt @@ -29,6 +29,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ListI import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Text import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ValueItem +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import java.util.Date @@ -39,6 +40,7 @@ class LatestPostSummaryUseCaseTest : BaseUnitTest() { @Mock lateinit var statsSiteProvider: StatsSiteProvider @Mock lateinit var site: SiteModel @Mock lateinit var tracker: AnalyticsTrackerWrapper + @Mock lateinit var popupMenuHandler: ItemPopupMenuHandler private lateinit var useCase: LatestPostSummaryUseCase @Before fun setUp() = test { @@ -47,7 +49,8 @@ class LatestPostSummaryUseCaseTest : BaseUnitTest() { insightsStore, statsSiteProvider, latestPostSummaryMapper, - tracker + tracker, + popupMenuHandler ) whenever(statsSiteProvider.siteModel).thenReturn(site) useCase.navigationTarget.observeForever {} diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCaseTest.kt index 980e5252169d..05f4833e86e4 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/MostPopularInsightsUseCaseTest.kt @@ -23,6 +23,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM_WITH_ICON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.TITLE import org.wordpress.android.ui.stats.refresh.utils.DateUtils +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.viewmodel.ResourceProvider import kotlin.math.roundToInt @@ -33,6 +34,7 @@ class MostPopularInsightsUseCaseTest : BaseUnitTest() { @Mock lateinit var site: SiteModel @Mock lateinit var dateUtils: DateUtils @Mock lateinit var resourceProvider: ResourceProvider + @Mock lateinit var popupMenuHandler: ItemPopupMenuHandler private lateinit var useCase: MostPopularInsightsUseCase private val day = 2 private val highestDayPercent = 15.0 @@ -47,7 +49,8 @@ class MostPopularInsightsUseCaseTest : BaseUnitTest() { insightsStore, statsSiteProvider, dateUtils, - resourceProvider + resourceProvider, + popupMenuHandler ) whenever(statsSiteProvider.siteModel).thenReturn(site) whenever(dateUtils.getWeekDay(day)).thenReturn(dayString) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCaseTest.kt index 7fcebe831534..52520000cb52 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/PublicizeUseCaseTest.kt @@ -29,6 +29,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ListI import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LINK import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.TITLE +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.ServiceMapper import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper @@ -39,6 +40,7 @@ class PublicizeUseCaseTest : BaseUnitTest() { @Mock lateinit var site: SiteModel @Mock lateinit var serviceMapper: ServiceMapper @Mock lateinit var tracker: AnalyticsTrackerWrapper + @Mock lateinit var popupMenuHandler: ItemPopupMenuHandler private lateinit var useCase: PublicizeUseCase private val itemsToLoad = 6 private val limitMode = LimitMode.Top(itemsToLoad) @@ -50,6 +52,7 @@ class PublicizeUseCaseTest : BaseUnitTest() { statsSiteProvider, serviceMapper, tracker, + popupMenuHandler, BLOCK ) whenever(statsSiteProvider.siteModel).thenReturn(site) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCaseTest.kt index dbfdb7f017af..b3df05e2bde4 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TagsAndCategoriesUseCaseTest.kt @@ -34,6 +34,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type. import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LINK import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM_WITH_ICON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.TITLE +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.viewmodel.ResourceProvider @@ -44,6 +45,7 @@ class TagsAndCategoriesUseCaseTest : BaseUnitTest() { @Mock lateinit var site: SiteModel @Mock lateinit var resourceProvider: ResourceProvider @Mock lateinit var tracker: AnalyticsTrackerWrapper + @Mock lateinit var popupMenuHandler: ItemPopupMenuHandler private lateinit var useCase: TagsAndCategoriesUseCase private val blockItemCount = 6 private val singleTagViews: Long = 10 @@ -59,6 +61,7 @@ class TagsAndCategoriesUseCaseTest : BaseUnitTest() { statsSiteProvider, resourceProvider, tracker, + popupMenuHandler, BLOCK ) whenever(statsSiteProvider.siteModel).thenReturn(site) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCaseTest.kt index 2f2bd9287148..62ec8b61fabb 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/TodayStatsUseCaseTest.kt @@ -23,11 +23,13 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ListI import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM_WITH_ICON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.TITLE +import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider class TodayStatsUseCaseTest : BaseUnitTest() { @Mock lateinit var insightsStore: TodayInsightsStore @Mock lateinit var statsSiteProvider: StatsSiteProvider + @Mock lateinit var popupMenuHandler: ItemPopupMenuHandler @Mock lateinit var site: SiteModel private lateinit var useCase: TodayStatsUseCase private val views = 10 @@ -39,7 +41,8 @@ class TodayStatsUseCaseTest : BaseUnitTest() { useCase = TodayStatsUseCase( Dispatchers.Unconfined, insightsStore, - statsSiteProvider + statsSiteProvider, + popupMenuHandler ) whenever(statsSiteProvider.siteModel).thenReturn(site) } From 8bb04997f4bf981307144566bb66e65c181f0c3a Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Thu, 21 Mar 2019 11:40:20 +0100 Subject: [PATCH 013/103] Removee unused code and fix lint issue --- .../ui/stats/refresh/lists/StatsListViewModel.kt | 4 ---- .../sections/insights/usecases/CommentsUseCase.kt | 10 +++++----- .../sections/insights/usecases/CommentsUseCaseTest.kt | 4 ++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index 00d20794df2d..10d4753c9c37 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -123,10 +123,6 @@ abstract class StatsListViewModel( statsUseCase.refreshTypes() } } - - enum class Action { - MOVE_DOWN, MOVE_UP, REMOVE - } } class InsightsListViewModel diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt index f0309244ba9f..29195d0506b1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCase.kt @@ -42,8 +42,8 @@ class CommentsUseCase private val commentsStore: CommentsStore, private val statsSiteProvider: StatsSiteProvider, private val analyticsTracker: AnalyticsTrackerWrapper, - private val useCaseMode: UseCaseMode, - private val popupMenuHandler: ItemPopupMenuHandler + private val popupMenuHandler: ItemPopupMenuHandler, + private val useCaseMode: UseCaseMode ) : StatefulUseCase(COMMENTS, mainDispatcher, 0) { override suspend fun fetchRemoteData(forced: Boolean): State { val fetchMode = if (useCaseMode == VIEW_ALL) LimitMode.All else LimitMode.Top(BLOCK_ITEM_COUNT) @@ -160,7 +160,7 @@ class CommentsUseCase private val commentsStore: CommentsStore, private val statsSiteProvider: StatsSiteProvider, private val analyticsTracker: AnalyticsTrackerWrapper, - private val popupMenuHandler: ItemPopupMenuHandler + private val popupMenuHandler: ItemPopupMenuHandler ) : InsightUseCaseFactory { override fun build(useCaseMode: UseCaseMode) = CommentsUseCase( @@ -168,8 +168,8 @@ class CommentsUseCase commentsStore, statsSiteProvider, analyticsTracker, - useCaseMode, - popupMenuHandler + popupMenuHandler, + useCaseMode ) } } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCaseTest.kt index 41420d60b7d7..38a1cfbfa2b6 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/usecases/CommentsUseCaseTest.kt @@ -61,8 +61,8 @@ class CommentsUseCaseTest : BaseUnitTest() { insightsStore, statsSiteProvider, tracker, - BLOCK, - popupMenuHandler + popupMenuHandler, + BLOCK ) whenever(statsSiteProvider.siteModel).thenReturn(site) } From bcdeddeb15352483e29e56c595c97cabd80b01ff Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Thu, 21 Mar 2019 12:31:49 +0100 Subject: [PATCH 014/103] Move the StatsListItemDecoration to the lists package --- .../android/ui/stats/refresh/lists/StatsListFragment.kt | 1 - .../ui/stats/refresh/{ => lists}/StatsListItemDecoration.kt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) rename WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/{ => lists}/StatsListItemDecoration.kt (95%) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index df877d8d860c..218354211c6a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -19,7 +19,6 @@ import kotlinx.android.synthetic.main.stats_error_view.* import kotlinx.android.synthetic.main.stats_list_fragment.* import org.wordpress.android.R import org.wordpress.android.R.dimen -import org.wordpress.android.ui.stats.refresh.StatsListItemDecoration import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.UiModel import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsListItemDecoration.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListItemDecoration.kt similarity index 95% rename from WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsListItemDecoration.kt rename to WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListItemDecoration.kt index ad26320b52ee..10fdf97ff384 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsListItemDecoration.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListItemDecoration.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.stats.refresh +package org.wordpress.android.ui.stats.refresh.lists import android.graphics.Rect import android.support.v7.widget.RecyclerView From a13459192b66bfbc2adacd029fda6a58d03dd425 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Thu, 21 Mar 2019 14:11:33 +0100 Subject: [PATCH 015/103] Reduce number of requests on insights screen --- .../ui/stats/refresh/lists/BaseListUseCase.kt | 16 +++++++++++----- .../refresh/lists/StatsBlockDiffCallback.kt | 3 +-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt index 29c43b9ea92b..4cddd61baf0f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt @@ -34,8 +34,8 @@ class BaseListUseCase( useCases.associateBy { it.type }.mapValues { entry -> entry.value.liveData } ) private val statsTypes = DistinctMutableLiveData>(listOf()) - val data: MediatorLiveData = mergeNotNull(statsTypes, blockListData) { insights, map -> - insights.mapNotNull { + val data: MediatorLiveData = mergeNotNull(statsTypes, blockListData) { types, map -> + types.mapNotNull { if (map.containsKey(it)) { map[it] } else { @@ -69,11 +69,12 @@ class BaseListUseCase( loadData(true, forced) } - suspend fun refreshTypes() { + suspend fun refreshTypes(): List { val items = getStatsTypes() withContext(mainDispatcher) { statsTypes.value = items } + return items } private suspend fun loadData(refresh: Boolean, forced: Boolean) { @@ -82,8 +83,13 @@ class BaseListUseCase( if (PackageUtils.isDebugBuild() && useCases.distinctBy { it.type }.size < useCases.size) { throw RuntimeException("Duplicate stats type in a use case") } - useCases.forEach { block -> launch { block.fetch(refresh, forced) } } - refreshTypes() + val visibleTypes = refreshTypes() + visibleTypes.forEach { type -> + useCases.find { it.type == type } + ?.let { block -> launch(bgDispatcher) { + block.fetch(refresh, forced) } + } + } } } else { mutableSnackbarMessage.value = R.string.stats_site_not_loaded_yet diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockDiffCallback.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockDiffCallback.kt index 16c949f8c8fc..af10b9d3118d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockDiffCallback.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockDiffCallback.kt @@ -1,7 +1,6 @@ package org.wordpress.android.ui.stats.refresh.lists import android.support.v7.util.DiffUtil.Callback -import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Success class StatsBlockDiffCallback( private val oldList: List, @@ -30,7 +29,7 @@ class StatsBlockDiffCallback( override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { val newItem = newList[newItemPosition] val oldItem = oldList[oldItemPosition] - if (oldItem is Success && newItem is Success) { + if (oldItem.type == newItem.type) { return Payload } return null From 33f5d8e8e59613d1f42e12143224b85e42475e4f Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Thu, 21 Mar 2019 16:36:43 +0100 Subject: [PATCH 016/103] Fix the throttle method in utils --- .../src/main/java/org/wordpress/android/util/LiveDataUtils.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/util/LiveDataUtils.kt b/WordPress/src/main/java/org/wordpress/android/util/LiveDataUtils.kt index b036b1270a95..84c9d8805982 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LiveDataUtils.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LiveDataUtils.kt @@ -204,8 +204,8 @@ fun LiveData.throttle( ): ThrottleLiveData { val mediatorLiveData: ThrottleLiveData = ThrottleLiveData(coroutineScope = coroutineScope, offset = offset) mediatorLiveData.addSource(this) { - if (it != mediatorLiveData.value || !distinct) { - mediatorLiveData.value = it + if ((it != mediatorLiveData.value || !distinct) && it != null) { + mediatorLiveData.postValue(it) } } return mediatorLiveData From fbfc384525fe8edd577f56015332f5f7310bf561 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Fri, 22 Mar 2019 09:28:26 +0100 Subject: [PATCH 017/103] Update FluxC version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c79187da8f28..ed8af793e12e 100644 --- a/build.gradle +++ b/build.gradle @@ -104,5 +104,5 @@ buildScan { } ext { - fluxCVersion = '8c78b7cb3c3960525a34d8af9125ca261cf50977' + fluxCVersion = 'e049ac97ac54f371aef152de5e02b1dc2eb32f82' } From 0f3de5bd04f60d66ab979aae2ac409d2f60bef7d Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Fri, 22 Mar 2019 09:45:26 +0100 Subject: [PATCH 018/103] Fix scroll issue in insights --- .../ui/stats/refresh/lists/sections/BlockListAdapter.kt | 6 +++--- WordPress/src/main/res/layout/stats_list_fragment.xml | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListAdapter.kt index b709a1fa71c6..9f5d045d855d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListAdapter.kt @@ -20,8 +20,8 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ListI import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ListItemWithIcon import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.LoadingItem import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.MapItem -import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ReferredItem import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.QuickScanItem +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ReferredItem import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.TabsItem import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Text import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Title @@ -39,8 +39,8 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type. import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM_WITH_ICON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LOADING_ITEM import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.MAP -import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.REFERRED_ITEM import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.QUICK_SCAN_ITEM +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.REFERRED_ITEM import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.TABS import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.TEXT import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.TITLE @@ -62,8 +62,8 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.ListIte import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.ListItemWithIconViewHolder import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.LoadingItemViewHolder import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.MapViewHolder -import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.ReferredItemViewHolder import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.QuickScanItemViewHolder +import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.ReferredItemViewHolder import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.TabsViewHolder import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.TextViewHolder import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.TitleViewHolder diff --git a/WordPress/src/main/res/layout/stats_list_fragment.xml b/WordPress/src/main/res/layout/stats_list_fragment.xml index a6c6c4e3db2c..5b30ad47a550 100644 --- a/WordPress/src/main/res/layout/stats_list_fragment.xml +++ b/WordPress/src/main/res/layout/stats_list_fragment.xml @@ -32,6 +32,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:clipToPadding="false" + android:descendantFocusability="beforeDescendants" android:scrollbars="vertical"/> @@ -39,6 +40,7 @@ android:id="@+id/recyclerView" style="@style/StatsList" android:clipToPadding="false" + android:descendantFocusability="beforeDescendants" android:scrollbars="vertical"/> From 38b5a14b01e68fa41f89ebe11bef475b2fcad63e Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 22 Mar 2019 12:07:16 +0100 Subject: [PATCH 019/103] Add new Insights management activity --- WordPress/src/main/AndroidManifest.xml | 6 +++- .../management/InsightsManagementActivity.kt | 30 +++++++++++++++++++ .../layout/insights_management_activity.xml | 17 +++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementActivity.kt create mode 100644 WordPress/src/main/res/layout/insights_management_activity.xml diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index 0ebf3554f775..60c471f30c52 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -288,9 +288,13 @@ android:theme="@style/Calypso.NoActionBar" /> + diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementActivity.kt new file mode 100644 index 000000000000..db70cc224060 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementActivity.kt @@ -0,0 +1,30 @@ +package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management + +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import android.view.MenuItem +import kotlinx.android.synthetic.main.toolbar.* +import org.wordpress.android.R + +class InsightsManagementActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContentView(R.layout.insights_management_activity) + + setSupportActionBar(toolbar) + supportActionBar?.let { + it.setHomeButtonEnabled(true) + it.setDisplayHomeAsUpEnabled(true) + it.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp) + } + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == android.R.id.home) { + onBackPressed() + return true + } + return super.onOptionsItemSelected(item) + } +} diff --git a/WordPress/src/main/res/layout/insights_management_activity.xml b/WordPress/src/main/res/layout/insights_management_activity.xml new file mode 100644 index 000000000000..7d722b665fb8 --- /dev/null +++ b/WordPress/src/main/res/layout/insights_management_activity.xml @@ -0,0 +1,17 @@ + + + + + + + + From 48bc11acfdb1e5dd5b88f13d4da948a2b7d647be Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 22 Mar 2019 12:07:34 +0100 Subject: [PATCH 020/103] Add the Inisghts Management fragment --- .../management/InsightsManagementFragment.kt | 58 +++++++++++++++++++ .../layout/insights_management_fragment.xml | 14 +++++ 2 files changed, 72 insertions(+) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt create mode 100644 WordPress/src/main/res/layout/insights_management_fragment.xml diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt new file mode 100644 index 000000000000..d68a15728b76 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -0,0 +1,58 @@ +package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management + +import android.arch.lifecycle.Observer +import android.arch.lifecycle.ViewModelProvider +import android.arch.lifecycle.ViewModelProviders +import android.os.Bundle +import android.support.design.widget.Snackbar +import android.support.v4.app.FragmentActivity +import android.support.v7.widget.LinearLayoutManager +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import dagger.android.support.DaggerFragment +import kotlinx.android.synthetic.main.insights_management_fragment.* +import org.wordpress.android.R +import javax.inject.Inject + +class InsightsManagementFragment : DaggerFragment() { + @Inject lateinit var viewModelFactory: ViewModelProvider.Factory + private lateinit var viewModel: InsightsManagementViewModel + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.insights_management_fragment, container, false) + } + + private fun initializeViews() { + removedInsights.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val nonNullActivity = checkNotNull(activity) + + initializeViews() + initializeViewModels(nonNullActivity) + } + + private fun initializeViewModels(activity: FragmentActivity) { + viewModel = ViewModelProviders.of(activity, viewModelFactory).get(InsightsManagementViewModel::class.java) + setupObservers(activity) + } + + private fun setupObservers(activity: FragmentActivity) { + viewModel.showSnackbarMessage.observe(this, Observer { holder -> + val parent = activity.findViewById(R.id.coordinatorLayout) + if (holder != null && parent != null) { + if (holder.buttonTitleRes == null) { + Snackbar.make(parent, getString(holder.messageRes), Snackbar.LENGTH_LONG).show() + } else { + val snackbar = Snackbar.make(parent, getString(holder.messageRes), Snackbar.LENGTH_LONG) + snackbar.setAction(getString(holder.buttonTitleRes)) { holder.buttonAction() } + snackbar.show() + } + } + }) + } +} diff --git a/WordPress/src/main/res/layout/insights_management_fragment.xml b/WordPress/src/main/res/layout/insights_management_fragment.xml new file mode 100644 index 000000000000..d94781380073 --- /dev/null +++ b/WordPress/src/main/res/layout/insights_management_fragment.xml @@ -0,0 +1,14 @@ + + + + + From 9c1dac6ae8ceec7c95c46e0bb1436eaba6104707 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 22 Mar 2019 12:08:41 +0100 Subject: [PATCH 021/103] Add new stats menut and update the button resource name --- WordPress/src/main/res/layout/stats_empty_view.xml | 2 +- WordPress/src/main/res/menu/menu_stats_insights.xml | 8 ++++++++ WordPress/src/main/res/values-ar/strings.xml | 2 +- WordPress/src/main/res/values-de/strings.xml | 2 +- WordPress/src/main/res/values-en-rAU/strings.xml | 2 +- WordPress/src/main/res/values-en-rCA/strings.xml | 2 +- WordPress/src/main/res/values-en-rGB/strings.xml | 2 +- WordPress/src/main/res/values-es-rCL/strings.xml | 2 +- WordPress/src/main/res/values-es/strings.xml | 2 +- WordPress/src/main/res/values-fr/strings.xml | 2 +- WordPress/src/main/res/values-he/strings.xml | 2 +- WordPress/src/main/res/values-id/strings.xml | 2 +- WordPress/src/main/res/values-it/strings.xml | 2 +- WordPress/src/main/res/values-ja/strings.xml | 2 +- WordPress/src/main/res/values-ko/strings.xml | 2 +- WordPress/src/main/res/values-nb/strings.xml | 2 +- WordPress/src/main/res/values-pl/strings.xml | 2 +- WordPress/src/main/res/values-pt-rBR/strings.xml | 2 +- WordPress/src/main/res/values-ro/strings.xml | 2 +- WordPress/src/main/res/values-ru/strings.xml | 2 +- WordPress/src/main/res/values-sq/strings.xml | 2 +- WordPress/src/main/res/values-sv/strings.xml | 2 +- WordPress/src/main/res/values-tr/strings.xml | 2 +- WordPress/src/main/res/values-zh-rCN/strings.xml | 2 +- WordPress/src/main/res/values-zh-rHK/strings.xml | 2 +- WordPress/src/main/res/values-zh-rTW/strings.xml | 2 +- WordPress/src/main/res/values/strings.xml | 2 +- 27 files changed, 34 insertions(+), 26 deletions(-) create mode 100644 WordPress/src/main/res/menu/menu_stats_insights.xml diff --git a/WordPress/src/main/res/layout/stats_empty_view.xml b/WordPress/src/main/res/layout/stats_empty_view.xml index a3cc137a8f9f..25517e67ecc3 100644 --- a/WordPress/src/main/res/layout/stats_empty_view.xml +++ b/WordPress/src/main/res/layout/stats_empty_view.xml @@ -7,7 +7,7 @@ android:layout_height="match_parent" android:background="@color/background_grey" android:visibility="gone" - app:aevButton="@string/stats_button_manage_insights" + app:aevButton="@string/manage_insights" app:aevImage="@drawable/img_illustration_insights_94dp" app:aevSubtitle="@string/stats_empty_insights_description" app:aevTitle="@string/stats_empty_insights_title"/> diff --git a/WordPress/src/main/res/menu/menu_stats_insights.xml b/WordPress/src/main/res/menu/menu_stats_insights.xml new file mode 100644 index 000000000000..9a9e74776d88 --- /dev/null +++ b/WordPress/src/main/res/menu/menu_stats_insights.xml @@ -0,0 +1,8 @@ + + + + diff --git a/WordPress/src/main/res/values-ar/strings.xml b/WordPress/src/main/res/values-ar/strings.xml index 1f59689046ae..4a3072747aa8 100644 --- a/WordPress/src/main/res/values-ar/strings.xml +++ b/WordPress/src/main/res/values-ar/strings.xml @@ -192,7 +192,7 @@ Language: ar إجمالي %1$s من المتابعين: %2$s البريد الإلكتروني وردبرس.كوم - إدارة الرؤى + إدارة الرؤى تخصيص الرؤى الخاصة بك والحصول على معلومات حول أداء موقعك لم تتم إضافة رى حتى الآن لا توجد بيانات حتى الآن diff --git a/WordPress/src/main/res/values-de/strings.xml b/WordPress/src/main/res/values-de/strings.xml index 336b59f800c4..37ace6a8303e 100644 --- a/WordPress/src/main/res/values-de/strings.xml +++ b/WordPress/src/main/res/values-de/strings.xml @@ -192,7 +192,7 @@ Language: de %1$s-Follower insgesamt: %2$s E-Mail WordPress.com - Einsichten verwalten + Einsichten verwalten Passe deine Einsichten an und erhalte Details zur Leistung deiner Website Noch keine Einsichten hinzugefügt Noch keine Daten diff --git a/WordPress/src/main/res/values-en-rAU/strings.xml b/WordPress/src/main/res/values-en-rAU/strings.xml index d853f66e5ae5..1779a1cbf5e4 100644 --- a/WordPress/src/main/res/values-en-rAU/strings.xml +++ b/WordPress/src/main/res/values-en-rAU/strings.xml @@ -192,7 +192,7 @@ Language: en_AU Total %1$s Followers: %2$s Email WordPress.com - Manage insights + Manage insights Customise your insights and get the low-down on your site’s performance No insights added yet No data yet diff --git a/WordPress/src/main/res/values-en-rCA/strings.xml b/WordPress/src/main/res/values-en-rCA/strings.xml index cffa36e88f9f..c9aa0fd1d3a0 100644 --- a/WordPress/src/main/res/values-en-rCA/strings.xml +++ b/WordPress/src/main/res/values-en-rCA/strings.xml @@ -192,7 +192,7 @@ Language: en_CA Total %1$s Followers: %2$s Email WordPress.com - Manage insights + Manage insights Customize your insights and get the low-down on your site’s performance No insights added yet No data yet diff --git a/WordPress/src/main/res/values-en-rGB/strings.xml b/WordPress/src/main/res/values-en-rGB/strings.xml index 0292d6de517c..29740d287f79 100644 --- a/WordPress/src/main/res/values-en-rGB/strings.xml +++ b/WordPress/src/main/res/values-en-rGB/strings.xml @@ -192,7 +192,7 @@ Language: en_GB Total %1$s Followers: %2$s E-mail WordPress.com - Manage insights + Manage insights Customise your insights and get the low-down on your site’s performance No insights added yet No data yet diff --git a/WordPress/src/main/res/values-es-rCL/strings.xml b/WordPress/src/main/res/values-es-rCL/strings.xml index 21657c635abb..0324765f6e74 100644 --- a/WordPress/src/main/res/values-es-rCL/strings.xml +++ b/WordPress/src/main/res/values-es-rCL/strings.xml @@ -62,7 +62,7 @@ Language: es_CL Total %1$s Seguidores: %2$s Email WordPress.com - Administrar estadísticas + Administrar estadísticas Aún no se ha añadido estadisticas Aún no hay datos Menú Depuración diff --git a/WordPress/src/main/res/values-es/strings.xml b/WordPress/src/main/res/values-es/strings.xml index fefd16609b97..c2bd6bee7252 100644 --- a/WordPress/src/main/res/values-es/strings.xml +++ b/WordPress/src/main/res/values-es/strings.xml @@ -192,7 +192,7 @@ Language: es Total %1$s seguidores: %2$s Correo electrónico WordPress.com - Gestionar impresiones + Gestionar impresiones Personaliza tus informes y profundiza en el rendimiento de tu sitio Aún no se han añadido impresiones Aún no hay datos diff --git a/WordPress/src/main/res/values-fr/strings.xml b/WordPress/src/main/res/values-fr/strings.xml index 9b4bf7bc681e..9647198efd1d 100644 --- a/WordPress/src/main/res/values-fr/strings.xml +++ b/WordPress/src/main/res/values-fr/strings.xml @@ -192,7 +192,7 @@ Language: fr Total des abonnés %1$s : %2$s E-mail WordPress.com - Gérer les tendances + Gérer les tendances Personnalisez vos tendances et obtenez les dernières informations sur les performances de votre site Aucune tendance n’a encore été ajoutée Aucune donnée pour le moment. diff --git a/WordPress/src/main/res/values-he/strings.xml b/WordPress/src/main/res/values-he/strings.xml index 4ee524455f00..bc5de15ce421 100644 --- a/WordPress/src/main/res/values-he/strings.xml +++ b/WordPress/src/main/res/values-he/strings.xml @@ -189,7 +189,7 @@ Language: he_IL סך הכול %1$s עוקבים: %2$s אימייל WordPress.com - ניהול תובנות + ניהול תובנות עדיין לא נוספו תובנות עדיין אין נתונים תפריט איתור באגים diff --git a/WordPress/src/main/res/values-id/strings.xml b/WordPress/src/main/res/values-id/strings.xml index 30260abdd5cf..1ddbb0c99615 100644 --- a/WordPress/src/main/res/values-id/strings.xml +++ b/WordPress/src/main/res/values-id/strings.xml @@ -189,7 +189,7 @@ Language: id Total %1$s Pengikut: %2$s Email WordPress.com - Kelola informasi + Kelola informasi Belum ada informasi yang ditambahkan Belum ada data Menu Debug diff --git a/WordPress/src/main/res/values-it/strings.xml b/WordPress/src/main/res/values-it/strings.xml index 206d38a48dc4..65344482186d 100644 --- a/WordPress/src/main/res/values-it/strings.xml +++ b/WordPress/src/main/res/values-it/strings.xml @@ -173,7 +173,7 @@ Language: it Totale follower da %1$s: %2$s Email WordPress.com - Gestisci insight + Gestisci insight Nessun insight aggiunto Nessun dato Menu di debug diff --git a/WordPress/src/main/res/values-ja/strings.xml b/WordPress/src/main/res/values-ja/strings.xml index fe790e4d35ad..dc5da4b845d9 100644 --- a/WordPress/src/main/res/values-ja/strings.xml +++ b/WordPress/src/main/res/values-ja/strings.xml @@ -192,7 +192,7 @@ Language: ja_JP Total %1$s Followers:%2$s メール WordPress.com - インサイトを管理 + インサイトを管理 インサイトをカスタマイズして、サイトのパフォーマンスを把握しましょう インサイトは追加されていません データはまだありません diff --git a/WordPress/src/main/res/values-ko/strings.xml b/WordPress/src/main/res/values-ko/strings.xml index 438ca161783b..9c3460d5c1fe 100644 --- a/WordPress/src/main/res/values-ko/strings.xml +++ b/WordPress/src/main/res/values-ko/strings.xml @@ -185,7 +185,7 @@ Language: ko_KR 총 %1$s 팔로워 수: %2$s 이메일 워드프레스닷컴 - 인사이트 관리 + 인사이트 관리 아직 추가된 인사이트가 없음 아직 데이터 없음 디버그 메뉴 diff --git a/WordPress/src/main/res/values-nb/strings.xml b/WordPress/src/main/res/values-nb/strings.xml index 3a54103ccb32..9818bf62260f 100644 --- a/WordPress/src/main/res/values-nb/strings.xml +++ b/WordPress/src/main/res/values-nb/strings.xml @@ -180,7 +180,7 @@ Language: nb_NO Totalt %1$s følgere: %2$s E-post WordPress.com - Behandle innsikter + Behandle innsikter Tilpass dine innsikter og få den viktigste informasjonen om ytelsen til nettstedet ditt Ingen innsikter lagt til ennå Ingen data ennå diff --git a/WordPress/src/main/res/values-pl/strings.xml b/WordPress/src/main/res/values-pl/strings.xml index 7f1344213975..c8b1af7ff225 100644 --- a/WordPress/src/main/res/values-pl/strings.xml +++ b/WordPress/src/main/res/values-pl/strings.xml @@ -192,7 +192,7 @@ Language: pl Całkowita liczba obserwujących %1$s: %2$s Email WordPress.com - Zarządzaj trendami + Zarządzaj trendami Spersonalizuj kartę Trendy i uzyskaj pełną informację o wynikach swojej witryny Brak trendów, jak dotąd Brak danych, jak dotąd diff --git a/WordPress/src/main/res/values-pt-rBR/strings.xml b/WordPress/src/main/res/values-pt-rBR/strings.xml index 3d566265fea0..189510e2d73b 100644 --- a/WordPress/src/main/res/values-pt-rBR/strings.xml +++ b/WordPress/src/main/res/values-pt-rBR/strings.xml @@ -192,7 +192,7 @@ Language: pt_BR Total de seguidores por %1$s: %2$s E-mail WordPress.com - Gerenciar informações + Gerenciar informações Personalize as informações de seu site para saber mais sobre seu desempenho Nenhuma informação adicionada ainda Nenhum dado ainda diff --git a/WordPress/src/main/res/values-ro/strings.xml b/WordPress/src/main/res/values-ro/strings.xml index a0830a235628..90fd9c6b12ec 100644 --- a/WordPress/src/main/res/values-ro/strings.xml +++ b/WordPress/src/main/res/values-ro/strings.xml @@ -192,7 +192,7 @@ Language: ro Total urmăritori %1$s: %2$s Prin email WordPress.com - Administrează perspectivele + Administrează perspectivele Personalizează-ți perspectivele și primești informații relevante despre performanța sitului Nu ai adăugat perspective până acum Încă nu există date diff --git a/WordPress/src/main/res/values-ru/strings.xml b/WordPress/src/main/res/values-ru/strings.xml index 9403379ef22a..1bcb45f8d0ee 100644 --- a/WordPress/src/main/res/values-ru/strings.xml +++ b/WordPress/src/main/res/values-ru/strings.xml @@ -192,7 +192,7 @@ Language: ru Всего %1$s Подписчики: %2$s Email WordPress.com - Настроить статистику + Настроить статистику Настройте вашу статистику и узнайте важное то, чем живет ваш сайт. Еще нет статистики Пока нет данных diff --git a/WordPress/src/main/res/values-sq/strings.xml b/WordPress/src/main/res/values-sq/strings.xml index 78c1c8d8d9d2..921a7281ff1b 100644 --- a/WordPress/src/main/res/values-sq/strings.xml +++ b/WordPress/src/main/res/values-sq/strings.xml @@ -192,7 +192,7 @@ Language: sq_AL %1$s Ndjekës Gjithsej: %2$s Email WordPress.com - Administroni tendenca + Administroni tendenca Përshtatni tendencat tuaj dhe merrni faktet mbi funksionimin e sajtit tuaj S’janë shtuar ende tendenca Ende pa të dhëna diff --git a/WordPress/src/main/res/values-sv/strings.xml b/WordPress/src/main/res/values-sv/strings.xml index f26041fa4df9..97cd23002f88 100644 --- a/WordPress/src/main/res/values-sv/strings.xml +++ b/WordPress/src/main/res/values-sv/strings.xml @@ -192,7 +192,7 @@ Language: sv_SE Totalt antal följare för ”%1$s”: %2$s E-post WordPress.com - Hantera insikter + Hantera insikter Anpassa dina insikter och se detaljerna om hur din webbplats presterar Inga insikter har lagts till än Inga data insamlade än diff --git a/WordPress/src/main/res/values-tr/strings.xml b/WordPress/src/main/res/values-tr/strings.xml index 346d553c15f3..5c1e9586504e 100644 --- a/WordPress/src/main/res/values-tr/strings.xml +++ b/WordPress/src/main/res/values-tr/strings.xml @@ -192,7 +192,7 @@ Language: tr Toplam %1$s takipçisi: %2$s E-posta WordPress.com - İçgörüleri yönet + İçgörüleri yönet Analizlerinizi özelleştirin ve sitenizin performansındaki düşüş hakkında bilgi edinin Henüz içgörü eklenmedi Henüz veri yok diff --git a/WordPress/src/main/res/values-zh-rCN/strings.xml b/WordPress/src/main/res/values-zh-rCN/strings.xml index 1b120dc73287..ba710ba92595 100644 --- a/WordPress/src/main/res/values-zh-rCN/strings.xml +++ b/WordPress/src/main/res/values-zh-rCN/strings.xml @@ -147,7 +147,7 @@ Language: zh_CN 共 %1$s 位粉丝:%2$s 电子邮件 WordPress.com - 管理见解 + 管理见解 尚未添加任何见解 尚无数据 正在更改密码… diff --git a/WordPress/src/main/res/values-zh-rHK/strings.xml b/WordPress/src/main/res/values-zh-rHK/strings.xml index a0967de2e49c..321d741ebc1d 100644 --- a/WordPress/src/main/res/values-zh-rHK/strings.xml +++ b/WordPress/src/main/res/values-zh-rHK/strings.xml @@ -147,7 +147,7 @@ Language: zh_TW %1$s 關注者總數:%2$s 電子郵件 WordPress.com - 管理洞察報告 + 管理洞察報告 尚未新增任何洞察報告 尚無資料 除錯選單 diff --git a/WordPress/src/main/res/values-zh-rTW/strings.xml b/WordPress/src/main/res/values-zh-rTW/strings.xml index a0967de2e49c..321d741ebc1d 100644 --- a/WordPress/src/main/res/values-zh-rTW/strings.xml +++ b/WordPress/src/main/res/values-zh-rTW/strings.xml @@ -147,7 +147,7 @@ Language: zh_TW %1$s 關注者總數:%2$s 電子郵件 WordPress.com - 管理洞察報告 + 管理洞察報告 尚未新增任何洞察報告 尚無資料 除錯選單 diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index b4d6162bf4a2..46dff65ce84f 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -790,7 +790,7 @@ No data for this period No insights added yet Customize your insights and get the low-down on your site’s performance - Manage insights + Manage insights WordPress.com Email Total %1$s Followers: %2$s From 13d6ba51195d486346499e64b78fef6e1e710c5c Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 22 Mar 2019 12:09:21 +0100 Subject: [PATCH 022/103] Add Inisights management ViewModel --- .../android/modules/ViewModelModule.java | 6 +++++ .../management/InsightsManagementViewModel.kt | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt diff --git a/WordPress/src/main/java/org/wordpress/android/modules/ViewModelModule.java b/WordPress/src/main/java/org/wordpress/android/modules/ViewModelModule.java index 3fe7ded47f22..bdf1f997e277 100644 --- a/WordPress/src/main/java/org/wordpress/android/modules/ViewModelModule.java +++ b/WordPress/src/main/java/org/wordpress/android/modules/ViewModelModule.java @@ -18,6 +18,7 @@ import org.wordpress.android.ui.stats.refresh.lists.MonthsListViewModel; import org.wordpress.android.ui.stats.refresh.lists.WeeksListViewModel; import org.wordpress.android.ui.stats.refresh.lists.YearsListViewModel; +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel; import org.wordpress.android.viewmodel.ViewModelFactory; import org.wordpress.android.viewmodel.ViewModelKey; import org.wordpress.android.viewmodel.activitylog.ActivityLogDetailViewModel; @@ -118,6 +119,11 @@ abstract class ViewModelModule { @ViewModelKey(StatsViewModel.class) abstract ViewModel statsViewModel(StatsViewModel viewModel); + @Binds + @IntoMap + @ViewModelKey(InsightsManagementViewModel.class) + abstract ViewModel insightsManagementViewModel(InsightsManagementViewModel viewModel); + @Binds @IntoMap @ViewModelKey(HistoryViewModel.class) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt new file mode 100644 index 000000000000..3433f69661e6 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -0,0 +1,25 @@ +package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management + +import android.arch.lifecycle.LiveData +import android.arch.lifecycle.MutableLiveData +import kotlinx.coroutines.CoroutineDispatcher +import org.wordpress.android.modules.UI_THREAD +import org.wordpress.android.ui.pages.SnackbarMessageHolder +import org.wordpress.android.util.map +import org.wordpress.android.viewmodel.ScopedViewModel +import javax.inject.Inject +import javax.inject.Named + +class InsightsManagementViewModel @Inject constructor( + @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher +) : ScopedViewModel(mainDispatcher) { + private val mutableSnackbarMessage = MutableLiveData() + + val showSnackbarMessage: LiveData = mutableSnackbarMessage.map { + SnackbarMessageHolder(it) + } + + override fun onCleared() { + mutableSnackbarMessage.value = null + } +} From 02ef98aafa7b0b3ec5e2f8a15e791c2e723def0f Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 22 Mar 2019 12:09:44 +0100 Subject: [PATCH 023/103] Remove unused member --- .../main/java/org/wordpress/android/ui/pages/PagesFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt index bddab6f30430..63825d8d51c4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt @@ -64,7 +64,6 @@ class PagesFragment : Fragment() { private lateinit var viewModel: PagesViewModel private lateinit var swipeToRefreshHelper: SwipeToRefreshHelper private lateinit var actionMenuItem: MenuItem - @Inject lateinit var postStore: PostStore @Inject lateinit var quickStartStore: QuickStartStore @Inject lateinit var dispatcher: Dispatcher private var quickStartEvent: QuickStartEvent? = null From 88da6c00e60e8cd9d710e02bf3d4bb557950100a Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 22 Mar 2019 12:13:06 +0100 Subject: [PATCH 024/103] Add the toolbar menu functionality for the Insights tab --- .../android/ui/ActivityLauncher.java | 6 +++ .../ui/stats/refresh/NavigationTarget.kt | 1 + .../android/ui/stats/refresh/StatsFragment.kt | 39 +++++++++++++++++-- .../ui/stats/refresh/StatsViewModel.kt | 13 +++++++ .../ui/stats/refresh/utils/StatsNavigator.kt | 4 ++ 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java b/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java index 884be283b692..dd039b8167d8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java @@ -73,6 +73,7 @@ import org.wordpress.android.ui.stats.models.StatsPostModel; import org.wordpress.android.ui.stats.refresh.StatsActivity; import org.wordpress.android.ui.stats.refresh.StatsViewAllFragment; +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementActivity; import org.wordpress.android.ui.stockmedia.StockMediaPickerActivity; import org.wordpress.android.ui.themes.ThemeBrowserActivity; import org.wordpress.android.util.AppLog; @@ -301,6 +302,11 @@ public static void viewAllGranularStats(Context context, StatsGranularity granul context.startActivity(intent); } + public static void viewInsightsManagement(Context context) { + Intent intent = new Intent(context, InsightsManagementActivity.class); + context.startActivity(intent); + } + public static void viewBlogStatsAfterJetpackSetup(Context context, SiteModel site) { if (site == null) { AppLog.e(T.STATS, "SiteModel is null when opening the stats."); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/NavigationTarget.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/NavigationTarget.kt index 402c3d73bb98..0a0ea56ade80 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/NavigationTarget.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/NavigationTarget.kt @@ -31,4 +31,5 @@ sealed class NavigationTarget : Event() { data class ViewSearchTerms(val statsGranularity: StatsGranularity, val selectedDate: Date) : NavigationTarget() data class ViewAuthors(val statsGranularity: StatsGranularity, val selectedDate: Date) : NavigationTarget() data class ViewUrl(val url: String) : NavigationTarget() + class ViewInsightsManagement : NavigationTarget() } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt index f7edf1c99190..0c5b8f8e25b5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt @@ -4,7 +4,6 @@ import android.arch.lifecycle.Observer import android.arch.lifecycle.ViewModelProvider import android.arch.lifecycle.ViewModelProviders import android.content.Context -import android.content.Intent import android.os.Bundle import android.support.design.widget.Snackbar import android.support.design.widget.TabLayout.OnTabSelectedListener @@ -15,6 +14,9 @@ import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentPagerAdapter import android.support.v4.view.ViewCompat import android.view.LayoutInflater +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem import android.view.MotionEvent import android.view.View import android.view.ViewGroup @@ -38,8 +40,10 @@ import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSect import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.MONTHS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.WEEKS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.YEARS +import org.wordpress.android.ui.stats.refresh.utils.StatsNavigator import org.wordpress.android.util.WPSwipeToRefreshHelper import org.wordpress.android.util.helpers.SwipeToRefreshHelper +import org.wordpress.android.util.observeEvent import javax.inject.Inject private val statsSections = listOf(INSIGHTS, DAYS, WEEKS, MONTHS, YEARS) @@ -48,6 +52,9 @@ class StatsFragment : DaggerFragment() { @Inject lateinit var viewModelFactory: ViewModelProvider.Factory private lateinit var viewModel: StatsViewModel private lateinit var swipeToRefreshHelper: SwipeToRefreshHelper + @Inject lateinit var navigator: StatsNavigator + + private var menu: Menu? = null private var restorePreviousSearch = false @@ -57,9 +64,25 @@ class StatsFragment : DaggerFragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + setHasOptionsMenu(true) + return inflater.inflate(R.layout.stats_fragment, container, false) } + override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { + super.onCreateOptionsMenu(menu, inflater) + + inflater?.inflate(R.menu.menu_stats_insights, menu) + this.menu = menu + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == R.id.manage_insights) { + viewModel.onManageInsightsButtonTapped() + } + return true + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -69,9 +92,6 @@ class StatsFragment : DaggerFragment() { initializeViews(nonNullActivity) } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - } - private fun initializeViews(activity: FragmentActivity) { statsPager.adapter = StatsPagerAdapter(activity, childFragmentManager) tabLayout.setupWithViewPager(statsPager) @@ -171,6 +191,17 @@ class StatsFragment : DaggerFragment() { viewModel.siteChanged.observe(this, Observer { viewModel.refreshData() }) + + viewModel.isMenuVisible.observe(this, Observer { isMenuVisible -> + isMenuVisible?.let { + menu?.findItem(R.id.manage_insights)?.isVisible = isMenuVisible + } + }) + + viewModel.navigationTarget.observeEvent(this) { target -> + navigator.navigate(activity, target) + return@observeEvent true + } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt index 8a40a971a27a..3289716f2ccf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt @@ -15,6 +15,7 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_PERIOD_YEARS_ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.pages.SnackbarMessageHolder +import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewInsightsManagement import org.wordpress.android.ui.stats.refresh.lists.BaseListUseCase import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.INSIGHTS @@ -41,6 +42,9 @@ class StatsViewModel private val _isRefreshing = MutableLiveData() val isRefreshing: LiveData = _isRefreshing + private val _isMenuVisible = MutableLiveData() + val isMenuVisible: LiveData = _isMenuVisible + private var isInitialized = false private val _showSnackbarMessage = mergeNotNull( @@ -50,6 +54,9 @@ class StatsViewModel ) val showSnackbarMessage: LiveData = _showSnackbarMessage + private val _navigationTarget = MutableLiveData() + val navigationTarget: LiveData = _navigationTarget + val siteChanged = statsSiteProvider.siteChanged private val _toolbarHasShadow = MutableLiveData() @@ -106,6 +113,8 @@ class StatsViewModel listUseCases[statsSection]?.onListSelected() _toolbarHasShadow.value = statsSection == INSIGHTS + _isMenuVisible.value = statsSection == INSIGHTS + when (statsSection) { StatsSection.INSIGHTS -> analyticsTracker.track(STATS_INSIGHTS_ACCESSED) StatsSection.DAYS -> analyticsTracker.track(STATS_PERIOD_DAYS_ACCESSED) @@ -115,6 +124,10 @@ class StatsViewModel } } + fun onManageInsightsButtonTapped() { + _navigationTarget.value = ViewInsightsManagement() + } + override fun onCleared() { super.onCleared() _showSnackbarMessage.value = null diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsNavigator.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsNavigator.kt index bdf00d6f17d0..099949898166 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsNavigator.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsNavigator.kt @@ -26,6 +26,7 @@ import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewClicks import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewCommentsStats import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewCountries import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewFollowersStats +import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewInsightsManagement import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewPost import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewPostDetailStats import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewPostsAndPages @@ -115,6 +116,9 @@ class StatsNavigator is ViewUrl -> { WPWebViewActivity.openURL(activity, target.url) } + is ViewInsightsManagement -> { + ActivityLauncher.viewInsightsManagement(activity) + } } } } From 29ee4eb447b02010aca670d70ab2d317175c3f66 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 22 Mar 2019 13:41:10 +0100 Subject: [PATCH 025/103] Add InsightsManagementFragment to the ApplicationModule --- .../java/org/wordpress/android/modules/ApplicationModule.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/modules/ApplicationModule.java b/WordPress/src/main/java/org/wordpress/android/modules/ApplicationModule.java index 00efcb527072..b068cb8704b9 100644 --- a/WordPress/src/main/java/org/wordpress/android/modules/ApplicationModule.java +++ b/WordPress/src/main/java/org/wordpress/android/modules/ApplicationModule.java @@ -12,6 +12,7 @@ import org.wordpress.android.ui.stats.refresh.StatsViewAllFragment; import org.wordpress.android.ui.stats.refresh.lists.StatsListFragment; import org.wordpress.android.ui.stats.refresh.lists.detail.StatsDetailFragment; +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementFragment; import org.wordpress.android.util.wizard.WizardManager; import org.wordpress.android.viewmodel.helpers.ConnectionStatus; import org.wordpress.android.viewmodel.helpers.ConnectionStatusLiveData; @@ -38,6 +39,9 @@ public static NewsService provideLocalNewsService(Context context) { @ContributesAndroidInjector abstract StatsViewAllFragment contributeStatsViewAllFragment(); + @ContributesAndroidInjector + abstract InsightsManagementFragment contributeInsightsManagementFragment(); + @ContributesAndroidInjector abstract StatsFragment contributeStatsFragment(); From 373e3493884bc6eb4ab6a0f5d247793700cd87d5 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 22 Mar 2019 13:41:28 +0100 Subject: [PATCH 026/103] Remove the extra toolbar --- .../sections/insights/management/InsightsManagementActivity.kt | 2 -- WordPress/src/main/res/layout/insights_management_activity.xml | 2 -- 2 files changed, 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementActivity.kt index db70cc224060..823d47df9ba3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementActivity.kt @@ -3,7 +3,6 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.managemen import android.os.Bundle import android.support.v7.app.AppCompatActivity import android.view.MenuItem -import kotlinx.android.synthetic.main.toolbar.* import org.wordpress.android.R class InsightsManagementActivity : AppCompatActivity() { @@ -12,7 +11,6 @@ class InsightsManagementActivity : AppCompatActivity() { setContentView(R.layout.insights_management_activity) - setSupportActionBar(toolbar) supportActionBar?.let { it.setHomeButtonEnabled(true) it.setDisplayHomeAsUpEnabled(true) diff --git a/WordPress/src/main/res/layout/insights_management_activity.xml b/WordPress/src/main/res/layout/insights_management_activity.xml index 7d722b665fb8..e44533e02dca 100644 --- a/WordPress/src/main/res/layout/insights_management_activity.xml +++ b/WordPress/src/main/res/layout/insights_management_activity.xml @@ -6,8 +6,6 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - Date: Fri, 22 Mar 2019 13:41:58 +0100 Subject: [PATCH 027/103] Update the title capitalization --- WordPress/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 1bded7218ca1..352d8b86c433 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -790,7 +790,7 @@ No data for this period No insights added yet Customize your insights and get the low-down on your site’s performance - Manage insights + Manage Insights WordPress.com Email Total %1$s Followers: %2$s From 6cef16f5900742b44459e4bf7b02e92a3ee5fb42 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 22 Mar 2019 13:44:51 +0100 Subject: [PATCH 028/103] Optimize imports --- .../main/java/org/wordpress/android/ui/pages/PagesFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt index 63825d8d51c4..72a0612f4216 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt @@ -33,7 +33,6 @@ import org.wordpress.android.WordPress import org.wordpress.android.fluxc.Dispatcher import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.page.PageModel -import org.wordpress.android.fluxc.store.PostStore import org.wordpress.android.fluxc.store.QuickStartStore import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTask import org.wordpress.android.ui.ActivityLauncher From 3f6e429d85101a57a530511f88fda3203e07f376 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Mon, 25 Mar 2019 21:06:01 +0100 Subject: [PATCH 029/103] Add insights management list item resources --- .../layout/insights_management_list_item.xml | 46 +++++++++++++++++++ WordPress/src/main/res/values/strings.xml | 2 + .../src/main/res/drawable/ic_gridicon_add.xml | 11 +++++ 3 files changed, 59 insertions(+) create mode 100644 WordPress/src/main/res/layout/insights_management_list_item.xml create mode 100644 libs/editor/WordPressEditor/src/main/res/drawable/ic_gridicon_add.xml diff --git a/WordPress/src/main/res/layout/insights_management_list_item.xml b/WordPress/src/main/res/layout/insights_management_list_item.xml new file mode 100644 index 000000000000..d7bc1a527a7b --- /dev/null +++ b/WordPress/src/main/res/layout/insights_management_list_item.xml @@ -0,0 +1,46 @@ + + + + + + + + + + diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 352d8b86c433..ee2bc880ee80 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -1029,6 +1029,8 @@ Path %1$d%% of views Posting Activity + Only see the most relevant stats. Add and organise your insights below. + Add Insights Months and Years diff --git a/libs/editor/WordPressEditor/src/main/res/drawable/ic_gridicon_add.xml b/libs/editor/WordPressEditor/src/main/res/drawable/ic_gridicon_add.xml new file mode 100644 index 000000000000..eeab770fdac0 --- /dev/null +++ b/libs/editor/WordPressEditor/src/main/res/drawable/ic_gridicon_add.xml @@ -0,0 +1,11 @@ + + + + + From ba8fcc9346b48d8e3d3d35c7b41f3e35355c01dd Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Mon, 25 Mar 2019 21:06:50 +0100 Subject: [PATCH 030/103] Update the insights management fragment layout with text items --- .../layout/insights_management_fragment.xml | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/res/layout/insights_management_fragment.xml b/WordPress/src/main/res/layout/insights_management_fragment.xml index d94781380073..3de35cc7a7a5 100644 --- a/WordPress/src/main/res/layout/insights_management_fragment.xml +++ b/WordPress/src/main/res/layout/insights_management_fragment.xml @@ -2,7 +2,32 @@ + android:layout_height="match_parent" + android:orientation="vertical"> + + + + + From aaa556749a779a170a84e173f7c1624c75f31f2c Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Mon, 25 Mar 2019 21:07:20 +0100 Subject: [PATCH 031/103] Add the insights management list adapter and view holder --- .../management/InsightsManagementAdapter.kt | 23 +++++++++++++++++++ .../InsightsManagementViewHolder.kt | 17 ++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt new file mode 100644 index 000000000000..d1e55eec07d9 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt @@ -0,0 +1,23 @@ +package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management + +import android.support.v7.recyclerview.extensions.ListAdapter +import android.support.v7.util.DiffUtil +import android.view.ViewGroup +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel + +class InsightsManagementAdapter : ListAdapter(DIFF_CALLBACK) { + companion object { + private val DIFF_CALLBACK = object : DiffUtil.ItemCallback() { + override fun areItemsTheSame(m1: InsightModel, m2: InsightModel): Boolean = m1.name == m2.name + override fun areContentsTheSame(m1: InsightModel, m2: InsightModel): Boolean = m1 == m2 + } + } + + override fun onCreateViewHolder(parent: ViewGroup, itemType: Int): InsightsManagementViewHolder { + return InsightsManagementViewHolder(parent) + } + + override fun onBindViewHolder(holder: InsightsManagementViewHolder, position: Int) { + holder.bind(getItem(position)) + } +} diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt new file mode 100644 index 000000000000..765db94181a5 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt @@ -0,0 +1,17 @@ +package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management + +import android.support.v7.widget.RecyclerView.ViewHolder +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.TextView +import org.wordpress.android.R +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel + +class InsightsManagementViewHolder( + parent: ViewGroup +) : ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.insights_management_list_item, parent, false)) { + private val title: TextView = itemView.findViewById(R.id.itemTitle) + fun bind(insightModel: InsightModel) { + title.setText(insightModel.name) + } +} From cc5c80a25cb2a410d23ed664a6c55ba27a5bcb46 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Mon, 25 Mar 2019 21:16:48 +0100 Subject: [PATCH 032/103] Add InsightModel and implement the removed insights loading --- .../management/InsightsManagementFragment.kt | 20 +++++++++ .../management/InsightsManagementViewModel.kt | 42 ++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index d68a15728b76..05296be357ca 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -13,6 +13,7 @@ import android.view.ViewGroup import dagger.android.support.DaggerFragment import kotlinx.android.synthetic.main.insights_management_fragment.* import org.wordpress.android.R +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel import javax.inject.Inject class InsightsManagementFragment : DaggerFragment() { @@ -39,6 +40,8 @@ class InsightsManagementFragment : DaggerFragment() { private fun initializeViewModels(activity: FragmentActivity) { viewModel = ViewModelProviders.of(activity, viewModelFactory).get(InsightsManagementViewModel::class.java) setupObservers(activity) + + viewModel.start() } private fun setupObservers(activity: FragmentActivity) { @@ -54,5 +57,22 @@ class InsightsManagementFragment : DaggerFragment() { } } }) + + viewModel.removedInsights.observe(this, Observer { + it?.let { items -> + updateRemovedInsights(items) + } + }) + } + + private fun updateRemovedInsights(insights: List) { + val adapter: InsightsManagementAdapter + if (removedInsights.adapter == null) { + adapter = InsightsManagementAdapter() + removedInsights.adapter = adapter + } else { + adapter = removedInsights.adapter as InsightsManagementAdapter + } + adapter.submitList(insights) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index 3433f69661e6..db30858ca154 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -2,24 +2,64 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.managemen import android.arch.lifecycle.LiveData import android.arch.lifecycle.MutableLiveData +import androidx.annotation.StringRes import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.launch +import org.wordpress.android.R +import org.wordpress.android.fluxc.store.StatsStore +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.* import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.pages.SnackbarMessageHolder +import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.util.map import org.wordpress.android.viewmodel.ScopedViewModel +import java.security.InvalidParameterException import javax.inject.Inject import javax.inject.Named class InsightsManagementViewModel @Inject constructor( - @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher + @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, + private val siteProvider: StatsSiteProvider, + private val statsStore: StatsStore ) : ScopedViewModel(mainDispatcher) { + private val _removedInsights = MutableLiveData>() + val removedInsights: LiveData> + get() = _removedInsights + private val mutableSnackbarMessage = MutableLiveData() val showSnackbarMessage: LiveData = mutableSnackbarMessage.map { SnackbarMessageHolder(it) } + fun start() { + loadRemovedInsights() + } + + fun loadRemovedInsights() { + launch { + val model = statsStore.getInsightsManagementModel(siteProvider.siteModel) + _removedInsights.value = model.removedTypes.map { InsightModel(it) } + } + } + override fun onCleared() { mutableSnackbarMessage.value = null } + + class InsightModel(insightsTypes: InsightsTypes) { + @StringRes val name: Int = when (insightsTypes) { + LATEST_POST_SUMMARY -> R.string.stats_insights_latest_post_summary + MOST_POPULAR_DAY_AND_HOUR -> R.string.stats_insights_popular + ALL_TIME_STATS -> R.string.stats_insights_all_time_stats + TAGS_AND_CATEGORIES -> R.string.stats_insights_tags_and_categories + COMMENTS -> R.string.stats_comments + FOLLOWERS -> R.string.stats_view_followers + TODAY_STATS -> R.string.stats_insights_today + POSTING_ACTIVITY -> R.string.stats_insights_posting_activity + PUBLICIZE -> R.string.stats_view_publicize + else -> R.string.unknown + } + } } From fae598f264c25cd3e27c04d725969b7b5201622d Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Tue, 26 Mar 2019 14:42:50 +0100 Subject: [PATCH 033/103] Add the drawable resources for insights management --- WordPress/src/main/res/drawable/ic_add_circle.xml | 5 +++++ .../res/drawable/ic_material_drag_handle_24dp.xml | 11 +++++++++++ .../src/main/res/drawable/ic_minus_small_24dp.xml | 13 +++++++++++++ .../src/main/res/drawable/ic_plus_small_24dp.xml | 13 +++++++++++++ .../src/main/res/drawable/ic_remove_circle.xml | 5 +++++ 5 files changed, 47 insertions(+) create mode 100644 WordPress/src/main/res/drawable/ic_add_circle.xml create mode 100644 WordPress/src/main/res/drawable/ic_material_drag_handle_24dp.xml create mode 100644 WordPress/src/main/res/drawable/ic_minus_small_24dp.xml create mode 100644 WordPress/src/main/res/drawable/ic_plus_small_24dp.xml create mode 100644 WordPress/src/main/res/drawable/ic_remove_circle.xml diff --git a/WordPress/src/main/res/drawable/ic_add_circle.xml b/WordPress/src/main/res/drawable/ic_add_circle.xml new file mode 100644 index 000000000000..b6826feeb3e3 --- /dev/null +++ b/WordPress/src/main/res/drawable/ic_add_circle.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/WordPress/src/main/res/drawable/ic_material_drag_handle_24dp.xml b/WordPress/src/main/res/drawable/ic_material_drag_handle_24dp.xml new file mode 100644 index 000000000000..6d333d8042a9 --- /dev/null +++ b/WordPress/src/main/res/drawable/ic_material_drag_handle_24dp.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/WordPress/src/main/res/drawable/ic_minus_small_24dp.xml b/WordPress/src/main/res/drawable/ic_minus_small_24dp.xml new file mode 100644 index 000000000000..0da31deb6983 --- /dev/null +++ b/WordPress/src/main/res/drawable/ic_minus_small_24dp.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/WordPress/src/main/res/drawable/ic_plus_small_24dp.xml b/WordPress/src/main/res/drawable/ic_plus_small_24dp.xml new file mode 100644 index 000000000000..9c2634168399 --- /dev/null +++ b/WordPress/src/main/res/drawable/ic_plus_small_24dp.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/WordPress/src/main/res/drawable/ic_remove_circle.xml b/WordPress/src/main/res/drawable/ic_remove_circle.xml new file mode 100644 index 000000000000..581a0cb7cac2 --- /dev/null +++ b/WordPress/src/main/res/drawable/ic_remove_circle.xml @@ -0,0 +1,5 @@ + + + + + From 32136a4060e682e5946339104384c365c844a665 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Tue, 26 Mar 2019 14:43:08 +0100 Subject: [PATCH 034/103] Add new drag & drop hint string resource --- WordPress/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index ee2bc880ee80..9516bb5c9477 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -1031,6 +1031,7 @@ Posting Activity Only see the most relevant stats. Add and organise your insights below. Add Insights + Items shown above will show in your Insights tab. Drag and drop to customize. Months and Years From b54109f116e2d575e511bcd3ca6c4c6acdb1b77e Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Tue, 26 Mar 2019 14:44:16 +0100 Subject: [PATCH 035/103] Update the list item layout --- .../layout/insights_management_list_item.xml | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/WordPress/src/main/res/layout/insights_management_list_item.xml b/WordPress/src/main/res/layout/insights_management_list_item.xml index d7bc1a527a7b..82b9ea93dba7 100644 --- a/WordPress/src/main/res/layout/insights_management_list_item.xml +++ b/WordPress/src/main/res/layout/insights_management_list_item.xml @@ -3,44 +3,58 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="match_parent" + android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools" android:background="@color/white"> + app:layout_constraintTop_toTopOf="parent" + tools:src="@drawable/ic_add_circle"/> + tools:text="Latest post" /> + + + app:layout_constraintStart_toStartOf="@+id/insightsManagementItemButton"/> From b4f3b2ec1881eb37fa0aaf4aea3534dc08e939c9 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Tue, 26 Mar 2019 14:44:56 +0100 Subject: [PATCH 036/103] Add the added insights list and drag & drop hint --- .../management/InsightsManagementFragment.kt | 22 +++-- .../InsightsManagementViewHolder.kt | 6 ++ .../management/InsightsManagementViewModel.kt | 23 +++-- .../layout/insights_management_fragment.xml | 86 ++++++++++++------- 4 files changed, 88 insertions(+), 49 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index 05296be357ca..200b671bce23 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -7,6 +7,7 @@ import android.os.Bundle import android.support.design.widget.Snackbar import android.support.v4.app.FragmentActivity import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -26,6 +27,7 @@ class InsightsManagementFragment : DaggerFragment() { private fun initializeViews() { removedInsights.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) + addedInsights.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -60,19 +62,21 @@ class InsightsManagementFragment : DaggerFragment() { viewModel.removedInsights.observe(this, Observer { it?.let { items -> - updateRemovedInsights(items) + updateInsights(items, removedInsights) + } + }) + + viewModel.addedInsights.observe(this, Observer { + it?.let { items -> + updateInsights(items, addedInsights) } }) } - private fun updateRemovedInsights(insights: List) { - val adapter: InsightsManagementAdapter - if (removedInsights.adapter == null) { - adapter = InsightsManagementAdapter() - removedInsights.adapter = adapter - } else { - adapter = removedInsights.adapter as InsightsManagementAdapter + private fun updateInsights(insights: List, recyclerView: RecyclerView) { + if (recyclerView.adapter == null) { + recyclerView.adapter = InsightsManagementAdapter() } - adapter.submitList(insights) + (recyclerView.adapter as InsightsManagementAdapter).submitList(insights) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt index 765db94181a5..817ffe09ec7a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt @@ -3,6 +3,7 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.managemen import android.support.v7.widget.RecyclerView.ViewHolder import android.view.LayoutInflater import android.view.ViewGroup +import android.widget.ImageButton import android.widget.TextView import org.wordpress.android.R import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel @@ -11,7 +12,12 @@ class InsightsManagementViewHolder( parent: ViewGroup ) : ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.insights_management_list_item, parent, false)) { private val title: TextView = itemView.findViewById(R.id.itemTitle) + private val managementButton: ImageButton = itemView.findViewById(R.id.insightsManagementItemButton) + private val dragAndDropButton: ImageButton = itemView.findViewById(R.id.dragAndDropItemButton) fun bind(insightModel: InsightModel) { title.setText(insightModel.name) + + val buttonImage = if (insightModel.isAdded) R.drawable.ic_remove_circle else R.drawable.ic_add_circle + managementButton.setImageResource(buttonImage) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index db30858ca154..f63146b26ca1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -4,7 +4,9 @@ import android.arch.lifecycle.LiveData import android.arch.lifecycle.MutableLiveData import androidx.annotation.StringRes import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import org.wordpress.android.R import org.wordpress.android.fluxc.store.StatsStore import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes @@ -14,7 +16,6 @@ import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.util.map import org.wordpress.android.viewmodel.ScopedViewModel -import java.security.InvalidParameterException import javax.inject.Inject import javax.inject.Named @@ -24,8 +25,10 @@ class InsightsManagementViewModel @Inject constructor( private val statsStore: StatsStore ) : ScopedViewModel(mainDispatcher) { private val _removedInsights = MutableLiveData>() - val removedInsights: LiveData> - get() = _removedInsights + val removedInsights: LiveData> = _removedInsights + + private val _addedInsights = MutableLiveData>() + val addedInsights: LiveData> = _addedInsights private val mutableSnackbarMessage = MutableLiveData() @@ -34,13 +37,19 @@ class InsightsManagementViewModel @Inject constructor( } fun start() { - loadRemovedInsights() + loadInsights() } - fun loadRemovedInsights() { + private fun loadInsights() { launch { val model = statsStore.getInsightsManagementModel(siteProvider.siteModel) - _removedInsights.value = model.removedTypes.map { InsightModel(it) } + _addedInsights.value = model.addedTypes + .filter { it != FOLLOWER_TOTALS && it != ANNUAL_SITE_STATS } + .map { InsightModel(it, true) } + + _removedInsights.value = model.removedTypes + .filter { it != FOLLOWER_TOTALS && it != ANNUAL_SITE_STATS } + .map { InsightModel(it, false) } } } @@ -48,7 +57,7 @@ class InsightsManagementViewModel @Inject constructor( mutableSnackbarMessage.value = null } - class InsightModel(insightsTypes: InsightsTypes) { + class InsightModel(insightsTypes: InsightsTypes, val isAdded: Boolean) { @StringRes val name: Int = when (insightsTypes) { LATEST_POST_SUMMARY -> R.string.stats_insights_latest_post_summary MOST_POPULAR_DAY_AND_HOUR -> R.string.stats_insights_popular diff --git a/WordPress/src/main/res/layout/insights_management_fragment.xml b/WordPress/src/main/res/layout/insights_management_fragment.xml index 3de35cc7a7a5..b672f1d360e0 100644 --- a/WordPress/src/main/res/layout/insights_management_fragment.xml +++ b/WordPress/src/main/res/layout/insights_management_fragment.xml @@ -1,40 +1,60 @@ - + android:layout_height="match_parent"> - - - - - + android:orientation="vertical"> + + + + + + + + + + + + - + From 20665e38a14608e5e133b7bbf8782944580a6ecc Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 27 Mar 2019 16:45:34 +0100 Subject: [PATCH 037/103] Add drag & drop ordering to added insights --- .../management/InsightsManagementAdapter.kt | 67 ++++++++++++++++--- .../management/InsightsManagementFragment.kt | 31 ++++++--- .../InsightsManagementViewHolder.kt | 23 ++++++- .../management/ItemTouchHelperCallback.kt | 28 ++++++++ 4 files changed, 128 insertions(+), 21 deletions(-) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt index d1e55eec07d9..77919e94f974 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt @@ -1,23 +1,70 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management -import android.support.v7.recyclerview.extensions.ListAdapter import android.support.v7.util.DiffUtil +import android.support.v7.util.DiffUtil.Callback +import android.support.v7.widget.RecyclerView.Adapter +import android.support.v7.widget.RecyclerView.ViewHolder import android.view.ViewGroup import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel +import java.util.Collections -class InsightsManagementAdapter : ListAdapter(DIFF_CALLBACK) { - companion object { - private val DIFF_CALLBACK = object : DiffUtil.ItemCallback() { - override fun areItemsTheSame(m1: InsightModel, m2: InsightModel): Boolean = m1.name == m2.name - override fun areContentsTheSame(m1: InsightModel, m2: InsightModel): Boolean = m1 == m2 - } - } +class InsightsManagementAdapter( + private val onStartDrag: ((viewHolder: ViewHolder) -> Unit)? = null +) : Adapter(), ItemTouchHelperAdapter { + private var items = ArrayList() override fun onCreateViewHolder(parent: ViewGroup, itemType: Int): InsightsManagementViewHolder { - return InsightsManagementViewHolder(parent) + return InsightsManagementViewHolder(parent, onStartDrag) } override fun onBindViewHolder(holder: InsightsManagementViewHolder, position: Int) { - holder.bind(getItem(position)) + holder.bind(items[position]) + } + + override fun onItemMove(fromPosition: Int, toPosition: Int) { + if (fromPosition < toPosition) { + for (i in fromPosition until toPosition) { + Collections.swap(items, i, i + 1) + } + } else { + for (i in fromPosition downTo toPosition + 1) { + Collections.swap(items, i, i - 1) + } + } + notifyItemMoved(fromPosition, toPosition) + } + + override fun getItemCount(): Int = items.size + + fun update(newItems: List) { + if (newItems.size >= items.size) { + val diffResult = DiffUtil.calculateDiff(InsightModelDiffCallback(items, newItems)) + items = ArrayList(newItems) + diffResult.dispatchUpdatesTo(this) + } else { + items = ArrayList(newItems) + notifyDataSetChanged() + } + } +} + +interface ItemTouchHelperAdapter { + fun onItemMove(fromPosition: Int, toPosition: Int) +} + +class InsightModelDiffCallback( + private val oldList: List, + private val newList: List +) : Callback() { + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + return oldList[oldItemPosition] == newList[oldItemPosition] + } + + override fun getOldListSize(): Int = oldList.size + + override fun getNewListSize(): Int = newList.size + + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + return oldList[oldItemPosition].name == newList[oldItemPosition].name } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index 200b671bce23..8691c18ddd98 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -7,19 +7,20 @@ import android.os.Bundle import android.support.design.widget.Snackbar import android.support.v4.app.FragmentActivity import android.support.v7.widget.LinearLayoutManager -import android.support.v7.widget.RecyclerView import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import dagger.android.support.DaggerFragment import kotlinx.android.synthetic.main.insights_management_fragment.* -import org.wordpress.android.R import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel import javax.inject.Inject +import android.support.v7.widget.helper.ItemTouchHelper +import org.wordpress.android.R class InsightsManagementFragment : DaggerFragment() { @Inject lateinit var viewModelFactory: ViewModelProvider.Factory private lateinit var viewModel: InsightsManagementViewModel + private lateinit var addedInsightsTouchHelper: ItemTouchHelper override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.insights_management_fragment, container, false) @@ -62,21 +63,35 @@ class InsightsManagementFragment : DaggerFragment() { viewModel.removedInsights.observe(this, Observer { it?.let { items -> - updateInsights(items, removedInsights) + updateRemovedInsights(items) } }) viewModel.addedInsights.observe(this, Observer { it?.let { items -> - updateInsights(items, addedInsights) + updateAddedInsights(items) } }) } - private fun updateInsights(insights: List, recyclerView: RecyclerView) { - if (recyclerView.adapter == null) { - recyclerView.adapter = InsightsManagementAdapter() + private fun updateRemovedInsights(insights: List) { + if (removedInsights.adapter == null) { + removedInsights.adapter = InsightsManagementAdapter() + } + val adapter = removedInsights.adapter as InsightsManagementAdapter + adapter.update(insights) + } + + private fun updateAddedInsights(insights: List) { + var adapter = addedInsights.adapter as? InsightsManagementAdapter + if (adapter == null) { + adapter = InsightsManagementAdapter { viewHolder -> addedInsightsTouchHelper.startDrag(viewHolder) } + addedInsights.adapter = adapter + + val callback = ItemTouchHelperCallback(adapter) + addedInsightsTouchHelper = ItemTouchHelper(callback) + addedInsightsTouchHelper.attachToRecyclerView(addedInsights) } - (recyclerView.adapter as InsightsManagementAdapter).submitList(insights) + adapter.update(insights) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt index 817ffe09ec7a..f5e071d14891 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt @@ -1,7 +1,10 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management +import android.support.v4.view.MotionEventCompat import android.support.v7.widget.RecyclerView.ViewHolder import android.view.LayoutInflater +import android.view.MotionEvent +import android.view.View import android.view.ViewGroup import android.widget.ImageButton import android.widget.TextView @@ -9,15 +12,29 @@ import org.wordpress.android.R import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel class InsightsManagementViewHolder( - parent: ViewGroup + parent: ViewGroup, + private val onStartDrag: ((viewHolder: ViewHolder) -> Unit)? ) : ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.insights_management_list_item, parent, false)) { private val title: TextView = itemView.findViewById(R.id.itemTitle) private val managementButton: ImageButton = itemView.findViewById(R.id.insightsManagementItemButton) - private val dragAndDropButton: ImageButton = itemView.findViewById(R.id.dragAndDropItemButton) - fun bind(insightModel: InsightModel) { + private val dragAndDropButton: View = itemView.findViewById(R.id.dragAndDropItemButton) + fun bind(insightModel: InsightModel): Boolean { title.setText(insightModel.name) val buttonImage = if (insightModel.isAdded) R.drawable.ic_remove_circle else R.drawable.ic_add_circle managementButton.setImageResource(buttonImage) + + if (insightModel.isAdded) { + dragAndDropButton.setOnTouchListener { _, event -> + if (MotionEventCompat.isFromSource(event, MotionEvent.ACTION_DOWN)) { + onStartDrag?.invoke(this) + } + return@setOnTouchListener true + } + dragAndDropButton.visibility = View.VISIBLE + } else { + dragAndDropButton.visibility = View.GONE + } + return true } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt new file mode 100644 index 000000000000..f4f1d2a83456 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt @@ -0,0 +1,28 @@ +package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management + +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.RecyclerView.ViewHolder +import android.support.v7.widget.helper.ItemTouchHelper + +class ItemTouchHelperCallback(private val mAdapter: ItemTouchHelperAdapter) : ItemTouchHelper.Callback() { + override fun isLongPressDragEnabled(): Boolean { + return true + } + + override fun isItemViewSwipeEnabled(): Boolean { + return false + } + + override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: ViewHolder): Int { + val dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN + return ItemTouchHelper.Callback.makeMovementFlags(dragFlags, 0) + } + + override fun onMove(recyclerView: RecyclerView, viewHolder: ViewHolder, target: ViewHolder): Boolean { + mAdapter.onItemMove(viewHolder.adapterPosition, target.adapterPosition) + return true + } + + override fun onSwiped(viewHolder: ViewHolder, direction: Int) { + } +} From ed85544dc4ef24f3e3df81620e7e3cdd536c76fa Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 27 Mar 2019 17:20:47 +0100 Subject: [PATCH 038/103] Remove redundant code --- .../org/wordpress/android/ui/stats/refresh/StatsFragment.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt index 89a6494e384a..f8d950afaafb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt @@ -58,14 +58,8 @@ class StatsFragment : DaggerFragment() { private var restorePreviousSearch = false - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setHasOptionsMenu(true) - } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { setHasOptionsMenu(true) - return inflater.inflate(R.layout.stats_fragment, container, false) } From 92d2c0bdb025853973774bbd7d633aed0b1113ae Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 27 Mar 2019 17:25:42 +0100 Subject: [PATCH 039/103] Add the save button to the insights management screen --- .../management/InsightsManagementFragment.kt | 17 +++++++++++++++++ .../management/InsightsManagementViewModel.kt | 16 +++++++++++++--- .../management/ItemTouchHelperCallback.kt | 4 ++-- .../main/res/menu/menu_insights_management.xml | 9 +++++++++ WordPress/src/main/res/values/strings.xml | 1 + 5 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 WordPress/src/main/res/menu/menu_insights_management.xml diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index 8691c18ddd98..bb80bb1e3c73 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -15,6 +15,9 @@ import kotlinx.android.synthetic.main.insights_management_fragment.* import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel import javax.inject.Inject import android.support.v7.widget.helper.ItemTouchHelper +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem import org.wordpress.android.R class InsightsManagementFragment : DaggerFragment() { @@ -23,9 +26,23 @@ class InsightsManagementFragment : DaggerFragment() { private lateinit var addedInsightsTouchHelper: ItemTouchHelper override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + setHasOptionsMenu(true) return inflater.inflate(R.layout.insights_management_fragment, container, false) } + override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { + super.onCreateOptionsMenu(menu, inflater) + + inflater?.inflate(R.menu.menu_insights_management, menu) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == R.id.save_insights) { + viewModel.onSaveInsights() + } + return true + } + private fun initializeViews() { removedInsights.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) addedInsights.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index f63146b26ca1..0aaa6413b6e9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -4,10 +4,9 @@ import android.arch.lifecycle.LiveData import android.arch.lifecycle.MutableLiveData import androidx.annotation.StringRes import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import org.wordpress.android.R +import org.wordpress.android.fluxc.model.stats.InsightTypesModel import org.wordpress.android.fluxc.store.StatsStore import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.* @@ -53,11 +52,22 @@ class InsightsManagementViewModel @Inject constructor( } } + fun onSaveInsights() { + launch { + val addedTypes = addedInsights.value?.map { it.insightsTypes } ?: emptyList() + val removedTypes = removedInsights.value?.map { it.insightsTypes } ?: emptyList() + val model = InsightTypesModel(addedTypes, removedTypes + FOLLOWER_TOTALS + ANNUAL_SITE_STATS) + statsStore.updateTypes(siteProvider.siteModel, model) + + mutableSnackbarMessage.value = R.string.stats_insights_saved_message + } + } + override fun onCleared() { mutableSnackbarMessage.value = null } - class InsightModel(insightsTypes: InsightsTypes, val isAdded: Boolean) { + class InsightModel(val insightsTypes: InsightsTypes, val isAdded: Boolean) { @StringRes val name: Int = when (insightsTypes) { LATEST_POST_SUMMARY -> R.string.stats_insights_latest_post_summary MOST_POPULAR_DAY_AND_HOUR -> R.string.stats_insights_popular diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt index f4f1d2a83456..aaa2470b661c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt @@ -4,7 +4,7 @@ import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView.ViewHolder import android.support.v7.widget.helper.ItemTouchHelper -class ItemTouchHelperCallback(private val mAdapter: ItemTouchHelperAdapter) : ItemTouchHelper.Callback() { +class ItemTouchHelperCallback(private val adapter: ItemTouchHelperAdapter) : ItemTouchHelper.Callback() { override fun isLongPressDragEnabled(): Boolean { return true } @@ -19,7 +19,7 @@ class ItemTouchHelperCallback(private val mAdapter: ItemTouchHelperAdapter) : It } override fun onMove(recyclerView: RecyclerView, viewHolder: ViewHolder, target: ViewHolder): Boolean { - mAdapter.onItemMove(viewHolder.adapterPosition, target.adapterPosition) + adapter.onItemMove(viewHolder.adapterPosition, target.adapterPosition) return true } diff --git a/WordPress/src/main/res/menu/menu_insights_management.xml b/WordPress/src/main/res/menu/menu_insights_management.xml new file mode 100644 index 000000000000..a58b0dce68e9 --- /dev/null +++ b/WordPress/src/main/res/menu/menu_insights_management.xml @@ -0,0 +1,9 @@ + + + + diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 9516bb5c9477..b3836419615b 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -1032,6 +1032,7 @@ Only see the most relevant stats. Add and organise your insights below. Add Insights Items shown above will show in your Insights tab. Drag and drop to customize. + Insights have been saved Months and Years From 46fae9bbd99e3c9399161cc4d61075612e8d71cd Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 27 Mar 2019 20:13:24 +0100 Subject: [PATCH 040/103] Fix snackbar display --- .../management/InsightsManagementFragment.kt | 14 ++++---------- .../res/layout/insights_management_fragment.xml | 1 + 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index bb80bb1e3c73..07e5b33772b6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -64,17 +64,11 @@ class InsightsManagementFragment : DaggerFragment() { viewModel.start() } - private fun setupObservers(activity: FragmentActivity) { + private fun setupObservers() { + val view = insightsManagementScrollView viewModel.showSnackbarMessage.observe(this, Observer { holder -> - val parent = activity.findViewById(R.id.coordinatorLayout) - if (holder != null && parent != null) { - if (holder.buttonTitleRes == null) { - Snackbar.make(parent, getString(holder.messageRes), Snackbar.LENGTH_LONG).show() - } else { - val snackbar = Snackbar.make(parent, getString(holder.messageRes), Snackbar.LENGTH_LONG) - snackbar.setAction(getString(holder.buttonTitleRes)) { holder.buttonAction() } - snackbar.show() - } + if (holder != null && view != null) { + Snackbar.make(view, getString(holder.messageRes), Snackbar.LENGTH_LONG).show() } }) diff --git a/WordPress/src/main/res/layout/insights_management_fragment.xml b/WordPress/src/main/res/layout/insights_management_fragment.xml index b672f1d360e0..38ba8d3c54b1 100644 --- a/WordPress/src/main/res/layout/insights_management_fragment.xml +++ b/WordPress/src/main/res/layout/insights_management_fragment.xml @@ -2,6 +2,7 @@ From ed38594385b8ee8eba8ac1596c5a33557389215d Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 27 Mar 2019 20:16:51 +0100 Subject: [PATCH 041/103] Update the ViewModel after dragging items --- .../management/InsightsManagementAdapter.kt | 12 +++++++--- .../management/InsightsManagementFragment.kt | 23 ++++++++++--------- .../management/InsightsManagementViewModel.kt | 9 ++++++++ .../management/ItemTouchHelperCallback.kt | 8 ++++++- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt index 77919e94f974..508a2647c009 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt @@ -9,7 +9,8 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management import java.util.Collections class InsightsManagementAdapter( - private val onStartDrag: ((viewHolder: ViewHolder) -> Unit)? = null + private val onStartDrag: ((viewHolder: ViewHolder) -> Unit)? = null, + private val ondDragFinished: ((List) -> Unit)? = null ) : Adapter(), ItemTouchHelperAdapter { private var items = ArrayList() @@ -21,7 +22,7 @@ class InsightsManagementAdapter( holder.bind(items[position]) } - override fun onItemMove(fromPosition: Int, toPosition: Int) { + override fun onItemMoved(fromPosition: Int, toPosition: Int) { if (fromPosition < toPosition) { for (i in fromPosition until toPosition) { Collections.swap(items, i, i + 1) @@ -34,6 +35,10 @@ class InsightsManagementAdapter( notifyItemMoved(fromPosition, toPosition) } + override fun onDragFinished() { + ondDragFinished?.invoke(items) + } + override fun getItemCount(): Int = items.size fun update(newItems: List) { @@ -49,7 +54,8 @@ class InsightsManagementAdapter( } interface ItemTouchHelperAdapter { - fun onItemMove(fromPosition: Int, toPosition: Int) + fun onItemMoved(fromPosition: Int, toPosition: Int) + fun onDragFinished() } class InsightModelDiffCallback( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index 07e5b33772b6..ada7df6b7b0e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -1,5 +1,6 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management +import android.app.Activity import android.arch.lifecycle.Observer import android.arch.lifecycle.ViewModelProvider import android.arch.lifecycle.ViewModelProviders @@ -7,18 +8,18 @@ import android.os.Bundle import android.support.design.widget.Snackbar import android.support.v4.app.FragmentActivity import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.helper.ItemTouchHelper import android.view.LayoutInflater +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem import android.view.View import android.view.ViewGroup import dagger.android.support.DaggerFragment import kotlinx.android.synthetic.main.insights_management_fragment.* +import org.wordpress.android.R import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel import javax.inject.Inject -import android.support.v7.widget.helper.ItemTouchHelper -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem -import org.wordpress.android.R class InsightsManagementFragment : DaggerFragment() { @Inject lateinit var viewModelFactory: ViewModelProvider.Factory @@ -51,16 +52,13 @@ class InsightsManagementFragment : DaggerFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val nonNullActivity = checkNotNull(activity) - initializeViews() - initializeViewModels(nonNullActivity) + initializeViewModels(requireActivity()) } private fun initializeViewModels(activity: FragmentActivity) { viewModel = ViewModelProviders.of(activity, viewModelFactory).get(InsightsManagementViewModel::class.java) - setupObservers(activity) - + setupObservers() viewModel.start() } @@ -96,7 +94,10 @@ class InsightsManagementFragment : DaggerFragment() { private fun updateAddedInsights(insights: List) { var adapter = addedInsights.adapter as? InsightsManagementAdapter if (adapter == null) { - adapter = InsightsManagementAdapter { viewHolder -> addedInsightsTouchHelper.startDrag(viewHolder) } + adapter = InsightsManagementAdapter( + { viewHolder -> addedInsightsTouchHelper.startDrag(viewHolder) }, + { list -> viewModel.onAddedItemsUpdated(list) } + ) addedInsights.adapter = adapter val callback = ItemTouchHelperCallback(adapter) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index 0aaa6413b6e9..1b88f5c797c6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -12,6 +12,8 @@ import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.* import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.pages.SnackbarMessageHolder +import org.wordpress.android.ui.stats.refresh.INSIGHTS_USE_CASE +import org.wordpress.android.ui.stats.refresh.lists.BaseListUseCase import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.util.map import org.wordpress.android.viewmodel.ScopedViewModel @@ -20,6 +22,7 @@ import javax.inject.Named class InsightsManagementViewModel @Inject constructor( @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, + @Named(INSIGHTS_USE_CASE) val insightsUseCase: BaseListUseCase, private val siteProvider: StatsSiteProvider, private val statsStore: StatsStore ) : ScopedViewModel(mainDispatcher) { @@ -60,9 +63,15 @@ class InsightsManagementViewModel @Inject constructor( statsStore.updateTypes(siteProvider.siteModel, model) mutableSnackbarMessage.value = R.string.stats_insights_saved_message + + insightsUseCase.refreshData() } } + fun onAddedItemsUpdated(items: List) { + _addedInsights.value = items + } + override fun onCleared() { mutableSnackbarMessage.value = null } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt index aaa2470b661c..b30a55a2a482 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt @@ -19,10 +19,16 @@ class ItemTouchHelperCallback(private val adapter: ItemTouchHelperAdapter) : Ite } override fun onMove(recyclerView: RecyclerView, viewHolder: ViewHolder, target: ViewHolder): Boolean { - adapter.onItemMove(viewHolder.adapterPosition, target.adapterPosition) + adapter.onItemMoved(viewHolder.adapterPosition, target.adapterPosition) return true } override fun onSwiped(viewHolder: ViewHolder, direction: Int) { } + + override fun clearView(recyclerView: RecyclerView, viewHolder: ViewHolder) { + super.clearView(recyclerView, viewHolder) + + adapter.onDragFinished() + } } From a6a2b8a6f49f36b0358dc938e69a97428e437739 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 27 Mar 2019 21:33:58 +0100 Subject: [PATCH 042/103] Whitespace clean up --- .../android/ui/stats/refresh/lists/StatsBlockAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockAdapter.kt index 260064dedce9..7d3225991eec 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockAdapter.kt @@ -15,6 +15,7 @@ import org.wordpress.android.util.image.ImageManager class StatsBlockAdapter(val imageManager: ImageManager) : Adapter() { private var items: List = listOf() + fun update(newItems: List) { val diffResult = DiffUtil.calculateDiff( StatsBlockDiffCallback( @@ -23,7 +24,6 @@ class StatsBlockAdapter(val imageManager: ImageManager) : Adapter Date: Wed, 27 Mar 2019 21:34:28 +0100 Subject: [PATCH 043/103] Fix insights diff util comparisons --- .../sections/insights/management/InsightsManagementAdapter.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt index 508a2647c009..d57e1c0d0a67 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt @@ -63,7 +63,7 @@ class InsightModelDiffCallback( private val newList: List ) : Callback() { override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - return oldList[oldItemPosition] == newList[oldItemPosition] + return oldList[oldItemPosition].insightsTypes == newList[newItemPosition].insightsTypes } override fun getOldListSize(): Int = oldList.size @@ -71,6 +71,6 @@ class InsightModelDiffCallback( override fun getNewListSize(): Int = newList.size override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - return oldList[oldItemPosition].name == newList[oldItemPosition].name + return oldList[oldItemPosition] == newList[newItemPosition] } } From 9fae18aaf421c992f999a3e5462d5d06a5170907 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 27 Mar 2019 21:35:27 +0100 Subject: [PATCH 044/103] Add insights adding and removal functionality --- .../management/InsightsManagementAdapter.kt | 11 ++++++----- .../management/InsightsManagementFragment.kt | 4 ++-- .../management/InsightsManagementViewHolder.kt | 6 +++++- .../management/InsightsManagementViewModel.kt | 16 +++++++++++++++- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt index d57e1c0d0a67..76c5e365d8df 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt @@ -9,17 +9,18 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management import java.util.Collections class InsightsManagementAdapter( - private val onStartDrag: ((viewHolder: ViewHolder) -> Unit)? = null, - private val ondDragFinished: ((List) -> Unit)? = null + private val onItemButtonClicked: (InsightModel) -> Unit, + private val onDragStarted: ((viewHolder: ViewHolder) -> Unit)? = null, + private val onDragFinished: ((List) -> Unit)? = null ) : Adapter(), ItemTouchHelperAdapter { private var items = ArrayList() override fun onCreateViewHolder(parent: ViewGroup, itemType: Int): InsightsManagementViewHolder { - return InsightsManagementViewHolder(parent, onStartDrag) + return InsightsManagementViewHolder(parent, onDragStarted) } override fun onBindViewHolder(holder: InsightsManagementViewHolder, position: Int) { - holder.bind(items[position]) + holder.bind(items[position], onItemButtonClicked) } override fun onItemMoved(fromPosition: Int, toPosition: Int) { @@ -36,7 +37,7 @@ class InsightsManagementAdapter( } override fun onDragFinished() { - ondDragFinished?.invoke(items) + onDragFinished?.invoke(items) } override fun getItemCount(): Int = items.size diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index ada7df6b7b0e..c0ebbbb96af1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -1,6 +1,5 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management -import android.app.Activity import android.arch.lifecycle.Observer import android.arch.lifecycle.ViewModelProvider import android.arch.lifecycle.ViewModelProviders @@ -85,7 +84,7 @@ class InsightsManagementFragment : DaggerFragment() { private fun updateRemovedInsights(insights: List) { if (removedInsights.adapter == null) { - removedInsights.adapter = InsightsManagementAdapter() + removedInsights.adapter = InsightsManagementAdapter({ item -> viewModel.onItemButtonClicked(item) }) } val adapter = removedInsights.adapter as InsightsManagementAdapter adapter.update(insights) @@ -95,6 +94,7 @@ class InsightsManagementFragment : DaggerFragment() { var adapter = addedInsights.adapter as? InsightsManagementAdapter if (adapter == null) { adapter = InsightsManagementAdapter( + { item -> viewModel.onItemButtonClicked(item) }, { viewHolder -> addedInsightsTouchHelper.startDrag(viewHolder) }, { list -> viewModel.onAddedItemsUpdated(list) } ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt index f5e071d14891..561e9da8bbe3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt @@ -18,11 +18,15 @@ class InsightsManagementViewHolder( private val title: TextView = itemView.findViewById(R.id.itemTitle) private val managementButton: ImageButton = itemView.findViewById(R.id.insightsManagementItemButton) private val dragAndDropButton: View = itemView.findViewById(R.id.dragAndDropItemButton) - fun bind(insightModel: InsightModel): Boolean { + + fun bind(insightModel: InsightModel, onButtonClicked: (InsightModel) -> Unit): Boolean { title.setText(insightModel.name) val buttonImage = if (insightModel.isAdded) R.drawable.ic_remove_circle else R.drawable.ic_add_circle managementButton.setImageResource(buttonImage) + managementButton.setOnClickListener { + onButtonClicked(insightModel) + } if (insightModel.isAdded) { dragAndDropButton.setOnTouchListener { _, event -> diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index 1b88f5c797c6..f8c06e8347bb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -4,6 +4,7 @@ import android.arch.lifecycle.LiveData import android.arch.lifecycle.MutableLiveData import androidx.annotation.StringRes import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.wordpress.android.R import org.wordpress.android.fluxc.model.stats.InsightTypesModel @@ -72,11 +73,24 @@ class InsightsManagementViewModel @Inject constructor( _addedInsights.value = items } + fun onItemButtonClicked(insight: InsightModel) { + launch { + delay(500) + if (insight.isAdded) { + _addedInsights.value = _addedInsights.value?.filter { it != insight } + _removedInsights.value = _removedInsights.value?.let { it + insight.copy(isAdded = false) } + } else { + _removedInsights.value = _removedInsights.value?.filter { it != insight } + _addedInsights.value = _addedInsights.value?.let { it + insight.copy(isAdded = true) } + } + } + } + override fun onCleared() { mutableSnackbarMessage.value = null } - class InsightModel(val insightsTypes: InsightsTypes, val isAdded: Boolean) { + data class InsightModel(val insightsTypes: InsightsTypes, val isAdded: Boolean) { @StringRes val name: Int = when (insightsTypes) { LATEST_POST_SUMMARY -> R.string.stats_insights_latest_post_summary MOST_POPULAR_DAY_AND_HOUR -> R.string.stats_insights_popular From 36b8aa276e74134c1c6b49bd8cd13ec4defba238 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Thu, 28 Mar 2019 13:48:33 +0100 Subject: [PATCH 045/103] Update string resources --- WordPress/src/main/AndroidManifest.xml | 2 +- WordPress/src/main/res/layout/stats_empty_view.xml | 2 +- WordPress/src/main/res/menu/menu_stats_insights.xml | 2 +- WordPress/src/main/res/values-ar/strings.xml | 2 +- WordPress/src/main/res/values-de/strings.xml | 2 +- WordPress/src/main/res/values-en-rAU/strings.xml | 2 +- WordPress/src/main/res/values-en-rCA/strings.xml | 2 +- WordPress/src/main/res/values-en-rGB/strings.xml | 2 +- WordPress/src/main/res/values-es-rCL/strings.xml | 2 +- WordPress/src/main/res/values-es/strings.xml | 2 +- WordPress/src/main/res/values-fr/strings.xml | 2 +- WordPress/src/main/res/values-he/strings.xml | 2 +- WordPress/src/main/res/values-id/strings.xml | 2 +- WordPress/src/main/res/values-it/strings.xml | 2 +- WordPress/src/main/res/values-ja/strings.xml | 2 +- WordPress/src/main/res/values-ko/strings.xml | 2 +- WordPress/src/main/res/values-nb/strings.xml | 2 +- WordPress/src/main/res/values-pl/strings.xml | 2 +- WordPress/src/main/res/values-pt-rBR/strings.xml | 2 +- WordPress/src/main/res/values-ro/strings.xml | 2 +- WordPress/src/main/res/values-ru/strings.xml | 2 +- WordPress/src/main/res/values-sq/strings.xml | 2 +- WordPress/src/main/res/values-sv/strings.xml | 2 +- WordPress/src/main/res/values-tr/strings.xml | 2 +- WordPress/src/main/res/values-zh-rCN/strings.xml | 2 +- WordPress/src/main/res/values-zh-rHK/strings.xml | 2 +- WordPress/src/main/res/values-zh-rTW/strings.xml | 2 +- WordPress/src/main/res/values/strings.xml | 3 ++- 28 files changed, 29 insertions(+), 28 deletions(-) diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index b0703fb7894a..44a83a641bf0 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -292,7 +292,7 @@ android:theme="@style/Calypso.NoActionBar" /> diff --git a/WordPress/src/main/res/menu/menu_stats_insights.xml b/WordPress/src/main/res/menu/menu_stats_insights.xml index 9a9e74776d88..8485da2b8f98 100644 --- a/WordPress/src/main/res/menu/menu_stats_insights.xml +++ b/WordPress/src/main/res/menu/menu_stats_insights.xml @@ -4,5 +4,5 @@ + android:title="@string/stats_menu_manage_insights_button"/> diff --git a/WordPress/src/main/res/values-ar/strings.xml b/WordPress/src/main/res/values-ar/strings.xml index 4a3072747aa8..412e55c843a9 100644 --- a/WordPress/src/main/res/values-ar/strings.xml +++ b/WordPress/src/main/res/values-ar/strings.xml @@ -192,7 +192,7 @@ Language: ar إجمالي %1$s من المتابعين: %2$s البريد الإلكتروني وردبرس.كوم - إدارة الرؤى + إدارة الرؤى تخصيص الرؤى الخاصة بك والحصول على معلومات حول أداء موقعك لم تتم إضافة رى حتى الآن لا توجد بيانات حتى الآن diff --git a/WordPress/src/main/res/values-de/strings.xml b/WordPress/src/main/res/values-de/strings.xml index 37ace6a8303e..dfa360a76995 100644 --- a/WordPress/src/main/res/values-de/strings.xml +++ b/WordPress/src/main/res/values-de/strings.xml @@ -192,7 +192,7 @@ Language: de %1$s-Follower insgesamt: %2$s E-Mail WordPress.com - Einsichten verwalten + Einsichten verwalten Passe deine Einsichten an und erhalte Details zur Leistung deiner Website Noch keine Einsichten hinzugefügt Noch keine Daten diff --git a/WordPress/src/main/res/values-en-rAU/strings.xml b/WordPress/src/main/res/values-en-rAU/strings.xml index 1779a1cbf5e4..15b98fe7c4ed 100644 --- a/WordPress/src/main/res/values-en-rAU/strings.xml +++ b/WordPress/src/main/res/values-en-rAU/strings.xml @@ -192,7 +192,7 @@ Language: en_AU Total %1$s Followers: %2$s Email WordPress.com - Manage insights + Manage insights Customise your insights and get the low-down on your site’s performance No insights added yet No data yet diff --git a/WordPress/src/main/res/values-en-rCA/strings.xml b/WordPress/src/main/res/values-en-rCA/strings.xml index c9aa0fd1d3a0..fbbca8e414dc 100644 --- a/WordPress/src/main/res/values-en-rCA/strings.xml +++ b/WordPress/src/main/res/values-en-rCA/strings.xml @@ -192,7 +192,7 @@ Language: en_CA Total %1$s Followers: %2$s Email WordPress.com - Manage insights + Manage insights Customize your insights and get the low-down on your site’s performance No insights added yet No data yet diff --git a/WordPress/src/main/res/values-en-rGB/strings.xml b/WordPress/src/main/res/values-en-rGB/strings.xml index 29740d287f79..2f75b8b56e4e 100644 --- a/WordPress/src/main/res/values-en-rGB/strings.xml +++ b/WordPress/src/main/res/values-en-rGB/strings.xml @@ -192,7 +192,7 @@ Language: en_GB Total %1$s Followers: %2$s E-mail WordPress.com - Manage insights + Manage insights Customise your insights and get the low-down on your site’s performance No insights added yet No data yet diff --git a/WordPress/src/main/res/values-es-rCL/strings.xml b/WordPress/src/main/res/values-es-rCL/strings.xml index 0324765f6e74..3d8fcd19ad9e 100644 --- a/WordPress/src/main/res/values-es-rCL/strings.xml +++ b/WordPress/src/main/res/values-es-rCL/strings.xml @@ -62,7 +62,7 @@ Language: es_CL Total %1$s Seguidores: %2$s Email WordPress.com - Administrar estadísticas + Administrar estadísticas Aún no se ha añadido estadisticas Aún no hay datos Menú Depuración diff --git a/WordPress/src/main/res/values-es/strings.xml b/WordPress/src/main/res/values-es/strings.xml index c2bd6bee7252..0654d1eaf7ca 100644 --- a/WordPress/src/main/res/values-es/strings.xml +++ b/WordPress/src/main/res/values-es/strings.xml @@ -192,7 +192,7 @@ Language: es Total %1$s seguidores: %2$s Correo electrónico WordPress.com - Gestionar impresiones + Gestionar impresiones Personaliza tus informes y profundiza en el rendimiento de tu sitio Aún no se han añadido impresiones Aún no hay datos diff --git a/WordPress/src/main/res/values-fr/strings.xml b/WordPress/src/main/res/values-fr/strings.xml index 9647198efd1d..43d7a1f8a922 100644 --- a/WordPress/src/main/res/values-fr/strings.xml +++ b/WordPress/src/main/res/values-fr/strings.xml @@ -192,7 +192,7 @@ Language: fr Total des abonnés %1$s : %2$s E-mail WordPress.com - Gérer les tendances + Gérer les tendances Personnalisez vos tendances et obtenez les dernières informations sur les performances de votre site Aucune tendance n’a encore été ajoutée Aucune donnée pour le moment. diff --git a/WordPress/src/main/res/values-he/strings.xml b/WordPress/src/main/res/values-he/strings.xml index bc5de15ce421..220b5b84b70c 100644 --- a/WordPress/src/main/res/values-he/strings.xml +++ b/WordPress/src/main/res/values-he/strings.xml @@ -189,7 +189,7 @@ Language: he_IL סך הכול %1$s עוקבים: %2$s אימייל WordPress.com - ניהול תובנות + ניהול תובנות עדיין לא נוספו תובנות עדיין אין נתונים תפריט איתור באגים diff --git a/WordPress/src/main/res/values-id/strings.xml b/WordPress/src/main/res/values-id/strings.xml index 1ddbb0c99615..7c2bc309b3c3 100644 --- a/WordPress/src/main/res/values-id/strings.xml +++ b/WordPress/src/main/res/values-id/strings.xml @@ -189,7 +189,7 @@ Language: id Total %1$s Pengikut: %2$s Email WordPress.com - Kelola informasi + Kelola informasi Belum ada informasi yang ditambahkan Belum ada data Menu Debug diff --git a/WordPress/src/main/res/values-it/strings.xml b/WordPress/src/main/res/values-it/strings.xml index 65344482186d..19c47bccba04 100644 --- a/WordPress/src/main/res/values-it/strings.xml +++ b/WordPress/src/main/res/values-it/strings.xml @@ -173,7 +173,7 @@ Language: it Totale follower da %1$s: %2$s Email WordPress.com - Gestisci insight + Gestisci insight Nessun insight aggiunto Nessun dato Menu di debug diff --git a/WordPress/src/main/res/values-ja/strings.xml b/WordPress/src/main/res/values-ja/strings.xml index dc5da4b845d9..14c46625b4a6 100644 --- a/WordPress/src/main/res/values-ja/strings.xml +++ b/WordPress/src/main/res/values-ja/strings.xml @@ -192,7 +192,7 @@ Language: ja_JP Total %1$s Followers:%2$s メール WordPress.com - インサイトを管理 + インサイトを管理 インサイトをカスタマイズして、サイトのパフォーマンスを把握しましょう インサイトは追加されていません データはまだありません diff --git a/WordPress/src/main/res/values-ko/strings.xml b/WordPress/src/main/res/values-ko/strings.xml index 9c3460d5c1fe..dcf7fac6b64b 100644 --- a/WordPress/src/main/res/values-ko/strings.xml +++ b/WordPress/src/main/res/values-ko/strings.xml @@ -185,7 +185,7 @@ Language: ko_KR 총 %1$s 팔로워 수: %2$s 이메일 워드프레스닷컴 - 인사이트 관리 + 인사이트 관리 아직 추가된 인사이트가 없음 아직 데이터 없음 디버그 메뉴 diff --git a/WordPress/src/main/res/values-nb/strings.xml b/WordPress/src/main/res/values-nb/strings.xml index 9818bf62260f..a79474553e7e 100644 --- a/WordPress/src/main/res/values-nb/strings.xml +++ b/WordPress/src/main/res/values-nb/strings.xml @@ -180,7 +180,7 @@ Language: nb_NO Totalt %1$s følgere: %2$s E-post WordPress.com - Behandle innsikter + Behandle innsikter Tilpass dine innsikter og få den viktigste informasjonen om ytelsen til nettstedet ditt Ingen innsikter lagt til ennå Ingen data ennå diff --git a/WordPress/src/main/res/values-pl/strings.xml b/WordPress/src/main/res/values-pl/strings.xml index c8b1af7ff225..2b3266779d50 100644 --- a/WordPress/src/main/res/values-pl/strings.xml +++ b/WordPress/src/main/res/values-pl/strings.xml @@ -192,7 +192,7 @@ Language: pl Całkowita liczba obserwujących %1$s: %2$s Email WordPress.com - Zarządzaj trendami + Zarządzaj trendami Spersonalizuj kartę Trendy i uzyskaj pełną informację o wynikach swojej witryny Brak trendów, jak dotąd Brak danych, jak dotąd diff --git a/WordPress/src/main/res/values-pt-rBR/strings.xml b/WordPress/src/main/res/values-pt-rBR/strings.xml index 189510e2d73b..2e35a73b5d00 100644 --- a/WordPress/src/main/res/values-pt-rBR/strings.xml +++ b/WordPress/src/main/res/values-pt-rBR/strings.xml @@ -192,7 +192,7 @@ Language: pt_BR Total de seguidores por %1$s: %2$s E-mail WordPress.com - Gerenciar informações + Gerenciar informações Personalize as informações de seu site para saber mais sobre seu desempenho Nenhuma informação adicionada ainda Nenhum dado ainda diff --git a/WordPress/src/main/res/values-ro/strings.xml b/WordPress/src/main/res/values-ro/strings.xml index 90fd9c6b12ec..3bb62e1dc6e0 100644 --- a/WordPress/src/main/res/values-ro/strings.xml +++ b/WordPress/src/main/res/values-ro/strings.xml @@ -192,7 +192,7 @@ Language: ro Total urmăritori %1$s: %2$s Prin email WordPress.com - Administrează perspectivele + Administrează perspectivele Personalizează-ți perspectivele și primești informații relevante despre performanța sitului Nu ai adăugat perspective până acum Încă nu există date diff --git a/WordPress/src/main/res/values-ru/strings.xml b/WordPress/src/main/res/values-ru/strings.xml index 1bcb45f8d0ee..0d20f1d1684b 100644 --- a/WordPress/src/main/res/values-ru/strings.xml +++ b/WordPress/src/main/res/values-ru/strings.xml @@ -192,7 +192,7 @@ Language: ru Всего %1$s Подписчики: %2$s Email WordPress.com - Настроить статистику + Настроить статистику Настройте вашу статистику и узнайте важное то, чем живет ваш сайт. Еще нет статистики Пока нет данных diff --git a/WordPress/src/main/res/values-sq/strings.xml b/WordPress/src/main/res/values-sq/strings.xml index 921a7281ff1b..b52c3d739158 100644 --- a/WordPress/src/main/res/values-sq/strings.xml +++ b/WordPress/src/main/res/values-sq/strings.xml @@ -192,7 +192,7 @@ Language: sq_AL %1$s Ndjekës Gjithsej: %2$s Email WordPress.com - Administroni tendenca + Administroni tendenca Përshtatni tendencat tuaj dhe merrni faktet mbi funksionimin e sajtit tuaj S’janë shtuar ende tendenca Ende pa të dhëna diff --git a/WordPress/src/main/res/values-sv/strings.xml b/WordPress/src/main/res/values-sv/strings.xml index 97cd23002f88..064030e49c9d 100644 --- a/WordPress/src/main/res/values-sv/strings.xml +++ b/WordPress/src/main/res/values-sv/strings.xml @@ -192,7 +192,7 @@ Language: sv_SE Totalt antal följare för ”%1$s”: %2$s E-post WordPress.com - Hantera insikter + Hantera insikter Anpassa dina insikter och se detaljerna om hur din webbplats presterar Inga insikter har lagts till än Inga data insamlade än diff --git a/WordPress/src/main/res/values-tr/strings.xml b/WordPress/src/main/res/values-tr/strings.xml index 5c1e9586504e..4f0e73ec898f 100644 --- a/WordPress/src/main/res/values-tr/strings.xml +++ b/WordPress/src/main/res/values-tr/strings.xml @@ -192,7 +192,7 @@ Language: tr Toplam %1$s takipçisi: %2$s E-posta WordPress.com - İçgörüleri yönet + İçgörüleri yönet Analizlerinizi özelleştirin ve sitenizin performansındaki düşüş hakkında bilgi edinin Henüz içgörü eklenmedi Henüz veri yok diff --git a/WordPress/src/main/res/values-zh-rCN/strings.xml b/WordPress/src/main/res/values-zh-rCN/strings.xml index ba710ba92595..f9368282b449 100644 --- a/WordPress/src/main/res/values-zh-rCN/strings.xml +++ b/WordPress/src/main/res/values-zh-rCN/strings.xml @@ -147,7 +147,7 @@ Language: zh_CN 共 %1$s 位粉丝:%2$s 电子邮件 WordPress.com - 管理见解 + 管理见解 尚未添加任何见解 尚无数据 正在更改密码… diff --git a/WordPress/src/main/res/values-zh-rHK/strings.xml b/WordPress/src/main/res/values-zh-rHK/strings.xml index 321d741ebc1d..f6e625861adb 100644 --- a/WordPress/src/main/res/values-zh-rHK/strings.xml +++ b/WordPress/src/main/res/values-zh-rHK/strings.xml @@ -147,7 +147,7 @@ Language: zh_TW %1$s 關注者總數:%2$s 電子郵件 WordPress.com - 管理洞察報告 + 管理洞察報告 尚未新增任何洞察報告 尚無資料 除錯選單 diff --git a/WordPress/src/main/res/values-zh-rTW/strings.xml b/WordPress/src/main/res/values-zh-rTW/strings.xml index 321d741ebc1d..f6e625861adb 100644 --- a/WordPress/src/main/res/values-zh-rTW/strings.xml +++ b/WordPress/src/main/res/values-zh-rTW/strings.xml @@ -147,7 +147,7 @@ Language: zh_TW %1$s 關注者總數:%2$s 電子郵件 WordPress.com - 管理洞察報告 + 管理洞察報告 尚未新增任何洞察報告 尚無資料 除錯選單 diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index b3836419615b..c9ae28d2f27a 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -790,7 +790,8 @@ No data for this period No insights added yet Customize your insights and get the low-down on your site’s performance - Manage Insights + Manage Insights + Manage WordPress.com Email Total %1$s Followers: %2$s From 00bed851c6427d1f29814d19a3699df8092f2262 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Thu, 28 Mar 2019 13:49:58 +0100 Subject: [PATCH 046/103] Create separate for added and removed insight types --- .../management/AddedInsightViewHolder.kt | 38 +++++++++++++++++++ .../management/InsightsManagementAdapter.kt | 33 +++++++++------- .../management/InsightsManagementFragment.kt | 6 ++- .../InsightsManagementViewHolder.kt | 37 ++---------------- .../management/InsightsManagementViewModel.kt | 20 ++++++---- .../management/RemovedInsightViewHolder.kt | 28 ++++++++++++++ 6 files changed, 107 insertions(+), 55 deletions(-) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/AddedInsightViewHolder.kt create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/RemovedInsightViewHolder.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/AddedInsightViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/AddedInsightViewHolder.kt new file mode 100644 index 000000000000..c8eeb01bb9ab --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/AddedInsightViewHolder.kt @@ -0,0 +1,38 @@ +package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management + +import android.support.v4.view.MotionEventCompat +import android.support.v7.widget.RecyclerView.ViewHolder +import android.view.MotionEvent +import android.view.View +import android.view.ViewGroup +import android.widget.ImageButton +import android.widget.TextView +import org.wordpress.android.R +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel + +class AddedInsightViewHolder( + val parent: ViewGroup, + private val onDragStarted: (viewHolder: ViewHolder) -> Unit, + private val onButtonClicked: (InsightModel) -> Unit +) : InsightsManagementViewHolder(parent) { + private val title: TextView = itemView.findViewById(R.id.itemTitle) + private val managementButton: ImageButton = itemView.findViewById(R.id.insightsManagementItemButton) + private val dragAndDropButton: View = itemView.findViewById(R.id.dragAndDropItemButton) + + override fun bind(insight: InsightModel) { + title.setText(insight.name) + + managementButton.setImageResource(R.drawable.ic_remove_circle) + managementButton.setOnClickListener { + onButtonClicked(insight) + } + + dragAndDropButton.setOnTouchListener { _, event -> + if (MotionEventCompat.isFromSource(event, MotionEvent.ACTION_DOWN)) { + onDragStarted(this) + } + return@setOnTouchListener true + } + dragAndDropButton.visibility = View.VISIBLE + } +} diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt index 76c5e365d8df..f933c5f600e6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt @@ -6,21 +6,31 @@ import android.support.v7.widget.RecyclerView.Adapter import android.support.v7.widget.RecyclerView.ViewHolder import android.view.ViewGroup import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel.Type.ADDED +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel.Type.REMOVED import java.util.Collections class InsightsManagementAdapter( private val onItemButtonClicked: (InsightModel) -> Unit, - private val onDragStarted: ((viewHolder: ViewHolder) -> Unit)? = null, - private val onDragFinished: ((List) -> Unit)? = null + private val onDragStarted: (viewHolder: ViewHolder) -> Unit, + private val onDragFinished: (List) -> Unit ) : Adapter(), ItemTouchHelperAdapter { private var items = ArrayList() override fun onCreateViewHolder(parent: ViewGroup, itemType: Int): InsightsManagementViewHolder { - return InsightsManagementViewHolder(parent, onDragStarted) + val type = InsightModel.Type.values()[itemType] + return when (type) { + ADDED -> AddedInsightViewHolder(parent, onDragStarted, onItemButtonClicked) + REMOVED -> RemovedInsightViewHolder(parent, onItemButtonClicked) + } } override fun onBindViewHolder(holder: InsightsManagementViewHolder, position: Int) { - holder.bind(items[position], onItemButtonClicked) + holder.bind(items[position]) + } + + override fun getItemViewType(position: Int): Int { + return items[position].type.ordinal } override fun onItemMoved(fromPosition: Int, toPosition: Int) { @@ -37,20 +47,17 @@ class InsightsManagementAdapter( } override fun onDragFinished() { - onDragFinished?.invoke(items) + onDragFinished.invoke(items) } override fun getItemCount(): Int = items.size + + fun update(newItems: List) { - if (newItems.size >= items.size) { - val diffResult = DiffUtil.calculateDiff(InsightModelDiffCallback(items, newItems)) - items = ArrayList(newItems) - diffResult.dispatchUpdatesTo(this) - } else { - items = ArrayList(newItems) - notifyDataSetChanged() - } + val diffResult = DiffUtil.calculateDiff(InsightModelDiffCallback(items, newItems)) + items = ArrayList(newItems) + diffResult.dispatchUpdatesTo(this) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index c0ebbbb96af1..8256853d1957 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -84,7 +84,11 @@ class InsightsManagementFragment : DaggerFragment() { private fun updateRemovedInsights(insights: List) { if (removedInsights.adapter == null) { - removedInsights.adapter = InsightsManagementAdapter({ item -> viewModel.onItemButtonClicked(item) }) + removedInsights.adapter = InsightsManagementAdapter( + { item -> viewModel.onItemButtonClicked(item) }, + { viewHolder -> addedInsightsTouchHelper.startDrag(viewHolder) }, + { list -> viewModel.onAddedItemsUpdated(list) } + ) } val adapter = removedInsights.adapter as InsightsManagementAdapter adapter.update(insights) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt index 561e9da8bbe3..8c4864c4272e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewHolder.kt @@ -1,44 +1,13 @@ package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management -import android.support.v4.view.MotionEventCompat import android.support.v7.widget.RecyclerView.ViewHolder import android.view.LayoutInflater -import android.view.MotionEvent -import android.view.View import android.view.ViewGroup -import android.widget.ImageButton -import android.widget.TextView import org.wordpress.android.R import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel -class InsightsManagementViewHolder( - parent: ViewGroup, - private val onStartDrag: ((viewHolder: ViewHolder) -> Unit)? +abstract class InsightsManagementViewHolder( + parent: ViewGroup ) : ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.insights_management_list_item, parent, false)) { - private val title: TextView = itemView.findViewById(R.id.itemTitle) - private val managementButton: ImageButton = itemView.findViewById(R.id.insightsManagementItemButton) - private val dragAndDropButton: View = itemView.findViewById(R.id.dragAndDropItemButton) - - fun bind(insightModel: InsightModel, onButtonClicked: (InsightModel) -> Unit): Boolean { - title.setText(insightModel.name) - - val buttonImage = if (insightModel.isAdded) R.drawable.ic_remove_circle else R.drawable.ic_add_circle - managementButton.setImageResource(buttonImage) - managementButton.setOnClickListener { - onButtonClicked(insightModel) - } - - if (insightModel.isAdded) { - dragAndDropButton.setOnTouchListener { _, event -> - if (MotionEventCompat.isFromSource(event, MotionEvent.ACTION_DOWN)) { - onStartDrag?.invoke(this) - } - return@setOnTouchListener true - } - dragAndDropButton.visibility = View.VISIBLE - } else { - dragAndDropButton.visibility = View.GONE - } - return true - } + abstract fun bind(insight: InsightModel) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index f8c06e8347bb..d5d6e73c3f60 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -15,6 +15,8 @@ import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.stats.refresh.INSIGHTS_USE_CASE import org.wordpress.android.ui.stats.refresh.lists.BaseListUseCase +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel.Type.ADDED +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel.Type.REMOVED import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.util.map import org.wordpress.android.viewmodel.ScopedViewModel @@ -48,11 +50,11 @@ class InsightsManagementViewModel @Inject constructor( val model = statsStore.getInsightsManagementModel(siteProvider.siteModel) _addedInsights.value = model.addedTypes .filter { it != FOLLOWER_TOTALS && it != ANNUAL_SITE_STATS } - .map { InsightModel(it, true) } + .map { InsightModel(it, ADDED) } _removedInsights.value = model.removedTypes .filter { it != FOLLOWER_TOTALS && it != ANNUAL_SITE_STATS } - .map { InsightModel(it, false) } + .map { InsightModel(it, REMOVED) } } } @@ -75,13 +77,12 @@ class InsightsManagementViewModel @Inject constructor( fun onItemButtonClicked(insight: InsightModel) { launch { - delay(500) - if (insight.isAdded) { + if (insight.type == ADDED) { _addedInsights.value = _addedInsights.value?.filter { it != insight } - _removedInsights.value = _removedInsights.value?.let { it + insight.copy(isAdded = false) } + _removedInsights.value = _removedInsights.value?.let { it + insight.copy(type = REMOVED) } } else { _removedInsights.value = _removedInsights.value?.filter { it != insight } - _addedInsights.value = _addedInsights.value?.let { it + insight.copy(isAdded = true) } + _addedInsights.value = _addedInsights.value?.let { it + insight.copy(type = ADDED) } } } } @@ -90,7 +91,7 @@ class InsightsManagementViewModel @Inject constructor( mutableSnackbarMessage.value = null } - data class InsightModel(val insightsTypes: InsightsTypes, val isAdded: Boolean) { + data class InsightModel(val insightsTypes: InsightsTypes, val type: Type) { @StringRes val name: Int = when (insightsTypes) { LATEST_POST_SUMMARY -> R.string.stats_insights_latest_post_summary MOST_POPULAR_DAY_AND_HOUR -> R.string.stats_insights_popular @@ -103,5 +104,10 @@ class InsightsManagementViewModel @Inject constructor( PUBLICIZE -> R.string.stats_view_publicize else -> R.string.unknown } + + enum class Type { + ADDED, + REMOVED + } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/RemovedInsightViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/RemovedInsightViewHolder.kt new file mode 100644 index 000000000000..bce66f30cf9a --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/RemovedInsightViewHolder.kt @@ -0,0 +1,28 @@ +package org.wordpress.android.ui.stats.refresh.lists.sections.insights.management + +import android.view.View +import android.view.ViewGroup +import android.widget.ImageButton +import android.widget.TextView +import org.wordpress.android.R +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel + +class RemovedInsightViewHolder( + val parent: ViewGroup, + private val onButtonClicked: (InsightModel) -> Unit +) : InsightsManagementViewHolder(parent) { + private val title: TextView = itemView.findViewById(R.id.itemTitle) + private val managementButton: ImageButton = itemView.findViewById(R.id.insightsManagementItemButton) + private val dragAndDropButton: View = itemView.findViewById(R.id.dragAndDropItemButton) + + override fun bind(insight: InsightModel) { + title.setText(insight.name) + + managementButton.setImageResource(R.drawable.ic_add_circle) + managementButton.setOnClickListener { + onButtonClicked(insight) + } + + dragAndDropButton.visibility = View.GONE + } +} From 2634449cad668034003dedb108d888452e908b83 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Thu, 28 Mar 2019 13:50:38 +0100 Subject: [PATCH 047/103] Animate list resize changes --- .../management/InsightsManagementFragment.kt | 24 ++++++++++++++++--- .../layout/insights_management_fragment.xml | 6 ++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index 8256853d1957..4d09239ecb7a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -16,9 +16,10 @@ import android.view.View import android.view.ViewGroup import dagger.android.support.DaggerFragment import kotlinx.android.synthetic.main.insights_management_fragment.* -import org.wordpress.android.R import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel import javax.inject.Inject +import android.animation.LayoutTransition +import org.wordpress.android.R class InsightsManagementFragment : DaggerFragment() { @Inject lateinit var viewModelFactory: ViewModelProvider.Factory @@ -44,8 +45,13 @@ class InsightsManagementFragment : DaggerFragment() { } private fun initializeViews() { - removedInsights.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) - addedInsights.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) + removedInsights.layoutManager = LinearLayoutManager(requireActivity(), LinearLayoutManager.VERTICAL, false) + addedInsights.layoutManager = LinearLayoutManager(requireActivity(), LinearLayoutManager.VERTICAL, false) + + val transition = LayoutTransition() + transition.disableTransitionType(LayoutTransition.DISAPPEARING) + transition.enableTransitionType(LayoutTransition.CHANGING) + insightsManagementContainer.layoutTransition = transition } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -72,12 +78,24 @@ class InsightsManagementFragment : DaggerFragment() { viewModel.removedInsights.observe(this, Observer { it?.let { items -> updateRemovedInsights(items) + + if (items.isEmpty()) { + addInsightsHeader.visibility = View.GONE + } else { + addInsightsHeader.visibility = View.VISIBLE + } } }) viewModel.addedInsights.observe(this, Observer { it?.let { items -> updateAddedInsights(items) + + if (items.isEmpty()) { + addedInsightsInfo.visibility = View.GONE + } else { + addedInsightsInfo.visibility = View.VISIBLE + } } }) } diff --git a/WordPress/src/main/res/layout/insights_management_fragment.xml b/WordPress/src/main/res/layout/insights_management_fragment.xml index 38ba8d3c54b1..5c70a325d142 100644 --- a/WordPress/src/main/res/layout/insights_management_fragment.xml +++ b/WordPress/src/main/res/layout/insights_management_fragment.xml @@ -7,9 +7,11 @@ android:layout_height="match_parent"> + android:orientation="vertical" + android:animateLayoutChanges="true"> Date: Thu, 28 Mar 2019 18:02:02 +0100 Subject: [PATCH 048/103] Close the insights management instead of showing a snackbar message --- .../management/InsightsManagementFragment.kt | 16 ++++++--------- .../management/InsightsManagementViewModel.kt | 20 +++++-------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index 4d09239ecb7a..6519f9dd5987 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -4,7 +4,6 @@ import android.arch.lifecycle.Observer import android.arch.lifecycle.ViewModelProvider import android.arch.lifecycle.ViewModelProviders import android.os.Bundle -import android.support.design.widget.Snackbar import android.support.v4.app.FragmentActivity import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.helper.ItemTouchHelper @@ -68,13 +67,6 @@ class InsightsManagementFragment : DaggerFragment() { } private fun setupObservers() { - val view = insightsManagementScrollView - viewModel.showSnackbarMessage.observe(this, Observer { holder -> - if (holder != null && view != null) { - Snackbar.make(view, getString(holder.messageRes), Snackbar.LENGTH_LONG).show() - } - }) - viewModel.removedInsights.observe(this, Observer { it?.let { items -> updateRemovedInsights(items) @@ -98,6 +90,10 @@ class InsightsManagementFragment : DaggerFragment() { } } }) + + viewModel.closeInsightsManagement.observe(this, Observer { + requireActivity().finish() + }) } private fun updateRemovedInsights(insights: List) { @@ -105,7 +101,7 @@ class InsightsManagementFragment : DaggerFragment() { removedInsights.adapter = InsightsManagementAdapter( { item -> viewModel.onItemButtonClicked(item) }, { viewHolder -> addedInsightsTouchHelper.startDrag(viewHolder) }, - { list -> viewModel.onAddedItemsUpdated(list) } + { list -> viewModel.onAddedInsightsReordered(list) } ) } val adapter = removedInsights.adapter as InsightsManagementAdapter @@ -118,7 +114,7 @@ class InsightsManagementFragment : DaggerFragment() { adapter = InsightsManagementAdapter( { item -> viewModel.onItemButtonClicked(item) }, { viewHolder -> addedInsightsTouchHelper.startDrag(viewHolder) }, - { list -> viewModel.onAddedItemsUpdated(list) } + { list -> viewModel.onAddedInsightsReordered(list) } ) addedInsights.adapter = adapter diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index d5d6e73c3f60..4d9264387d35 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -4,7 +4,6 @@ import android.arch.lifecycle.LiveData import android.arch.lifecycle.MutableLiveData import androidx.annotation.StringRes import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.wordpress.android.R import org.wordpress.android.fluxc.model.stats.InsightTypesModel @@ -12,14 +11,13 @@ import org.wordpress.android.fluxc.store.StatsStore import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.* import org.wordpress.android.modules.UI_THREAD -import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.stats.refresh.INSIGHTS_USE_CASE import org.wordpress.android.ui.stats.refresh.lists.BaseListUseCase import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel.Type.ADDED import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel.Type.REMOVED import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider -import org.wordpress.android.util.map import org.wordpress.android.viewmodel.ScopedViewModel +import org.wordpress.android.viewmodel.SingleLiveEvent import javax.inject.Inject import javax.inject.Named @@ -35,11 +33,8 @@ class InsightsManagementViewModel @Inject constructor( private val _addedInsights = MutableLiveData>() val addedInsights: LiveData> = _addedInsights - private val mutableSnackbarMessage = MutableLiveData() - - val showSnackbarMessage: LiveData = mutableSnackbarMessage.map { - SnackbarMessageHolder(it) - } + private val _closeInsightsManagement = SingleLiveEvent() + val closeInsightsManagement: LiveData = _closeInsightsManagement fun start() { loadInsights() @@ -65,13 +60,12 @@ class InsightsManagementViewModel @Inject constructor( val model = InsightTypesModel(addedTypes, removedTypes + FOLLOWER_TOTALS + ANNUAL_SITE_STATS) statsStore.updateTypes(siteProvider.siteModel, model) - mutableSnackbarMessage.value = R.string.stats_insights_saved_message - insightsUseCase.refreshData() + _closeInsightsManagement.call() } } - fun onAddedItemsUpdated(items: List) { + fun onAddedInsightsReordered(items: List) { _addedInsights.value = items } @@ -87,10 +81,6 @@ class InsightsManagementViewModel @Inject constructor( } } - override fun onCleared() { - mutableSnackbarMessage.value = null - } - data class InsightModel(val insightsTypes: InsightsTypes, val type: Type) { @StringRes val name: Int = when (insightsTypes) { LATEST_POST_SUMMARY -> R.string.stats_insights_latest_post_summary From 39a2f9d42b1c96be9732cd6f164566a80c2666f8 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Mon, 1 Apr 2019 09:38:26 +0200 Subject: [PATCH 049/103] Update the FluxC reference --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ed8af793e12e..23239a6f8edb 100644 --- a/build.gradle +++ b/build.gradle @@ -104,5 +104,5 @@ buildScan { } ext { - fluxCVersion = 'e049ac97ac54f371aef152de5e02b1dc2eb32f82' + fluxCVersion = '4c90ed6514fe54e38b0a23e8ede639e59e4cc128' } From f9830d81ee345303563322eb15dec0e7f9b631c0 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Mon, 1 Apr 2019 09:41:04 +0200 Subject: [PATCH 050/103] Rename the layout view IDs for consistency --- .../ui/stats/refresh/StatsViewAllFragment.kt | 22 +++++++------- .../stats/refresh/lists/StatsListFragment.kt | 29 +++++++++++-------- .../lists/detail/StatsDetailFragment.kt | 10 +++---- .../layout/insights_management_list_item.xml | 9 ------ .../main/res/layout/stats_date_selector.xml | 25 ++++++++-------- .../src/main/res/layout/stats_empty_view.xml | 6 ++-- .../src/main/res/layout/stats_error_view.xml | 2 +- .../main/res/layout/stats_list_fragment.xml | 5 +--- 8 files changed, 52 insertions(+), 56 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllFragment.kt index 655c29531704..30322f059767 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllFragment.kt @@ -80,7 +80,7 @@ class StatsViewAllFragment : DaggerFragment() { super.onSaveInstanceState(outState) } - private fun initializeViews(savedInstanceState: Bundle?) { + private fun initializeViews(savedInstanceState: Bundle?) { val layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) savedInstanceState?.getParcelable(listStateKey)?.let { @@ -94,10 +94,10 @@ class StatsViewAllFragment : DaggerFragment() { viewModel.onPullToRefresh() } - select_next_date.setOnClickListener { + nextDateButton.setOnClickListener { viewModel.onNextDateSelected() } - select_previous_date.setOnClickListener { + previousDateButton.setOnClickListener { viewModel.onPreviousDateSelected() } } @@ -162,8 +162,8 @@ class StatsViewAllFragment : DaggerFragment() { if (it != null) { recyclerView.visibility = if (it is StatsBlock.Success) View.VISIBLE else View.GONE loadingContainer.visibility = if (it is StatsBlock.Loading) View.VISIBLE else View.GONE - actionable_error_view.visibility = if (it is StatsBlock.Error) View.VISIBLE else View.GONE - actionable_empty_view.visibility = if (it is StatsBlock.EmptyBlock) View.VISIBLE else View.GONE + statsErrorView.visibility = if (it is StatsBlock.Error) View.VISIBLE else View.GONE + statsEmptyView.visibility = if (it is StatsBlock.EmptyBlock) View.VISIBLE else View.GONE when (it) { is StatsBlock.Success -> { loadData(recyclerView, prepareLayout(it.data, it.type)) @@ -172,7 +172,7 @@ class StatsViewAllFragment : DaggerFragment() { loadData(loadingRecyclerView, prepareLayout(it.data, it.type)) } is StatsBlock.Error -> { - actionable_error_view.button.setOnClickListener { + statsErrorView.button.setOnClickListener { viewModel.onRetryClick() } } @@ -190,14 +190,14 @@ class StatsViewAllFragment : DaggerFragment() { if (date_selection_toolbar.visibility != dateSelectorVisibility) { date_selection_toolbar.visibility = dateSelectorVisibility } - selected_date.text = dateSelectorUiModel?.date ?: "" + selectedDateTextView.text = dateSelectorUiModel?.date ?: "" val enablePreviousButton = dateSelectorUiModel?.enableSelectPrevious == true - if (select_previous_date.isEnabled != enablePreviousButton) { - select_previous_date.isEnabled = enablePreviousButton + if (previousDateButton.isEnabled != enablePreviousButton) { + previousDateButton.isEnabled = enablePreviousButton } val enableNextButton = dateSelectorUiModel?.enableSelectNext == true - if (select_next_date.isEnabled != enableNextButton) { - select_next_date.isEnabled = enableNextButton + if (nextDateButton.isEnabled != enableNextButton) { + nextDateButton.isEnabled = enableNextButton } }) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index 7f1746998d42..0aa0d6369512 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -96,11 +96,11 @@ class StatsListFragment : DaggerFragment() { } }) - select_next_date.setOnClickListener { + nextDateButton.setOnClickListener { viewModel.onNextDateSelected() } - select_previous_date.setOnClickListener { + previousDateButton.setOnClickListener { viewModel.onPreviousDateSelected() } } @@ -144,10 +144,13 @@ class StatsListFragment : DaggerFragment() { } is UiModel.Error -> { recyclerView.visibility = View.GONE - actionable_error_view.visibility = View.VISIBLE - actionable_error_view.button.setOnClickListener { - viewModel.onRetryClick() - } + statsErrorView.visibility = View.VISIBLE + statsEmptyView.visibility = View.GONE + } + is UiModel.Empty -> { + recyclerView.visibility = View.GONE + statsEmptyView.visibility = View.VISIBLE + statsEmptyView.visibility = View.GONE } } } @@ -158,14 +161,14 @@ class StatsListFragment : DaggerFragment() { if (date_selection_toolbar.visibility != dateSelectorVisibility) { date_selection_toolbar.visibility = dateSelectorVisibility } - selected_date.text = dateSelectorUiModel?.date ?: "" + selectedDateTextView.text = dateSelectorUiModel?.date ?: "" val enablePreviousButton = dateSelectorUiModel?.enableSelectPrevious == true - if (select_previous_date.isEnabled != enablePreviousButton) { - select_previous_date.isEnabled = enablePreviousButton + if (previousDateButton.isEnabled != enablePreviousButton) { + previousDateButton.isEnabled = enablePreviousButton } val enableNextButton = dateSelectorUiModel?.enableSelectNext == true - if (select_next_date.isEnabled != enableNextButton) { - select_next_date.isEnabled = enableNextButton + if (nextDateButton.isEnabled != enableNextButton) { + nextDateButton.isEnabled = enableNextButton } }) @@ -191,7 +194,9 @@ class StatsListFragment : DaggerFragment() { private fun updateInsights(statsState: List) { recyclerView.visibility = View.VISIBLE - actionable_error_view.visibility = View.GONE + statsErrorView.visibility = View.GONE + statsEmptyView.visibility = View.GONE + val adapter: StatsBlockAdapter if (recyclerView.adapter == null) { adapter = StatsBlockAdapter(imageManager) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailFragment.kt index 9de2fd9dc9f0..49cc75aac41a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailFragment.kt @@ -87,14 +87,14 @@ class StatsDetailFragment : DaggerFragment() { if (date_selection_toolbar.visibility != dateSelectorVisibility) { date_selection_toolbar.visibility = dateSelectorVisibility } - selected_date.text = dateSelectorUiModel?.date ?: "" + selectedDateTextView.text = dateSelectorUiModel?.date ?: "" val enablePreviousButton = dateSelectorUiModel?.enableSelectPrevious == true - if (select_previous_date.isEnabled != enablePreviousButton) { - select_previous_date.isEnabled = enablePreviousButton + if (previousDateButton.isEnabled != enablePreviousButton) { + previousDateButton.isEnabled = enablePreviousButton } val enableNextButton = dateSelectorUiModel?.enableSelectNext == true - if (select_next_date.isEnabled != enableNextButton) { - select_next_date.isEnabled = enableNextButton + if (nextDateButton.isEnabled != enableNextButton) { + nextDateButton.isEnabled = enableNextButton } }) } diff --git a/WordPress/src/main/res/layout/insights_management_list_item.xml b/WordPress/src/main/res/layout/insights_management_list_item.xml index 82b9ea93dba7..0d9ed7bae92c 100644 --- a/WordPress/src/main/res/layout/insights_management_list_item.xml +++ b/WordPress/src/main/res/layout/insights_management_list_item.xml @@ -48,13 +48,4 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"/> - - diff --git a/WordPress/src/main/res/layout/stats_date_selector.xml b/WordPress/src/main/res/layout/stats_date_selector.xml index 0f73956ca697..ceba1b68e147 100644 --- a/WordPress/src/main/res/layout/stats_date_selector.xml +++ b/WordPress/src/main/res/layout/stats_date_selector.xml @@ -1,13 +1,14 @@ - + diff --git a/WordPress/src/main/res/layout/stats_error_view.xml b/WordPress/src/main/res/layout/stats_error_view.xml index c789a623c1d0..a87dc3fd881b 100644 --- a/WordPress/src/main/res/layout/stats_error_view.xml +++ b/WordPress/src/main/res/layout/stats_error_view.xml @@ -3,7 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/actionable_error_view" + android:id="@+id/statsErrorView" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" diff --git a/WordPress/src/main/res/layout/stats_list_fragment.xml b/WordPress/src/main/res/layout/stats_list_fragment.xml index 5b30ad47a550..2981a45bd21b 100644 --- a/WordPress/src/main/res/layout/stats_list_fragment.xml +++ b/WordPress/src/main/res/layout/stats_list_fragment.xml @@ -17,10 +17,7 @@ android:layout_weight="1"/> + layout="@layout/stats_empty_view" /> Date: Mon, 1 Apr 2019 09:46:33 +0200 Subject: [PATCH 051/103] Initialize empty and error views --- .../stats/refresh/lists/StatsListFragment.kt | 10 ++++ .../stats/refresh/lists/StatsListViewModel.kt | 13 ++++- .../ui/stats/refresh/lists/UiModelMapper.kt | 54 ++++++++++--------- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index 0aa0d6369512..e13d913e490a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -15,6 +15,7 @@ import android.view.View import android.view.ViewGroup import dagger.android.support.DaggerFragment import kotlinx.android.synthetic.main.stats_date_selector.* +import kotlinx.android.synthetic.main.stats_empty_view.* import kotlinx.android.synthetic.main.stats_error_view.* import kotlinx.android.synthetic.main.stats_list_fragment.* import org.wordpress.android.R @@ -88,6 +89,10 @@ class StatsListFragment : DaggerFragment() { ) ) + statsEmptyView.button.setOnClickListener { + viewModel.onEmptyInsightsButtonClicked() + } + recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { if (!recyclerView.canScrollVertically(1) && dy != 0) { @@ -103,6 +108,10 @@ class StatsListFragment : DaggerFragment() { previousDateButton.setOnClickListener { viewModel.onPreviousDateSelected() } + + statsErrorView.button.setOnClickListener { + viewModel.onRetryClick() + } } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -204,6 +213,7 @@ class StatsListFragment : DaggerFragment() { } else { adapter = recyclerView.adapter as StatsBlockAdapter } + val layoutManager = recyclerView?.layoutManager val recyclerViewState = layoutManager?.onSaveInstanceState() adapter.update(statsState) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index 2da9d58940d5..7e251b750c7e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -1,6 +1,7 @@ package org.wordpress.android.ui.stats.refresh.lists import android.arch.lifecycle.LiveData +import android.arch.lifecycle.MutableLiveData import android.support.annotation.StringRes import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers @@ -14,6 +15,7 @@ import org.wordpress.android.ui.stats.refresh.DAY_STATS_USE_CASE import org.wordpress.android.ui.stats.refresh.INSIGHTS_USE_CASE import org.wordpress.android.ui.stats.refresh.MONTH_STATS_USE_CASE import org.wordpress.android.ui.stats.refresh.NavigationTarget +import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewInsightsManagement import org.wordpress.android.ui.stats.refresh.StatsViewModel.DateSelectorUiModel import org.wordpress.android.ui.stats.refresh.WEEK_STATS_USE_CASE import org.wordpress.android.ui.stats.refresh.YEAR_STATS_USE_CASE @@ -26,6 +28,7 @@ import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsDateSelector import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.util.mapNullable +import org.wordpress.android.util.mergeNotNull import org.wordpress.android.util.throttle import org.wordpress.android.viewmodel.ScopedViewModel import javax.inject.Inject @@ -38,7 +41,7 @@ abstract class StatsListViewModel( private val statsUseCase: BaseListUseCase, private val analyticsTracker: AnalyticsTrackerWrapper, private val dateSelector: StatsDateSelector, - private val popupMenuHandler: ItemPopupMenuHandler? = null + popupMenuHandler: ItemPopupMenuHandler? = null ) : ScopedViewModel(defaultDispatcher) { private var trackJob: Job? = null private var isInitialized = false @@ -54,7 +57,8 @@ abstract class StatsListViewModel( val selectedDate = dateSelector.selectedDate - val navigationTarget: LiveData = statsUseCase.navigationTarget + private val _navigationTarget = MutableLiveData() + val navigationTarget: LiveData = mergeNotNull(statsUseCase.navigationTarget, _navigationTarget) val listSelected = statsUseCase.listSelected @@ -108,6 +112,10 @@ abstract class StatsListViewModel( dateSelector.updateDateSelector() } + fun onEmptyInsightsButtonClicked() { + _navigationTarget.value = ViewInsightsManagement() + } + fun start() { if (!isInitialized) { isInitialized = true @@ -122,6 +130,7 @@ abstract class StatsListViewModel( sealed class UiModel { data class Success(val data: List) : UiModel() class Error(val message: Int = R.string.stats_loading_error) : UiModel() + object Empty : UiModel() } fun onTypeMoved() { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt index 36d2d86a69f8..9be8185271fa 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt @@ -73,33 +73,37 @@ class UiModelMapper } val overviewHasData = useCaseModels.any { it.type == overViewType && it.data != null } return if (!allFailing) { - UiModel.Success(useCaseModels.mapNotNull { useCaseModel -> - if ((useCaseModel.type == overViewType) && useCaseModel.data != null) { - StatsBlock.Success(useCaseModel.type, useCaseModel.data) - } else { - when (useCaseModel.state) { - SUCCESS -> StatsBlock.Success(useCaseModel.type, useCaseModel.data ?: listOf()) - ERROR -> useCaseModel.stateData?.let { - StatsBlock.Error( - useCaseModel.type, - useCaseModel.stateData - ) - } - LOADING -> useCaseModel.stateData?.let { - StatsBlock.Loading( - useCaseModel.type, - useCaseModel.stateData - ) - } - EMPTY -> useCaseModel.stateData?.let { - StatsBlock.EmptyBlock( - useCaseModel.type, - useCaseModel.stateData - ) + if (useCaseModels.isNotEmpty()) { + UiModel.Success(useCaseModels.mapNotNull { useCaseModel -> + if ((useCaseModel.type == overViewType) && useCaseModel.data != null) { + StatsBlock.Success(useCaseModel.type, useCaseModel.data) + } else { + when (useCaseModel.state) { + SUCCESS -> StatsBlock.Success(useCaseModel.type, useCaseModel.data ?: listOf()) + ERROR -> useCaseModel.stateData?.let { + StatsBlock.Error( + useCaseModel.type, + useCaseModel.stateData + ) + } + LOADING -> useCaseModel.stateData?.let { + StatsBlock.Loading( + useCaseModel.type, + useCaseModel.stateData + ) + } + EMPTY -> useCaseModel.stateData?.let { + StatsBlock.EmptyBlock( + useCaseModel.type, + useCaseModel.stateData + ) + } } } - } - }) + }) + } else { + UiModel.Empty + } } else if (overviewHasData) { showError(getErrorMessage()) UiModel.Success(useCaseModels.mapNotNull { useCaseModel -> From 08b47adaeca568f36d47bd8003d1e92c2722df9d Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Mon, 1 Apr 2019 09:46:53 +0200 Subject: [PATCH 052/103] Remove unused string resource --- WordPress/src/main/res/values/strings.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 50cac2ce82a6..ec37ffd93b16 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -789,7 +789,6 @@ No data yet No data for this period No insights added yet - Customize your insights and get the low-down on your site’s performance Manage Insights Manage WordPress.com From fa838f8b077ae1c558d8e7c1d531f74c15bb4a9a Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Mon, 1 Apr 2019 09:47:37 +0200 Subject: [PATCH 053/103] Add list item decorators --- .../insights/management/InsightsManagementFragment.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index 6519f9dd5987..0f8bed2fbe3d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -15,10 +15,12 @@ import android.view.View import android.view.ViewGroup import dagger.android.support.DaggerFragment import kotlinx.android.synthetic.main.insights_management_fragment.* -import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel import javax.inject.Inject import android.animation.LayoutTransition import org.wordpress.android.R +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel +import org.wordpress.android.util.DisplayUtils +import org.wordpress.android.widgets.RecyclerItemDecoration class InsightsManagementFragment : DaggerFragment() { @Inject lateinit var viewModelFactory: ViewModelProvider.Factory @@ -47,6 +49,9 @@ class InsightsManagementFragment : DaggerFragment() { removedInsights.layoutManager = LinearLayoutManager(requireActivity(), LinearLayoutManager.VERTICAL, false) addedInsights.layoutManager = LinearLayoutManager(requireActivity(), LinearLayoutManager.VERTICAL, false) + removedInsights.addItemDecoration(RecyclerItemDecoration(0, DisplayUtils.dpToPx(activity, 1))) + addedInsights.addItemDecoration(RecyclerItemDecoration(0, DisplayUtils.dpToPx(activity, 1))) + val transition = LayoutTransition() transition.disableTransitionType(LayoutTransition.DISAPPEARING) transition.enableTransitionType(LayoutTransition.CHANGING) From 08973d15d747a1b72226ccbcef56a3e6325bb37a Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Mon, 1 Apr 2019 09:48:48 +0200 Subject: [PATCH 054/103] Don't wait for data to refresh when leaving the insights management --- .../insights/management/InsightsManagementViewModel.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index 4d9264387d35..cfddc8d1e870 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -13,6 +13,7 @@ import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.* import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.INSIGHTS_USE_CASE import org.wordpress.android.ui.stats.refresh.lists.BaseListUseCase +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel.Type import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel.Type.ADDED import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel.Type.REMOVED import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider @@ -60,7 +61,9 @@ class InsightsManagementViewModel @Inject constructor( val model = InsightTypesModel(addedTypes, removedTypes + FOLLOWER_TOTALS + ANNUAL_SITE_STATS) statsStore.updateTypes(siteProvider.siteModel, model) - insightsUseCase.refreshData() + launch { + insightsUseCase.refreshData() + } _closeInsightsManagement.call() } } @@ -73,7 +76,7 @@ class InsightsManagementViewModel @Inject constructor( launch { if (insight.type == ADDED) { _addedInsights.value = _addedInsights.value?.filter { it != insight } - _removedInsights.value = _removedInsights.value?.let { it + insight.copy(type = REMOVED) } + _removedInsights.value = _removedInsights.value?.let { it + insight.copy(type = Type.REMOVED) } } else { _removedInsights.value = _removedInsights.value?.filter { it != insight } _addedInsights.value = _addedInsights.value?.let { it + insight.copy(type = ADDED) } @@ -88,7 +91,7 @@ class InsightsManagementViewModel @Inject constructor( ALL_TIME_STATS -> R.string.stats_insights_all_time_stats TAGS_AND_CATEGORIES -> R.string.stats_insights_tags_and_categories COMMENTS -> R.string.stats_comments - FOLLOWERS -> R.string.stats_view_followers + FOLLOWERS -> R.string.stats_view_followers TODAY_STATS -> R.string.stats_insights_today POSTING_ACTIVITY -> R.string.stats_insights_posting_activity PUBLICIZE -> R.string.stats_view_publicize From 24f5351c9fd85a22f55614fbf92be55de47c8308 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Mon, 1 Apr 2019 14:50:23 +0200 Subject: [PATCH 055/103] Fix the empty isnights actionable screen display --- .../ui/stats/refresh/lists/BaseListUseCase.kt | 4 +- .../stats/refresh/lists/StatsListFragment.kt | 2 +- .../ui/stats/refresh/lists/UiModelMapper.kt | 66 ++++++++++--------- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt index 4cddd61baf0f..59772a62e26c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt @@ -14,7 +14,6 @@ import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.UiModel import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.UseCaseModel import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider -import org.wordpress.android.util.DistinctMutableLiveData import org.wordpress.android.util.PackageUtils import org.wordpress.android.util.combineMap import org.wordpress.android.util.distinct @@ -33,7 +32,7 @@ class BaseListUseCase( private val blockListData = combineMap( useCases.associateBy { it.type }.mapValues { entry -> entry.value.liveData } ) - private val statsTypes = DistinctMutableLiveData>(listOf()) + private val statsTypes = MutableLiveData>() val data: MediatorLiveData = mergeNotNull(statsTypes, blockListData) { types, map -> types.mapNotNull { if (map.containsKey(it)) { @@ -98,7 +97,6 @@ class BaseListUseCase( fun onCleared() { mutableSnackbarMessage.value = null - statsTypes.clear() blockListData.value = null useCases.forEach { it.clear() } data.value = null diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index e13d913e490a..805b5f15f4d8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -159,7 +159,7 @@ class StatsListFragment : DaggerFragment() { is UiModel.Empty -> { recyclerView.visibility = View.GONE statsEmptyView.visibility = View.VISIBLE - statsEmptyView.visibility = View.GONE + statsErrorView.visibility = View.GONE } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt index 9be8185271fa..0ca85f8ead59 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt @@ -17,40 +17,44 @@ import javax.inject.Inject class UiModelMapper @Inject constructor(private val networkUtilsWrapper: NetworkUtilsWrapper) { fun mapInsights(useCaseModels: List, showError: (Int) -> Unit): UiModel { - val allFailing = useCaseModels.isNotEmpty() && useCaseModels.fold(true) { acc, useCaseModel -> - acc && useCaseModel.state == ERROR - } - val allFailingWithoutData = useCaseModels.isNotEmpty() && useCaseModels.fold(true) { acc, useCaseModel -> - acc && useCaseModel.state == ERROR && useCaseModel.data == null - } - return if (!allFailing && !allFailingWithoutData) { - UiModel.Success(useCaseModels.map { useCaseModel -> - when (useCaseModel.state) { - SUCCESS -> StatsBlock.Success(useCaseModel.type, useCaseModel.data ?: listOf()) - ERROR -> StatsBlock.Error( - useCaseModel.type, - useCaseModel.stateData ?: useCaseModel.data ?: listOf() - ) - LOADING -> StatsBlock.Loading( - useCaseModel.type, - useCaseModel.stateData ?: useCaseModel.data ?: listOf() - ) - EMPTY -> StatsBlock.EmptyBlock( + if (useCaseModels.isNotEmpty()) { + val allFailing = useCaseModels.fold(true) { acc, useCaseModel -> + acc && useCaseModel.state == ERROR + } + val allFailingWithoutData = useCaseModels.isNotEmpty() && useCaseModels.fold(true) { acc, useCaseModel -> + acc && useCaseModel.state == ERROR && useCaseModel.data == null + } + return if (!allFailing && !allFailingWithoutData) { + UiModel.Success(useCaseModels.map { useCaseModel -> + when (useCaseModel.state) { + SUCCESS -> StatsBlock.Success(useCaseModel.type, useCaseModel.data ?: listOf()) + ERROR -> StatsBlock.Error( + useCaseModel.type, + useCaseModel.stateData ?: useCaseModel.data ?: listOf() + ) + LOADING -> StatsBlock.Loading( + useCaseModel.type, + useCaseModel.stateData ?: useCaseModel.data ?: listOf() + ) + EMPTY -> StatsBlock.EmptyBlock( + useCaseModel.type, + useCaseModel.stateData ?: useCaseModel.data ?: listOf() + ) + } + }) + } else if (!allFailingWithoutData) { + showError(getErrorMessage()) + UiModel.Success(useCaseModels.map { useCaseModel -> + Error( useCaseModel.type, - useCaseModel.stateData ?: useCaseModel.data ?: listOf() + useCaseModel.data ?: useCaseModel.stateData ?: listOf() ) - } - }) - } else if (!allFailingWithoutData) { - showError(getErrorMessage()) - UiModel.Success(useCaseModels.map { useCaseModel -> - Error( - useCaseModel.type, - useCaseModel.data ?: useCaseModel.stateData ?: listOf() - ) - }) + }) + } else { + UiModel.Error(getErrorMessage()) + } } else { - UiModel.Error(getErrorMessage()) + return UiModel.Empty } } From 8e6998bcf07d75dcbd81b0be0521b8d96ad04932 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Mon, 1 Apr 2019 15:26:16 +0200 Subject: [PATCH 056/103] Fix ktlint --- .../insights/management/InsightsManagementAdapter.kt | 2 -- .../management/InsightsManagementViewModel.kt | 12 +++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt index f933c5f600e6..64c8894ee72b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt @@ -52,8 +52,6 @@ class InsightsManagementAdapter( override fun getItemCount(): Int = items.size - - fun update(newItems: List) { val diffResult = DiffUtil.calculateDiff(InsightModelDiffCallback(items, newItems)) items = ArrayList(newItems) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index cfddc8d1e870..16a287461d08 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -9,7 +9,17 @@ import org.wordpress.android.R import org.wordpress.android.fluxc.model.stats.InsightTypesModel import org.wordpress.android.fluxc.store.StatsStore import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes -import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.* +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.ALL_TIME_STATS +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.ANNUAL_SITE_STATS +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.COMMENTS +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.FOLLOWERS +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.FOLLOWER_TOTALS +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.LATEST_POST_SUMMARY +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.MOST_POPULAR_DAY_AND_HOUR +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.POSTING_ACTIVITY +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.PUBLICIZE +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.TAGS_AND_CATEGORIES +import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.TODAY_STATS import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.INSIGHTS_USE_CASE import org.wordpress.android.ui.stats.refresh.lists.BaseListUseCase From 73be580cdb08f5f88fe2f30f822976d8ef0a4756 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Mon, 1 Apr 2019 15:42:10 +0200 Subject: [PATCH 057/103] Update the release notes --- RELEASE-NOTES.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 0309b5fccf45..a32e0b8a83ca 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,6 +1,8 @@ 12.2 ----- +* New Insights Management for selecting the most relevant stats + 12.1 ----- * Design improvements for the new site creation flow From bb5f8c159d10907987c093a9c687ba6c41a5f8aa Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Tue, 9 Apr 2019 11:58:53 +0200 Subject: [PATCH 058/103] Only load insights once --- .../insights/management/InsightsManagementViewModel.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index 16a287461d08..bf01d87e71dc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -47,8 +47,13 @@ class InsightsManagementViewModel @Inject constructor( private val _closeInsightsManagement = SingleLiveEvent() val closeInsightsManagement: LiveData = _closeInsightsManagement + private var isInitialized = false + fun start() { - loadInsights() + if (!isInitialized) { + isInitialized = true + loadInsights() + } } private fun loadInsights() { From 2415e7c7bf1a1e6904dd2f726b38854865319b14 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Tue, 9 Apr 2019 18:33:57 +0200 Subject: [PATCH 059/103] Use larger vertical margin for the subtitle --- .../src/main/res/layout/insights_management_fragment.xml | 5 ++++- WordPress/src/main/res/values/dimens.xml | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/res/layout/insights_management_fragment.xml b/WordPress/src/main/res/layout/insights_management_fragment.xml index 5c70a325d142..6d82cec5054d 100644 --- a/WordPress/src/main/res/layout/insights_management_fragment.xml +++ b/WordPress/src/main/res/layout/insights_management_fragment.xml @@ -19,7 +19,10 @@ android:textColor="@color/grey_darken_20" android:textSize="@dimen/text_sz_large" android:gravity="center_horizontal" - android:layout_margin="@dimen/margin_extra_large" + android:layout_marginStart="@dimen/margin_extra_large" + android:layout_marginEnd="@dimen/margin_extra_large" + android:layout_marginTop="@dimen/stats_insights_management_margin" + android:layout_marginBottom="@dimen/stats_insights_management_margin" android:text="@string/stats_insights_management_title"/> 8dp 56dp 1dp + 24dp 24dp From 422918d367870ad8f9f1bbd9c839d6facd3fe780 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Tue, 9 Apr 2019 20:30:18 +0200 Subject: [PATCH 060/103] Hide the Save button until some change is made --- .../management/InsightsManagementFragment.kt | 22 ++++++++++++------- .../management/InsightsManagementViewModel.kt | 6 +++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index 0f8bed2fbe3d..16a50c3f9865 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -27,6 +27,8 @@ class InsightsManagementFragment : DaggerFragment() { private lateinit var viewModel: InsightsManagementViewModel private lateinit var addedInsightsTouchHelper: ItemTouchHelper + private var menu: Menu? = null + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { setHasOptionsMenu(true) return inflater.inflate(R.layout.insights_management_fragment, container, false) @@ -36,6 +38,10 @@ class InsightsManagementFragment : DaggerFragment() { super.onCreateOptionsMenu(menu, inflater) inflater?.inflate(R.menu.menu_insights_management, menu) + this.menu = menu + + initializeViews() + initializeViewModels(requireActivity()) } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -58,17 +64,11 @@ class InsightsManagementFragment : DaggerFragment() { insightsManagementContainer.layoutTransition = transition } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - initializeViews() - initializeViewModels(requireActivity()) - } - private fun initializeViewModels(activity: FragmentActivity) { viewModel = ViewModelProviders.of(activity, viewModelFactory).get(InsightsManagementViewModel::class.java) - setupObservers() viewModel.start() + + setupObservers() } private fun setupObservers() { @@ -99,6 +99,12 @@ class InsightsManagementFragment : DaggerFragment() { viewModel.closeInsightsManagement.observe(this, Observer { requireActivity().finish() }) + + viewModel.isMenuVisible.observe(this, Observer { isMenuVisible -> + isMenuVisible?.let { + menu?.findItem(R.id.save_insights)?.isVisible = isMenuVisible + } + }) } private fun updateRemovedInsights(insights: List) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index bf01d87e71dc..6c6e7f2d48d0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -47,11 +47,15 @@ class InsightsManagementViewModel @Inject constructor( private val _closeInsightsManagement = SingleLiveEvent() val closeInsightsManagement: LiveData = _closeInsightsManagement + private val _isMenuVisible = MutableLiveData() + val isMenuVisible: LiveData = _isMenuVisible + private var isInitialized = false fun start() { if (!isInitialized) { isInitialized = true + _isMenuVisible.value = false loadInsights() } } @@ -85,6 +89,7 @@ class InsightsManagementViewModel @Inject constructor( fun onAddedInsightsReordered(items: List) { _addedInsights.value = items + _isMenuVisible.value = true } fun onItemButtonClicked(insight: InsightModel) { @@ -97,6 +102,7 @@ class InsightsManagementViewModel @Inject constructor( _addedInsights.value = _addedInsights.value?.let { it + insight.copy(type = ADDED) } } } + _isMenuVisible.value = true } data class InsightModel(val insightsTypes: InsightsTypes, val type: Type) { From 3789129cec1aaf92fa261d06194800b2a72784e2 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Tue, 9 Apr 2019 20:33:57 +0200 Subject: [PATCH 061/103] Show the touch feedback on ellipsis tap --- WordPress/src/main/res/layout/stats_block_title_item.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/res/layout/stats_block_title_item.xml b/WordPress/src/main/res/layout/stats_block_title_item.xml index 4ff1df73b702..39f5d1193f28 100644 --- a/WordPress/src/main/res/layout/stats_block_title_item.xml +++ b/WordPress/src/main/res/layout/stats_block_title_item.xml @@ -21,7 +21,7 @@ android:id="@+id/menu" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="@color/transparent" + android:background="?attr/selectableItemBackgroundBorderless" android:src="@drawable/ic_ellipsis_vertical_grey_darken_48dp" android:contentDescription="@string/stats_item_settings"/> From b4c2941284cff7a1648cfcc686bab2db843ae894 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 10 Apr 2019 10:18:25 +0200 Subject: [PATCH 062/103] Force showing a menu icon --- .../refresh/utils/ItemPopupMenuHandler.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt index 4cd6a7a70920..921424332c57 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt @@ -40,9 +40,12 @@ class ItemPopupMenuHandler withContext(mainDispatcher) { val popup = PopupMenu(view.context, view) val popupMenu = popup.menu + showIcons(popup) + popup.inflate(R.menu.menu_stats_item) popupMenu.findItem(R.id.action_move_up).isVisible = showUpAction popupMenu.findItem(R.id.action_move_down).isVisible = showDownAction + popup.show() popup.setOnMenuItemClickListener { menuItem -> when (menuItem.itemId) { @@ -74,5 +77,26 @@ class ItemPopupMenuHandler } } + private fun showIcons(popup: PopupMenu) { + try { + val fields = popup.javaClass.declaredFields + for (field in fields) { + if ("mPopup" == field.name) { + field.isAccessible = true + val menuPopupHelper = field.get(popup) + val classPopupHelper = Class.forName(menuPopupHelper.javaClass.name) + val setForceIcons = classPopupHelper.getMethod( + "setForceShowIcon", + Boolean::class.javaPrimitiveType!! + ) + setForceIcons.invoke(menuPopupHelper, true) + break + } + } + } catch (e: Exception) { + e.printStackTrace() + } + } + data class TypeChangeEvent(val types: StatsTypes) : Event() } From 808156442c9e5656af95c4b7b0835bce4cb1eacd Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 10 Apr 2019 12:19:22 +0200 Subject: [PATCH 063/103] Replace the simple popup menu with a custom popup window --- .../sections/insights/InsightsMenuAdapter.kt | 73 +++++++++++++++++++ .../refresh/utils/ItemPopupMenuHandler.kt | 61 ++++++---------- .../layout/stats_insights_popup_menu_item.xml | 27 +++++++ .../src/main/res/menu/menu_stats_item.xml | 15 ---- 4 files changed, 121 insertions(+), 55 deletions(-) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/InsightsMenuAdapter.kt create mode 100644 WordPress/src/main/res/layout/stats_insights_popup_menu_item.xml delete mode 100644 WordPress/src/main/res/menu/menu_stats_item.xml diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/InsightsMenuAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/InsightsMenuAdapter.kt new file mode 100644 index 000000000000..b2a4735614d0 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/InsightsMenuAdapter.kt @@ -0,0 +1,73 @@ +package org.wordpress.android.ui.stats.refresh.lists.sections.insights + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.BaseAdapter +import android.widget.ImageView +import android.widget.TextView + +import org.wordpress.android.R +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightsMenuAdapter.InsightsMenuItem.DOWN +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightsMenuAdapter.InsightsMenuItem.REMOVE +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightsMenuAdapter.InsightsMenuItem.UP + +class InsightsMenuAdapter(context: Context, isUpVisible: Boolean, isDownVisible: Boolean) : BaseAdapter() { + private val mInflater: LayoutInflater = LayoutInflater.from(context) + private val items = listOfNotNull(if (isUpVisible) UP else null, if (isDownVisible) DOWN else null, REMOVE) + + override fun getCount(): Int { + return items.size + } + + override fun getItem(position: Int): Any { + return items[position] + } + + override fun getItemId(position: Int): Long { + return items[position].id + } + + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + var view = convertView + val holder: MenuHolder + if (view == null) { + view = mInflater.inflate(R.layout.stats_insights_popup_menu_item, parent, false) + holder = MenuHolder(view!!) + view.tag = holder + } else { + holder = view.tag as MenuHolder + } + + val textRes: Int + val iconRes: Int + when (items[position]) { + UP -> { + textRes = R.string.stats_menu_move_up + iconRes = R.drawable.ic_arrow_up_grey_dark_24dp + } + DOWN -> { + textRes = R.string.stats_menu_move_down + iconRes = R.drawable.ic_arrow_down_grey_dark_24dp + } + REMOVE -> { + textRes = R.string.stats_menu_remove + iconRes = R.drawable.ic_trash_grey_dark_24dp + } + } + + holder.text.setText(textRes) + holder.icon.setImageResource(iconRes) + return view + } + + internal inner class MenuHolder(view: View) { + val text: TextView = view.findViewById(R.id.text) + val icon: ImageView = view.findViewById(R.id.image) + } + + enum class InsightsMenuItem(val id: Long) { + UP(0), DOWN(1), REMOVE(2) + } +} diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt index 921424332c57..ad9b70fab130 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt @@ -2,7 +2,6 @@ package org.wordpress.android.ui.stats.refresh.utils import android.arch.lifecycle.LiveData import android.arch.lifecycle.MutableLiveData -import android.support.v7.widget.PopupMenu import android.view.View import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.GlobalScope @@ -18,6 +17,12 @@ import org.wordpress.android.util.Event import javax.inject.Inject import javax.inject.Named import javax.inject.Singleton +import android.support.v7.widget.ListPopupWindow +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightsMenuAdapter +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightsMenuAdapter.InsightsMenuItem +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightsMenuAdapter.InsightsMenuItem.DOWN +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightsMenuAdapter.InsightsMenuItem.REMOVE +import org.wordpress.android.ui.stats.refresh.lists.sections.insights.InsightsMenuAdapter.InsightsMenuItem.UP @Singleton class ItemPopupMenuHandler @@ -29,6 +34,7 @@ class ItemPopupMenuHandler ) { private val mutableTypeMoved = MutableLiveData() val typeMoved: LiveData = mutableTypeMoved + fun onMenuClick(view: View, statsType: StatsTypes) { GlobalScope.launch(bgDispatcher) { val type = statsType as InsightsTypes @@ -37,66 +43,41 @@ class ItemPopupMenuHandler val indexOfBlock = insights.indexOfFirst { it == type } val showUpAction = indexOfBlock > 0 val showDownAction = indexOfBlock < insights.size - 1 - withContext(mainDispatcher) { - val popup = PopupMenu(view.context, view) - val popupMenu = popup.menu - showIcons(popup) - - popup.inflate(R.menu.menu_stats_item) - popupMenu.findItem(R.id.action_move_up).isVisible = showUpAction - popupMenu.findItem(R.id.action_move_down).isVisible = showDownAction - popup.show() - popup.setOnMenuItemClickListener { menuItem -> - when (menuItem.itemId) { - R.id.action_move_up -> { + withContext(mainDispatcher) { + val popup = ListPopupWindow(view.context) + val adapter = InsightsMenuAdapter(view.context, showUpAction, showDownAction) + popup.setAdapter(adapter) + popup.width = view.context.resources.getDimensionPixelSize(R.dimen.menu_item_width) + popup.anchorView = view + popup.isModal = true + popup.setOnItemClickListener { _, _, _, id -> + when (InsightsMenuItem.values()[id.toInt()]) { + UP -> { GlobalScope.launch(bgDispatcher) { statsStore.moveTypeUp(statsSiteProvider.siteModel, type) mutableTypeMoved.postValue(TypeChangeEvent(type)) } - true } - R.id.action_move_down -> { + DOWN -> { GlobalScope.launch(bgDispatcher) { statsStore.moveTypeDown(statsSiteProvider.siteModel, type) mutableTypeMoved.postValue(TypeChangeEvent(type)) } - true } - R.id.action_remove -> { + REMOVE -> { GlobalScope.launch(bgDispatcher) { statsStore.removeType(statsSiteProvider.siteModel, type) mutableTypeMoved.postValue(TypeChangeEvent(type)) } - true } - else -> false } + popup.dismiss() } + popup.show() } } } - private fun showIcons(popup: PopupMenu) { - try { - val fields = popup.javaClass.declaredFields - for (field in fields) { - if ("mPopup" == field.name) { - field.isAccessible = true - val menuPopupHelper = field.get(popup) - val classPopupHelper = Class.forName(menuPopupHelper.javaClass.name) - val setForceIcons = classPopupHelper.getMethod( - "setForceShowIcon", - Boolean::class.javaPrimitiveType!! - ) - setForceIcons.invoke(menuPopupHelper, true) - break - } - } - } catch (e: Exception) { - e.printStackTrace() - } - } - data class TypeChangeEvent(val types: StatsTypes) : Event() } diff --git a/WordPress/src/main/res/layout/stats_insights_popup_menu_item.xml b/WordPress/src/main/res/layout/stats_insights_popup_menu_item.xml new file mode 100644 index 000000000000..d7c3bb9bbf60 --- /dev/null +++ b/WordPress/src/main/res/layout/stats_insights_popup_menu_item.xml @@ -0,0 +1,27 @@ + + + + + + + diff --git a/WordPress/src/main/res/menu/menu_stats_item.xml b/WordPress/src/main/res/menu/menu_stats_item.xml deleted file mode 100644 index 4c707d8be788..000000000000 --- a/WordPress/src/main/res/menu/menu_stats_item.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - From 151714a480c954674c3aa37a363574eaa5697106 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 10 Apr 2019 12:36:35 +0200 Subject: [PATCH 064/103] Fix the resources --- .../main/res/layout/stats_insights_popup_menu_item.xml | 8 +++----- WordPress/src/main/res/values/dimens.xml | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/WordPress/src/main/res/layout/stats_insights_popup_menu_item.xml b/WordPress/src/main/res/layout/stats_insights_popup_menu_item.xml index d7c3bb9bbf60..1b589cd3d7e5 100644 --- a/WordPress/src/main/res/layout/stats_insights_popup_menu_item.xml +++ b/WordPress/src/main/res/layout/stats_insights_popup_menu_item.xml @@ -12,16 +12,14 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@null" - android:layout_marginEnd="@dimen/margin_large" - tools:src="@drawable/ic_reader_follow_white_24dp" - tools:tint="@color/reader_follow" /> + android:layout_marginEnd="@dimen/margin_extra_large" + tools:src="@drawable/ic_arrow_up_grey_dark_24dp" /> + tools:text="@string/stats_menu_remove" /> diff --git a/WordPress/src/main/res/values/dimens.xml b/WordPress/src/main/res/values/dimens.xml index 5300e9102030..b584cbd40964 100644 --- a/WordPress/src/main/res/values/dimens.xml +++ b/WordPress/src/main/res/values/dimens.xml @@ -233,7 +233,7 @@ 7dp 15dp - 48sp + 48dp 256sp 16dp 24dp From d1f2915a64e933aafd8d82452c7efbc6f9209fab Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 10 Apr 2019 12:49:28 +0200 Subject: [PATCH 065/103] Change the menu width --- .../android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt | 2 +- WordPress/src/main/res/values/dimens.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt index ad9b70fab130..ae1321821558 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/ItemPopupMenuHandler.kt @@ -48,7 +48,7 @@ class ItemPopupMenuHandler val popup = ListPopupWindow(view.context) val adapter = InsightsMenuAdapter(view.context, showUpAction, showDownAction) popup.setAdapter(adapter) - popup.width = view.context.resources.getDimensionPixelSize(R.dimen.menu_item_width) + popup.width = view.context.resources.getDimensionPixelSize(R.dimen.stats_insights_menu_item_width) popup.anchorView = view popup.isModal = true popup.setOnItemClickListener { _, _, _, id -> diff --git a/WordPress/src/main/res/values/dimens.xml b/WordPress/src/main/res/values/dimens.xml index b584cbd40964..7e57faae6c61 100644 --- a/WordPress/src/main/res/values/dimens.xml +++ b/WordPress/src/main/res/values/dimens.xml @@ -401,6 +401,7 @@ 56dp 1dp 24dp + 231dp 24dp From 7b8fa0466947684d3179a94663efff0bf79c9f74 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Thu, 11 Apr 2019 19:26:15 +0200 Subject: [PATCH 066/103] Allow dragged list items to move over the entire screen --- WordPress/src/main/res/layout/insights_management_fragment.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/res/layout/insights_management_fragment.xml b/WordPress/src/main/res/layout/insights_management_fragment.xml index 6d82cec5054d..c33004ff6f5e 100644 --- a/WordPress/src/main/res/layout/insights_management_fragment.xml +++ b/WordPress/src/main/res/layout/insights_management_fragment.xml @@ -11,6 +11,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" + android:clipChildren="false" android:animateLayoutChanges="true"> Date: Thu, 11 Apr 2019 19:26:40 +0200 Subject: [PATCH 067/103] Make the added list items topmost --- WordPress/src/main/res/layout/insights_management_fragment.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/res/layout/insights_management_fragment.xml b/WordPress/src/main/res/layout/insights_management_fragment.xml index c33004ff6f5e..75970a9d523b 100644 --- a/WordPress/src/main/res/layout/insights_management_fragment.xml +++ b/WordPress/src/main/res/layout/insights_management_fragment.xml @@ -31,6 +31,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:nestedScrollingEnabled="false" + android:translationZ="1dp" android:scrollbars="none" tools:listitem="@layout/insights_management_list_item"/> From 8ceb2b814c70f26cb4934dc563062184b87d0747 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Thu, 11 Apr 2019 19:27:24 +0200 Subject: [PATCH 068/103] Display a shadow (elevation) while an item is being dragged --- .../sections/insights/management/AddedInsightViewHolder.kt | 5 +++++ .../insights/management/InsightsManagementAdapter.kt | 6 ++++-- .../sections/insights/management/ItemTouchHelperCallback.kt | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/AddedInsightViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/AddedInsightViewHolder.kt index c8eeb01bb9ab..c7bd22f1d2c9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/AddedInsightViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/AddedInsightViewHolder.kt @@ -30,9 +30,14 @@ class AddedInsightViewHolder( dragAndDropButton.setOnTouchListener { _, event -> if (MotionEventCompat.isFromSource(event, MotionEvent.ACTION_DOWN)) { onDragStarted(this) + itemView.elevation = 10f } return@setOnTouchListener true } dragAndDropButton.visibility = View.VISIBLE } + + fun onDragFinished() { + itemView.elevation = 0f + } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt index 64c8894ee72b..662d604e5eae 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementAdapter.kt @@ -46,8 +46,10 @@ class InsightsManagementAdapter( notifyItemMoved(fromPosition, toPosition) } - override fun onDragFinished() { + override fun onDragFinished(viewHolder: ViewHolder) { onDragFinished.invoke(items) + + (viewHolder as? AddedInsightViewHolder)?.onDragFinished() } override fun getItemCount(): Int = items.size @@ -61,7 +63,7 @@ class InsightsManagementAdapter( interface ItemTouchHelperAdapter { fun onItemMoved(fromPosition: Int, toPosition: Int) - fun onDragFinished() + fun onDragFinished(viewHolder: ViewHolder) } class InsightModelDiffCallback( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt index b30a55a2a482..9c73401988c2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt @@ -29,6 +29,6 @@ class ItemTouchHelperCallback(private val adapter: ItemTouchHelperAdapter) : Ite override fun clearView(recyclerView: RecyclerView, viewHolder: ViewHolder) { super.clearView(recyclerView, viewHolder) - adapter.onDragFinished() + adapter.onDragFinished(viewHolder) } } From 3c4ce39f30e42e43e303d621ef9e5c65b10c8cfc Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 10:09:10 +0200 Subject: [PATCH 069/103] Add the Edit button to the bottom of the insights list --- .../ui/stats/refresh/BlockDiffCallback.kt | 2 + .../stats/refresh/lists/StatsListViewModel.kt | 45 ++++++++++++++++--- .../lists/sections/BlockListAdapter.kt | 5 +++ .../refresh/lists/sections/BlockListItem.kt | 12 +++-- .../viewholders/LinkButtonViewHolder.kt | 19 ++++++++ .../lists/viewholders/BaseStatsViewHolder.kt | 3 ++ .../layout/stats_block_link_button_item.xml | 25 +++++++++++ WordPress/src/main/res/values/dimens.xml | 1 + 8 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/viewholders/LinkButtonViewHolder.kt create mode 100644 WordPress/src/main/res/layout/stats_block_link_button_item.xml diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/BlockDiffCallback.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/BlockDiffCallback.kt index 16c3df8d201b..f6345be554d2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/BlockDiffCallback.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/BlockDiffCallback.kt @@ -21,6 +21,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type. import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.HEADER import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.INFO import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LINK +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LINK_BUTTON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM_WITH_ICON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LOADING_ITEM @@ -65,6 +66,7 @@ class BlockDiffCallback( CHART_LEGEND, REFERRED_ITEM, QUICK_SCAN_ITEM, + LINK_BUTTON, EMPTY -> oldItem == newItem } } else { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index 7e251b750c7e..c3ad53610e23 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker +import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.DAY_STATS_USE_CASE import org.wordpress.android.ui.stats.refresh.INSIGHTS_USE_CASE @@ -19,14 +20,20 @@ import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewInsightsManag import org.wordpress.android.ui.stats.refresh.StatsViewModel.DateSelectorUiModel import org.wordpress.android.ui.stats.refresh.WEEK_STATS_USE_CASE import org.wordpress.android.ui.stats.refresh.YEAR_STATS_USE_CASE +import org.wordpress.android.ui.stats.refresh.lists.InsightsListViewModel.InsightsTypes.LINK_BUTTON +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.LOADING import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.DAYS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.INSIGHTS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.MONTHS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.WEEKS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.YEARS +import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.UiModel.Success +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.LinkButton +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.NavigationAction import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsDateSelector import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +import org.wordpress.android.util.map import org.wordpress.android.util.mapNullable import org.wordpress.android.util.mergeNotNull import org.wordpress.android.util.throttle @@ -57,12 +64,14 @@ abstract class StatsListViewModel( val selectedDate = dateSelector.selectedDate - private val _navigationTarget = MutableLiveData() - val navigationTarget: LiveData = mergeNotNull(statsUseCase.navigationTarget, _navigationTarget) + protected val mutableNavigationTarget = MutableLiveData() + val navigationTarget: LiveData = mergeNotNull( + statsUseCase.navigationTarget, mutableNavigationTarget + ) val listSelected = statsUseCase.listSelected - val uiModel: LiveData = statsUseCase.data.throttle(this, distinct = true) + open val uiModel: LiveData = statsUseCase.data.throttle(this, distinct = true) val dateSelectorData: LiveData = dateSelector.dateSelectorData.mapNullable { it ?: DateSelectorUiModel(false) @@ -113,7 +122,7 @@ abstract class StatsListViewModel( } fun onEmptyInsightsButtonClicked() { - _navigationTarget.value = ViewInsightsManagement() + mutableNavigationTarget.value = ViewInsightsManagement() } fun start() { @@ -153,7 +162,33 @@ class InsightsListViewModel analyticsTracker, dateSelectorFactory.build(INSIGHTS), popupMenuHandler -) +) { + override val uiModel: LiveData = super.uiModel.map { model -> + if (model is Success && model.data.none { item -> item.type == LOADING }) { + return@map Success( + model.data + listOf( + StatsBlock.Success( + LINK_BUTTON, + listOf( + LinkButton( + R.string.edit, + NavigationAction.create { + mutableNavigationTarget.value = ViewInsightsManagement() + } + ) + ) + ) + ) + ) + } else { + return@map model + } + } + + enum class InsightsTypes : StatsTypes { + LINK_BUTTON + } +} class YearsListViewModel @Inject constructor( @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListAdapter.kt index 9f5d045d855d..3c1dbb5addcf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListAdapter.kt @@ -16,6 +16,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Expan import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Header import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Information import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Link +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.LinkButton import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ListItem import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.ListItemWithIcon import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.LoadingItem @@ -35,6 +36,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type. import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.HEADER import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.INFO import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LINK +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LINK_BUTTON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM_WITH_ICON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LOADING_ITEM @@ -57,6 +59,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.Expanda import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.FourColumnsViewHolder import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.HeaderViewHolder import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.InformationViewHolder +import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.LinkButtonViewHolder import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.LinkViewHolder import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.ListItemViewHolder import org.wordpress.android.ui.stats.refresh.lists.sections.viewholders.ListItemWithIconViewHolder @@ -121,6 +124,7 @@ class BlockListAdapter(val imageManager: ImageManager) : Adapter ActivityViewHolder(parent) REFERRED_ITEM -> ReferredItemViewHolder(parent) QUICK_SCAN_ITEM -> QuickScanItemViewHolder(parent) + LINK_BUTTON -> LinkButtonViewHolder(parent) } } @@ -155,6 +159,7 @@ class BlockListAdapter(val imageManager: ImageManager) : Adapter holder.bind(item as LoadingItem) is ReferredItemViewHolder -> holder.bind(item as ReferredItem) is QuickScanItemViewHolder -> holder.bind(item as QuickScanItem) + is LinkButtonViewHolder -> holder.bind(item as LinkButton) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItem.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItem.kt index 706b5c25088c..a4d88e3d3314 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItem.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItem.kt @@ -14,6 +14,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type. import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.HEADER import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.INFO import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LINK +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LINK_BUTTON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LIST_ITEM_WITH_ICON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.Type.LOADING_ITEM @@ -52,7 +53,8 @@ sealed class BlockListItem(val type: Type) { LOADING_ITEM, ACTIVITY_ITEM, REFERRED_ITEM, - QUICK_SCAN_ITEM + QUICK_SCAN_ITEM, + LINK_BUTTON } data class Title( @@ -139,8 +141,12 @@ sealed class BlockListItem(val type: Type) { @DrawableRes val icon: Int? = null, @StringRes val text: Int, val navigateAction: NavigationAction - ) : - BlockListItem(LINK) + ) : BlockListItem(LINK) + + data class LinkButton( + @StringRes val text: Int, + val navigateAction: NavigationAction + ) : BlockListItem(LINK_BUTTON) data class BarChartItem( val entries: List, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/viewholders/LinkButtonViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/viewholders/LinkButtonViewHolder.kt new file mode 100644 index 000000000000..7b99ec6c6ae2 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/viewholders/LinkButtonViewHolder.kt @@ -0,0 +1,19 @@ +package org.wordpress.android.ui.stats.refresh.lists.sections.viewholders + +import android.view.ViewGroup +import android.widget.TextView +import org.wordpress.android.R +import org.wordpress.android.R.id +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.LinkButton + +class LinkButtonViewHolder(val parent: ViewGroup) : BlockListItemViewHolder( + parent, + R.layout.stats_block_link_button_item +) { + private val text = itemView.findViewById(id.text) + + fun bind(item: LinkButton) { + text.setText(item.text) + text.setOnClickListener { item.navigateAction.click() } + } +} diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt index 37ed84b8acfb..3ac45cc03469 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt @@ -9,6 +9,7 @@ import android.view.ViewGroup import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.LATEST_POST_SUMMARY import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.OVERVIEW +import org.wordpress.android.ui.stats.refresh.lists.InsightsListViewModel.InsightsTypes.LINK_BUTTON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem abstract class BaseStatsViewHolder( @@ -20,6 +21,8 @@ abstract class BaseStatsViewHolder( if (statsTypes == OVERVIEW || statsTypes == LATEST_POST_SUMMARY) { val layoutParams = itemView.layoutParams as? StaggeredGridLayoutManager.LayoutParams layoutParams?.isFullSpan = true + } else if (statsTypes == LINK_BUTTON) { + itemView.background = null } } } diff --git a/WordPress/src/main/res/layout/stats_block_link_button_item.xml b/WordPress/src/main/res/layout/stats_block_link_button_item.xml new file mode 100644 index 000000000000..c3c12abdcf90 --- /dev/null +++ b/WordPress/src/main/res/layout/stats_block_link_button_item.xml @@ -0,0 +1,25 @@ + + + + + + diff --git a/WordPress/src/main/res/values/dimens.xml b/WordPress/src/main/res/values/dimens.xml index 7e57faae6c61..f4a701c6ac82 100644 --- a/WordPress/src/main/res/values/dimens.xml +++ b/WordPress/src/main/res/values/dimens.xml @@ -402,6 +402,7 @@ 1dp 24dp 231dp + 52dp 24dp From d5f313a6479a62b0eefd8d1080f3561962dc4dba Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 10:11:59 +0200 Subject: [PATCH 070/103] Remove the old Manage menu --- .../android/ui/stats/refresh/StatsFragment.kt | 27 ------------------- .../ui/stats/refresh/StatsViewModel.kt | 12 --------- .../src/main/res/menu/menu_stats_insights.xml | 8 ------ 3 files changed, 47 deletions(-) delete mode 100644 WordPress/src/main/res/menu/menu_stats_insights.xml diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt index f8d950afaafb..aa453c66a4fa 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt @@ -54,8 +54,6 @@ class StatsFragment : DaggerFragment() { private lateinit var swipeToRefreshHelper: SwipeToRefreshHelper @Inject lateinit var navigator: StatsNavigator - private var menu: Menu? = null - private var restorePreviousSearch = false override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -63,20 +61,6 @@ class StatsFragment : DaggerFragment() { return inflater.inflate(R.layout.stats_fragment, container, false) } - override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { - super.onCreateOptionsMenu(menu, inflater) - - inflater?.inflate(R.menu.menu_stats_insights, menu) - this.menu = menu - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (item.itemId == R.id.manage_insights) { - viewModel.onManageInsightsButtonTapped() - } - return true - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -186,17 +170,6 @@ class StatsFragment : DaggerFragment() { viewModel.siteChanged.observe(this, Observer { viewModel.refreshData() }) - - viewModel.isMenuVisible.observe(this, Observer { isMenuVisible -> - isMenuVisible?.let { - menu?.findItem(R.id.manage_insights)?.isVisible = isMenuVisible - } - }) - - viewModel.navigationTarget.observeEvent(this) { target -> - navigator.navigate(activity, target) - return@observeEvent true - } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt index 64652f3c6e96..2268edc70454 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt @@ -15,7 +15,6 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_PERIOD_YEARS_ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.pages.SnackbarMessageHolder -import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewInsightsManagement import org.wordpress.android.ui.stats.refresh.lists.BaseListUseCase import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.DAYS @@ -47,9 +46,6 @@ class StatsViewModel private val _isRefreshing = MutableLiveData() val isRefreshing: LiveData = _isRefreshing - private val _isMenuVisible = MutableLiveData() - val isMenuVisible: LiveData = _isMenuVisible - private var isInitialized = false private val _showSnackbarMessage = mergeNotNull( @@ -59,9 +55,6 @@ class StatsViewModel ) val showSnackbarMessage: LiveData = _showSnackbarMessage - private val _navigationTarget = MutableLiveData() - val navigationTarget: LiveData = _navigationTarget - val siteChanged = statsSiteProvider.siteChanged private val _toolbarHasShadow = MutableLiveData() @@ -118,7 +111,6 @@ class StatsViewModel listUseCases[statsSection]?.onListSelected() _toolbarHasShadow.value = statsSection == INSIGHTS - _isMenuVisible.value = statsSection == INSIGHTS when (statsSection) { INSIGHTS -> analyticsTracker.track(STATS_INSIGHTS_ACCESSED) @@ -131,10 +123,6 @@ class StatsViewModel } } - fun onManageInsightsButtonTapped() { - _navigationTarget.value = ViewInsightsManagement() - } - override fun onCleared() { super.onCleared() _showSnackbarMessage.value = null diff --git a/WordPress/src/main/res/menu/menu_stats_insights.xml b/WordPress/src/main/res/menu/menu_stats_insights.xml deleted file mode 100644 index 8485da2b8f98..000000000000 --- a/WordPress/src/main/res/menu/menu_stats_insights.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - From 01420e1bf4c605cbdda87afcf8201a266d89b752 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 11:51:22 +0200 Subject: [PATCH 071/103] Add a new type of StatsBlock to allow empty background for the link button --- .../android/ui/stats/refresh/lists/StatsBlock.kt | 9 ++++++++- .../ui/stats/refresh/lists/StatsBlockAdapter.kt | 4 ++++ .../ui/stats/refresh/lists/StatsListViewModel.kt | 2 +- .../lists/viewholders/BaseStatsViewHolder.kt | 2 -- .../lists/viewholders/BlockListViewHolder.kt | 2 +- .../lists/viewholders/ControlViewHolder.kt | 16 ++++++++++++++++ 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/ControlViewHolder.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt index 0a71e078f20f..db78504341ec 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt @@ -1,6 +1,7 @@ package org.wordpress.android.ui.stats.refresh.lists import org.wordpress.android.fluxc.store.StatsStore.StatsTypes +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.CONTROL import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.EMPTY import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.ERROR import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.LOADING @@ -12,7 +13,8 @@ sealed class StatsBlock(val type: Type, open val statsTypes: StatsTypes, open va SUCCESS, ERROR, EMPTY, - LOADING + LOADING, + CONTROL } data class Success( @@ -34,4 +36,9 @@ sealed class StatsBlock(val type: Type, open val statsTypes: StatsTypes, open va override val statsTypes: StatsTypes, override val data: List ) : StatsBlock(LOADING, statsTypes, data) + + data class Control( + override val statsTypes: StatsTypes, + override val data: List + ) : StatsBlock(CONTROL, statsTypes, data) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockAdapter.kt index 7d3225991eec..0a1fa0b54af5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockAdapter.kt @@ -3,6 +3,7 @@ package org.wordpress.android.ui.stats.refresh.lists import android.support.v7.util.DiffUtil import android.support.v7.widget.RecyclerView.Adapter import android.view.ViewGroup +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.CONTROL import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.EMPTY import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.ERROR import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.LOADING @@ -10,6 +11,7 @@ import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.SUCCESS import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.values import org.wordpress.android.ui.stats.refresh.lists.viewholders.BaseStatsViewHolder import org.wordpress.android.ui.stats.refresh.lists.viewholders.BlockListViewHolder +import org.wordpress.android.ui.stats.refresh.lists.viewholders.ControlViewHolder import org.wordpress.android.ui.stats.refresh.lists.viewholders.LoadingViewHolder import org.wordpress.android.util.image.ImageManager @@ -31,6 +33,7 @@ class StatsBlockAdapter(val imageManager: ImageManager) : Adapter BlockListViewHolder(parent, imageManager) LOADING -> LoadingViewHolder(parent, imageManager) + CONTROL -> ControlViewHolder(parent, imageManager) } } @@ -45,6 +48,7 @@ class StatsBlockAdapter(val imageManager: ImageManager) : Adapter holder.bind(item.statsTypes, item.data) is LoadingViewHolder -> holder.bind(item.statsTypes, item.data) + is ControlViewHolder -> holder.bind(item.statsTypes, item.data) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index c3ad53610e23..74ae0052ebc6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -167,7 +167,7 @@ class InsightsListViewModel if (model is Success && model.data.none { item -> item.type == LOADING }) { return@map Success( model.data + listOf( - StatsBlock.Success( + StatsBlock.Control( LINK_BUTTON, listOf( LinkButton( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt index 3ac45cc03469..9906f5c47f56 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt @@ -21,8 +21,6 @@ abstract class BaseStatsViewHolder( if (statsTypes == OVERVIEW || statsTypes == LATEST_POST_SUMMARY) { val layoutParams = itemView.layoutParams as? StaggeredGridLayoutManager.LayoutParams layoutParams?.isFullSpan = true - } else if (statsTypes == LINK_BUTTON) { - itemView.background = null } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt index 639527968409..65db94e5239b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt @@ -10,7 +10,7 @@ import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListAdapter import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem import org.wordpress.android.util.image.ImageManager -class BlockListViewHolder(parent: ViewGroup, val imageManager: ImageManager) : BaseStatsViewHolder( +open class BlockListViewHolder(parent: ViewGroup, val imageManager: ImageManager) : BaseStatsViewHolder( parent, R.layout.stats_list_block ) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/ControlViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/ControlViewHolder.kt new file mode 100644 index 000000000000..55cc57ea3d47 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/ControlViewHolder.kt @@ -0,0 +1,16 @@ +package org.wordpress.android.ui.stats.refresh.lists.viewholders + +import android.view.ViewGroup +import org.wordpress.android.fluxc.store.StatsStore.StatsTypes +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem +import org.wordpress.android.util.image.ImageManager + +class ControlViewHolder(val parent: ViewGroup, imageManager: ImageManager) : BlockListViewHolder( + parent, + imageManager +) { + override fun bind(statsTypes: StatsTypes, items: List) { + super.bind(statsTypes, items) + itemView.background = null + } +} From 0b234fee3c35cb24834bd2b7040ac6d29c759bfd Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 11:51:52 +0200 Subject: [PATCH 072/103] Disable the click listener after a tap to prevent a crash --- .../lists/sections/insights/management/AddedInsightViewHolder.kt | 1 + .../sections/insights/management/RemovedInsightViewHolder.kt | 1 + 2 files changed, 2 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/AddedInsightViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/AddedInsightViewHolder.kt index c7bd22f1d2c9..61db19e6ff0d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/AddedInsightViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/AddedInsightViewHolder.kt @@ -24,6 +24,7 @@ class AddedInsightViewHolder( managementButton.setImageResource(R.drawable.ic_remove_circle) managementButton.setOnClickListener { + managementButton.setOnClickListener(null) onButtonClicked(insight) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/RemovedInsightViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/RemovedInsightViewHolder.kt index bce66f30cf9a..222d25512219 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/RemovedInsightViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/RemovedInsightViewHolder.kt @@ -20,6 +20,7 @@ class RemovedInsightViewHolder( managementButton.setImageResource(R.drawable.ic_add_circle) managementButton.setOnClickListener { + managementButton.setOnClickListener(null) onButtonClicked(insight) } From 5fc462d59ad867cca3370af148c9920b151d5f51 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 11:52:40 +0200 Subject: [PATCH 073/103] Avoid using LiveData state as in-memory cache --- .../management/InsightsManagementFragment.kt | 7 +-- .../management/InsightsManagementViewModel.kt | 43 ++++++++++--------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index 16a50c3f9865..dfaf49e62c91 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -108,14 +108,15 @@ class InsightsManagementFragment : DaggerFragment() { } private fun updateRemovedInsights(insights: List) { - if (removedInsights.adapter == null) { - removedInsights.adapter = InsightsManagementAdapter( + var adapter = removedInsights.adapter as? InsightsManagementAdapter + if (adapter == null) { + adapter = InsightsManagementAdapter( { item -> viewModel.onItemButtonClicked(item) }, { viewHolder -> addedInsightsTouchHelper.startDrag(viewHolder) }, { list -> viewModel.onAddedInsightsReordered(list) } ) + removedInsights.adapter = adapter } - val adapter = removedInsights.adapter as InsightsManagementAdapter adapter.update(insights) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index 6c6e7f2d48d0..ced0fd26696e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -50,6 +50,7 @@ class InsightsManagementViewModel @Inject constructor( private val _isMenuVisible = MutableLiveData() val isMenuVisible: LiveData = _isMenuVisible + private lateinit var insights: List private var isInitialized = false fun start() { @@ -63,20 +64,25 @@ class InsightsManagementViewModel @Inject constructor( private fun loadInsights() { launch { val model = statsStore.getInsightsManagementModel(siteProvider.siteModel) - _addedInsights.value = model.addedTypes - .filter { it != FOLLOWER_TOTALS && it != ANNUAL_SITE_STATS } - .map { InsightModel(it, ADDED) } - - _removedInsights.value = model.removedTypes - .filter { it != FOLLOWER_TOTALS && it != ANNUAL_SITE_STATS } - .map { InsightModel(it, REMOVED) } + insights = model.addedTypes + .filter { it != FOLLOWER_TOTALS && it != ANNUAL_SITE_STATS } + .map { InsightModel(it, ADDED) } + + model.removedTypes + .filter { it != FOLLOWER_TOTALS && it != ANNUAL_SITE_STATS } + .map { InsightModel(it, REMOVED) } + displayInsights() } } + private fun displayInsights() { + _addedInsights.value = insights.filter { it.type == ADDED } + _removedInsights.value = insights.filter { it.type == REMOVED } + } + fun onSaveInsights() { launch { - val addedTypes = addedInsights.value?.map { it.insightsTypes } ?: emptyList() - val removedTypes = removedInsights.value?.map { it.insightsTypes } ?: emptyList() + val addedTypes = insights.filter { it.type == ADDED }.map { it.insightsTypes } + val removedTypes = insights.filter { it.type == REMOVED }.map { it.insightsTypes } val model = InsightTypesModel(addedTypes, removedTypes + FOLLOWER_TOTALS + ANNUAL_SITE_STATS) statsStore.updateTypes(siteProvider.siteModel, model) @@ -87,25 +93,22 @@ class InsightsManagementViewModel @Inject constructor( } } - fun onAddedInsightsReordered(items: List) { - _addedInsights.value = items + fun onAddedInsightsReordered(addedInsights: List) { + insights = addedInsights + insights.filter { it.type == REMOVED } _isMenuVisible.value = true } fun onItemButtonClicked(insight: InsightModel) { - launch { - if (insight.type == ADDED) { - _addedInsights.value = _addedInsights.value?.filter { it != insight } - _removedInsights.value = _removedInsights.value?.let { it + insight.copy(type = Type.REMOVED) } - } else { - _removedInsights.value = _removedInsights.value?.filter { it != insight } - _addedInsights.value = _addedInsights.value?.let { it + insight.copy(type = ADDED) } - } + if (insight.type == ADDED) { + insight.type = REMOVED + } else { + insight.type = ADDED } + displayInsights() _isMenuVisible.value = true } - data class InsightModel(val insightsTypes: InsightsTypes, val type: Type) { + data class InsightModel(val insightsTypes: InsightsTypes, var type: Type) { @StringRes val name: Int = when (insightsTypes) { LATEST_POST_SUMMARY -> R.string.stats_insights_latest_post_summary MOST_POPULAR_DAY_AND_HOUR -> R.string.stats_insights_popular From c6145a1008c8037abb5f827b3b5df908f9bdd734 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 12:18:08 +0200 Subject: [PATCH 074/103] Use constraint layout to fix the peroper list height that shows all items --- .../layout/insights_management_fragment.xml | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/WordPress/src/main/res/layout/insights_management_fragment.xml b/WordPress/src/main/res/layout/insights_management_fragment.xml index 75970a9d523b..22bd082d3cc6 100644 --- a/WordPress/src/main/res/layout/insights_management_fragment.xml +++ b/WordPress/src/main/res/layout/insights_management_fragment.xml @@ -1,30 +1,33 @@ - + android:gravity="center_horizontal" + android:text="@string/stats_insights_management_title" + android:textColor="@color/grey_darken_20" + android:textSize="@dimen/text_sz_large" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"/> - + From 942dbfcf4ce26bbdd88e03e0a303f42ae17138ab Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 12:21:42 +0200 Subject: [PATCH 075/103] Optimize imports --- .../org/wordpress/android/ui/stats/refresh/StatsFragment.kt | 4 ---- .../insights/management/InsightsManagementViewModel.kt | 1 - .../refresh/lists/sections/viewholders/TabsViewHolder.kt | 1 - .../ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt | 1 - .../ui/stats/refresh/lists/viewholders/LoadingViewHolder.kt | 1 - 5 files changed, 8 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt index aa453c66a4fa..141a514e20e4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsFragment.kt @@ -14,9 +14,6 @@ import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentPagerAdapter import android.support.v4.view.ViewCompat import android.view.LayoutInflater -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem import android.view.MotionEvent import android.view.View import android.view.ViewGroup @@ -43,7 +40,6 @@ import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSect import org.wordpress.android.ui.stats.refresh.utils.StatsNavigator import org.wordpress.android.util.WPSwipeToRefreshHelper import org.wordpress.android.util.helpers.SwipeToRefreshHelper -import org.wordpress.android.util.observeEvent import javax.inject.Inject private val statsSections = listOf(INSIGHTS, DAYS, WEEKS, MONTHS, YEARS) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index ced0fd26696e..99bd061842c9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -23,7 +23,6 @@ import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.TODAY_STATS import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.INSIGHTS_USE_CASE import org.wordpress.android.ui.stats.refresh.lists.BaseListUseCase -import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel.Type import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel.Type.ADDED import org.wordpress.android.ui.stats.refresh.lists.sections.insights.management.InsightsManagementViewModel.InsightModel.Type.REMOVED import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/viewholders/TabsViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/viewholders/TabsViewHolder.kt index 7e8cf853ad40..6c48d0b285ca 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/viewholders/TabsViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/viewholders/TabsViewHolder.kt @@ -6,7 +6,6 @@ import android.support.design.widget.TabLayout.Tab import android.view.ViewGroup import org.wordpress.android.R import org.wordpress.android.R.id -import org.wordpress.android.R.layout import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.TabsItem import org.wordpress.android.util.image.ImageManager diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt index 65db94e5239b..eb5874239058 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt @@ -4,7 +4,6 @@ import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.view.ViewGroup import org.wordpress.android.R -import org.wordpress.android.R.layout import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListAdapter import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/LoadingViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/LoadingViewHolder.kt index dff184a738b3..4dd36bcaffcd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/LoadingViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/LoadingViewHolder.kt @@ -4,7 +4,6 @@ import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.view.ViewGroup import org.wordpress.android.R -import org.wordpress.android.R.layout import org.wordpress.android.fluxc.store.StatsStore import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListAdapter import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem From c2412c872a93052d45a3fe086a858e7bb0403734 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 12:30:27 +0200 Subject: [PATCH 076/103] Prevent long-press dragging --- .../sections/insights/management/ItemTouchHelperCallback.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt index 9c73401988c2..3c93659e02e6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/ItemTouchHelperCallback.kt @@ -6,7 +6,7 @@ import android.support.v7.widget.helper.ItemTouchHelper class ItemTouchHelperCallback(private val adapter: ItemTouchHelperAdapter) : ItemTouchHelper.Callback() { override fun isLongPressDragEnabled(): Boolean { - return true + return false } override fun isItemViewSwipeEnabled(): Boolean { From 9ec6c79333e9ecb9f6800d8df190282d67a1ef86 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 12:35:55 +0200 Subject: [PATCH 077/103] Set basline aligned attribute for better performance --- .../src/main/res/layout/stats_block_four_columns_item.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/res/layout/stats_block_four_columns_item.xml b/WordPress/src/main/res/layout/stats_block_four_columns_item.xml index 10fa560668f3..804e1cae3fbb 100644 --- a/WordPress/src/main/res/layout/stats_block_four_columns_item.xml +++ b/WordPress/src/main/res/layout/stats_block_four_columns_item.xml @@ -4,7 +4,8 @@ android:id="@+id/column_container" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> + android:orientation="horizontal" + android:baselineAligned="false"> Date: Fri, 12 Apr 2019 12:42:46 +0200 Subject: [PATCH 078/103] Remove unused string resource --- WordPress/src/main/res/values/strings.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index ec37ffd93b16..cba1649d2055 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -1032,7 +1032,6 @@ Only see the most relevant stats. Add and organise your insights below. Add Insights Items shown above will show in your Insights tab. Drag and drop to customize. - Insights have been saved Months and Years From 2c9fd4ecbd345973c6587c84afea0409a43f0679 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 12:45:43 +0200 Subject: [PATCH 079/103] Optimize imports --- .../ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt index 9906f5c47f56..37ed84b8acfb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt @@ -9,7 +9,6 @@ import android.view.ViewGroup import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.LATEST_POST_SUMMARY import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes.OVERVIEW -import org.wordpress.android.ui.stats.refresh.lists.InsightsListViewModel.InsightsTypes.LINK_BUTTON import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem abstract class BaseStatsViewHolder( From f03cd7fdee523bf83bbfcc1fc2ae8c2a646e13a8 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 12:48:42 +0200 Subject: [PATCH 080/103] Get rid of an extra coroutine builder --- .../insights/management/InsightsManagementViewModel.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index 99bd061842c9..0dd3c5aa6171 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -85,11 +85,9 @@ class InsightsManagementViewModel @Inject constructor( val model = InsightTypesModel(addedTypes, removedTypes + FOLLOWER_TOTALS + ANNUAL_SITE_STATS) statsStore.updateTypes(siteProvider.siteModel, model) - launch { - insightsUseCase.refreshData() - } - _closeInsightsManagement.call() + insightsUseCase.refreshData() } + _closeInsightsManagement.call() } fun onAddedInsightsReordered(addedInsights: List) { From a0373326479be8a6118245bff44bf80690fed814 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 12:56:40 +0200 Subject: [PATCH 081/103] Remove unused string resource --- WordPress/src/main/res/values/strings.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index cba1649d2055..a78673abfe2c 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -790,7 +790,6 @@ No data for this period No insights added yet Manage Insights - Manage WordPress.com Email Total %1$s Followers: %2$s From 8452113cce90a571c7df5ffb9087cf76d0cf982a Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Fri, 12 Apr 2019 20:31:19 +0200 Subject: [PATCH 082/103] Add the missing drawable resources --- .../src/main/res/drawable/shape_oval_green.xml | 4 ++++ .../src/main/res/drawable/shape_oval_red.xml | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 libs/login/WordPressLoginFlow/src/main/res/drawable/shape_oval_green.xml create mode 100644 libs/login/WordPressLoginFlow/src/main/res/drawable/shape_oval_red.xml diff --git a/libs/login/WordPressLoginFlow/src/main/res/drawable/shape_oval_green.xml b/libs/login/WordPressLoginFlow/src/main/res/drawable/shape_oval_green.xml new file mode 100644 index 000000000000..de3dbf83a696 --- /dev/null +++ b/libs/login/WordPressLoginFlow/src/main/res/drawable/shape_oval_green.xml @@ -0,0 +1,4 @@ + + + + diff --git a/libs/login/WordPressLoginFlow/src/main/res/drawable/shape_oval_red.xml b/libs/login/WordPressLoginFlow/src/main/res/drawable/shape_oval_red.xml new file mode 100644 index 000000000000..c04efe4258dc --- /dev/null +++ b/libs/login/WordPressLoginFlow/src/main/res/drawable/shape_oval_red.xml @@ -0,0 +1,4 @@ + + + + From deecbba7dab844af6b56093a55901c403141caea Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Tue, 16 Apr 2019 00:38:37 +0200 Subject: [PATCH 083/103] Remove the common statsTypes parameter from StatsBlocks --- .../ui/stats/refresh/lists/StatsBlock.kt | 21 +++++++++---------- .../stats/refresh/lists/StatsBlockAdapter.kt | 17 ++++++++++++--- .../refresh/lists/StatsBlockDiffCallback.kt | 13 +++++++++++- .../lists/viewholders/BaseStatsViewHolder.kt | 2 +- .../lists/viewholders/BlockListViewHolder.kt | 2 +- .../lists/viewholders/ControlViewHolder.kt | 5 ++--- .../lists/viewholders/LoadingViewHolder.kt | 2 +- 7 files changed, 41 insertions(+), 21 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt index db78504341ec..ff33a723fb75 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlock.kt @@ -8,7 +8,7 @@ import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.LOADING import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.SUCCESS import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem -sealed class StatsBlock(val type: Type, open val statsTypes: StatsTypes, open val data: List) { +sealed class StatsBlock(val type: Type, open val data: List) { enum class Type { SUCCESS, ERROR, @@ -18,27 +18,26 @@ sealed class StatsBlock(val type: Type, open val statsTypes: StatsTypes, open va } data class Success( - override val statsTypes: StatsTypes, + val statsTypes: StatsTypes, override val data: List - ) : StatsBlock(SUCCESS, statsTypes, data) + ) : StatsBlock(SUCCESS, data) data class Error( - override val statsTypes: StatsTypes, + val statsTypes: StatsTypes, override val data: List = listOf() - ) : StatsBlock(ERROR, statsTypes, data) + ) : StatsBlock(ERROR, data) data class EmptyBlock( - override val statsTypes: StatsTypes, + val statsTypes: StatsTypes, override val data: List - ) : StatsBlock(EMPTY, statsTypes, data) + ) : StatsBlock(EMPTY, data) data class Loading( - override val statsTypes: StatsTypes, + val statsTypes: StatsTypes, override val data: List - ) : StatsBlock(LOADING, statsTypes, data) + ) : StatsBlock(LOADING, data) data class Control( - override val statsTypes: StatsTypes, override val data: List - ) : StatsBlock(CONTROL, statsTypes, data) + ) : StatsBlock(CONTROL, data) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockAdapter.kt index 0a1fa0b54af5..8cb991d513d6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockAdapter.kt @@ -3,6 +3,10 @@ package org.wordpress.android.ui.stats.refresh.lists import android.support.v7.util.DiffUtil import android.support.v7.widget.RecyclerView.Adapter import android.view.ViewGroup +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.EmptyBlock +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Loading +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Success +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Error import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.CONTROL import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.EMPTY import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.ERROR @@ -46,9 +50,16 @@ class StatsBlockAdapter(val imageManager: ImageManager) : Adapter) { val item = items[position] when (holder) { - is BlockListViewHolder -> holder.bind(item.statsTypes, item.data) - is LoadingViewHolder -> holder.bind(item.statsTypes, item.data) - is ControlViewHolder -> holder.bind(item.statsTypes, item.data) + is ControlViewHolder -> holder.bind(item.data) + is BlockListViewHolder, + is LoadingViewHolder -> { + when (item) { + is Success -> holder.bind(item.statsTypes, item.data) + is Loading -> holder.bind(item.statsTypes, item.data) + is EmptyBlock -> holder.bind(item.statsTypes, item.data) + is Error -> holder.bind(item.statsTypes, item.data) + } + } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockDiffCallback.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockDiffCallback.kt index af10b9d3118d..53fc7dd5c1f5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockDiffCallback.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsBlockDiffCallback.kt @@ -1,6 +1,11 @@ package org.wordpress.android.ui.stats.refresh.lists import android.support.v7.util.DiffUtil.Callback +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Control +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.EmptyBlock +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Loading +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Success +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Error class StatsBlockDiffCallback( private val oldList: List, @@ -10,7 +15,13 @@ class StatsBlockDiffCallback( override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val newItem = newList[newItemPosition] val oldItem = oldList[oldItemPosition] - return oldItem.statsTypes == newItem.statsTypes + return oldItem.type == newItem.type && when (oldItem) { + is Success -> oldItem.statsTypes == (newItem as Success).statsTypes + is EmptyBlock -> oldItem.statsTypes == (newItem as EmptyBlock).statsTypes + is Error -> oldItem.statsTypes == (newItem as Error).statsTypes + is Loading -> oldItem.statsTypes == (newItem as Loading).statsTypes + is Control -> true + } } override fun getOldListSize(): Int = oldList.size diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt index 37ed84b8acfb..6894c5620444 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BaseStatsViewHolder.kt @@ -16,7 +16,7 @@ abstract class BaseStatsViewHolder( @LayoutRes layout: Int ) : ViewHolder(LayoutInflater.from(parent.context).inflate(layout, parent, false)) { @CallSuper - open fun bind(statsTypes: StatsTypes, items: List) { + open fun bind(statsTypes: StatsTypes?, items: List) { if (statsTypes == OVERVIEW || statsTypes == LATEST_POST_SUMMARY) { val layoutParams = itemView.layoutParams as? StaggeredGridLayoutManager.LayoutParams layoutParams?.isFullSpan = true diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt index eb5874239058..8f020eddcd7c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/BlockListViewHolder.kt @@ -14,7 +14,7 @@ open class BlockListViewHolder(parent: ViewGroup, val imageManager: ImageManager R.layout.stats_list_block ) { private val list: RecyclerView = itemView.findViewById(R.id.stats_block_list) - override fun bind(statsTypes: StatsTypes, items: List) { + override fun bind(statsTypes: StatsTypes?, items: List) { super.bind(statsTypes, items) list.isNestedScrollingEnabled = false if (list.adapter == null) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/ControlViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/ControlViewHolder.kt index 55cc57ea3d47..afd9155f6afd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/ControlViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/ControlViewHolder.kt @@ -1,7 +1,6 @@ package org.wordpress.android.ui.stats.refresh.lists.viewholders import android.view.ViewGroup -import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem import org.wordpress.android.util.image.ImageManager @@ -9,8 +8,8 @@ class ControlViewHolder(val parent: ViewGroup, imageManager: ImageManager) : Blo parent, imageManager ) { - override fun bind(statsTypes: StatsTypes, items: List) { - super.bind(statsTypes, items) + fun bind(items: List) { + super.bind(null, items) itemView.background = null } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/LoadingViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/LoadingViewHolder.kt index 4dd36bcaffcd..637d7d809966 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/LoadingViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/viewholders/LoadingViewHolder.kt @@ -14,7 +14,7 @@ class LoadingViewHolder(parent: ViewGroup, val imageManager: ImageManager) : Bas R.layout.stats_loading_view ) { private val list: RecyclerView = itemView.findViewById(R.id.stats_block_list) - override fun bind(statsTypes: StatsStore.StatsTypes, items: List) { + override fun bind(statsTypes: StatsStore.StatsTypes?, items: List) { super.bind(statsTypes, items) list.isNestedScrollingEnabled = false if (list.adapter == null) { From 88b0acf77436d2f9e58dd3ac456e0e83778ba98b Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Tue, 16 Apr 2019 00:40:13 +0200 Subject: [PATCH 084/103] Move the UiModel construction to the mapper --- .../ui/stats/refresh/lists/BaseListUseCase.kt | 9 ++-- .../stats/refresh/lists/StatsListViewModel.kt | 39 ++-------------- .../ui/stats/refresh/lists/UiModelMapper.kt | 44 +++++++++++++++---- 3 files changed, 44 insertions(+), 48 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt index 59772a62e26c..ad4d5ddc8016 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt @@ -27,7 +27,9 @@ class BaseListUseCase( private val statsSiteProvider: StatsSiteProvider, private val useCases: List>, private val getStatsTypes: suspend () -> List, - private val mapUiModel: (useCaseModels: List, showError: (Int) -> Unit) -> UiModel + private val mapUiModel: (useCaseModels: List, + MutableLiveData, + showError: (Int) -> Unit) -> UiModel ) { private val blockListData = combineMap( useCases.associateBy { it.type }.mapValues { entry -> entry.value.liveData } @@ -42,13 +44,14 @@ class BaseListUseCase( } } }.map { useCaseModels -> - mapUiModel(useCaseModels) { message -> + mapUiModel(useCaseModels, mutableNavigationTarget) { message -> mutableSnackbarMessage.postValue(message) } }.distinct() + private val mutableNavigationTarget = MutableLiveData() val navigationTarget: LiveData = mergeNotNull( - useCases.map { it.navigationTarget }, + useCases.map { it.navigationTarget } + mutableNavigationTarget, distinct = false ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index 74ae0052ebc6..a7dc996aa8c6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -10,7 +10,6 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker -import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.refresh.DAY_STATS_USE_CASE import org.wordpress.android.ui.stats.refresh.INSIGHTS_USE_CASE @@ -20,20 +19,14 @@ import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewInsightsManag import org.wordpress.android.ui.stats.refresh.StatsViewModel.DateSelectorUiModel import org.wordpress.android.ui.stats.refresh.WEEK_STATS_USE_CASE import org.wordpress.android.ui.stats.refresh.YEAR_STATS_USE_CASE -import org.wordpress.android.ui.stats.refresh.lists.InsightsListViewModel.InsightsTypes.LINK_BUTTON -import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Type.LOADING import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.DAYS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.INSIGHTS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.MONTHS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.WEEKS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.YEARS -import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.UiModel.Success -import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.LinkButton -import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.NavigationAction import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.StatsDateSelector import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper -import org.wordpress.android.util.map import org.wordpress.android.util.mapNullable import org.wordpress.android.util.mergeNotNull import org.wordpress.android.util.throttle @@ -64,14 +57,14 @@ abstract class StatsListViewModel( val selectedDate = dateSelector.selectedDate - protected val mutableNavigationTarget = MutableLiveData() + private val mutableNavigationTarget = MutableLiveData() val navigationTarget: LiveData = mergeNotNull( statsUseCase.navigationTarget, mutableNavigationTarget ) val listSelected = statsUseCase.listSelected - open val uiModel: LiveData = statsUseCase.data.throttle(this, distinct = true) + val uiModel: LiveData = statsUseCase.data.throttle(this, distinct = true) val dateSelectorData: LiveData = dateSelector.dateSelectorData.mapNullable { it ?: DateSelectorUiModel(false) @@ -162,33 +155,7 @@ class InsightsListViewModel analyticsTracker, dateSelectorFactory.build(INSIGHTS), popupMenuHandler -) { - override val uiModel: LiveData = super.uiModel.map { model -> - if (model is Success && model.data.none { item -> item.type == LOADING }) { - return@map Success( - model.data + listOf( - StatsBlock.Control( - LINK_BUTTON, - listOf( - LinkButton( - R.string.edit, - NavigationAction.create { - mutableNavigationTarget.value = ViewInsightsManagement() - } - ) - ) - ) - ) - ) - } else { - return@map model - } - } - - enum class InsightsTypes : StatsTypes { - LINK_BUTTON - } -} +) class YearsListViewModel @Inject constructor( @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt index 0ca85f8ead59..7ee9e3c35fd0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapper.kt @@ -1,22 +1,30 @@ package org.wordpress.android.ui.stats.refresh.lists +import android.arch.lifecycle.MutableLiveData import org.wordpress.android.R.string import org.wordpress.android.fluxc.store.StatsStore.PostDetailTypes import org.wordpress.android.fluxc.store.StatsStore.StatsTypes import org.wordpress.android.fluxc.store.StatsStore.TimeStatsTypes -import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Error +import org.wordpress.android.ui.stats.refresh.NavigationTarget +import org.wordpress.android.ui.stats.refresh.NavigationTarget.ViewInsightsManagement import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.UiModel import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.UseCaseModel import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.UseCaseModel.UseCaseState.EMPTY import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.UseCaseModel.UseCaseState.ERROR import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.UseCaseModel.UseCaseState.LOADING import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.UseCaseModel.UseCaseState.SUCCESS +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.LinkButton +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.NavigationAction import org.wordpress.android.util.NetworkUtilsWrapper import javax.inject.Inject class UiModelMapper @Inject constructor(private val networkUtilsWrapper: NetworkUtilsWrapper) { - fun mapInsights(useCaseModels: List, showError: (Int) -> Unit): UiModel { + fun mapInsights( + useCaseModels: List, + navigationTarget: MutableLiveData, + showError: (Int) -> Unit + ): UiModel { if (useCaseModels.isNotEmpty()) { val allFailing = useCaseModels.fold(true) { acc, useCaseModel -> acc && useCaseModel.state == ERROR @@ -25,7 +33,7 @@ class UiModelMapper acc && useCaseModel.state == ERROR && useCaseModel.data == null } return if (!allFailing && !allFailingWithoutData) { - UiModel.Success(useCaseModels.map { useCaseModel -> + val data = useCaseModels.map { useCaseModel -> when (useCaseModel.state) { SUCCESS -> StatsBlock.Success(useCaseModel.type, useCaseModel.data ?: listOf()) ERROR -> StatsBlock.Error( @@ -41,11 +49,21 @@ class UiModelMapper useCaseModel.stateData ?: useCaseModel.data ?: listOf() ) } - }) + }.toMutableList() + + val allUseCasesLoaded = useCaseModels.none { it.state == LOADING } + if (allUseCasesLoaded) { + data += StatsBlock.Control(listOf(LinkButton(string.edit, + NavigationAction.create { + navigationTarget.value = ViewInsightsManagement() + } + ))) + } + UiModel.Success(data) } else if (!allFailingWithoutData) { showError(getErrorMessage()) UiModel.Success(useCaseModels.map { useCaseModel -> - Error( + StatsBlock.Error( useCaseModel.type, useCaseModel.data ?: useCaseModel.stateData ?: listOf() ) @@ -58,12 +76,20 @@ class UiModelMapper } } - fun mapTimeStats(useCaseModels: List, showError: (Int) -> Unit): UiModel { + fun mapTimeStats( + useCaseModels: List, + navigationTarget: MutableLiveData, + showError: (Int) -> Unit + ): UiModel { return mapStatsWithOverview(TimeStatsTypes.OVERVIEW, useCaseModels, showError) } - fun mapDetailStats(useCaseModels: List, showError: (Int) -> Unit): UiModel { - return mapStatsWithOverview(PostDetailTypes.POST_OVERVIEW, useCaseModels, showError) + fun mapDetailStats( + useCaseModels: List, + navigationTarget: MutableLiveData, + showError: (Int) -> Unit + ): UiModel { + return mapStatsWithOverview(PostDetailTypes.POST_OVERVIEW, useCaseModels, showError) } private fun mapStatsWithOverview( @@ -115,7 +141,7 @@ class UiModelMapper StatsBlock.Success(useCaseModel.type, useCaseModel.data) } else { useCaseModel.stateData?.let { - Error( + StatsBlock.Error( useCaseModel.type, useCaseModel.stateData ) From b4f3bbcef4d52269d947e3d5892cdfc16e42d3b9 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Tue, 16 Apr 2019 00:59:16 +0200 Subject: [PATCH 085/103] Fix the unit tests --- .../ui/stats/refresh/lists/UiModelMapperTest.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapperTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapperTest.kt index 6b1489c6526b..a0d79ed41a30 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapperTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapperTest.kt @@ -1,5 +1,6 @@ package org.wordpress.android.ui.stats.refresh.lists +import android.arch.lifecycle.MutableLiveData import kotlinx.coroutines.ExperimentalCoroutinesApi import org.assertj.core.api.Assertions.assertThat import org.junit.Before @@ -8,9 +9,12 @@ import org.mockito.Mock import org.wordpress.android.BaseUnitTest import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.FOLLOWER_TOTALS +import org.wordpress.android.ui.stats.refresh.NavigationTarget +import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Success import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.UiModel import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.UseCaseModel import org.wordpress.android.ui.stats.refresh.lists.sections.BaseStatsUseCase.UseCaseModel.UseCaseState.SUCCESS +import org.wordpress.android.ui.stats.refresh.lists.sections.BlockListItem.LinkButton import org.wordpress.android.util.NetworkUtilsWrapper class UiModelMapperTest : BaseUnitTest() { @@ -25,15 +29,19 @@ class UiModelMapperTest : BaseUnitTest() { @Test fun `mapInsights returns success ui model when all the inputs are successful`() { var error: Int? = null - val uiModel = mapper.mapInsights(listOf(UseCaseModel(FOLLOWER_TOTALS, data = listOf(), state = SUCCESS))) { + val navigationTarget = MutableLiveData() + val uiModel = mapper.mapInsights(listOf( + UseCaseModel(FOLLOWER_TOTALS, data = listOf(), state = SUCCESS)), navigationTarget) { error = it } val model = uiModel as UiModel.Success - assertThat(model.data).hasSize(1) - assertThat(model.data[0].statsTypes).isEqualTo(InsightsTypes.FOLLOWER_TOTALS) + assertThat(model.data).hasSize(2) + assertThat((model.data[0] as Success).statsTypes).isEqualTo(FOLLOWER_TOTALS) assertThat(model.data[0].type).isEqualTo(StatsBlock.Type.SUCCESS) assertThat(model.data[0].data).isEmpty() + assertThat(model.data[1].type).isEqualTo(StatsBlock.Type.CONTROL) + assertThat(model.data[1].data.first() is LinkButton).isTrue() assertThat(error).isNull() } } From 1af8339c8b420b7a7453f49950ca2ba3c687e983 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Tue, 16 Apr 2019 01:02:45 +0200 Subject: [PATCH 086/103] Fix ktlint --- .../android/ui/stats/refresh/lists/BaseListUseCase.kt | 6 ++++-- .../android/ui/stats/refresh/lists/UiModelMapperTest.kt | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt index ad4d5ddc8016..fcbb4faaac31 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/BaseListUseCase.kt @@ -27,9 +27,11 @@ class BaseListUseCase( private val statsSiteProvider: StatsSiteProvider, private val useCases: List>, private val getStatsTypes: suspend () -> List, - private val mapUiModel: (useCaseModels: List, + private val mapUiModel: ( + useCaseModels: List, MutableLiveData, - showError: (Int) -> Unit) -> UiModel + showError: (Int) -> Unit + ) -> UiModel ) { private val blockListData = combineMap( useCases.associateBy { it.type }.mapValues { entry -> entry.value.liveData } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapperTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapperTest.kt index a0d79ed41a30..5d8ca47748d5 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapperTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/lists/UiModelMapperTest.kt @@ -7,7 +7,6 @@ import org.junit.Before import org.junit.Test import org.mockito.Mock import org.wordpress.android.BaseUnitTest -import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes import org.wordpress.android.fluxc.store.StatsStore.InsightsTypes.FOLLOWER_TOTALS import org.wordpress.android.ui.stats.refresh.NavigationTarget import org.wordpress.android.ui.stats.refresh.lists.StatsBlock.Success From 8645831ebbe2352e67e142ec9e72cb1873feb923 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 17 Apr 2019 19:27:54 +0200 Subject: [PATCH 087/103] Fix the newly added insights data loading --- .../sections/insights/management/InsightsManagementViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index 0dd3c5aa6171..284b339fb15d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -85,7 +85,7 @@ class InsightsManagementViewModel @Inject constructor( val model = InsightTypesModel(addedTypes, removedTypes + FOLLOWER_TOTALS + ANNUAL_SITE_STATS) statsStore.updateTypes(siteProvider.siteModel, model) - insightsUseCase.refreshData() + insightsUseCase.refreshData(true) } _closeInsightsManagement.call() } From ddbf15aacc6b927efca008afe45676bb14878427 Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 17 Apr 2019 20:06:54 +0200 Subject: [PATCH 088/103] Add additional padding between the footer and the Add Insights header --- WordPress/src/main/res/layout/insights_management_fragment.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/res/layout/insights_management_fragment.xml b/WordPress/src/main/res/layout/insights_management_fragment.xml index 22bd082d3cc6..dfe276dd784c 100644 --- a/WordPress/src/main/res/layout/insights_management_fragment.xml +++ b/WordPress/src/main/res/layout/insights_management_fragment.xml @@ -63,7 +63,8 @@ android:textStyle="bold" android:layout_marginStart="@dimen/margin_extra_large" android:layout_marginEnd="@dimen/margin_extra_large" - android:layout_marginTop="@dimen/margin_large" + android:layout_marginTop="@dimen/margin_extra_large" + android:paddingTop="@dimen/margin_large" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/addedInsightsInfo" From 02bf4e70c55759809347353574e5796dcd5a03aa Mon Sep 17 00:00:00 2001 From: Ondrej Ruttkay Date: Wed, 17 Apr 2019 20:52:41 +0200 Subject: [PATCH 089/103] Add the reduced width layout for wide screens (landcape) --- .../insights_management_fragment.xml | 111 ++++++++++++++++++ .../layout/insights_management_fragment.xml | 3 +- .../main/res/values-w528dp/stats_styles.xml | 6 + .../main/res/values-w720dp/stats_styles.xml | 6 + .../src/main/res/values/stats_styles.xml | 5 + 5 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 WordPress/src/main/res/layout-w528dp/insights_management_fragment.xml diff --git a/WordPress/src/main/res/layout-w528dp/insights_management_fragment.xml b/WordPress/src/main/res/layout-w528dp/insights_management_fragment.xml new file mode 100644 index 000000000000..ac3ac56dec80 --- /dev/null +++ b/WordPress/src/main/res/layout-w528dp/insights_management_fragment.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WordPress/src/main/res/layout/insights_management_fragment.xml b/WordPress/src/main/res/layout/insights_management_fragment.xml index dfe276dd784c..47ef60c78215 100644 --- a/WordPress/src/main/res/layout/insights_management_fragment.xml +++ b/WordPress/src/main/res/layout/insights_management_fragment.xml @@ -9,8 +9,7 @@ diff --git a/WordPress/src/main/res/values-w528dp/stats_styles.xml b/WordPress/src/main/res/values-w528dp/stats_styles.xml index 711082a1ae55..0de4a22b9943 100644 --- a/WordPress/src/main/res/values-w528dp/stats_styles.xml +++ b/WordPress/src/main/res/values-w528dp/stats_styles.xml @@ -6,4 +6,10 @@ 1 center_horizontal + + diff --git a/WordPress/src/main/res/values-w720dp/stats_styles.xml b/WordPress/src/main/res/values-w720dp/stats_styles.xml index efb9b785aef1..78df3fc4485e 100644 --- a/WordPress/src/main/res/values-w720dp/stats_styles.xml +++ b/WordPress/src/main/res/values-w720dp/stats_styles.xml @@ -6,4 +6,10 @@ 1 center_horizontal + + diff --git a/WordPress/src/main/res/values/stats_styles.xml b/WordPress/src/main/res/values/stats_styles.xml index 021dbb27e5a9..76e0c8ba8acb 100644 --- a/WordPress/src/main/res/values/stats_styles.xml +++ b/WordPress/src/main/res/values/stats_styles.xml @@ -200,6 +200,11 @@ 1 + +