-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add new post list powered by wordpress-rs #22585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e3fc4d7
Add new Compose post list backed by wordpress-rs
nbradbury b6a07ee
Use scrollable tabs in post list to prevent label wrapping
nbradbury f047e40
Add create post button to empty state in post list
nbradbury 0fbd59e
Use tab-specific empty messages matching existing post list
nbradbury 2891d74
Remove unused snapshotFlow import
nbradbury 557e849
Remove unused fields and tighten visibility in post list
nbradbury 0c67beb
Use relative time formatting for post dates in post list
nbradbury 88721e4
Fix date parsing for posts without timezone offset
nbradbury c7ccb02
Add floating action button for creating new posts
nbradbury 94c80a5
Move rslist package to ui.posts_rs
nbradbury da8626c
Simplify ViewModel coroutine handling and remove redundant code
nbradbury 0ab5593
Consolidate posts-rs feature gating into ActivityLauncher
nbradbury 3544080
Fix checkstyle and detekt violations
nbradbury fbf9877
Extract composables from PostRsListActivity into screens package
nbradbury 1848a54
Refresh post list when a post finishes uploading
nbradbury 3d63b84
Merge branch 'trunk' into feature/rs-post-list
nbradbury 83b4f96
Replace local stripHtml with HtmlUtils.fastStripHtml
nbradbury 56902b7
Use Channel for one-shot UI events to prevent race conditions
nbradbury a68a06c
Replace hardcoded strings with existing string resources
nbradbury cbd9bcc
Debounce tab selection to avoid redundant network requests
nbradbury 447aaf9
Use snapshotFlow for load-more observer to fix stale state reads
nbradbury 819f7c7
Use PostStatus enum instead of strings and fix double tab selection
nbradbury 4493382
Scope UI event collection to STARTED lifecycle state
nbradbury a1aa4a1
Merge trunk and remove NAV_MENUS experimental feature flag
nbradbury d54adde
Corrected string resource indentation
nbradbury 8be7c7a
Added comment
nbradbury 8a2cd0c
Use view context instead of edit context for post list API
nbradbury b44ea51
Add authorId to PostRsModel
nbradbury 700d9b5
Use ConcurrentHashMap for thread-safe loadedCounts access
nbradbury File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
WordPress/src/main/java/org/wordpress/android/ui/postsrs/PostRsListActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| package org.wordpress.android.ui.postsrs | ||
|
|
||
| import android.content.Context | ||
| import android.content.Intent | ||
| import android.os.Build | ||
| import android.os.Bundle | ||
| import androidx.activity.viewModels | ||
| import androidx.compose.runtime.collectAsState | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.ui.platform.ComposeView | ||
| import androidx.compose.ui.platform.ViewCompositionStrategy | ||
| import androidx.lifecycle.Lifecycle | ||
| import androidx.lifecycle.lifecycleScope | ||
| import androidx.lifecycle.repeatOnLifecycle | ||
| import dagger.hilt.android.AndroidEntryPoint | ||
| import kotlinx.coroutines.launch | ||
| import org.wordpress.android.R | ||
| import org.wordpress.android.fluxc.store.PostStore | ||
| import org.wordpress.android.ui.ActivityLauncher | ||
| import org.wordpress.android.ui.PagePostCreationSourcesDetail | ||
| import org.wordpress.android.ui.main.BaseAppCompatActivity | ||
| import org.wordpress.android.ui.mysite.SelectedSiteRepository | ||
| import org.wordpress.android.ui.posts.PostUtils.EntryPoint | ||
| import org.wordpress.android.ui.postsrs.screens.PostRsListScreen | ||
| import org.wordpress.android.util.ToastUtils | ||
| import javax.inject.Inject | ||
|
|
||
| @AndroidEntryPoint | ||
| class PostRsListActivity : BaseAppCompatActivity() { | ||
| private val viewModel by viewModels<PostRsListViewModel>() | ||
|
|
||
| @Inject lateinit var postStore: PostStore | ||
| @Inject lateinit var selectedSiteRepository: SelectedSiteRepository | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
|
|
||
| val composeView = ComposeView(this) | ||
| setContentView( | ||
| composeView.apply { | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | ||
| this.isForceDarkAllowed = false | ||
| } | ||
| setViewCompositionStrategy( | ||
| ViewCompositionStrategy | ||
| .DisposeOnViewTreeLifecycleDestroyed | ||
| ) | ||
| setContent { | ||
| val selectedTab by viewModel | ||
| .selectedTab.collectAsState() | ||
| PostRsListScreen( | ||
| selectedTab = selectedTab, | ||
| tabStateFlow = viewModel::tabState, | ||
| onTabSelected = viewModel::onTabSelected, | ||
| onPostClick = viewModel::onPostClicked, | ||
| onRefresh = viewModel::refreshPosts, | ||
| onLoadMore = viewModel::loadMorePosts, | ||
| onCreatePost = ::createNewPost, | ||
| onBack = ::finish | ||
| ) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| observeUiEvents() | ||
| } | ||
|
|
||
| private fun observeUiEvents() { | ||
| lifecycleScope.launch { | ||
| repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
| viewModel.uiEvent.collect { event -> | ||
| handleUiEvent(event) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun handleUiEvent(event: PostRsListUiEvent) { | ||
| when (event) { | ||
| is PostRsListUiEvent.ShowError -> { | ||
| ToastUtils.showToast( | ||
| this, event.message, ToastUtils.Duration.LONG | ||
| ) | ||
| } | ||
| is PostRsListUiEvent.OpenPost -> { | ||
| openPostEditor(event.remotePostId) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun openPostEditor(remotePostId: Long) { | ||
| val site = | ||
| selectedSiteRepository.getSelectedSite() ?: return | ||
| val post = postStore.getPostByRemotePostId( | ||
| remotePostId, site | ||
| ) | ||
| if (post != null) { | ||
| ActivityLauncher.editPostOrPageForResult( | ||
| this, site, post | ||
| ) | ||
| } else { | ||
| ToastUtils.showToast( | ||
| this, | ||
| R.string.post_not_found, | ||
| ToastUtils.Duration.SHORT | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private fun createNewPost() { | ||
| val site = | ||
| selectedSiteRepository.getSelectedSite() | ||
| ?: return | ||
| ActivityLauncher.addNewPostForResult( | ||
| this, | ||
| site, | ||
| false, | ||
| PagePostCreationSourcesDetail | ||
| .POST_FROM_POSTS_LIST, | ||
| -1, | ||
| EntryPoint.MY_SITE_CARD_ANSWER_PROMPT | ||
| ) | ||
| } | ||
|
|
||
| companion object { | ||
| @JvmStatic | ||
| fun createIntent(context: Context): Intent { | ||
| return Intent( | ||
| context, PostRsListActivity::class.java | ||
| ) | ||
| } | ||
| } | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
WordPress/src/main/java/org/wordpress/android/ui/postsrs/PostRsListTab.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package org.wordpress.android.ui.postsrs | ||
|
|
||
| import androidx.annotation.StringRes | ||
| import org.wordpress.android.R | ||
| import uniffi.wp_api.PostStatus | ||
| import uniffi.wp_api.WpApiParamOrder | ||
|
|
||
| /** | ||
| * Tabs for the wordpress-rs post list, each mapping | ||
| * to one or more [PostStatus] values. | ||
| */ | ||
| enum class PostRsListTab( | ||
| @StringRes val titleResId: Int, | ||
| val statuses: List<PostStatus>, | ||
| val order: WpApiParamOrder | ||
| ) { | ||
| PUBLISHED( | ||
| titleResId = R.string.post_list_tab_published_posts, | ||
| statuses = listOf( | ||
| PostStatus.Publish, | ||
| PostStatus.Private | ||
| ), | ||
| order = WpApiParamOrder.DESC | ||
| ), | ||
| DRAFTS( | ||
| titleResId = R.string.post_list_tab_drafts, | ||
| statuses = listOf( | ||
| PostStatus.Draft, | ||
| PostStatus.Pending | ||
| ), | ||
| order = WpApiParamOrder.DESC | ||
| ), | ||
| SCHEDULED( | ||
| titleResId = R.string.post_list_tab_scheduled_posts, | ||
| statuses = listOf(PostStatus.Future), | ||
| order = WpApiParamOrder.ASC | ||
| ), | ||
| TRASHED( | ||
| titleResId = R.string.post_list_tab_trashed_posts, | ||
| statuses = listOf(PostStatus.Trash), | ||
| order = WpApiParamOrder.DESC | ||
| ) | ||
| } |
116 changes: 116 additions & 0 deletions
116
WordPress/src/main/java/org/wordpress/android/ui/postsrs/PostRsListUiState.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package org.wordpress.android.ui.postsrs | ||
|
|
||
| import org.wordpress.android.R | ||
| import org.wordpress.android.ui.postsrs.models.PostRsModel | ||
| import org.wordpress.android.util.DateTimeUtils | ||
| import org.wordpress.android.util.DateTimeUtilsWrapper | ||
| import org.wordpress.android.util.HtmlUtils | ||
| import org.wordpress.android.viewmodel.ResourceProvider | ||
| import uniffi.wp_api.PostStatus | ||
| import java.text.DateFormat | ||
|
|
||
| /** | ||
| * UI state for a single tab in the post list. | ||
| */ | ||
| data class PostTabUiState( | ||
| val isLoading: Boolean = false, | ||
| val isRefreshing: Boolean = false, | ||
| val isLoadingMore: Boolean = false, | ||
| val canLoadMore: Boolean = false, | ||
| val posts: List<PostUiModel> = emptyList(), | ||
| val error: String? = null | ||
| ) | ||
|
|
||
| /** | ||
| * Display model for a single post in the list. | ||
| */ | ||
| data class PostUiModel( | ||
| val remoteId: Long, | ||
| val title: String, | ||
| val excerpt: String, | ||
| val dateFormatted: String, | ||
| val statusLabel: String | ||
| ) | ||
|
|
||
| /** | ||
| * One-time UI events emitted by the ViewModel. | ||
| */ | ||
| sealed class PostRsListUiEvent { | ||
| data class ShowError( | ||
| val message: String | ||
| ) : PostRsListUiEvent() | ||
|
|
||
| data class OpenPost( | ||
| val remotePostId: Long | ||
| ) : PostRsListUiEvent() | ||
| } | ||
|
|
||
| // ========== Mapping Functions ========== | ||
|
|
||
| fun PostRsModel.toUiModel( | ||
| dateTimeUtilsWrapper: DateTimeUtilsWrapper, | ||
| resourceProvider: ResourceProvider | ||
| ): PostUiModel { | ||
| val parsed = DateTimeUtils.dateUTCFromIso8601( | ||
| normalizeIso8601(date) | ||
| ) | ||
| val formatted = if (status is PostStatus.Future && parsed != null) { | ||
| DateFormat.getDateTimeInstance( | ||
| DateFormat.MEDIUM, | ||
| DateFormat.SHORT | ||
| ).format(parsed) | ||
| } else { | ||
| dateTimeUtilsWrapper.javaDateToTimeSpan(parsed) | ||
| } | ||
| return PostUiModel( | ||
| remoteId = remotePostId, | ||
| title = title.ifBlank { | ||
| resourceProvider.getString( | ||
| R.string.untitled_in_parentheses | ||
| ) | ||
| }, | ||
| excerpt = HtmlUtils.fastStripHtml(excerpt) | ||
| .take(MAX_EXCERPT_LENGTH), | ||
| dateFormatted = formatted, | ||
| statusLabel = mapStatusLabel(status, resourceProvider) | ||
| ) | ||
| } | ||
|
|
||
| private fun mapStatusLabel( | ||
| status: PostStatus, | ||
| resourceProvider: ResourceProvider | ||
| ): String { | ||
| return when (status) { | ||
| is PostStatus.Publish -> resourceProvider.getString( | ||
| R.string.post_status_post_published | ||
| ) | ||
| is PostStatus.Draft -> resourceProvider.getString( | ||
| R.string.post_status_draft | ||
| ) | ||
| is PostStatus.Pending -> resourceProvider.getString( | ||
| R.string.post_status_pending_review | ||
| ) | ||
| is PostStatus.Private -> resourceProvider.getString( | ||
| R.string.post_status_post_private | ||
| ) | ||
| is PostStatus.Future -> resourceProvider.getString( | ||
| R.string.post_status_post_scheduled | ||
| ) | ||
| is PostStatus.Trash -> resourceProvider.getString( | ||
| R.string.post_status_post_trashed | ||
| ) | ||
| is PostStatus.Custom -> status.v1.replaceFirstChar { | ||
| it.uppercase() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun normalizeIso8601(date: String): String { | ||
| return if (date.contains("+") || date.endsWith("Z")) { | ||
| date | ||
| } else { | ||
| "${date}+0000" | ||
| } | ||
| } | ||
|
|
||
| private const val MAX_EXCERPT_LENGTH = 150 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.