Put the transport toggles in an expandable view (no animations).

This commit is contained in:
akwizgran
2020-02-05 17:15:19 +00:00
parent 802e599f09
commit 3ab88181eb
5 changed files with 268 additions and 308 deletions

View File

@@ -7,9 +7,7 @@ import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;
import com.google.android.material.navigation.NavigationView;
@@ -47,9 +45,7 @@ import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;
import static android.view.View.FOCUS_DOWN;
import static android.view.View.GONE;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static androidx.core.view.GravityCompat.START;
import static androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
@@ -92,7 +88,6 @@ public class NavDrawerActivity extends BriarActivity implements
LifecycleManager lifecycleManager;
private DrawerLayout drawerLayout;
private ScrollView drawerScrollView;
private NavigationView navigation;
@Override
@@ -114,26 +109,8 @@ public class NavDrawerActivity extends BriarActivity implements
if (ask) showDozeDialog(getString(R.string.setup_doze_intro));
});
drawerScrollView = findViewById(R.id.drawerScrollView);
View chevronView = drawerScrollView.findViewById(R.id.chevronView);
drawerScrollView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// hide/show chevron depending on whether we can scroll
if (drawerScrollView.canScrollVertically(1)) {
chevronView.setVisibility(VISIBLE);
} else {
chevronView.setVisibility(INVISIBLE);
}
drawerScrollView.getViewTreeObserver()
.removeOnGlobalLayoutListener(this);
}
});
View drawerScrollView = findViewById(R.id.drawerScrollView);
new PluginViewController(drawerScrollView, this, viewModel);
chevronView.setOnClickListener(v ->
drawerScrollView.fullScroll(FOCUS_DOWN)
);
Toolbar toolbar = findViewById(R.id.toolbar);
drawerLayout = findViewById(R.id.drawer_layout);

View File

@@ -2,6 +2,7 @@ package org.briarproject.briar.android.navdrawer;
import android.view.View;
import android.widget.ImageView;
import android.widget.ScrollView;
import org.briarproject.bramble.api.plugin.BluetoothConstants;
import org.briarproject.bramble.api.plugin.LanTcpConstants;
@@ -13,6 +14,9 @@ import org.briarproject.briar.R;
import androidx.appcompat.widget.SwitchCompat;
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;
@@ -22,15 +26,38 @@ import static org.briarproject.briar.android.navdrawer.NavDrawerViewModel.TRANSP
class PluginViewController {
private final ImageView torIcon, wifiIcon, btIcon;
private final ImageView torIconExpanded, torIconCollapsed;
private final ImageView wifiIconExpanded, wifiIconCollapsed;
private final ImageView btIconExpanded, btIconCollapsed;
private final SwitchCompat torSwitch, wifiSwitch, btSwitch;
PluginViewController(View v, LifecycleOwner owner,
NavDrawerViewModel viewModel) {
torIcon = v.findViewById(R.id.torIcon);
wifiIcon = v.findViewById(R.id.wifiIcon);
btIcon = v.findViewById(R.id.btIcon);
ScrollView scrollView = v.findViewById(R.id.drawerScrollView);
View expandedLayout = v.findViewById(R.id.expandedLayout);
View collapsedLayout = v.findViewById(R.id.collapsedLayout);
expandedLayout.addOnLayoutChangeListener((view, left, top, right,
bottom, oldLeft, oldTop, oldRight, oldBottom) ->
scrollView.fullScroll(FOCUS_DOWN));
v.findViewById(R.id.chevronViewCollapsed).setOnClickListener(view -> {
expandedLayout.setVisibility(VISIBLE);
collapsedLayout.setVisibility(GONE);
});
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);
torSwitch = v.findViewById(R.id.torSwitch);
wifiSwitch = v.findViewById(R.id.wifiSwitch);
@@ -52,7 +79,8 @@ class PluginViewController {
}
private void stateUpdate(TransportId id, State state) {
updateIcon(getIcon(id), state);
updateIcon(getExpandedIcon(id), state);
updateIcon(getCollapsedIcon(id), state);
updateSwitch(getSwitch(id), state);
}
@@ -69,10 +97,17 @@ class PluginViewController {
switchCompat.setEnabled(state != STARTING_STOPPING);
}
private ImageView getIcon(TransportId id) {
if (id == TorConstants.ID) return torIcon;
if (id == BluetoothConstants.ID) return btIcon;
if (id == LanTcpConstants.ID) return wifiIcon;
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;
throw new AssertionError();
}