Skip to content

Commit

Permalink
checking newlocale
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielcoderX authored and markpash committed Aug 31, 2024
1 parent 08cf04a commit 6eb68b6
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 45 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
}
}
androidResources {
generateLocaleConfig true
generateLocaleConfig false
}
buildFeatures {
dataBinding = true
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:localeConfig="@xml/locale_config"
android:banner="@mipmap/tv_banner"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
Expand Down
26 changes: 16 additions & 10 deletions app/src/main/java/org/bepass/oblivion/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ protected int getStatusBarColor() {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Initialize the LocaleHandler and set the locale
localeHandler = new LocaleHandler(this);
// Update background based on current theme
ThemeHelper.getInstance().updateActivityBackground(binding.getRoot());
FileManager.cleanOrMigrateSettings(this); // Pass this context
FileManager.cleanOrMigrateSettings(this);
setupUI();
setupVPNConnection();
requestNotificationPermission();
Expand Down Expand Up @@ -89,17 +87,24 @@ private void handleVpnSwitch(boolean enableVpn) {
if (vpnIntent != null) {
vpnPermissionLauncher.launch(vpnIntent);
} else {
startVpnService(this); // Use this context
startVpnService(this);
}
NetworkUtils.monitorInternetConnection(lastKnownConnectionState, this);
} else if (lastKnownConnectionState.isConnecting()) {
stopVpnService(this); // Use this context
stopVpnService(this);
}
} else {
if (!lastKnownConnectionState.isDisconnected()) {
stopVpnService(this); // Use this context
stopVpnService(this);
}
}
refreshUI(); // Force refresh of the UI after VPN state changes
}

private void refreshUI() {
// This will force a refresh of the UI based on the current data bindings
binding.invalidateAll();
binding.executePendingBindings();
}

private void handleBackPress() {
Expand Down Expand Up @@ -166,6 +171,7 @@ public void onConnectionStateChange(ConnectionState state) {
updateUIForConnectedState();
break;
}
refreshUI(); // Refresh UI whenever the connection state changes
});
}

Expand Down Expand Up @@ -194,22 +200,22 @@ private void updateUIForConnectedState() {
lanIP = NetworkUtils.getLocalIpAddress(this);
binding.stateText.setText(String.format(Locale.getDefault(), "%s\n socks5 over LAN on\n %s:%s", getString(R.string.connected), lanIP, FileManager.getString("USERSETTING_port")));
} catch (Exception e) {
binding.stateText.setText(String.format(Locale.getDefault(), "%s\n socks5 over LAN on\n 127.0.0.1:%s", getString(R.string.connected), FileManager.getString("USERSETTING_port")));
binding.stateText.setText(String.format(Locale.getDefault(), "%s\n socks5 over LAN on\n 0.0.0.0:%s", getString(R.string.connected), FileManager.getString("USERSETTING_port")));
}
} else {
binding.stateText.setText(String.format(Locale.getDefault(), "%s\nsocks5 on 127.0.0.1:%s", getString(R.string.connected), FileManager.getString("USERSETTING_port")));
}
}else {
} else {
binding.stateText.setText(R.string.connected);
}
binding.switchButton.setChecked(true, false);
binding.ipProgressBar.setVisibility(View.GONE);
PublicIPUtils.getInstance().getIPDetails((details) -> {
PublicIPUtils.getInstance().getIPDetails((details) -> runOnUiThread(() -> { // Ensure UI updates are done on the main thread
if (details.ip != null) {
String ipString = details.ip + " " + details.flag;
binding.publicIP.setText(ipString);
binding.publicIP.setVisibility(View.VISIBLE);
}
});
}));
}
}
16 changes: 15 additions & 1 deletion app/src/main/java/org/bepass/oblivion/utils/LocaleHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.AlertDialog;
import android.content.Context;
import android.util.Log;

import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.os.LocaleListCompat;
Expand All @@ -22,7 +23,20 @@ public class LocaleHandler {

public LocaleHandler(Context context) {
this.context = context;
this.configuredLocales = LocaleConfigXKt.getConfiguredLocales(context);

// Safely load configured locales
LocaleListCompat locales;
try {
locales = LocaleConfigXKt.getConfiguredLocales(context);
if (locales.isEmpty()) {
throw new Exception("Locale configuration is empty or null.");
}
} catch (Exception e) {
Log.e("LocaleHandler", "Failed to load locale configuration. Falling back to default locale.", e);
locales = LocaleListCompat.create(Locale.forLanguageTag(DEFAULT_LOCALE));
}

this.configuredLocales = locales;
}

public void setPersianAsDefaultLocaleIfNeeds() {
Expand Down
27 changes: 7 additions & 20 deletions app/src/main/java/org/bepass/oblivion/utils/NetworkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

import org.bepass.oblivion.enums.ConnectionState;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Locale;

public class NetworkUtils {
Expand Down Expand Up @@ -58,7 +56,7 @@ private static boolean isConnectedToInternet(Context context) {
}
return false;
}
public static String getLocalIpAddress(Context context) {
public static String getLocalIpAddress(Context context) throws Exception {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();

Expand All @@ -67,40 +65,29 @@ public static String getLocalIpAddress(Context context) {
// Get IP Address from Wi-Fi
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
int ipAddress = wifiManager.getConnectionInfo().getIpAddress();
return String.format(Locale.US,"%d.%d.%d.%d",
return String.format(Locale.US, "%d.%d.%d.%d",
(ipAddress & 0xff),
(ipAddress >> 8 & 0xff),
(ipAddress >> 16 & 0xff),
(ipAddress >> 24 & 0xff));
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
// Get IP Address from Mobile Data using InetAddress
try {
InetAddress ip = InetAddress.getByName("google.com");
return ip.getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
// Throw exception if connected to Mobile Data (4G)
throw new Exception("Operation not allowed on cellular data (4G). Please connect to Wi-Fi.");
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// For devices running Android Marshmallow or higher
NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork());
if (capabilities != null && capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
// Get IP Address from Wi-Fi
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
int ipAddress = wifiManager.getConnectionInfo().getIpAddress();
return String.format(Locale.US,"%d.%d.%d.%d",
return String.format(Locale.US, "%d.%d.%d.%d",
(ipAddress & 0xff),
(ipAddress >> 8 & 0xff),
(ipAddress >> 16 & 0xff),
(ipAddress >> 24 & 0xff));
} else if (capabilities != null && capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
// Get IP Address from Mobile Data using InetAddress
try {
InetAddress ip = InetAddress.getByName("google.com");
return ip.getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
// Throw exception if connected to Mobile Data (4G)
throw new Exception("Operation not allowed on cellular data (4G). Please connect to Wi-Fi.");
}
}

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
<string name="proxy_mode">حالت پراکسی</string>
<string name="running_in_proxy_mode_not_vpn">در حال اجرا در حالت پراکسی، نه VPN</string>
<string-array name="countries">
<item>استرالیا</item>
<item>اتریش</item>
<item>بلژیک</item>
<item>برزیل</item>
<item>بلغارستان</item>
<item>کانادا</item>
<item>کرواسی</item>
Expand All @@ -88,7 +88,6 @@
<item>اسپانیا</item>
<item>سوئد</item>
<item>سوئیس</item>
<item>اوکراین</item>
<item>بریتانیا</item>
<item>ایالات متحده</item>
</string-array>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
<string name="proxy_mode">Режим прокси</string>
<string name="running_in_proxy_mode_not_vpn">Работает в режиме прокси, а не VPN</string>
<string-array name="countries">
<item>Австралия</item>
<item>Австрия</item>
<item>Бельгия</item>
<item>Бразилия</item>
<item>Болгария</item>
<item>Канада</item>
<item>Хорватия</item>
Expand All @@ -88,7 +88,6 @@
<item>Испания</item>
<item>Швеция</item>
<item>Швейцария</item>
<item>Украина</item>
<item>Великобритания</item>
<item>Соединенные Штаты</item>
</string-array>
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
<string name="proxy_mode">Proxy Modu</string>
<string name="running_in_proxy_mode_not_vpn">Proxy modunda çalışıyor, VPN değil</string>
<string-array name="countries">
<item>Avustralya</item>
<item>Avusturya</item>
<item>Belçika</item>
<item>Brezilya</item>
<item>Bulgaristan</item>
<item>Kanada</item>
<item>Hırvatistan</item>
Expand All @@ -88,8 +88,7 @@
<item>İspanya</item>
<item>İsveç</item>
<item>İsviçre</item>
<item>Ukrayna</item>
<item>Birleşik Krallık</item>
<item>Birleşik Devletler</item>
<item>Amerika Birleşik Devletleri</item>
</string-array>
</resources>
3 changes: 1 addition & 2 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
<string name="proxy_mode">代理模式</string>
<string name="running_in_proxy_mode_not_vpn">以代理模式运行,而不是VPN</string>
<string-array name="countries">
<item>澳大利亚</item>
<item>奥地利</item>
<item>比利时</item>
<item>巴西</item>
<item>保加利亚</item>
<item>加拿大</item>
<item>克罗地亚</item>
Expand All @@ -87,7 +87,6 @@
<item>西班牙</item>
<item>瑞典</item>
<item>瑞士</item>
<item>乌克兰</item>
<item>英国</item>
<item>美国</item>
</string-array>
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
<string name="proxy_mode">Proxy Mode</string>
<string name="running_in_proxy_mode_not_vpn">Running in proxy mode, not VPN</string>
<string-array name="countries">
<item>Australia</item>
<item>Austria</item>
<item>Belgium</item>
<item>Brazil</item>
<item>Bulgaria</item>
<item>Canada</item>
<item>Croatia</item>
Expand All @@ -88,14 +88,13 @@
<item>Spain</item>
<item>Sweden</item>
<item>Switzerland</item>
<item>Ukraine</item>
<item>United Kingdom</item>
<item>United States</item>
</string-array>
<string-array name="englishCountries">
<item>Australia</item>
<item>Austria</item>
<item>Belgium</item>
<item>Brazil</item>
<item>Bulgaria</item>
<item>Canada</item>
<item>Croatia</item>
Expand All @@ -122,7 +121,6 @@
<item>Spain</item>
<item>Sweden</item>
<item>Switzerland</item>
<item>Ukraine</item>
<item>United Kingdom</item>
<item>United States</item>
</string-array>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/locale_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
<locale android:name="en"/> <!-- English -->
<locale android:name="fa"/> <!-- Persian -->
<locale android:name="ru"/> <!-- Russian -->
<locale android:name="tr"/> <!-- Turkish -->
<locale android:name="zh"/> <!-- Chinese -->
</locale-config>

0 comments on commit 6eb68b6

Please sign in to comment.