Skip to content

Commit

Permalink
Merge branch 'issue/19341-post-list-compact-layout' into issue/19341-…
Browse files Browse the repository at this point in the history
…update-post-list-layout
  • Loading branch information
zwarm committed Oct 22, 2023
2 parents a7718af + a990898 commit 5daf137
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 479 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
import org.wordpress.android.ui.posts.EditPostSettingsFragment;
import org.wordpress.android.ui.posts.HistoryListFragment;
import org.wordpress.android.ui.posts.PostDatePickerDialogFragment;
import org.wordpress.android.ui.posts.PostListCreateMenuFragment;
import org.wordpress.android.ui.posts.PostListFragment;
import org.wordpress.android.ui.posts.PostNotificationScheduleTimeDialogFragment;
import org.wordpress.android.ui.posts.PostSettingsListDialogFragment;
Expand Down Expand Up @@ -479,8 +478,6 @@ public interface AppComponent {

void inject(ReaderDiscoverLogic object);

void inject(PostListCreateMenuFragment object);

void inject(SuggestionActivity object);

void inject(MediaPickerActivity object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
import org.wordpress.android.viewmodel.pages.PagesViewModel;
import org.wordpress.android.viewmodel.pages.SearchListViewModel;
import org.wordpress.android.viewmodel.plugins.PluginBrowserViewModel;
import org.wordpress.android.viewmodel.posts.PostListCreateMenuViewModel;
import org.wordpress.android.viewmodel.posts.PostListViewModel;
import org.wordpress.android.viewmodel.quickstart.QuickStartViewModel;
import org.wordpress.android.viewmodel.storage.StorageUtilsViewModel;
Expand Down Expand Up @@ -353,11 +352,6 @@ abstract class ViewModelModule {
@ViewModelKey(PrepublishingPublishSettingsViewModel.class)
abstract ViewModel prepublishingPublishSettingsViewModel(PrepublishingPublishSettingsViewModel viewModel);

@Binds
@IntoMap
@ViewModelKey(PostListCreateMenuViewModel.class)
abstract ViewModel postListCreateMenuViewModel(PostListCreateMenuViewModel postListCreateMenuViewModel);

@Binds
@IntoMap
@ViewModelKey(StoryComposerViewModel.class)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.wordpress.android.R
import org.wordpress.android.analytics.AnalyticsTracker.Stat.POST_LIST_AUTHOR_FILTER_CHANGED
import org.wordpress.android.analytics.AnalyticsTracker.Stat.POST_LIST_CREATE_POST_TAPPED
import org.wordpress.android.analytics.AnalyticsTracker.Stat.POST_LIST_SEARCH_ACCESSED
import org.wordpress.android.analytics.AnalyticsTracker.Stat.POST_LIST_TAB_CHANGED
import org.wordpress.android.fluxc.Dispatcher
Expand All @@ -32,7 +33,6 @@ import org.wordpress.android.fluxc.store.PostStore
import org.wordpress.android.fluxc.store.UploadStore
import org.wordpress.android.modules.BG_THREAD
import org.wordpress.android.modules.UI_THREAD
import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper
import org.wordpress.android.ui.pages.SnackbarMessageHolder
import org.wordpress.android.ui.posts.PostListType.DRAFTS
import org.wordpress.android.ui.posts.PostListType.PUBLISHED
Expand All @@ -44,7 +44,6 @@ import org.wordpress.android.ui.uploads.UploadStarter
import org.wordpress.android.ui.utils.UiString.UiStringRes
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.NetworkUtilsWrapper
import org.wordpress.android.util.SiteUtilsWrapper
import org.wordpress.android.util.ToastUtils.Duration
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import org.wordpress.android.util.analytics.AnalyticsUtils
Expand All @@ -65,6 +64,8 @@ private val FAB_VISIBLE_POST_LIST_PAGES = listOf(PUBLISHED, DRAFTS, SCHEDULED, T
val POST_LIST_PAGES = listOf(PUBLISHED, DRAFTS, SCHEDULED, TRASHED)
private const val TRACKS_SELECTED_TAB = "selected_tab"
private const val TRACKS_SELECTED_AUTHOR_FILTER = "author_filter_selection"
private const val TRACKS_ACTION = "action"
private const val TRACKS_CREATE_NEW_POST = "create_new_post"

class PostListMainViewModel @Inject constructor(
private val dispatcher: Dispatcher,
Expand All @@ -81,9 +82,7 @@ class PostListMainViewModel @Inject constructor(
private val savePostToDbUseCase: SavePostToDbUseCase,
@Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher,
@Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher,
private val uploadStarter: UploadStarter,
private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper,
private val siteUtilsWrapper: SiteUtilsWrapper
private val uploadStarter: UploadStarter
) : ViewModel(), CoroutineScope {
private val lifecycleOwner = object : LifecycleOwner {
val lifecycleRegistry = LifecycleRegistry(this)
Expand Down Expand Up @@ -137,15 +136,6 @@ class PostListMainViewModel @Inject constructor(
private val _searchQuery = MutableLiveData<String?>()
val searchQuery: LiveData<String?> = _searchQuery

private val _onFabClicked = MutableLiveData<Event<Unit>>()
val onFabClicked: LiveData<Event<Unit>> = _onFabClicked

private val _onFabLongPressedForCreateMenu = MutableLiveData<Event<Unit>>()
val onFabLongPressedForCreateMenu: LiveData<Event<Unit>> = _onFabLongPressedForCreateMenu

private val _onFabLongPressedForPostList = MutableLiveData<Event<Unit>>()
val onFabLongPressedForPostList: LiveData<Event<Unit>> = _onFabLongPressedForPostList

private val uploadStatusTracker = PostModelUploadStatusTracker(
uploadStore = uploadStore,
uploadActionUseCase = uploadActionUseCase
Expand Down Expand Up @@ -361,21 +351,13 @@ class PostListMainViewModel @Inject constructor(
}

fun fabClicked() {
if (siteUtilsWrapper.supportsStoriesFeature(site, jetpackFeatureRemovalPhaseHelper)) {
_onFabClicked.postValue(Event(Unit))
} else {
newPost()
}
}
analyticsTracker.track(POST_LIST_CREATE_POST_TAPPED,
mapOf(TRACKS_ACTION to TRACKS_CREATE_NEW_POST )
)

fun newPost() {
postActionHandler.newPost()
}

fun newStoryPost() {
postActionHandler.newStoryPost()
}

fun updateAuthorFilterSelection(selectionId: Long) {
val selection = AuthorFilterSelection.fromId(selectionId)

Expand Down Expand Up @@ -576,14 +558,6 @@ class PostListMainViewModel @Inject constructor(
}
}

fun onFabLongPressed() {
if (siteUtilsWrapper.supportsStoriesFeature(site, jetpackFeatureRemovalPhaseHelper)) {
_onFabLongPressedForCreateMenu.postValue(Event(Unit))
} else {
_onFabLongPressedForPostList.postValue(Event(Unit))
}
}

fun refreshUiStateForAuthorFilter() {
_viewState.value = _viewState.value?.copy()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import org.wordpress.android.ui.ScrollableViewInitializedListener
import org.wordpress.android.ui.blaze.BlazeFeatureUtils
import org.wordpress.android.ui.bloggingreminders.BloggingReminderUtils.observeBottomSheet
import org.wordpress.android.ui.bloggingreminders.BloggingRemindersViewModel
import org.wordpress.android.ui.main.MainActionListItem.ActionType
import org.wordpress.android.ui.notifications.SystemNotificationsTracker
import org.wordpress.android.ui.pages.SnackbarMessageHolder
import org.wordpress.android.ui.photopicker.MediaPickerLauncher
Expand All @@ -66,7 +65,6 @@ import org.wordpress.android.util.extensions.getSerializableExtraCompat
import org.wordpress.android.util.extensions.redirectContextClickToLongPressListener
import org.wordpress.android.util.extensions.setLiftOnScrollTargetViewIdAndRequestLayout
import org.wordpress.android.viewmodel.observeEvent
import org.wordpress.android.viewmodel.posts.PostListCreateMenuViewModel
import javax.inject.Inject
import android.R as AndroidR

Expand Down Expand Up @@ -136,7 +134,6 @@ class PostsListActivity : LocaleAwareActivity(),
override fun getEditPostRepository() = editPostRepository

private lateinit var viewModel: PostListMainViewModel
private lateinit var postListCreateMenuViewModel: PostListCreateMenuViewModel

private lateinit var postsPagerAdapter: PostsPagerAdapter
private lateinit var searchActionButton: MenuItem
Expand Down Expand Up @@ -206,14 +203,13 @@ class PostsListActivity : LocaleAwareActivity(),
LocalId(savedInstanceState.getInt(STATE_KEY_BOTTOMSHEET_POST_ID, 0))
}

val actionsShownByDefault = intent.getBooleanExtra(ACTIONS_SHOWN_BY_DEFAULT, false)
val tabIndex = intent.getIntExtra(TAB_INDEX, PostListType.PUBLISHED.ordinal)

setupActionBar()
setupContent()
initViewModel(initPreviewState, currentBottomSheetPostId)
initBloggingReminders()
initCreateMenuViewModel(tabIndex, actionsShownByDefault)
initTabLayout(tabIndex)
loadIntentData(intent)
}
}
Expand All @@ -239,7 +235,11 @@ class PostsListActivity : LocaleAwareActivity(),
}

fabButton.setOnLongClickListener {
viewModel.onFabLongPressed()
if (fabButton.isHapticFeedbackEnabled) {
fabButton.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
}

Toast.makeText(fabButton.context, R.string.create_post_fab_tooltip, Toast.LENGTH_SHORT).show()
return@setOnLongClickListener true
}

Expand All @@ -249,46 +249,9 @@ class PostsListActivity : LocaleAwareActivity(),
postPager.adapter = postsPagerAdapter
}

private fun PostListActivityBinding.initCreateMenuViewModel(tabIndex: Int, actionsShownByDefault: Boolean) {
postListCreateMenuViewModel =
ViewModelProvider(this@PostsListActivity, viewModelFactory)[PostListCreateMenuViewModel::class.java]

postListCreateMenuViewModel.isBottomSheetShowing.observeEvent(this@PostsListActivity) { isBottomSheetShowing ->
var createMenuFragment = supportFragmentManager.findFragmentByTag(PostListCreateMenuFragment.TAG)
if (createMenuFragment == null) {
if (isBottomSheetShowing) {
createMenuFragment = PostListCreateMenuFragment.newInstance()
createMenuFragment.show(supportFragmentManager, PostListCreateMenuFragment.TAG)
}
} else {
if (!isBottomSheetShowing) {
createMenuFragment as PostListCreateMenuFragment
createMenuFragment.dismiss()
}
}
}

postListCreateMenuViewModel.fabUiState.observe(this@PostsListActivity) { fabUiState ->
val message = resources.getString(fabUiState.CreateContentMessageId)
fabButton.contentDescription = message
}

postListCreateMenuViewModel.createAction.observe(this@PostsListActivity) { createAction ->
when (createAction) {
ActionType.CREATE_NEW_POST -> viewModel.newPost()
ActionType.CREATE_NEW_STORY -> viewModel.newStoryPost()
ActionType.CREATE_NEW_PAGE -> Unit // Do nothing
ActionType.NO_ACTION -> Unit // Do nothing
ActionType.ANSWER_BLOGGING_PROMPT -> Unit // Do nothing
ActionType.CREATE_NEW_PAGE_FROM_PAGES_CARD -> Unit // Do nothing
null -> Unit // Do nothing
}
}

// Notification opens in Drafts tab
private fun PostListActivityBinding.initTabLayout(tabIndex: Int) {
// Notification opens in Drafts tab
tabLayout.getTabAt(tabIndex)?.select()

postListCreateMenuViewModel.start(site, actionsShownByDefault)
}

private fun PostListActivityBinding.initViewModel(
Expand Down Expand Up @@ -352,8 +315,6 @@ class PostsListActivity : LocaleAwareActivity(),
prepublishingFragment.show(supportFragmentManager, PrepublishingBottomSheetFragment.TAG)
}
}

setupFabEvents()
}

private fun initBloggingReminders() {
Expand Down Expand Up @@ -394,24 +355,6 @@ class PostsListActivity : LocaleAwareActivity(),
}
}

private fun PostListActivityBinding.setupFabEvents() {
viewModel.onFabClicked.observeEvent(this@PostsListActivity) {
postListCreateMenuViewModel.onFabClicked()
}

viewModel.onFabLongPressedForCreateMenu.observeEvent(this@PostsListActivity) {
postListCreateMenuViewModel.onFabLongPressed()
Toast.makeText(fabButton.context, R.string.create_post_story_fab_tooltip, Toast.LENGTH_SHORT).show()
}

viewModel.onFabLongPressedForPostList.observe(this@PostsListActivity) {
if (fabButton.isHapticFeedbackEnabled) {
fabButton.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
}
Toast.makeText(fabButton.context, R.string.create_post_fab_tooltip, Toast.LENGTH_SHORT).show()
}
}

private fun PostListActivityBinding.loadViewState(state: PostListMainViewState) {
if (state.isFabVisible) {
fabButton.show()
Expand Down Expand Up @@ -473,7 +416,6 @@ class PostsListActivity : LocaleAwareActivity(),
public override fun onResume() {
super.onResume()
ActivityId.trackLastActivity(ActivityId.POSTS)
postListCreateMenuViewModel.onResume()
}

@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION")
Expand Down
Loading

0 comments on commit 5daf137

Please sign in to comment.