Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add country flags + switch theme change #403

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
25 changes: 15 additions & 10 deletions app/src/main/java/org/bepass/oblivion/ui/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,14 @@ public void onNothingSelected(AdapterView<?> parent) {
FileManager.set("USERSETTING_proxymode", isChecked);
};

binding.txtDarkMode.setOnClickListener(view -> binding.checkBoxDarkMode.setChecked(!binding.checkBoxDarkMode.isChecked()));

// Set the initial state of the checkbox based on the current theme
binding.checkBoxDarkMode.setChecked(ThemeHelper.getInstance().getCurrentTheme() == ThemeHelper.Theme.DARK);
// Set up the listener to change the theme when the checkbox is toggled
binding.checkBoxDarkMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
// Determine the new theme based on the checkbox state
ThemeHelper.Theme newTheme = isChecked ? ThemeHelper.Theme.DARK : ThemeHelper.Theme.LIGHT;

binding.txtDarkMode.setOnClickListener(view -> binding.switchDarkMode.setChecked(!binding.switchDarkMode.isActivated()));

// Set the initial state of the switch based on the current theme
binding.switchDarkMode.setChecked(ThemeHelper.getInstance().getCurrentTheme() == ThemeHelper.Theme.DARK);
// Set up the listener to change the theme when the switch is toggled
binding.switchDarkMode.setOnCheckedChangeListener((buttonView, isActive) -> {
// Determine the new theme based on the switch state
ThemeHelper.Theme newTheme = isActive ? ThemeHelper.Theme.DARK : ThemeHelper.Theme.LIGHT;
// Use ThemeHelper to apply the new theme
ThemeHelper.getInstance().select(newTheme);
});
Expand Down Expand Up @@ -195,7 +194,13 @@ private void settingBasicValuesFromSPF() {
binding.license.setText(FileManager.getString("USERSETTING_license"));

int index = FileManager.getInt("USERSETTING_country_index");
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.countries, R.layout.country_item_layout);
String[] countryList = getResources().getStringArray(R.array.countries);
String[] countryLocaleList = getResources().getStringArray(R.array.localeCountries);
String[] countryFlagList = new String[countryList.length];
for (int i= 0;i<countryList.length;i++){
countryFlagList[i] = countryList[i]+" "+CountryUtils.localeToFlagEmoji(countryLocaleList[i]);
}
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,countryFlagList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
binding.country.post(() -> {
binding.country.setAdapter(adapter);
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/org/bepass/oblivion/utils/CountryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public static Triple<String, String, Integer> getCountryCode(Context context, St
// Return the triple of country code, full country name, and index
return new Triple<>(countryCode, countryCodeAndName.component2(), countryCodeAndName.component3());
}

public static String localeToFlagEmoji(String locale) {
// Convert the country code to the flag emoji
StringBuilder flagEmoji = new StringBuilder();
for (char character : locale.toCharArray()) {
// Convert each character to the corresponding regional indicator symbol
flagEmoji.append(Character.toChars(character + 127397));
}

return flagEmoji.toString();
}

private static Triple<String, String, Integer> translateToEnglish(String name, String[] translatedNames, String[] englishNames) {
for (int i = 0; i < translatedNames.length; i++) {
Expand Down
15 changes: 6 additions & 9 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,12 @@
android:layout_height="wrap_content"
android:layout_weight="2">

<CheckBox
android:id="@+id/check_box_dark_mode"
android:layout_width="50dp"
android:layout_height="38dp"
android:layout_marginStart="10dp"
android:buttonTint="@color/checkbox_tint"
android:scaleX="1.5"
android:scaleY="1.5"
android:translationX="5dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch_dark_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

</LinearLayout>

<TextView
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,39 @@
<item>United Kingdom</item>
<item>United States</item>
</string-array>
<string-array name="localeCountries">
<item>AU</item>
<item>AT</item>
<item>BE</item>
<item>BG</item>
<item>CA</item>
<item>HR</item>
<item>CZ</item>
<item>DK</item>
<item>EE</item>
<item>FI</item>
<item>FR</item>
<item>DE</item>
<item>HU</item>
<item>IN</item>
<item>IE</item>
<item>IT</item>
<item>JP</item>
<item>LV</item>
<item>NL</item>
<item>NO</item>
<item>PL</item>
<item>PT</item>
<item>RO</item>
<item>RS</item>
<item>SG</item>
<item>SK</item>
<item>ES</item>
<item>SE</item>
<item>CH</item>
<item>GB</item>
<item>US</item>
</string-array>
<string-array name="endpointType">
<item>Auto</item>
<item>IPv4</item>
Expand Down