Commit 63d5eddc authored by akwizgran's avatar akwizgran

WIP: Transition from one constraint set to another.

parent 05e230da
......@@ -12,11 +12,11 @@ import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.briar.R;
import androidx.appcompat.widget.SwitchCompat;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.lifecycle.LifecycleOwner;
import static android.view.View.FOCUS_DOWN;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static androidx.core.content.ContextCompat.getColor;
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
import static org.briarproject.bramble.api.plugin.Plugin.State.DISABLED;
......@@ -26,38 +26,34 @@ import static org.briarproject.briar.android.navdrawer.NavDrawerViewModel.TRANSP
class PluginViewController {
private final ImageView torIconExpanded, torIconCollapsed;
private final ImageView wifiIconExpanded, wifiIconCollapsed;
private final ImageView btIconExpanded, btIconCollapsed;
private final ConstraintLayout drawerContent;
private final View backgroundView;
private final ImageView torIcon, wifiIcon, btIcon;
private final SwitchCompat torSwitch, wifiSwitch, btSwitch;
private boolean expanded = false;
PluginViewController(View v, LifecycleOwner owner,
NavDrawerViewModel viewModel) {
drawerContent = v.findViewById(R.id.drawerContent);
backgroundView = v.findViewById(R.id.backgroundView);
ScrollView scrollView = v.findViewById(R.id.drawerScrollView);
View expandedLayout = v.findViewById(R.id.expandedLayout);
View collapsedLayout = v.findViewById(R.id.collapsedLayout);
ConstraintSet cs = new ConstraintSet();
cs.load(v.getContext(), R.xml.transports_list_collapsed);
drawerContent.setConstraintSet(cs);
backgroundView.setOnClickListener(view -> toggleExpandedView());
expandedLayout.addOnLayoutChangeListener((view, left, top, right,
ScrollView scrollView = v.findViewById(R.id.drawerScrollView);
drawerContent.addOnLayoutChangeListener((view, left, top, right,
bottom, oldLeft, oldTop, oldRight, oldBottom) ->
scrollView.fullScroll(FOCUS_DOWN));
collapsedLayout.setOnClickListener(view -> {
expandedLayout.setVisibility(VISIBLE);
collapsedLayout.setVisibility(GONE);
});
v.findViewById(R.id.chevronView).setOnClickListener(view ->
toggleExpandedView());
v.findViewById(R.id.chevronViewExpanded).setOnClickListener(view -> {
expandedLayout.setVisibility(GONE);
collapsedLayout.setVisibility(VISIBLE);
});
torIconExpanded = v.findViewById(R.id.torIconExpanded);
torIconCollapsed = v.findViewById(R.id.torIconCollapsed);
wifiIconExpanded = v.findViewById(R.id.wifiIconExpanded);
wifiIconCollapsed = v.findViewById(R.id.wifiIconCollapsed);
btIconExpanded = v.findViewById(R.id.btIconExpanded);
btIconCollapsed = v.findViewById(R.id.btIconCollapsed);
torIcon = v.findViewById(R.id.torIcon);
wifiIcon = v.findViewById(R.id.wifiIcon);
btIcon = v.findViewById(R.id.btIcon);
torSwitch = v.findViewById(R.id.torSwitch);
wifiSwitch = v.findViewById(R.id.wifiSwitch);
......@@ -78,9 +74,25 @@ class PluginViewController {
}
}
private void toggleExpandedView() {
ConstraintSet cs = new ConstraintSet();
if (expanded) {
cs.load(drawerContent.getContext(),
R.xml.transports_list_collapsed);
drawerContent.setConstraintSet(cs);
backgroundView.setOnClickListener(v -> toggleExpandedView());
expanded = false;
} else {
cs.load(drawerContent.getContext(),
R.xml.transports_list_expanded);
drawerContent.setConstraintSet(cs);
backgroundView.setOnClickListener(null);
expanded = true;
}
}
private void stateUpdate(TransportId id, State state) {
updateIcon(getExpandedIcon(id), state);
updateIcon(getCollapsedIcon(id), state);
updateIcon(getIcon(id), state);
updateSwitch(getSwitch(id), state);
}
......@@ -97,17 +109,10 @@ class PluginViewController {
switchCompat.setEnabled(state != STARTING_STOPPING);
}
private ImageView getExpandedIcon(TransportId id) {
if (id == TorConstants.ID) return torIconExpanded;
if (id == BluetoothConstants.ID) return btIconExpanded;
if (id == LanTcpConstants.ID) return wifiIconExpanded;
throw new AssertionError();
}
private ImageView getCollapsedIcon(TransportId id) {
if (id == TorConstants.ID) return torIconCollapsed;
if (id == BluetoothConstants.ID) return btIconCollapsed;
if (id == LanTcpConstants.ID) return wifiIconCollapsed;
private ImageView getIcon(TransportId id) {
if (id == TorConstants.ID) return torIcon;
if (id == BluetoothConstants.ID) return btIcon;
if (id == LanTcpConstants.ID) return wifiIcon;
throw new AssertionError();
}
......
......@@ -9,6 +9,7 @@
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"
......
<?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