Move sort button to toolbar

This commit is contained in:
Vitaliy 2020-09-22 13:02:34 +03:00
parent 525ce78e00
commit 9cf447eab2
4 changed files with 46 additions and 14 deletions

View file

@ -11,6 +11,9 @@
Thx - Hardy
-->
<string name="sort_name_ascending">Name: A Z</string>
<string name="sort_name_descending">Name: Z A</string>
<string name="sort_last_modified">Last modified</string>
<string name="release_3_8">
• Updated "Plan a route" function: allows using different navigation types per segment and the inclusion of tracks\n\n
• New "Appearance" menu for tracks: select color, thickness, display direction arrows, start/finish icons\n\n

View file

@ -88,10 +88,14 @@ public abstract class OsmandExpandableListFragment extends BaseOsmAndFragment
public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconId, int menuItemType,
boolean flipIconForRtl) {
int color = isLightActionBar() ? R.color.active_buttons_and_links_text_light : R.color.active_buttons_and_links_text_dark;
return createMenuItem(m, id, titleRes, iconId, menuItemType, false, color);
}
public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconId, int menuItemType,
boolean flipIconForRtl, int iconColor) {
OsmandApplication app = requireMyApplication();
Drawable d = iconId == 0 ? null : app.getUIUtilities().getIcon(iconId, isLightActionBar() ?
R.color.active_buttons_and_links_text_light :
R.color.active_buttons_and_links_text_dark);
Drawable d = iconId == 0 ? null : app.getUIUtilities().getIcon(iconId, iconColor);
MenuItem menuItem = m.add(0, id, 0, titleRes);
if (d != null) {
if (flipIconForRtl) {

View file

@ -19,6 +19,7 @@ import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
@ -83,7 +84,6 @@ import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.TracksSortByMode;
import net.osmand.plus.widgets.IconPopupMenu;
import java.io.File;
import java.text.Collator;
@ -436,10 +436,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
public void onCreateOptionsMenu(Menu menu, @NonNull MenuInflater inflater) {
menu.clear();
MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_dark, MenuItem.SHOW_AS_ACTION_ALWAYS
| MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_dark,
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
SearchView searchView = new SearchView(getActivity());
FavoritesActivity.updateSearchView(getActivity(), searchView);
mi.setActionView(searchView);
@ -475,6 +475,24 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
}
});
menu.addSubMenu(Menu.NONE, R.string.shared_string_sort, Menu.NONE, R.string.shared_string_sort);
SubMenu sortMenu = menu.findItem(R.string.shared_string_sort).getSubMenu();
mi = sortMenu.getItem();
mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
mi.setIcon(getIcon(R.drawable.ic_sort_waypoint_dark, isLightActionBar() ? R.color.active_buttons_and_links_text_light : R.color.active_buttons_and_links_text_dark));
for (final TracksSortByMode mode : TracksSortByMode.values()) {
mi = createMenuItem(sortMenu, mode.getNameId(), mode.getNameId(), mode.getIconId(),
MenuItem.SHOW_AS_ACTION_ALWAYS, false, R.color.icon_color_default_light);
mi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
updateTracksSort(mode);
return false;
}
});
}
if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
menu = ((FavoritesActivity) getActivity()).getClearToolbar(true).getMenu();
} else {
@ -574,9 +592,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
((FavoritesActivity) getActivity()).addTrack();
}
private void updateTracksSort() {
sortByName = !sortByName;
app.getSettings().SORT_TRACKS_BY_NAME.set(sortByName);
private void updateTracksSort(TracksSortByMode sortByMode) {
this.sortByMode = sortByMode;
app.getSettings().TRACKS_SORT_BY_MODE.set(sortByMode);
reloadTracks();
}

View file

@ -4104,13 +4104,15 @@ public class OsmandSettings {
}
public enum TracksSortByMode {
BY_DATE(R.drawable.ic_action_time_start),
BY_NAME_ASCENDING(R.drawable.ic_action_sort_by_name_ascending),
BY_NAME_DESCENDING(R.drawable.ic_action_sort_by_name_descending);
BY_DATE(R.string.sort_last_modified, R.drawable.ic_action_time_start),
BY_NAME_ASCENDING(R.string.sort_name_ascending, R.drawable.ic_action_sort_by_name_ascending),
BY_NAME_DESCENDING(R.string.sort_name_descending, R.drawable.ic_action_sort_by_name_descending);
private final int iconId;
private final int nameId;
TracksSortByMode(int iconId) {
TracksSortByMode(int nameId, int iconId) {
this.nameId = nameId;
this.iconId = iconId;
}
@ -4122,6 +4124,11 @@ public class OsmandSettings {
return this == BY_DATE;
}
@StringRes
public int getNameId() {
return nameId;
}
@DrawableRes
public int getIconId() {
return iconId;