mirror of https://github.com/M66B/FairEmail.git
Added collapsible toolbar
This commit is contained in:
parent
f66effc2e5
commit
79b458f708
|
@ -73,6 +73,8 @@ import androidx.lifecycle.LifecycleOwner;
|
|||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -106,19 +108,31 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
|||
public void setContentView(View view) {
|
||||
LayoutInflater inflater = LayoutInflater.from(this);
|
||||
|
||||
ViewGroup container = (ViewGroup) inflater.inflate(R.layout.toolbar_holder, null);
|
||||
View placeholder = container.findViewById(R.id.placeholder);
|
||||
container.removeView(placeholder);
|
||||
container.addView(view, placeholder.getLayoutParams());
|
||||
ViewGroup holder = (ViewGroup) inflater.inflate(R.layout.toolbar_holder, null);
|
||||
|
||||
AppBarLayout appbar = holder.findViewById(R.id.appbar);
|
||||
Toolbar toolbar = holder.findViewById(R.id.toolbar);
|
||||
View placeholder = holder.findViewById(R.id.placeholder);
|
||||
|
||||
Toolbar toolbar = container.findViewById(R.id.toolbar);
|
||||
toolbar.setPopupTheme(getThemeId());
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
FragmentDialogTheme.setBackground(this, container, this instanceof ActivityCompose);
|
||||
holder.removeView(placeholder);
|
||||
holder.addView(view, placeholder.getLayoutParams());
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(container, (v, windowInsets) -> {
|
||||
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(holder, (v, windowInsets) -> {
|
||||
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
|
||||
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
|
||||
|
@ -133,7 +147,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
|||
|
||||
if (this instanceof ActivityCompose)
|
||||
ViewCompat.setWindowInsetsAnimationCallback(
|
||||
container,
|
||||
holder,
|
||||
new WindowInsetsAnimationCompat.Callback(WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_STOP) {
|
||||
@NonNull
|
||||
@Override
|
||||
|
@ -146,7 +160,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
|||
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
int bottom = windowInsets.getInsets(WindowInsetsCompat.Type.ime()).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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
view.post(new RunnableEx("setBackgroundColor") {
|
||||
|
|
|
@ -1,71 +1,78 @@
|
|||
<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:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="eu.faircode.email.ActivityView">
|
||||
|
||||
<eu.faircode.email.ToolbarEx
|
||||
android:id="@+id/toolbar"
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:theme="@style/actionBarStyle"
|
||||
android:elevation="8dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
<eu.faircode.email.ToolbarEx
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:elevation="8dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_scrollFlags="scroll|enterAlways"
|
||||
app:theme="@style/actionBarStyle">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:text="Title"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
app:layout_constraintEnd_toStartOf="@+id/count"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:paddingStart="6dp"
|
||||
android:singleLine="true"
|
||||
android:text="123"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
|
||||
android:textSize="12dp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/title"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/title" />
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:text="Title"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
app:layout_constraintEnd_toStartOf="@+id/count"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subtitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="start"
|
||||
android:singleLine="true"
|
||||
android:text="Subtitle"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/title" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</eu.faircode.email.ToolbarEx>
|
||||
<TextView
|
||||
android:id="@+id/count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:paddingStart="6dp"
|
||||
android:singleLine="true"
|
||||
android:text="123"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
|
||||
android:textSize="12dp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/title"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subtitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="start"
|
||||
android:singleLine="true"
|
||||
android:text="Subtitle"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/title" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</eu.faircode.email.ToolbarEx>
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/placeholder"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/toolbar" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
Loading…
Reference in New Issue