-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rilling/main
Merge from main branch
- Loading branch information
Showing
13 changed files
with
799 additions
and
10 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
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
75 changes: 75 additions & 0 deletions
75
src/main/java/de/dennisguse/opentracks/settings/ProfileSettingsFragment.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,75 @@ | ||
package de.dennisguse.opentracks.settings; | ||
|
||
import android.content.SharedPreferences; | ||
import android.os.Bundle; | ||
import android.text.InputFilter; | ||
|
||
|
||
import androidx.preference.EditTextPreference; | ||
import androidx.preference.ListPreference; | ||
import androidx.preference.PreferenceFragmentCompat; | ||
|
||
import de.dennisguse.opentracks.R; | ||
|
||
public class ProfileSettingsFragment extends PreferenceFragmentCompat { | ||
|
||
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (sharedPreferences, key) -> { | ||
if (PreferencesUtils.isKey(R.string.night_mode_key, key)) { | ||
getActivity().runOnUiThread(PreferencesUtils::applyNightMode); | ||
} | ||
}; | ||
|
||
@Override | ||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { | ||
addPreferencesFromResource(R.xml.settings_profile); | ||
ListPreference countryPreference = findPreference(getString(R.string.settings_profile_country_key)); | ||
|
||
|
||
String selectedCountryValue = PreferencesUtils.getSelectedCountry(); | ||
countryPreference.setSummary(selectedCountryValue); | ||
|
||
countryPreference.setOnPreferenceChangeListener((preference, newValue) -> { | ||
// Save the selected country to SharedPreferences | ||
PreferencesUtils.setSelectedCountry((String) newValue); | ||
|
||
// Update summary with selected country | ||
preference.setSummary((String) newValue); | ||
return true; | ||
}); | ||
} | ||
|
||
@Override | ||
public void onStart() { | ||
super.onStart(); | ||
((SettingsActivity) getActivity()).getSupportActionBar().setTitle(R.string.settings_profile_title); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
|
||
EditTextPreference nickNameInput = findPreference(getString(R.string.settings_profile_nickname_key)); | ||
nickNameInput.setDialogTitle(getString(R.string.settings_profile_nickname_dialog_title)); | ||
nickNameInput.setOnBindEditTextListener(editText -> { | ||
editText.setSingleLine(true); | ||
editText.selectAll(); // select all text | ||
int maxNicknameLength = 20; | ||
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxNicknameLength)}); | ||
}); | ||
|
||
ListPreference countryPreference = findPreference(getString(R.string.settings_profile_country_key)); | ||
String selectedCountryValue = PreferencesUtils.getSelectedCountry(); | ||
if (selectedCountryValue != null && !selectedCountryValue.isEmpty()) { | ||
// Update summary with saved selected country | ||
countryPreference.setSummary(selectedCountryValue); | ||
} | ||
|
||
PreferencesUtils.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
super.onPause(); | ||
PreferencesUtils.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="?attr/colorControlNormal"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,5c1.66,0 3,1.34 3,3s-1.34,3 -3,3 -3,-1.34 -3,-3 1.34,-3 3,-3zM12,19.2c-2.5,0 -4.71,-1.28 -6,-3.22 0.03,-1.99 4,-3.08 6,-3.08 1.99,0 5.97,1.09 6,3.08 -1.29,1.94 -3.5,3.22 -6,3.22z"/> | ||
</vector> |
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,20 @@ | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="horizontal" | ||
android:padding="1dp" | ||
android:gravity="center"> | ||
|
||
<NumberPicker | ||
android:id="@+id/monthPicker" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:descendantFocusability="blocksDescendants"/> | ||
|
||
<NumberPicker | ||
android:id="@+id/dayPicker" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:descendantFocusability="blocksDescendants"/> | ||
|
||
</LinearLayout> |
Oops, something went wrong.