You've already forked android-client
mirror of
https://github.com/netbirdio/android-client.git
synced 2026-05-22 17:10:49 -07:00
Propagate exception when selecting / deselecting routes
So that when toggling a route switch, it won't be in an inconsistent state in case of error from engine
This commit is contained in:
@@ -159,13 +159,13 @@ public class VPNServiceRepository {
|
||||
}
|
||||
}
|
||||
|
||||
public void selectRoute(String route) {
|
||||
public void selectRoute(String route) throws Exception {
|
||||
if (binder != null) {
|
||||
binder.selectRoute(route);
|
||||
}
|
||||
}
|
||||
|
||||
public void deselectRoute(String route) {
|
||||
public void deselectRoute(String route) throws Exception {
|
||||
if (binder != null) {
|
||||
binder.deselectRoute(route);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import io.netbird.client.databinding.ListItemResourceBinding;
|
||||
|
||||
public class NetworksAdapter extends RecyclerView.Adapter<NetworksAdapter.ResourceViewHolder> {
|
||||
public interface RouteSwitchToggleHandler {
|
||||
void handleSwitchToggle(String route, boolean isChecked);
|
||||
void handleSwitchToggle(String route, boolean isChecked) throws Exception;
|
||||
}
|
||||
|
||||
private final List<Resource> resourcesList;
|
||||
@@ -145,8 +145,19 @@ public class NetworksAdapter extends RecyclerView.Adapter<NetworksAdapter.Resour
|
||||
binding.peer.setText(resource.getPeer());
|
||||
|
||||
binding.switchControl.setChecked(resource.isSelected());
|
||||
binding.switchControl.setTag(false);
|
||||
binding.switchControl.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
this.switchToggleHandler.handleSwitchToggle(resource.getName(), isChecked);
|
||||
try {
|
||||
boolean tag = (boolean)binding.switchControl.getTag();
|
||||
if (!tag) {
|
||||
this.switchToggleHandler.handleSwitchToggle(resource.getName(), isChecked);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// This is done so that reversing the toggle action won't retrigger the toggle handler.
|
||||
binding.switchControl.setTag(true);
|
||||
binding.switchControl.setChecked(!isChecked);
|
||||
binding.switchControl.setTag(false);
|
||||
}
|
||||
});
|
||||
|
||||
binding.verticalLine.setBackgroundResource(getConnectionStatusIndicatorDrawable(resource, peers));
|
||||
|
||||
@@ -107,7 +107,7 @@ public class NetworksFragment extends Fragment {
|
||||
);
|
||||
}
|
||||
|
||||
private void routeSwitchToggleHandler(String route, boolean isChecked) {
|
||||
private void routeSwitchToggleHandler(String route, boolean isChecked) throws Exception {
|
||||
if (isChecked) {
|
||||
model.selectRoute(route);
|
||||
} else {
|
||||
|
||||
@@ -67,11 +67,11 @@ public class NetworksFragmentViewModel extends ViewModel implements VPNServiceBi
|
||||
uiState.postValue(new NetworksFragmentUiState(resources, peers));
|
||||
}
|
||||
|
||||
public void selectRoute(String route) {
|
||||
public void selectRoute(String route) throws Exception {
|
||||
this.repository.selectRoute(route);
|
||||
}
|
||||
|
||||
public void deselectRoute(String route) {
|
||||
public void deselectRoute(String route) throws Exception {
|
||||
this.repository.deselectRoute(route);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,23 +168,25 @@ class EngineRunner {
|
||||
}
|
||||
}
|
||||
|
||||
public void selectRoute(String route) {
|
||||
public void selectRoute(String route) throws Exception {
|
||||
Log.d(LOGTAG, String.format("selecting route: %s", route));
|
||||
try {
|
||||
goClient.selectRoute(route);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "goClient error", e);
|
||||
notifyError(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void deselectRoute(String route) {
|
||||
public void deselectRoute(String route) throws Exception {
|
||||
Log.d(LOGTAG, String.format("deselecting route: %s", route));
|
||||
try {
|
||||
goClient.deselectRoute(route);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "goClient error", e);
|
||||
notifyError(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,11 +180,11 @@ public class VPNService extends android.net.VpnService {
|
||||
}
|
||||
}
|
||||
|
||||
public void selectRoute(String route) {
|
||||
public void selectRoute(String route) throws Exception {
|
||||
engineRunner.selectRoute(route);
|
||||
}
|
||||
|
||||
public void deselectRoute(String route) {
|
||||
public void deselectRoute(String route) throws Exception {
|
||||
engineRunner.deselectRoute(route);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user