Skip to content

Commit

Permalink
Implement translations and fix issues
Browse files Browse the repository at this point in the history
Implement translations and fix issues

Implement translations and fix issues
  • Loading branch information
DanielcoderX authored and markpash committed May 30, 2024
1 parent ea65517 commit 2f3b84a
Show file tree
Hide file tree
Showing 23 changed files with 615 additions and 194 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
android:label="@string/app_name"
android:banner="@mipmap/tv_banner"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="false"
android:supportsRtl="true"
tools:replace="android:supportsRtl"
android:screenOrientation="portrait"
android:enableOnBackInvokedCallback="true"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/bepass/oblivion/EditSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public EditSheet(Context context, String title, String sharedPrefKey, SheetsCall
this.context = context;
fileManager = FileManager.getInstance(context);

this.title = "تغییر مقدار " + title;
this.title = context.getString(R.string.editSheetEndpoint).replace("Endpoint",title);
this.sharedPrefKey = sharedPrefKey;

this.sheetsCallBack = sheetsCallBack;
Expand Down
113 changes: 113 additions & 0 deletions app/src/main/java/org/bepass/oblivion/LocaleHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package org.bepass.oblivion;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.Log;

import java.util.Locale;

public class LocaleHandler {
private static final String SELECTED_LANGUAGE = "SelectedLanguage";
private static final String DEFAULT_LANGUAGE = "fa";
private static final String[] AVAILABLE_LANGUAGES = {"fa", "en", "ru", "zh"};
private final Context context;
private final FileManager fileManager;

public LocaleHandler(Context context) {
this.context = context;
fileManager = FileManager.getInstance(context);
setLocale(); // Ensure the locale is set when the handler is created
}

public void setLocale() {
String language = fileManager.getString(SELECTED_LANGUAGE, DEFAULT_LANGUAGE);
setLanguage(language);
}

private void setLanguage(String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);

Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
DisplayMetrics displayMetrics = resources.getDisplayMetrics();

configuration.setLocale(locale);

resources.updateConfiguration(configuration, displayMetrics);
}

public void showLanguageSelectionDialog(Runnable onLanguageSelected) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Select Language")
.setItems(getAvailableLanguagesNames(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
String selectedLanguage = AVAILABLE_LANGUAGES[which];
saveSelectedLanguage(selectedLanguage);
setLanguage(selectedLanguage);
onLanguageSelected.run(); // Run the callback
}
})
.show();
}


private void saveSelectedLanguage(String language) {
fileManager.set(SELECTED_LANGUAGE, language);
}

private String[] getAvailableLanguagesNames() {
String[] languageNames = new String[AVAILABLE_LANGUAGES.length];
for (int i = 0; i < AVAILABLE_LANGUAGES.length; i++) {
languageNames[i] = getLanguageName(AVAILABLE_LANGUAGES[i]);
}
return languageNames;
}

private String getLanguageName(String languageCode) {
switch (languageCode) {
case "fa":
return "Persian";
case "en":
return "English";
case "ru":
return "Russian";
case "zh":
return "Chinese";
default:
return languageCode;
}
}

// private void restartActivity(Context context) {
// Log.d("BeforeRestart", fileManager.getString(
// SELECTED_LANGUAGE
// ));
// context.recre
//// Intent intent = new Intent(context.getPackageManager().getLeanbackLaunchIntentForPackage(context.getPackageName()));
//// intent
//// context.startActivity(context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()));
//// System.exit(0);
// }

public void restartActivity(Context context) {
Log.d("BeforeRestart", fileManager.getString(SELECTED_LANGUAGE));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
((Activity) context).recreate();
} else {
Intent intent = ((Activity) context).getIntent();
context.startActivity(intent);
((Activity) context).finish();
context.startActivity(intent);
}
}
}
23 changes: 15 additions & 8 deletions app/src/main/java/org/bepass/oblivion/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.bepass.oblivion;

import static org.bepass.oblivion.OblivionVpnService.startVpnService;
import static org.bepass.oblivion.OblivionVpnService.stopVpnService;

import android.Manifest;
Expand All @@ -18,7 +17,6 @@
import android.os.Handler;
import android.os.PowerManager;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
Expand All @@ -32,6 +30,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.util.HashSet;
import java.util.Set;

Expand All @@ -42,15 +42,14 @@ public class MainActivity extends StateAwareBaseActivity {
private PublicIPUtils pIPUtils;
private long backPressedTime;
private Toast backToast;

private static final int REQUEST_CODE_BATTERY_OPTIMIZATIONS = 1;
private LocaleHandler localeHandler;
private final ActivityResultLauncher<Intent> batteryOptimizationLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
// Do nothing, as no return value is expected
});

private Handler handler = new Handler();
private final Handler handler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -61,8 +60,16 @@ protected void onCreate(Bundle savedInstanceState) {
// Get the global PublicIPUtils instance
pIPUtils = PublicIPUtils.getInstance(getApplicationContext());

// Initialize the LocaleHandler and set the locale
localeHandler = new LocaleHandler(this);

// Set the layout of the main activity
setContentView(R.layout.activity_main);

// Handle language change based on floatingActionButton value
FloatingActionButton floatingActionButton = findViewById(R.id.floatingActionButton);
floatingActionButton.setOnClickListener(v -> localeHandler.showLanguageSelectionDialog(()->
localeHandler.restartActivity(this)));
if (!isIgnoringBatteryOptimizations()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestIgnoreBatteryOptimizations();
Expand Down Expand Up @@ -245,21 +252,21 @@ void onConnectionStateChange(ConnectionState state) {
switch (state) {
case DISCONNECTED:
publicIP.setVisibility(View.GONE);
stateText.setText("متصل نیستید");
stateText.setText(R.string.notConnected);
ipProgressBar.setVisibility(View.GONE);
switchButton.setEnabled(true);
switchButton.setChecked(false, false);
break;
case CONNECTING:
stateText.setText("در حال اتصال...");
stateText.setText(R.string.connecting);
publicIP.setVisibility(View.GONE);
ipProgressBar.setVisibility(View.VISIBLE);
switchButton.setChecked(true, false);
switchButton.setEnabled(true);
break;
case CONNECTED:
switchButton.setEnabled(true);
stateText.setText("اتصال برقرار شد");
stateText.setText(R.string.connected);
switchButton.setChecked(true, false);
ipProgressBar.setVisibility(View.GONE);
pIPUtils.getIPDetails((details) -> {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/bepass/oblivion/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public void handleOnBackPressed() {

SheetsCallBack sheetsCallBack = this::settingBasicValuesFromSPF;
// Listen to Changes
endpointLayout.setOnClickListener(v -> (new EditSheet(this, "اندپوینت", "endpoint", sheetsCallBack)).start());
portLayout.setOnClickListener(v -> (new EditSheet(this, "پورت", "port", sheetsCallBack)).start());
licenseLayout.setOnClickListener(v -> (new EditSheet(this, "لایسنس", "license", sheetsCallBack)).start());
endpointLayout.setOnClickListener(v -> (new EditSheet(this, getString(R.string.endpointText), "endpoint", sheetsCallBack)).start());
portLayout.setOnClickListener(v -> (new EditSheet(this, getString(R.string.portTunText), "port", sheetsCallBack)).start());
licenseLayout.setOnClickListener(v -> (new EditSheet(this, getString(R.string.licenseText), "license", sheetsCallBack)).start());

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.countries, R.layout.country_item_layout);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Expand Down
23 changes: 19 additions & 4 deletions app/src/main/java/org/bepass/oblivion/SplashScreenActivity.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
package org.bepass.oblivion;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

public class SplashScreenActivity extends AppCompatActivity {
@SuppressLint("CustomSplashScreen")
public class SplashScreenActivity extends AppCompatActivity implements View.OnClickListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initialize the LocaleHandler and set the locale
LocaleHandler localeHandler = new LocaleHandler(this);
setContentView(R.layout.activity_splash_screen);
final int SPLASH_DISPLAY_LENGTH = 2750; // 2.75s
final int SHORT_SPLASH_DISPLAY_LENGTH = 1000; // 1 second
findViewById(R.id.splashScreen).setOnClickListener(this);
new Handler().postDelayed(() -> {
// Create an Intent that will start the Main Activity.
Intent mainIntent = new Intent(SplashScreenActivity.this, MainActivity.class);
SplashScreenActivity.this.startActivity(mainIntent);
SplashScreenActivity.this.finish();
}, SPLASH_DISPLAY_LENGTH);
}, SHORT_SPLASH_DISPLAY_LENGTH);
}

@Override
public void onClick(View v) {
// If the user clicks on the splash screen, move to the MainActivity immediately
Intent mainIntent = new Intent(SplashScreenActivity.this, MainActivity.class);
SplashScreenActivity.this.startActivity(mainIntent);
SplashScreenActivity.this.finish();
}
}
}
Binary file added app/src/main/res/drawable-hdpi/ic_translate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_translate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_translate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_translate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions app/src/main/res/layout/activity_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:fontFamily="@font/shabnamlight"
android:text="درباره برنامه"
android:text="@string/aboutApp"
android:textColor="@color/black"
android:textSize="32sp" />

Expand All @@ -46,8 +46,8 @@
android:layout_marginTop="16dp"
android:fontFamily="@font/shabnammedium"
android:paddingHorizontal="12dp"
android:text='این برنامه با هدف دسترسی به اینترنت آزاد تهیه شده و هرگونه استفاده تجاری از آن مجاز نیست.\n\n\n" اینترنت برای همه، یا هیچ‌کس! "'
android:textAlignment="textEnd"
android:text='@string/aboutAppDesc'
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="16sp" />

Expand Down Expand Up @@ -101,7 +101,7 @@
android:layout_marginTop="8dp"
android:fontFamily="@font/shabnam"
android:gravity="center"
android:text="App Version: 2"
android:text="@string/appVersion"
android:textColor="@color/black"
android:textSize="14sp" />

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_log.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:fontFamily="@font/shabnamlight"
android:text="لاگ برنامه"
android:text="@string/logApp"
android:textColor="@color/black"
android:textSize="32sp" />

Expand Down
22 changes: 18 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
android:background="@drawable/background_gradient"
tools:context="org.bepass.oblivion.MainActivity">

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginBottom="24dp"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_translate"
android:tint="#ffffff"
app:backgroundTint="#ffa200"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<RelativeLayout
android:id="@+id/top_bar"
android:layout_width="match_parent"
Expand Down Expand Up @@ -96,7 +110,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="96dp"
android:fontFamily="@font/shabnammedium"
android:text="متصل نیستید"
android:text="@string/stateText"
android:textColor="@color/black"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -110,7 +124,6 @@
android:layout_marginTop="24dp"
android:fontFamily="@font/emoji"
android:visibility="invisible"
android:text="Public IP"
android:textStyle="bold"
android:textColor="@color/black"
android:textSize="18sp"
Expand All @@ -136,8 +149,9 @@
android:layout_width="wrap_content"
android:layout_height="60dp"
android:fontFamily="@font/shabnambold"
android:text="OBLIVION"
android:text="@string/app_name"
android:textColor="@color/black"
android:textAllCaps="true"
android:textSize="48sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -151,7 +165,7 @@
android:layout_width="212dp"
android:layout_height="wrap_content"
android:fontFamily="@font/shabnammedium"
android:text="بر پایه وارپ"
android:text="@string/basedOnWarp"
android:textColor="#FFA200"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Loading

0 comments on commit 2f3b84a

Please sign in to comment.