Skip to content
Merged
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 @@ -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;
Expand Down Expand Up @@ -298,6 +299,7 @@ public void onStop() {

@Override
protected void onDestroy() {
removeTtsContainerHeightListener();
EventHelper.unregister(this);

super.onDestroy();
Expand Down Expand Up @@ -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()
Expand All @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/res/layout/article.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_scrollFlags="scroll|enterAlways|snap" />
app:layout_scrollFlags="scroll|enterAlways|snap|enterAlwaysCollapsed" />

</com.google.android.material.appbar.AppBarLayout>

Expand Down Expand Up @@ -106,4 +107,12 @@

</androidx.core.widget.NestedScrollView>

<FrameLayout
android:id="@+id/tts_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
android:elevation="8dp"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>