Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions app/src/main/java/io/netbird/client/CustomTabURLOpener.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ public CustomTabURLOpener(AppCompatActivity activity, OnCustomTabResult resultC
this.context = activity;

this.customTabLauncher = activity.registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult o) {
isOpened = false;
resultCallback.onClosed();
}
new ActivityResultContracts.StartActivityForResult(), o -> {
isOpened = false;
resultCallback.onClosed();
}
);
}
Expand Down
74 changes: 69 additions & 5 deletions app/src/main/java/io/netbird/client/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import android.animation.StateListAnimator;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
Expand All @@ -32,7 +30,6 @@
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
Expand All @@ -41,7 +38,7 @@
import androidx.appcompat.app.AppCompatActivity;

import io.netbird.client.databinding.ActivityMainBinding;
import io.netbird.client.tool.NetworkChangeNotifier;
import io.netbird.client.tool.RouteChangeListener;
import io.netbird.client.tool.ServiceStateListener;
import io.netbird.client.tool.VPNService;
import io.netbird.client.ui.PreferenceUI;
Expand Down Expand Up @@ -119,6 +116,9 @@ protected void onCreate(Bundle savedInstanceState) {

// Set the listener for menu item selections
navigationView.setNavigationItemSelectedListener(this);

// Update profile menu item with active profile name
updateProfileMenuItem(navigationView);

// On TV, request focus when drawer opens so D-pad navigation works
if (isRunningOnTV) {
Expand Down Expand Up @@ -168,6 +168,10 @@ public void onDrawerClosed(View drawerView) {
navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
if (destination.getId() == R.id.nav_home) {
removeToolbarShadow();
// Update profile menu item when returning to home (e.g., after profile switch)
if (binding != null && binding.navView != null) {
updateProfileMenuItem(binding.navView);
}
} else {
resetToolbar();
}
Expand Down Expand Up @@ -256,6 +260,10 @@ public void onStart() {
@Override
protected void onResume() {
super.onResume();
// Update profile menu item when returning to MainActivity
if (binding != null && binding.navView != null) {
updateProfileMenuItem(binding.navView);
}
}

@Override
Expand Down Expand Up @@ -369,6 +377,46 @@ public NetworkArray getNetworks() {
return mBinder.networks();
}

@Override
public void selectRoute(String route) throws Exception {
if (mBinder == null) {
Log.w(LOGTAG, "VPN binder is null");
return;
}

mBinder.selectRoute(route);
}

@Override
public void deselectRoute(String route) throws Exception {
if (mBinder == null) {
Log.w(LOGTAG, "VPN binder is null");
return;
}

mBinder.deselectRoute(route);
}

@Override
public void addRouteChangeListener(RouteChangeListener listener) {
if (mBinder == null) {
Log.w(LOGTAG, "VPN binder is null");
return;
}

mBinder.addRouteChangeListener(listener);
}

@Override
public void removeRouteChangeListener(RouteChangeListener listener) {
if (mBinder == null) {
Log.w(LOGTAG, "VPN binder is null");
return;
}

mBinder.removeRouteChangeListener(listener);
}


@Override
public void registerServiceStateListener(StateListener listener) {
Expand Down Expand Up @@ -563,6 +611,22 @@ public void onError(String msg) {
}
};

private void updateProfileMenuItem(NavigationView navigationView) {
try {
// Get active profile from ProfileManager instead of reading file
io.netbird.client.tool.ProfileManagerWrapper profileManager =
new io.netbird.client.tool.ProfileManagerWrapper(this);
String activeProfile = profileManager.getActiveProfile();
Menu menu = navigationView.getMenu();
MenuItem profileItem = menu.findItem(R.id.nav_profiles);
if (profileItem != null && activeProfile != null) {
profileItem.setTitle(activeProfile);
}
} catch (Exception e) {
Log.e(LOGTAG, "Failed to update profile menu item", e);
}
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (!isRunningOnTV) {
Expand All @@ -572,7 +636,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.d(LOGTAG, "Key pressed: " + keyCode + " (" + KeyEvent.keyCodeToString(keyCode) + "), repeat: " + event.getRepeatCount());

if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
boolean isOnHomeScreen = navController != null &&
boolean isOnHomeScreen = navController != null &&
navController.getCurrentDestination() != null &&
navController.getCurrentDestination().getId() == R.id.nav_home;

Expand Down
9 changes: 0 additions & 9 deletions app/src/main/java/io/netbird/client/MyApplication.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package io.netbird.client;

import android.app.Application;
import android.content.IntentFilter;
import android.content.SharedPreferences;

import androidx.appcompat.app.AppCompatDelegate;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import io.netbird.client.repository.VPNServiceRepository;
import io.netbird.client.tool.NetworkChangeNotifier;

public class MyApplication extends Application {

Expand All @@ -20,8 +15,4 @@ public void onCreate() {
int themeMode = prefs.getInt("theme_mode", AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
AppCompatDelegate.setDefaultNightMode(themeMode);
}

public VPNServiceRepository getVPNServiceRepository() {
return new VPNServiceRepository(this);
}
}
7 changes: 7 additions & 0 deletions app/src/main/java/io/netbird/client/ServiceAccessor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.netbird.client;

import io.netbird.client.tool.RouteChangeListener;
import io.netbird.gomobile.android.NetworkArray;
import io.netbird.gomobile.android.PeerInfoArray;

Expand All @@ -10,4 +11,10 @@ public interface ServiceAccessor {

NetworkArray getNetworks();
void stopEngine();

void selectRoute(String route) throws Exception;
void deselectRoute(String route) throws Exception;

void addRouteChangeListener(RouteChangeListener listener);
void removeRouteChangeListener(RouteChangeListener listener);
}

This file was deleted.

This file was deleted.

Loading