Skip to content

Commit

Permalink
Merge pull request #214 from caarmen/more-scrolling
Browse files Browse the repository at this point in the history
More adjustments related to scrolling...
  • Loading branch information
caarmen authored Jan 5, 2025
2 parents cc52c43 + 9e82443 commit 463fafe
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,24 @@
android:supportsRtl="true"
android:enableOnBackInvokedCallback="true"
android:theme="@style/AppTheme">
<!--
Set windowSoftInputMode=adjustPan.
Without this, we have this problem:
- Have a long poem already entered.
- Launch the app.
- Swipe to the composer tab.
- Scroll to the end of the poem.
- Open the keyboard at the end.
- Type a few lines.
The lines are entered, but the keyboard is still covering them.
You'd have to swipe the view to scroll it up, to reveal the new lines.
-->
<activity
android:name=".main.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import android.view.MenuItem
import android.view.Window
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import androidx.activity.OnBackPressedCallback
import androidx.core.view.updatePadding
import androidx.lifecycle.ViewModelProvider
import ca.rmen.android.poetassistant.BuildConfig
Expand Down Expand Up @@ -136,15 +135,6 @@ class MainActivity : AppCompatActivity(), OnWordClickListener, WarningNoSpaceDia
top = insets.top,
)
}
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (mBinding.appBarLayout.top < 0) {
mBinding.appBarLayout.setExpanded(true, true)
} else {
finish()
}
}
})
val searchView = mBinding.searchView
val suggestionsViewModel = ViewModelProvider(this).get(SuggestionsViewModel::class.java)
mSearch.setSearchView(searchView, suggestionsViewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ class ReaderFragment : Fragment(), ConfirmDialogFragment.ConfirmDialogListener {
DebounceTextWatcher.debounce(mBinding.tvText) { mViewModel.updateWordCount() }
TextPopupMenu.addSelectionPopupMenu(mBinding.root, mBinding.tvText, activity as OnWordClickListener)
mViewModel.playButtonStateLiveData.observe(this, mPlayButtonStateObserver)
// Add padding to the bottom of the reader content when the keyboard is open.
// Without this, we have this problem:
// 1. Have a long poem already entered.
// 2. Launch the app.
// 3. Swipe to the composer tab.
// 4. Tap in the middle of the poem to open the keyboard.
// You can't scroll down to the end of the poem.
//
// Note this has a little glitch, but maybe pas grave?:
// 4. Tap in the end of the poem (instead of the middle).
// You can scroll down to the end of the poem, and you see quite a bit of
// empty padding underneath it.
ViewCompat.setOnApplyWindowInsetsListener(mBinding.tvText) { _, insets ->
val imeHeight = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom
mBinding.readerContent.updatePadding(
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/res/layout/fragment_reader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,22 @@
type="ca.rmen.android.poetassistant.main.reader.ReaderFragment.ButtonListener"/>
</data>

<ScrollView
<!--
Use NestedScrollView.
Without this, we have this problem:
- have a long poem already entered.
- launch the app.
- swipe to the composer tab.
- don't open the keyboard (don't tap inside the edit text).
- try to scroll down.
You can't scroll down to the end of the poem
-->
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:fillViewport="false"
android:nestedScrollingEnabled="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
Expand Down Expand Up @@ -94,5 +103,5 @@
app:layout_constraintBottom_toBottomOf="parent"
tools:text="45 words, 300 characters"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.core.widget.NestedScrollView>
</layout>

0 comments on commit 463fafe

Please sign in to comment.