Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL

private var contributionsSize = 0
private var userName: String? = null
private var pendingScrollState: Parcelable? = null

private val galleryPickLauncherForResult = registerForActivityResult<Intent, ActivityResult>(
StartActivityForResult()
Expand Down Expand Up @@ -271,7 +272,12 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
if (list != null) {
contributionsSize = list.size
}
adapter!!.submitList(list)
adapter!!.submitList(list) {
pendingScrollState?.let { state ->
rvContributionsList?.layoutManager?.onRestoreInstanceState(state)
pendingScrollState = null
}
}
if (callback != null) {
callback!!.notifyDataSetChanged()
}
Expand All @@ -284,7 +290,8 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
if (callback != null) {
callback!!.notifyDataSetChanged()
}
if (itemCount > 0 && positionStart == 0) {
val countBeforeInsertion = adapter!!.itemCount - itemCount
if (itemCount > 0 && positionStart == 0 && countBeforeInsertion > 0) {
if (adapter!!.getContributionForPosition(positionStart) != null) {
rvContributionsList!!
.scrollToPosition(0) //Newly upload items are always added to the top
Expand Down Expand Up @@ -470,9 +477,8 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
override fun onViewStateRestored(savedInstanceState: Bundle?) {
super.onViewStateRestored(savedInstanceState)
if (null != savedInstanceState) {
val savedRecyclerLayoutState =
pendingScrollState =
BundleCompat.getParcelable(savedInstanceState, RV_STATE, Parcelable::class.java)
rvContributionsList!!.layoutManager!!.onRestoreInstanceState(savedRecyclerLayoutState)
}
Comment on lines 477 to 482
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,39 @@ after opening the app.
}

private fun restoreActiveFragment(fragmentName: String) {
val existing = supportFragmentManager.findFragmentById(R.id.fragmentContainer)
if (fragmentName == ActiveFragment.CONTRIBUTIONS.name) {
title = getString(R.string.contributions_fragment)
loadFragment(newInstance(), false)
if (existing is ContributionsFragment) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about simplifying this block and making it DRYer? Do we really need the fragmentName anymore?

contributionsFragment = existing
activeFragment = ActiveFragment.CONTRIBUTIONS
} else {
loadFragment(newInstance(), false)
}
} else if (fragmentName == ActiveFragment.NEARBY.name) {
title = getString(R.string.nearby_fragment)
loadFragment(NearbyParentFragment.newInstance(), false)
if (existing is NearbyParentFragment) {
nearbyParentFragment = existing
activeFragment = ActiveFragment.NEARBY
} else {
loadFragment(NearbyParentFragment.newInstance(), false)
}
} else if (fragmentName == ActiveFragment.EXPLORE.name) {
title = getString(R.string.navigation_item_explore)
loadFragment(ExploreFragment.newInstance(), false)
if (existing is ExploreFragment) {
exploreFragment = existing
activeFragment = ActiveFragment.EXPLORE
} else {
loadFragment(ExploreFragment.newInstance(), false)
}
} else if (fragmentName == ActiveFragment.BOOKMARK.name) {
title = getString(R.string.bookmarks)
loadFragment(BookmarkFragment.newInstance(), false)
if (existing is BookmarkFragment) {
bookmarkFragment = existing
activeFragment = ActiveFragment.BOOKMARK
} else {
loadFragment(BookmarkFragment.newInstance(), false)
}
}
}

Expand Down
Loading