diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java b/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java index 570854c66..559e3e145 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java @@ -14,6 +14,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; import android.webkit.ConsoleMessage; @@ -298,6 +299,7 @@ public void onStop() { @Override protected void onDestroy() { + removeTtsContainerHeightListener(); EventHelper.unregister(this); super.onDestroy(); @@ -1293,12 +1295,14 @@ public void toggleTTS(boolean autoPlay) { getSupportFragmentManager() .beginTransaction() - .add(R.id.viewMain, ttsFragment, TAG_TTS_FRAGMENT) + .add(R.id.tts_container, ttsFragment, TAG_TTS_FRAGMENT) .commit(); settings.setTtsVisible(true); initTtsForArticle(); + + setupTtsContainerHeightListener(); } else { getSupportFragmentManager() .beginTransaction() @@ -1308,11 +1312,64 @@ public void toggleTTS(boolean autoPlay) { ttsFragment = null; settings.setTtsVisible(false); + + adjustScrollViewPaddingForTts(0); + + removeTtsContainerHeightListener(); } invalidateOptionsMenu(); } + private ViewTreeObserver.OnGlobalLayoutListener ttsContainerLayoutListener; + + private void setupTtsContainerHeightListener() { + FrameLayout ttsContainer = findViewById(R.id.tts_container); + if (ttsContainer == null) return; + + removeTtsContainerHeightListener(); + + ttsContainerLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { + private int lastHeight = -1; + + @Override + public void onGlobalLayout() { + FrameLayout container = findViewById(R.id.tts_container); + if (container != null) { + int currentHeight = container.getHeight(); + if (currentHeight != lastHeight && currentHeight > 0) { + lastHeight = currentHeight; + adjustScrollViewPaddingForTts(currentHeight); + } + } + } + }; + + ttsContainer.getViewTreeObserver().addOnGlobalLayoutListener(ttsContainerLayoutListener); + } + + private void removeTtsContainerHeightListener() { + if (ttsContainerLayoutListener != null) { + FrameLayout ttsContainer = findViewById(R.id.tts_container); + if (ttsContainer != null) { + ttsContainer.getViewTreeObserver().removeOnGlobalLayoutListener(ttsContainerLayoutListener); + ttsContainer.getViewTreeObserver().removeOnGlobalLayoutListener(ttsContainerLayoutListener); + } + ttsContainerLayoutListener = null; + } + } + + private void adjustScrollViewPaddingForTts(int ttsHeight) { + if (scrollView != null) { + scrollView.setPadding( + scrollView.getPaddingLeft(), + scrollView.getPaddingTop(), + scrollView.getPaddingRight(), + ttsHeight + ); + } + } + private void initTtsForArticle() { if (ttsFragment != null) { ttsFragment.initForArticle(article); diff --git a/app/src/main/res/layout/article.xml b/app/src/main/res/layout/article.xml index 5f67c882d..a71305279 100644 --- a/app/src/main/res/layout/article.xml +++ b/app/src/main/res/layout/article.xml @@ -12,14 +12,15 @@ android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:fitsSystemWindows="true"> + android:fitsSystemWindows="true" + app:liftOnScroll="true"> + app:layout_scrollFlags="scroll|enterAlways|snap|enterAlwaysCollapsed" /> @@ -106,4 +107,12 @@ + + \ No newline at end of file