Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
352cc3a
A very rough first pass at integrating ListManager to post list
oguzkocer Oct 17, 2018
e0bcee4
Update FluxC hash, add lots of todos to post list and minor fixes
oguzkocer Oct 17, 2018
766fe4d
Featured images are properly handled in post list
oguzkocer Oct 17, 2018
45f8c74
Fix local changes not reflecting in post list
oguzkocer Oct 17, 2018
d94b356
Correctly handle upload events in post list
oguzkocer Oct 17, 2018
e4ac3aa
Add loading layout for post list
oguzkocer Oct 17, 2018
c1fb27f
Refresh the post list after an upload
oguzkocer Oct 17, 2018
14c8eaf
Adds a workaround to local drafts briefly disappearing when it's push…
oguzkocer Oct 18, 2018
3edc2dc
Skeleton view for loading posts in post list
oguzkocer Oct 18, 2018
b014196
Remove unused property and enum and replace if with when in PostListA…
oguzkocer Oct 18, 2018
36fc606
Empty view in post list should be correctly updated now
oguzkocer Oct 19, 2018
48f6e89
Fix an issue with comparing local items in post list
oguzkocer Oct 19, 2018
ae83827
Basic hide post support added for post list
oguzkocer Oct 19, 2018
1fe0f13
Update FluxC hash and implement necessary changes in post list
oguzkocer Oct 22, 2018
29a71b7
Update FluxC hash and resolve several todos in PostListFragment
oguzkocer Oct 23, 2018
60e5209
Save trashed and uploaded post ids in the instance state
oguzkocer Oct 23, 2018
be31015
Merge branch 'feature/list-store-integration-for-post-list-master' in…
oguzkocer Oct 23, 2018
5714744
Merge branch 'feature/list-store-integration-for-post-list-master' in…
oguzkocer Oct 23, 2018
9adc90d
Add a style for post list skeleton buttons
oguzkocer Oct 23, 2018
d399213
Major cleanup/reorder of PostListFragment and PostListAdapter
oguzkocer Oct 24, 2018
2d1814f
Second take at improving PostListFragment
oguzkocer Oct 24, 2018
f333500
Fix an issue for when a uploaded local draft doesn't show up in post …
oguzkocer Oct 24, 2018
8719cdf
Throw illegal exception if a view type is not handled in PostListAdapter
oguzkocer Oct 24, 2018
ee5e054
Improve empty view handling for list manager changes
oguzkocer Oct 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update FluxC hash, add lots of todos to post list and minor fixes
  • Loading branch information
oguzkocer committed Oct 17, 2018
commit e0bcee4bff3b9168b9f000728ff9e81c43cbed3a
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ class PostListFragment : Fragment(),
private var actionableEmptyView: ActionableEmptyView? = null
private var progressLoadMore: ProgressBar? = null

private var canLoadMorePosts = true
private var targetPost: PostModel? = null
private var isFetchingPosts: Boolean = false
private var shouldCancelPendingDraftNotification = false
private var postIdForPostToBeDeleted = 0

Expand Down Expand Up @@ -153,8 +151,6 @@ class PostListFragment : Fragment(),

EventBus.getDefault().register(this)
dispatcher.register(this)

refreshListManagerFromStore(listDescriptor, fetchAfter = (savedInstanceState == null))
}

private fun refreshListManagerFromStore(listDescriptor: ListDescriptor, fetchAfter: Boolean) {
Expand Down Expand Up @@ -236,21 +232,8 @@ class PostListFragment : Fragment(),
fabView?.visibility = View.GONE
fabView?.setOnClickListener { newPost() }

// TODO: This shouldn't be necessary anymore
// if (savedInstanceState == null) {
// if (UploadService.hasPendingOrInProgressPostUploads()) {
// // if there are some in-progress uploads, we'd better just load the DB Posts and reflect upload
// // changes there. Otherwise, a duplicate-post situation can happen when:
// // a FETCH_POSTS completing *after* the post has been uploaded to the server but *before*
// // the PUSH_POST action completes and a PUSHED_POST is emitted.
// loadPosts(LoadMode.IF_CHANGED)
// } else {
// // refresh normally
// requestPosts(false)
// }
// }

initSwipeToRefreshHelper()
refreshListManagerFromStore(listDescriptor, fetchAfter = (savedInstanceState == null))

return view
}
Expand Down Expand Up @@ -298,10 +281,6 @@ class PostListFragment : Fragment(),
)
}

private fun loadPosts(mode: LoadMode) {
postListAdapter.loadPosts(mode)
}

private fun newPost() {
if (!isAdded) {
return
Expand All @@ -312,8 +291,7 @@ class PostListFragment : Fragment(),
override fun onResume() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned here this is not actually removed, but just moved.

super.onResume()

// always (re) load when resumed to reflect changes made elsewhere
loadPosts(LoadMode.IF_CHANGED)
// TODO: refresh from store

// scale in the fab after a brief delay if it's not already showing
if (fabView?.visibility != View.VISIBLE) {
Expand Down Expand Up @@ -343,7 +321,7 @@ class PostListFragment : Fragment(),
*/
fun onEventMainThread(event: PostEvents.PostUploadStarted) {
if (isAdded && site.id == event.mLocalBlogId) {
loadPosts(LoadMode.FORCED)
// TODO: Update single row
}
}

Expand All @@ -352,7 +330,7 @@ class PostListFragment : Fragment(),
*/
fun onEventMainThread(event: PostEvents.PostUploadCanceled) {
if (isAdded && site.id == event.localSiteId) {
loadPosts(LoadMode.FORCED)
// TODO: Update single row
}
}

Expand Down Expand Up @@ -403,7 +381,7 @@ class PostListFragment : Fragment(),
return
}

if (postCount == 0 && !isFetchingPosts) {
if (postCount == 0 && listManager?.isFetchingFirstPage != true) {
if (NetworkUtils.isNetworkAvailable(nonNullActivity)) {
updateEmptyView(EmptyViewMessageType.NO_CONTENT)
} else {
Expand Down Expand Up @@ -644,30 +622,7 @@ class PostListFragment : Fragment(),
@Subscribe(threadMode = ThreadMode.MAIN)
fun onPostChanged(event: OnPostChanged) {
// TODO: do we need this at all?
// if (event.causeOfChange is CauseOfOnPostChanged.UpdatePost) {
// // if a Post is updated, let's refresh the whole list, because we can't really know
// // from FluxC which post has changed, or when. So to make sure, we go to the source,
// // which is the FluxC PostStore.
// /*
// * Please note that the above comment is no longer correct as `CauseOfOnPostChanged.UpdatePost` has fields
// * for local and remote post id. However, this class will be completely refactored in an upcoming PR, so
// * both the original comment and this note is kept for record keeping.
// */
// if (!event.isError) {
// loadPosts(LoadMode.IF_CHANGED)
// }
// } else if (event.causeOfChange is CauseOfOnPostChanged.FetchPosts ||
// event.causeOfChange is CauseOfOnPostChanged.FetchPages) {
// isFetchingPosts = false
// if (!isAdded) {
// return
// }
//
// hideLoadMoreProgress()
// if (!event.isError) {
// canLoadMorePosts = event.canLoadMore
// loadPosts(LoadMode.IF_CHANGED)
// } else {
// TODO: We just need to handle the errors, I think...
// val error = event.error
// when (error.type) {
// PostStore.PostErrorType.UNAUTHORIZED -> updateEmptyView(EmptyViewMessageType.PERMISSION_ERROR)
Expand Down Expand Up @@ -704,7 +659,9 @@ class PostListFragment : Fragment(),
@Subscribe(threadMode = ThreadMode.MAIN)
fun onPostUploaded(event: OnPostUploaded) {
if (isAdded && event.post != null && event.post.localSiteId == site.id) {
loadPosts(LoadMode.FORCED)
postListAdapter.getPositionForPost(event.post)?.let {
postListAdapter.notifyItemChanged(it)
}
UploadUtils.onPostUploadedSnackbarHandler(
nonNullActivity,
nonNullActivity.findViewById(R.id.coordinator),
Expand Down Expand Up @@ -744,8 +701,7 @@ class PostListFragment : Fragment(),
// (meaning there is no other pending media to be uploaded for this post)
// then we should refresh it to show its new state
if (!UploadService.isPostUploadingOrQueued(post)) {
// TODO: replace loadPosts for getPostListAdapter().notifyItemChanged(); kind of thing
loadPosts(LoadMode.FORCED)
postListAdapter.updateRowForPost(post)
}
} else {
postListAdapter.updateProgressForPost(post)
Expand Down Expand Up @@ -847,7 +803,12 @@ class DiffCallback(
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = old?.getItem(oldItemPosition, false, false)
val newItem = new.getItem(newItemPosition, false, false)
return (oldItem == null && newItem == null) || (oldItem != null &&
newItem != null && oldItem.lastModified == newItem.lastModified)
if (oldItem == null && newItem == null) {
return true
}
if (oldItem == null || newItem == null) {
return false
}
return oldItem.lastModified == newItem.lastModified
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ class PostListAdapter(
onPostSelectedListener?.onPostSelected(post)
}
}
// TODO: Handle the null case with a loading bar or something
}

private fun showFeaturedImage(postId: Int, imgFeatured: ImageView) {
Expand Down Expand Up @@ -498,15 +499,16 @@ class PostListAdapter(
animOut.start()
}

fun getPositionForPost(post: PostModel): Int? {
return listManager?.getPositionOfItem(post.remotePostId)
}

fun loadPosts(mode: LoadMode) {
if (isLoadingPosts) {
AppLog.d(AppLog.T.POSTS, "post adapter > already loading posts")
fun getPositionForPost(post: PostModel): Int? =
if (post.isLocalDraft) {
listManager?.positionOfLocalItem { it.id == post.id }
} else {
LoadPostsTask(mode).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
listManager?.positionOfRemoteItem(post.remotePostId)
}

fun updateRowForPost(post: PostModel) {
getPositionForPost(post)?.let { position ->
notifyItemChanged(position)
}
}

Expand Down Expand Up @@ -545,7 +547,7 @@ class PostListAdapter(

fun unhidePost(post: PostModel) {
if (hiddenPosts.remove(post)) {
loadPosts(LoadMode.IF_CHANGED)
// TODO: Handle this when the hide post is implemented
}
}

Expand Down Expand Up @@ -599,6 +601,7 @@ class PostListAdapter(
// }
}

// TODO: Completely remove this!
@SuppressLint("StaticFieldLeak")
private inner class LoadPostsTask internal constructor(private val mLoadMode: LoadMode)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need this task as ListStore takes care of it for us.

: AsyncTask<Void, Void, Boolean>() {
Expand Down Expand Up @@ -691,7 +694,3 @@ class PostListAdapter(
}
}
}

fun <T> ListManager<T>.getPositionOfItem(remoteItemId: Long): Int? {
return null
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ subprojects {
}

ext {
fluxCVersion = '79cff8ce9fe38403bbfa27ee7133cf23b4f8c019'
fluxCVersion = 'e614fdac6ca1d8cb94ec6a1b54ba875b5867caa8'
}