Added collapsible toolbar

pull/215/head
M66B 1 year ago
parent f66effc2e5
commit 79b458f708

@ -73,6 +73,8 @@ import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.OnLifecycleEvent; import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import com.google.android.material.appbar.AppBarLayout;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -106,19 +108,31 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
public void setContentView(View view) { public void setContentView(View view) {
LayoutInflater inflater = LayoutInflater.from(this); LayoutInflater inflater = LayoutInflater.from(this);
ViewGroup container = (ViewGroup) inflater.inflate(R.layout.toolbar_holder, null); ViewGroup holder = (ViewGroup) inflater.inflate(R.layout.toolbar_holder, null);
View placeholder = container.findViewById(R.id.placeholder);
container.removeView(placeholder);
container.addView(view, placeholder.getLayoutParams());
Toolbar toolbar = container.findViewById(R.id.toolbar); AppBarLayout appbar = holder.findViewById(R.id.appbar);
toolbar.setPopupTheme(getThemeId()); Toolbar toolbar = holder.findViewById(R.id.toolbar);
View placeholder = holder.findViewById(R.id.placeholder);
toolbar.setPopupTheme(getThemeId());
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
FragmentDialogTheme.setBackground(this, container, this instanceof ActivityCompose); holder.removeView(placeholder);
holder.addView(view, placeholder.getLayoutParams());
int abh = Helper.getActionBarHeight(this);
appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
mlp.topMargin = abh + i;
view.setLayoutParams(mlp);
}
});
FragmentDialogTheme.setBackground(this, holder, this instanceof ActivityCompose);
ViewCompat.setOnApplyWindowInsetsListener(container, (v, windowInsets) -> { ViewCompat.setOnApplyWindowInsetsListener(holder, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams(); ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
@ -133,7 +147,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
if (this instanceof ActivityCompose) if (this instanceof ActivityCompose)
ViewCompat.setWindowInsetsAnimationCallback( ViewCompat.setWindowInsetsAnimationCallback(
container, holder,
new WindowInsetsAnimationCompat.Callback(WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_STOP) { new WindowInsetsAnimationCompat.Callback(WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_STOP) {
@NonNull @NonNull
@Override @Override
@ -146,7 +160,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
int bottom = windowInsets.getInsets(WindowInsetsCompat.Type.ime()).bottom; int bottom = windowInsets.getInsets(WindowInsetsCompat.Type.ime()).bottom;
int pad = bottom - insets.bottom; int pad = bottom - insets.bottom;
container.setPaddingRelative(0, 0, 0, pad < 0 ? 0 : pad); holder.setPaddingRelative(0, 0, 0, pad < 0 ? 0 : pad);
break; break;
} }
@ -154,7 +168,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
} }
}); });
super.setContentView(container); super.setContentView(holder);
int colorPrimaryDark = Helper.resolveColor(this, androidx.appcompat.R.attr.colorPrimaryDark); int colorPrimaryDark = Helper.resolveColor(this, androidx.appcompat.R.attr.colorPrimaryDark);
view.post(new RunnableEx("setBackgroundColor") { view.post(new RunnableEx("setBackgroundColor") {

@ -1,20 +1,26 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="eu.faircode.email.ActivityView"> tools:context="eu.faircode.email.ActivityView">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<eu.faircode.email.ToolbarEx <eu.faircode.email.ToolbarEx
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
app:theme="@style/actionBarStyle"
android:elevation="8dp" android:elevation="8dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent"
app:layout_scrollFlags="scroll|enterAlways"
app:theme="@style/actionBarStyle">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -59,13 +65,14 @@
app:layout_constraintTop_toBottomOf="@id/title" /> app:layout_constraintTop_toBottomOf="@id/title" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ToolbarEx> </eu.faircode.email.ToolbarEx>
</com.google.android.material.appbar.AppBarLayout>
<View <View
android:id="@+id/placeholder" android:id="@+id/placeholder"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" /> app:layout_constraintTop_toBottomOf="@id/toolbar" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

Loading…
Cancel
Save