Made side toolbar collapsible

This commit is contained in:
M66B 2019-08-15 11:35:10 +02:00
parent 5bc03f059c
commit 2946ef5e1a
2 changed files with 81 additions and 4 deletions

View File

@ -292,6 +292,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private View vSeparatorBody;
private ImageButton ibExpander;
private ImageButton ibFull;
private ImageButton ibImages;
private ImageButton ibDecrypt;
@ -433,6 +434,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
vSeparatorBody = vsBody.findViewById(R.id.vSeparatorBody);
ibExpander = vsBody.findViewById(R.id.ibExpander);
ibFull = vsBody.findViewById(R.id.ibFull);
ibImages = vsBody.findViewById(R.id.ibImages);
ibDecrypt = vsBody.findViewById(R.id.ibDecrypt);
@ -505,6 +507,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
btnDownloadAttachments.setOnClickListener(this);
btnSaveAttachments.setOnClickListener(this);
ibExpander.setOnClickListener(this);
ibFull.setOnClickListener(this);
ibImages.setOnClickListener(this);
ibDecrypt.setOnClickListener(this);
@ -541,6 +544,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
btnDownloadAttachments.setOnClickListener(null);
btnSaveAttachments.setOnClickListener(null);
ibExpander.setOnClickListener(null);
ibFull.setOnClickListener(null);
ibImages.setOnClickListener(null);
ibDecrypt.setOnClickListener(null);
@ -891,6 +895,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
vSeparatorBody.setVisibility(View.GONE);
ibExpander.setVisibility(View.GONE);
ibFull.setVisibility(View.GONE);
ibImages.setVisibility(View.GONE);
ibDecrypt.setVisibility(View.GONE);
@ -965,6 +970,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
vSeparatorBody.setVisibility(View.VISIBLE);
initToolbar();
ibFull.setVisibility(View.GONE);
ibImages.setVisibility(View.GONE);
@ -1475,6 +1482,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
onSaveAttachments(message);
break;
case R.id.ibExpander:
onToggleToolbar();
break;
case R.id.ibFull:
onShowFull(message);
break;
@ -1872,6 +1882,61 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
bindExpanded(message);
}
private void onToggleToolbar() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean toolbar = prefs.getBoolean("toolbar", true);
prefs.edit().putBoolean("toolbar", !toolbar).apply();
initToolbar();
}
private void initToolbar() {
ibExpander.setVisibility(View.VISIBLE);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean toolbar = prefs.getBoolean("toolbar", true);
if (toolbar) {
ibExpander.setImageLevel(0 /* less */);
expand(ibFull);
expand(ibImages);
expand(ibDecrypt);
expand(ibMore);
expand(ibDelete);
expand(ibMove);
expand(ibArchive);
expand(ibForward);
expand(ibReply);
} else {
ibExpander.setImageLevel(1 /* more */);
collapse(ibFull);
collapse(ibImages);
collapse(ibDecrypt);
collapse(ibMore);
collapse(ibDelete);
collapse(ibMove);
collapse(ibArchive);
collapse(ibForward);
collapse(ibReply);
}
}
private void expand(View view) {
int dp6 = Helper.dp2pixels(view.getContext(), 6);
int dp36 = Helper.dp2pixels(view.getContext(), 36);
view.setPadding(dp6, dp6, dp6, dp6);
ViewGroup.LayoutParams lparam = view.getLayoutParams();
lparam.width = dp36;
lparam.height = dp36;
view.setLayoutParams(lparam);
}
private void collapse(View view) {
view.setPadding(0, 0, 0, 0);
ViewGroup.LayoutParams lparam = view.getLayoutParams();
lparam.width = 0;
lparam.height = 0;
view.setLayoutParams(lparam);
}
private void onDownloadAttachments(final TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);

View File

@ -66,16 +66,28 @@
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="42dp"
android:layout_marginEnd="6dp"
android:fontFamily="monospace"
android:minHeight="396dp"
android:minHeight="432dp"
android:paddingBottom="6dp"
android:text="Body"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ibFull"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNoInternetBody" />
<ImageButton
android:id="@+id/ibExpander"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/title_legend_expander"
android:padding="6dp"
android:rotation="90"
android:src="@drawable/expander"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tvBody" />
<ImageButton
android:id="@+id/ibFull"
android:layout_width="36dp"
@ -90,7 +102,7 @@
android:tint="@color/bottomnav_foreground"
android:tooltipText="@string/title_legend_show_full"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tvBody" />
app:layout_constraintTop_toBottomOf="@id/ibExpander" />
<ImageButton
android:id="@+id/ibImages"