MainSettingsFragment new UI with profiles list
This commit is contained in:
parent
aedb503597
commit
4812fa58f4
3 changed files with 105 additions and 35 deletions
|
@ -11,6 +11,8 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="reorder_profiles">Reorder</string>
|
||||
<string name="selected_profile">Selected profile</string>
|
||||
<string name="rendering_value_walkingRoutesOSMCNodes_name">Node networks</string>
|
||||
<string name="rendering_attr_showCycleNodeNetworkRoutes_name">Show node network cycle routes</string>
|
||||
<string name="join_segments">Join segments</string>
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
android:selectable="false" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="application_profiles"
|
||||
android:key="selected_profile"
|
||||
android:layout="@layout/preference_category_with_descr"
|
||||
android:title="@string/application_profiles" />
|
||||
android:title="@string/selected_profile" />
|
||||
|
||||
<Preference
|
||||
android:key="configure_profile"
|
||||
|
@ -30,13 +30,35 @@
|
|||
app:fragment="net.osmand.plus.settings.ConfigureProfileFragment"
|
||||
tools:icon="@drawable/ic_action_car_dark" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="app_profiles"
|
||||
android:layout="@layout/preference_category_with_descr"
|
||||
android:title="@string/application_profiles" />
|
||||
|
||||
<Preference
|
||||
android:key="manage_profiles"
|
||||
android:layout="@layout/preference_with_descr"
|
||||
android:layout="@layout/simple_divider_item"
|
||||
android:selectable="false" />
|
||||
|
||||
<Preference
|
||||
android:key="create_profile"
|
||||
android:layout="@layout/preference_button"
|
||||
android:persistent="false"
|
||||
android:summary="@string/manage_profiles_descr"
|
||||
android:title="@string/manage_profiles"
|
||||
tools:icon="@drawable/ic_action_manage_profiles" />
|
||||
android:title="@string/new_profile"
|
||||
tools:icon="@drawable/ic_action_plus" />
|
||||
|
||||
<Preference
|
||||
android:key="import_profile"
|
||||
android:layout="@layout/preference_button"
|
||||
android:persistent="false"
|
||||
android:title="@string/profile_import"
|
||||
tools:icon="@drawable/ic_action_import" />
|
||||
|
||||
<Preference
|
||||
android:key="reorder_profiles"
|
||||
android:layout="@layout/preference_button"
|
||||
android:persistent="false"
|
||||
android:title="@string/reorder_profiles"
|
||||
tools:icon="@drawable/ic_action_edit_dark" />
|
||||
|
||||
<Preference
|
||||
android:layout="@layout/card_bottom_divider"
|
||||
|
|
|
@ -1,24 +1,47 @@
|
|||
package net.osmand.plus.settings;
|
||||
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.support.v7.preference.SwitchPreferenceCompat;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.profiles.SettingsProfileFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MainSettingsFragment extends BaseSettingsFragment {
|
||||
|
||||
public static final String TAG = MainSettingsFragment.class.getSimpleName();
|
||||
|
||||
private static final String CONFIGURE_PROFILE = "configure_profile";
|
||||
private static final String APP_PROFILES = "app_profiles";
|
||||
private static final String SELECTED_PROFILE = "selected_profile";
|
||||
private static final String CREATE_PROFILE = "create_profile";
|
||||
private static final String IMPORT_PROFILE = "import_profile";
|
||||
private static final String REORDER_PROFILES = "reorder_profiles";
|
||||
private List<ApplicationMode> allAppModes;
|
||||
private Set<ApplicationMode> availableAppModes;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
allAppModes = new ArrayList<>(ApplicationMode.allPossibleValues());
|
||||
allAppModes.remove(ApplicationMode.DEFAULT);
|
||||
availableAppModes = new LinkedHashSet<>(ApplicationMode.values(getMyApplication()));
|
||||
availableAppModes.remove(ApplicationMode.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ColorRes
|
||||
|
@ -30,9 +53,13 @@ public class MainSettingsFragment extends BaseSettingsFragment {
|
|||
protected void setupPreferences() {
|
||||
Preference globalSettings = findPreference("global_settings");
|
||||
globalSettings.setIcon(getContentIcon(R.drawable.ic_action_settings));
|
||||
|
||||
PreferenceCategory selectedProfile = (PreferenceCategory) findPreference(SELECTED_PROFILE);
|
||||
selectedProfile.setIconSpaceReserved(false);
|
||||
setupConfigureProfilePref();
|
||||
setupManageProfilesPref();
|
||||
PreferenceCategory appProfiles = (PreferenceCategory) findPreference(APP_PROFILES);
|
||||
appProfiles.setIconSpaceReserved(false);
|
||||
setupAppProfiles(appProfiles);
|
||||
profileManagementPref();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,41 +68,60 @@ public class MainSettingsFragment extends BaseSettingsFragment {
|
|||
|
||||
String key = preference.getKey();
|
||||
if (CONFIGURE_PROFILE.equals(key)) {
|
||||
View iconContainer = holder.itemView.findViewById(R.id.icon_container);
|
||||
if (iconContainer != null) {
|
||||
int profileColor = getActiveProfileColor();
|
||||
int bgColor = UiUtilities.getColorWithAlpha(profileColor, 0.1f);
|
||||
Drawable backgroundDrawable;
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
|
||||
int selectedColor = UiUtilities.getColorWithAlpha(profileColor, 0.3f);
|
||||
Drawable background = getPaintedIcon(R.drawable.circle_background_light, bgColor);
|
||||
Drawable ripple = getPaintedIcon(R.drawable.ripple_circle, selectedColor);
|
||||
backgroundDrawable = new LayerDrawable(new Drawable[] {background, ripple});
|
||||
} else {
|
||||
backgroundDrawable = getPaintedIcon(R.drawable.circle_background_light, bgColor);
|
||||
}
|
||||
AndroidUtils.setBackground(iconContainer, backgroundDrawable);
|
||||
View selectedProfile = holder.itemView.findViewById(R.id.selectable_list_item);
|
||||
if (selectedProfile != null) {
|
||||
int activeProfileColor = getActiveProfileColor();
|
||||
Drawable backgroundDrawable = new ColorDrawable(UiUtilities.getColorWithAlpha(activeProfileColor, 0.15f));
|
||||
AndroidUtils.setBackground(selectedProfile, backgroundDrawable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupManageProfilesPref() {
|
||||
Preference manageProfiles = findPreference("manage_profiles");
|
||||
manageProfiles.setIcon(getContentIcon(R.drawable.ic_action_manage_profiles));
|
||||
manageProfiles.setFragment(SettingsProfileFragment.class.getName());
|
||||
}
|
||||
|
||||
private void setupConfigureProfilePref() {
|
||||
ApplicationMode selectedMode = getSelectedAppMode();
|
||||
|
||||
String title = selectedMode.toHumanString(getContext());
|
||||
String profileType = getAppModeDescription(getContext(), selectedMode);
|
||||
int iconRes = selectedMode.getIconRes();
|
||||
|
||||
Preference configureProfile = findPreference(CONFIGURE_PROFILE);
|
||||
configureProfile.setIcon(getPaintedIcon(iconRes, getActiveProfileColor()));
|
||||
configureProfile.setTitle(title);
|
||||
configureProfile.setSummary(profileType);
|
||||
}
|
||||
|
||||
private void profileManagementPref() {
|
||||
Preference createProfile = findPreference(CREATE_PROFILE);
|
||||
createProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_plus,
|
||||
isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
|
||||
Preference importProfile = findPreference(IMPORT_PROFILE);
|
||||
importProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_import,
|
||||
isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
|
||||
Preference reorderProfiles = findPreference(REORDER_PROFILES);
|
||||
reorderProfiles.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_edit_dark,
|
||||
isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
|
||||
}
|
||||
|
||||
private void setupAppProfiles(PreferenceCategory preferenceCategory) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app == null) {
|
||||
return;
|
||||
}
|
||||
for (ApplicationMode applicationMode : allAppModes) {
|
||||
boolean isAppProfileEnabled = availableAppModes.contains(applicationMode);
|
||||
SwitchPreferenceCompat pref = new SwitchPreferenceCompat(app);
|
||||
pref.setPersistent(false);
|
||||
pref.setKey(applicationMode.getStringKey());
|
||||
pref.setIcon(getAppProfilesIcon(applicationMode, isAppProfileEnabled));
|
||||
pref.setTitle(applicationMode.toHumanString(getContext()));
|
||||
pref.setSummary(getAppModeDescription(getContext(), applicationMode));
|
||||
pref.setChecked(isAppProfileEnabled);
|
||||
pref.setLayoutResource(R.layout.preference_with_descr_dialog_and_switch);
|
||||
preferenceCategory.addPreference(pref);
|
||||
}
|
||||
}
|
||||
|
||||
private Drawable getAppProfilesIcon(ApplicationMode applicationMode, boolean appProfileEnabled) {
|
||||
int iconResId = applicationMode.getIconRes();
|
||||
return appProfileEnabled ? app.getUIUtilities().getIcon(applicationMode.getIconRes(), applicationMode.getIconColorInfo().getColor(isNightMode()))
|
||||
: getIcon(iconResId, isNightMode() ? R.color.icon_color_secondary_dark : R.color.icon_color_secondary_light);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue