Skip to content

Commit

Permalink
Merge pull request #41 from thanhpd/feat/94
Browse files Browse the repository at this point in the history
Profile Settings: Create a new Profile menu item in settings and open new screen accordingly
  • Loading branch information
thanhpd committed Mar 23, 2024
2 parents 2a0695c + 4a3f78e commit 51e530a
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public class MainSettingsFragment extends PreferenceFragmentCompat {
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.settings);

findPreference(getString(R.string.settings_profile_key)).setOnPreferenceClickListener(preference -> {
((SettingsActivity) getActivity()).openScreen(getString(R.string.settings_profile_key));
return true;
});

findPreference(getString(R.string.settings_defaults_key)).setOnPreferenceClickListener(preference -> {
((SettingsActivity) getActivity()).openScreen(getString(R.string.settings_defaults_key));
return true;
Expand Down Expand Up @@ -67,4 +72,4 @@ public void onDisplayPreferenceDialog(@NonNull Preference preference) {

super.onDisplayPreferenceDialog(preference);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package de.dennisguse.opentracks.settings;

import android.content.SharedPreferences;
import android.os.Bundle;

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);
}

@Override
public void onStart() {
super.onStart();
((SettingsActivity) getActivity()).getSupportActionBar().setTitle(R.string.settings_profile_title);
}

@Override
public void onResume() {
super.onResume();
PreferencesUtils.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}

@Override
public void onPause() {
super.onPause();
PreferencesUtils.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ private PreferenceFragmentCompat getPreferenceScreen(String key) {

if (key.equals(getString(R.string.settings_defaults_key))) {
fragment = new DefaultsSettingsFragment();
} else if (key.equals(getString(R.string.settings_profile_key))) {
fragment = new ProfileSettingsFragment();
} else if (key.equals(getString(R.string.settings_ui_key))) {
fragment = new UserInterfaceSettingsFragment();
} else if (key.equals(getString(R.string.settings_gps_key))) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/res/drawable/ic_profile.xml
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>
14 changes: 14 additions & 0 deletions src/main/res/layout/fragment_profile_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".settings.ProfileSettingsFragment">

<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />

</FrameLayout>
7 changes: 7 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ limitations under the License.
<string name="settings_announcements_average_speed_pace">Average speed/pace</string>
<string name="settings_announcements_lap_speed_pace">Lap speed/pace</string>

<!-- Settings Profile -->
<string name="settings_profile_title">Profile</string>
<string name="settings_profile_summary">Profile management</string>
<string name="settings_profile_key">settingsProfile</string>

<!-- Custom Layout -->


Expand Down Expand Up @@ -709,4 +714,6 @@ limitations under the License.
<string name="always">Always</string>

<string name="introduction_osm_dashboard">OpenTracks itself does not provide a map. Please install OSMDashboard to view your recordings on a map.</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
5 changes: 5 additions & 0 deletions src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/menu_settings">
<Preference
android:icon="@drawable/ic_profile"
android:key="@string/settings_profile_key"
android:summary="@string/settings_profile_summary"
android:title="@string/settings_profile_title" />

<Preference
android:icon="@drawable/ic_units"
Expand Down
7 changes: 7 additions & 0 deletions src/main/res/xml/settings_profile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/settings_profile_title">

</PreferenceScreen>

0 comments on commit 51e530a

Please sign in to comment.