Skip to content
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

Fix #5615 : Scroll Position For Policies Screen On Orientation Change #5616

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
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 @@ -48,6 +48,12 @@ class PoliciesFragment : InjectableFragment() {
POLICIES_FRAGMENT_POLICY_PAGE_ARGUMENT_PROTO,
PoliciesFragmentArguments.getDefaultInstance()
)
return policiesFragmentPresenter.handleCreateView(inflater, container, policies)
return policiesFragmentPresenter
.handleCreateView(inflater, container, policies, savedInstanceState)
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
policiesFragmentPresenter.handleSaveInstanceState(outState)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.oppia.android.app.policies

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ScrollView
import androidx.appcompat.app.AppCompatActivity
import org.oppia.android.R
import org.oppia.android.app.fragment.FragmentScope
Expand All @@ -22,22 +24,39 @@ class PoliciesFragmentPresenter @Inject constructor(
private val resourceHandler: AppLanguageResourceHandler
) : HtmlParser.PolicyOppiaTagActionListener {

private lateinit var binding: PoliciesFragmentBinding
private var scrollPosition = 0

/** Handles onCreate() method of the [PoliciesFragment]. */
fun handleCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
policiesFragmentArguments: PoliciesFragmentArguments
policiesFragmentArguments: PoliciesFragmentArguments,
savedInstanceState: Bundle?
): View {
val binding = PoliciesFragmentBinding.inflate(
binding = PoliciesFragmentBinding.inflate(
inflater,
container,
/* attachToRoot= */ false
)

savedInstanceState?.let {
scrollPosition = it.getInt(KEY_SCROLL_Y, 0)
}

setUpContentForTextViews(policiesFragmentArguments.policyPage, binding)

(binding.root as ScrollView).viewTreeObserver.addOnGlobalLayoutListener {
binding.root.scrollTo(0, scrollPosition)
}

return binding.root
}

fun handleSaveInstanceState(outState: Bundle) {
outState.putInt(KEY_SCROLL_Y, (binding.root as ScrollView).scrollY)
}

private fun setUpContentForTextViews(
policyPage: PolicyPage,
binding: PoliciesFragmentBinding
Expand Down Expand Up @@ -86,4 +105,8 @@ class PoliciesFragmentPresenter @Inject constructor(
(activity as RouteToPoliciesListener).onRouteToPolicies(PolicyPage.TERMS_OF_SERVICE)
}
}

companion object {
private const val KEY_SCROLL_Y = "policies_scroll_y"
}
}
Loading