Commit 5d73ff8e authored by akwizgran's avatar akwizgran

Transition from one constraint set to another.

parent 63d5eddc
Pipeline #4129 passed with stage
in 11 minutes and 5 seconds
......@@ -11,11 +11,14 @@ import org.briarproject.bramble.api.plugin.TorConstants;
import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.briar.R;
import androidx.appcompat.widget.AppCompatImageButton;
import androidx.appcompat.widget.SwitchCompat;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.lifecycle.LifecycleOwner;
import static android.os.Build.VERSION.SDK_INT;
import static android.transition.TransitionManager.beginDelayedTransition;
import static android.view.View.FOCUS_DOWN;
import static androidx.core.content.ContextCompat.getColor;
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
......@@ -27,7 +30,8 @@ import static org.briarproject.briar.android.navdrawer.NavDrawerViewModel.TRANSP
class PluginViewController {
private final ConstraintLayout drawerContent;
private final View backgroundView;
private final ConstraintSet collapsedConstraints, expandedConstraints;
private final AppCompatImageButton chevronView;
private final ImageView torIcon, wifiIcon, btIcon;
private final SwitchCompat torSwitch, wifiSwitch, btSwitch;
......@@ -36,20 +40,28 @@ class PluginViewController {
PluginViewController(View v, LifecycleOwner owner,
NavDrawerViewModel viewModel) {
drawerContent = v.findViewById(R.id.drawerContent);
backgroundView = v.findViewById(R.id.backgroundView);
ConstraintSet cs = new ConstraintSet();
cs.load(v.getContext(), R.xml.transports_list_collapsed);
drawerContent.setConstraintSet(cs);
backgroundView.setOnClickListener(view -> toggleExpandedView());
collapsedConstraints = new ConstraintSet();
collapsedConstraints.clone(v.getContext(),
R.layout.navigation_menu_collapsed);
expandedConstraints = new ConstraintSet();
expandedConstraints.clone(v.getContext(),
R.layout.navigation_menu_expanded);
// Scroll the drawer to the bottom when the view is expanded/collapsed
ScrollView scrollView = v.findViewById(R.id.drawerScrollView);
drawerContent.addOnLayoutChangeListener((view, left, top, right,
bottom, oldLeft, oldTop, oldRight, oldBottom) ->
scrollView.fullScroll(FOCUS_DOWN));
v.findViewById(R.id.chevronView).setOnClickListener(view ->
toggleExpandedView());
// Clicking the chevron expands or collapses the view
chevronView = v.findViewById(R.id.chevronView);
chevronView.setOnClickListener(view -> expandOrCollapseView());
// The whole view is clickable when collapsed
v.findViewById(R.id.connectionsBackground).setOnClickListener(view ->
expandOrCollapseView());
torIcon = v.findViewById(R.id.torIcon);
wifiIcon = v.findViewById(R.id.wifiIcon);
......@@ -74,21 +86,16 @@ class PluginViewController {
}
}
private void toggleExpandedView() {
ConstraintSet cs = new ConstraintSet();
private void expandOrCollapseView() {
if (SDK_INT >= 19) beginDelayedTransition(drawerContent);
if (expanded) {
cs.load(drawerContent.getContext(),
R.xml.transports_list_collapsed);
drawerContent.setConstraintSet(cs);
backgroundView.setOnClickListener(v -> toggleExpandedView());
expanded = false;
collapsedConstraints.applyTo(drawerContent);
chevronView.setImageResource(R.drawable.chevron_up_white);
} else {
cs.load(drawerContent.getContext(),
R.xml.transports_list_expanded);
drawerContent.setConstraintSet(cs);
backgroundView.setOnClickListener(null);
expanded = true;
expandedConstraints.applyTo(drawerContent);
chevronView.setImageResource(R.drawable.chevron_down_white);
}
expanded = !expanded;
}
private void stateUpdate(TransportId id, State state) {
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerScrollView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
......@@ -8,30 +7,6 @@
android:fillViewport="true"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/drawerContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/window_background"
android:orientation="vertical">
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/window_background"
app:elevation="0dp"
app:headerLayout="@layout/navigation_header"
app:itemBackground="@drawable/navigation_item_background"
app:itemIconTint="?attr/colorControlNormal"
app:itemTextColor="?android:textColorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:menu="@menu/navigation_drawer" />
<include layout="@layout/transports_list" />
</androidx.constraintlayout.widget.ConstraintLayout>
<include layout="@layout/navigation_menu_collapsed" />
</ScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/drawerContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/window_background">
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/window_background"
app:elevation="0dp"
app:headerLayout="@layout/navigation_header"
app:itemBackground="@drawable/navigation_item_background"
app:itemIconTint="?attr/colorControlNormal"
app:itemTextColor="?android:textColorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:menu="@menu/navigation_drawer" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/chevronView"
android:layout_width="0dp"
android:layout_height="24dp"
android:layout_marginBottom="8dp"
android:background="@color/divider"
android:foreground="?attr/selectableItemBackground"
android:src="@drawable/chevron_up_white"
app:layout_constraintBottom_toTopOf="@+id/connectionsLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/navigation"
app:layout_constraintVertical_bias="1.0"
app:layout_constraintVertical_chainStyle="packed"
app:tint="?attr/colorControlNormal"
tools:ignore="ContentDescription,UnusedAttribute" />
<View
android:id="@+id/connectionsBackground"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chevronView" />
<TextView
android:id="@+id/connectionsLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:text="@string/transport_connection"
android:textSize="12sp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/torIcon"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chevronView" />
<!-- Hidden -->
<View
android:id="@+id/longRangeBackground"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/item_background_highlight"
android:visibility="gone"
tools:ignore="MissingConstraints" />
<!-- Hidden -->
<TextView
android:id="@+id/longRangeLabel"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="@string/transport_internet"
android:textSize="12sp"
android:visibility="gone"
tools:ignore="MissingConstraints" />
<ImageView
android:id="@+id/torIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/transport_tor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/wifiIcon"
app:layout_constraintTop_toBottomOf="@+id/chevronView"
tools:ignore="ContentDescription"
tools:tint="@color/briar_green" />
<!-- Hidden -->
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/torSwitch"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="@string/transport_tor"
android:visibility="gone"
tools:ignore="MissingConstraints" />
<!-- Hidden -->
<TextView
android:id="@+id/nearbyLabel"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="@string/transport_nearby"
android:textSize="12sp"
android:visibility="gone"
tools:ignore="MissingConstraints" />
<ImageView
android:id="@+id/wifiIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/transport_lan"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btIcon"
app:layout_constraintTop_toBottomOf="@+id/chevronView"
tools:checked="true"
tools:ignore="ContentDescription"
tools:tint="@color/briar_green" />
<!-- Hidden -->
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/wifiSwitch"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="@string/transport_lan"
android:visibility="gone"
tools:ignore="MissingConstraints" />
<ImageView
android:id="@+id/btIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/transport_bt"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chevronView"
tools:checked="true"
tools:ignore="ContentDescription"
tools:tint="@color/briar_green" />
<!-- Hidden -->
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/btSwitch"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="@string/transport_bt"
android:visibility="gone"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:showIn="@layout/navigation_menu">
android:id="@+id/drawerContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/window_background">
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/window_background"
app:elevation="0dp"
app:headerLayout="@layout/navigation_header"
app:itemBackground="@drawable/navigation_item_background"
app:itemIconTint="?attr/colorControlNormal"
app:itemTextColor="?android:textColorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:menu="@menu/navigation_drawer" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/chevronView"
......@@ -11,21 +29,44 @@
android:layout_marginBottom="8dp"
android:background="@color/divider"
android:foreground="?attr/selectableItemBackground"
android:src="@drawable/chevron_down_white"
app:layout_constraintBottom_toTopOf="@+id/longRangeLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/navigation"
app:layout_constraintVertical_bias="1.0"
app:layout_constraintVertical_chainStyle="packed"
app:tint="?attr/colorControlNormal"
tools:ignore="ContentDescription,UnusedAttribute" />
<!-- Hidden -->
<View
android:id="@+id/connectionsBackground"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="gone"
tools:ignore="MissingConstraints" />
<!-- Hidden -->
<TextView
android:id="@+id/connectionsLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="@string/transport_connection"
android:textSize="12sp" />
android:textSize="12sp"
android:visibility="gone"
tools:ignore="MissingConstraints" />
<View
android:id="@+id/backgroundView"
android:id="@+id/longRangeBackground"
android:layout_width="0dp"
android:layout_height="0dp" />
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:background="@color/item_background_highlight"
app:layout_constraintBottom_toTopOf="@+id/nearbyLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chevronView" />
<TextView
android:id="@+id/longRangeLabel"
......@@ -33,13 +74,21 @@
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="@string/transport_internet"
android:textSize="12sp" />
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="@+id/torSwitch"
app:layout_constraintStart_toStartOf="@+id/torIcon"
app:layout_constraintTop_toBottomOf="@+id/chevronView" />
<ImageView
android:id="@+id/torIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:src="@drawable/transport_tor"
app:layout_constraintBottom_toBottomOf="@+id/torSwitch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/torSwitch"
tools:ignore="ContentDescription"
tools:tint="@color/briar_green" />
......@@ -53,23 +102,34 @@
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:text="@string/transport_tor"
app:layout_constraintBottom_toTopOf="@+id/nearbyLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/torIcon"
app:layout_constraintTop_toBottomOf="@+id/longRangeLabel"
tools:checked="true" />
<TextView
android:id="@+id/nearbyLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:text="@string/transport_nearby"
android:textSize="12sp" />
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="@+id/wifiSwitch"
app:layout_constraintStart_toStartOf="@+id/torIcon"
app:layout_constraintTop_toBottomOf="@+id/torSwitch" />
<ImageView
android:id="@+id/wifiIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:src="@drawable/transport_lan"
app:layout_constraintBottom_toBottomOf="@+id/wifiSwitch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/wifiSwitch"
tools:checked="true"
tools:ignore="ContentDescription"
tools:tint="@color/briar_green" />
......@@ -84,13 +144,22 @@
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
android:text="@string/transport_lan"
app:layout_constraintBottom_toTopOf="@+id/btSwitch"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/wifiIcon"
app:layout_constraintTop_toBottomOf="@+id/nearbyLabel"
tools:checked="true" />
<ImageView
android:id="@+id/btIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:src="@drawable/transport_bt"
app:layout_constraintBottom_toBottomOf="@+id/btSwitch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/btSwitch"
tools:checked="true"
tools:ignore="ContentDescription"
tools:tint="@color/briar_green" />
......@@ -105,6 +174,10 @@
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
android:text="@string/transport_bt"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btIcon"
app:layout_constraintTop_toBottomOf="@+id/wifiSwitch"
tools:checked="true" />
</merge>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ConstraintSet xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Constraint
android:id="@+id/chevronView"
android:clickable="false"
android:focusable="false"
android:src="@drawable/chevron_up_white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/navigation"
app:layout_constraintVertical_bias="1.0" />
<Constraint
android:id="@+id/backgroundView"
android:layout_marginBottom="8dp"
android:background="@color/window_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chevronView" />
<Constraint
android:id="@+id/connectionsLabel"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/torIcon"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chevronView" />
<Constraint
android:id="@+id/torIcon"
android:layout_margin="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/wifiIcon"
app:layout_constraintTop_toBottomOf="@+id/chevronView" />
<Constraint
android:id="@+id/wifiIcon"
android:layout_margin="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btIcon"
app:layout_constraintTop_toBottomOf="@+id/chevronView" />
<Constraint
android:id="@+id/btIcon"
android:layout_margin="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chevronView" />
<Constraint
android:id="@+id/longRangeLabel"
android:visibility="gone" />
<Constraint
android:id="@+id/torSwitch"
android:visibility="gone" />
<Constraint
android:id="@+id/nearbyLabel"
android:visibility="gone" />
<Constraint
android:id="@+id/wifiSwitch"
android:visibility="gone" />
<Constraint
android:id="@+id/btSwitch"
android:visibility="gone" />
</ConstraintSet>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ConstraintSet xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Constraint
android:id="@+id/chevronView"
android:clickable="true"
android:focusable="true"
android:src="@drawable/chevron_down_white"
app:layout_constraintBottom_toTopOf="@+id/longRangeLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/navigation"
app:layout_constraintVertical_bias="1.0" />
<Constraint
android:id="@+id/backgroundView"
android:layout_marginBottom="8dp"
android:background="@color/item_background_highlight"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/nearbyLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chevronView" />
<Constraint
android:id="@+id/longRangeLabel"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/torSwitch"
app:layout_constraintStart_toStartOf="@+id/torIcon" />
<Constraint
android:id="@+id/torIcon"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
app:layout_constraintBottom_toBottomOf="@+id/torSwitch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/torSwitch" />
<Constraint
android:id="@+id/torSwitch"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/nearbyLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/torIcon" />
<Constraint
android:id="@+id/nearbyLabel"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/wifiSwitch"
app:layout_constraintStart_toStartOf="@+id/torIcon" />
<Constraint
android:id="@+id/wifiIcon"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
app:layout_constraintBottom_toBottomOf="@+id/wifiSwitch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/wifiSwitch" />
<Constraint
android:id="@+id/wifiSwitch"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/btSwitch"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/wifiIcon" />
<Constraint
android:id="@+id/btIcon"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
app:layout_constraintBottom_toBottomOf="@+id/btSwitch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/btSwitch" />
<Constraint
android:id="@+id/btSwitch"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btIcon" />
<Constraint
android:id="@+id/connectionsLabel"
android:visibility="gone" />
</ConstraintSet>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment