-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement translations and fix issues
Implement translations and fix issues Implement translations and fix issues
- Loading branch information
1 parent
ea65517
commit 2f3b84a
Showing
23 changed files
with
615 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
app/src/main/java/org/bepass/oblivion/LocaleHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 19 additions & 4 deletions
23
app/src/main/java/org/bepass/oblivion/SplashScreenActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.