Replaced tabs with bottom navigation at track fragment

This commit is contained in:
Alexey Kulish 2018-05-07 19:44:52 +03:00
parent bf6d670105
commit 36d6bf5d39
7 changed files with 275 additions and 175 deletions

View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/track_activity_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/wikivoyage_card_bg_color"
android:visibility="gone"
tools:visibility="visible"
app:itemBackground="?attr/wikivoyage_card_bg_color"
app:menu="@menu/track_bottom_navigation"
tools:itemIconTint="@color/bottom_navigation_color_selector_light"
tools:itemTextColor="@color/bottom_navigation_color_selector_light"/>
</LinearLayout>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_track"
android:icon="@drawable/ic_action_polygom_dark"
android:title="@string/gpx_track"/>
<item
android:id="@+id/action_points"
android:icon="@drawable/ic_action_folder"
android:title="@string/points"/>
</menu>

View file

@ -87,6 +87,12 @@ public class AndroidUtils {
} }
public static ColorStateList createBottomNavColorStateList(Context ctx, boolean nightMode) {
return AndroidUtils.createCheckedColorStateList(ctx, nightMode,
R.color.icon_color, R.color.wikivoyage_active_light,
R.color.icon_color, R.color.wikivoyage_active_dark);
}
public static String trimExtension(String src) { public static String trimExtension(String src) {
if (src != null) { if (src != null) {
int index = src.lastIndexOf('.'); int index = src.lastIndexOf('.');

View file

@ -1,13 +1,15 @@
package net.osmand.plus.activities; package net.osmand.plus.activities;
import android.content.Intent; import android.content.Intent;
import android.content.res.ColorStateList;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -34,7 +36,6 @@ import net.osmand.plus.myplaces.SplitSegmentDialogFragment;
import net.osmand.plus.myplaces.TrackPointFragment; import net.osmand.plus.myplaces.TrackPointFragment;
import net.osmand.plus.myplaces.TrackSegmentFragment; import net.osmand.plus.myplaces.TrackSegmentFragment;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import java.io.File; import java.io.File;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -49,7 +50,6 @@ public class TrackActivity extends TabActivity {
public static final String CURRENT_RECORDING = "CURRENT_RECORDING"; public static final String CURRENT_RECORDING = "CURRENT_RECORDING";
protected List<WeakReference<Fragment>> fragList = new ArrayList<>(); protected List<WeakReference<Fragment>> fragList = new ArrayList<>();
private OsmandApplication app; private OsmandApplication app;
protected PagerSlidingTabStrip slidingTabLayout;
private File file = null; private File file = null;
private GPXFile gpxFile; private GPXFile gpxFile;
private GpxDataItem gpxDataItem; private GpxDataItem gpxDataItem;
@ -79,13 +79,13 @@ public class TrackActivity extends TabActivity {
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
if (actionBar != null) { if (actionBar != null) {
if(file != null) { if (file != null) {
String fn = file.getName().replace(".gpx", "").replace("/", " ").replace("_", " "); String fn = file.getName().replace(".gpx", "").replace("/", " ").replace("_", " ");
actionBar.setTitle(fn); actionBar.setTitle(fn);
} else { } else {
actionBar.setTitle(getString(R.string.shared_string_currently_recording_track)); actionBar.setTitle(getString(R.string.shared_string_currently_recording_track));
} }
actionBar.setElevation(0); actionBar.setElevation(AndroidUtils.dpToPx(app, 4f));
} }
if (intent.hasExtra(OPEN_POINTS_TAB)) { if (intent.hasExtra(OPEN_POINTS_TAB)) {
openPointsTab = true; openPointsTab = true;
@ -93,7 +93,7 @@ public class TrackActivity extends TabActivity {
if (intent.hasExtra(OPEN_TRACKS_LIST)) { if (intent.hasExtra(OPEN_TRACKS_LIST)) {
openTracksList = true; openTracksList = true;
} }
setContentView(R.layout.tab_content); setContentView(R.layout.track_content);
} }
public void addPoint(PointDescription pointDescription) { public void addPoint(PointDescription pointDescription) {
@ -239,17 +239,11 @@ public class TrackActivity extends TabActivity {
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
stopped = false; stopped = false;
slidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs);
if (slidingTabLayout != null) {
slidingTabLayout.setShouldExpand(true);
mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager = (ViewPager) findViewById(R.id.pager);
setViewPagerAdapter(mViewPager, new ArrayList<TabActivity.TabItem>()); setViewPagerAdapter(mViewPager, new ArrayList<TabActivity.TabItem>());
slidingTabLayout.setViewPager(mViewPager);
new GPXFileLoaderTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); new GPXFileLoaderTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
} }
}
public OsmandApplication getMyApplication() { public OsmandApplication getMyApplication() {
return (OsmandApplication) getApplication(); return (OsmandApplication) getApplication();
@ -266,16 +260,6 @@ public class TrackActivity extends TabActivity {
stopped = true; stopped = true;
} }
public Toolbar getClearToolbar(boolean visible) {
final Toolbar tb = (Toolbar) findViewById(R.id.bottomControls);
if (tb != null) {
tb.setTitle(null);
tb.getMenu().clear();
tb.setVisibility(visible ? View.VISIBLE : View.GONE);
}
return tb;
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId(); int itemId = item.getItemId();
@ -324,14 +308,70 @@ public class TrackActivity extends TabActivity {
return getGpx() != null && getGpx().hasRtePt(); return getGpx() != null && getGpx().hasRtePt();
} }
@Nullable
public GPXFile getGpx() { public GPXFile getGpx() {
return gpxFile; return gpxFile;
} }
@Nullable
public GpxDataItem getGpxDataItem() { public GpxDataItem getGpxDataItem() {
return gpxDataItem; return gpxDataItem;
} }
private void onGPXFileReady(@Nullable GPXFile gpxFile) {
setGpx(gpxFile);
setGpxDataItem(file != null ? app.getGpxDatabase().getItem(file) : null);
for (WeakReference<Fragment> f : fragList) {
Fragment frag = f.get();
if (frag instanceof TrackSegmentFragment) {
((TrackSegmentFragment) frag).updateContent();
} else if (frag instanceof SplitSegmentDialogFragment) {
((SplitSegmentDialogFragment) frag).updateContent();
} else if (frag instanceof TrackPointFragment) {
((TrackPointFragment) frag).setContent();
}
}
OsmandFragmentPagerAdapter pagerAdapter = (OsmandFragmentPagerAdapter) mViewPager.getAdapter();
if (pagerAdapter != null) {
pagerAdapter.addTab(getTabIndicator(R.string.gpx_track, TrackSegmentFragment.class));
if (isHavingWayPoints() || isHavingRoutePoints()) {
pagerAdapter.addTab(getTabIndicator(R.string.points, TrackPointFragment.class));
if (openPointsTab) {
mViewPager.setCurrentItem(1, false);
}
}
if (pagerAdapter.getCount() > 1) {
boolean nightMode = !app.getSettings().isLightContent();
final ColorStateList navColorStateList = AndroidUtils.createBottomNavColorStateList(this, nightMode);
final BottomNavigationView bottomNav = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNav.setItemIconTintList(navColorStateList);
bottomNav.setItemTextColor(navColorStateList);
bottomNav.setVisibility(View.VISIBLE);
bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int position = -1;
switch (item.getItemId()) {
case R.id.action_track:
position = 0;
break;
case R.id.action_points:
position = 1;
break;
}
if (position != -1 && position != mViewPager.getCurrentItem()) {
mViewPager.setCurrentItem(position);
return true;
}
return false;
}
});
}
}
}
private static class GPXFileLoaderTask extends AsyncTask<Void, Void, GPXFile> { private static class GPXFileLoaderTask extends AsyncTask<Void, Void, GPXFile> {
private OsmandApplication app; private OsmandApplication app;
@ -383,41 +423,14 @@ public class TrackActivity extends TabActivity {
return result; return result;
} }
protected void onPostExecute(GPXFile result) { @Override
protected void onPostExecute(@Nullable GPXFile result) {
TrackActivity activity = getTrackActivity(); TrackActivity activity = getTrackActivity();
if (activity != null) { if (activity != null) {
activity.setSupportProgressBarIndeterminateVisibility(false); activity.setSupportProgressBarIndeterminateVisibility(false);
if (!activity.stopped) { if (!activity.stopped) {
activity.setGpx(result); activity.onGPXFileReady(result);
activity.setGpxDataItem(file != null ? app.getGpxDatabase().getItem(file) : null);
for (WeakReference<Fragment> f : activity.fragList) {
Fragment frag = f.get();
if (frag instanceof TrackSegmentFragment) {
((TrackSegmentFragment) frag).updateContent();
} else if (frag instanceof SplitSegmentDialogFragment) {
((SplitSegmentDialogFragment) frag).updateContent();
} else if (frag instanceof TrackPointFragment) {
((TrackPointFragment) frag).setContent();
}
}
OsmandFragmentPagerAdapter pagerAdapter = (OsmandFragmentPagerAdapter) activity.mViewPager.getAdapter();
if (pagerAdapter != null) {
pagerAdapter.addTab(activity.getTabIndicator(R.string.gpx_track, TrackSegmentFragment.class));
if (activity.isHavingWayPoints() || activity.isHavingRoutePoints()) {
pagerAdapter.addTab(activity.getTabIndicator(R.string.points, TrackPointFragment.class));
if (activity.openPointsTab) {
activity.mViewPager.setCurrentItem(1, false);
}
} else {
activity.slidingTabLayout.setVisibility(View.GONE);
ActionBar actionBar = activity.getSupportActionBar();
if (actionBar != null) {
actionBar.setElevation(AndroidUtils.dpToPx(app, 4f));
}
}
}
} }
} }
} }

View file

@ -57,11 +57,11 @@ import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.base.OsmandExpandableListFragment; import net.osmand.plus.base.OsmandExpandableListFragment;
import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.measurementtool.NewGpxData; import net.osmand.plus.measurementtool.NewGpxData;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.io.File; import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -248,11 +248,17 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
} }
private void addPoint(PointDescription pointDescription) { private void addPoint(PointDescription pointDescription) {
getTrackActivity().addPoint(pointDescription); TrackActivity activity = getTrackActivity();
if (activity != null) {
activity.addPoint(pointDescription);
}
} }
private void addNewGpxData(NewGpxData.ActionType actionType) { private void addNewGpxData(NewGpxData.ActionType actionType) {
getTrackActivity().addNewGpxData(actionType); TrackActivity activity = getTrackActivity();
if (activity != null) {
activity.addNewGpxData(actionType);
}
} }
private void openMenu() { private void openMenu() {
@ -277,16 +283,21 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
menuOpened = false; menuOpened = false;
} }
@Nullable
public TrackActivity getTrackActivity() { public TrackActivity getTrackActivity() {
return (TrackActivity) getActivity(); return (TrackActivity) getActivity();
} }
@Nullable
private GPXFile getGpx() { private GPXFile getGpx() {
return getTrackActivity().getGpx(); TrackActivity activity = getTrackActivity();
return activity != null ? activity.getGpx() : null;
} }
@Nullable
private GpxDataItem getGpxDataItem() { private GpxDataItem getGpxDataItem() {
return getTrackActivity().getGpxDataItem(); TrackActivity activity = getTrackActivity();
return activity != null ? activity.getGpxDataItem() : null;
} }
private void expandAllGroups() { private void expandAllGroups() {
@ -322,8 +333,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
private List<GpxDisplayGroup> filterGroups() { private List<GpxDisplayGroup> filterGroups() {
List<GpxDisplayGroup> groups = new ArrayList<>(); List<GpxDisplayGroup> groups = new ArrayList<>();
if (getTrackActivity() != null) { TrackActivity activity = getTrackActivity();
List<GpxDisplayGroup> result = getTrackActivity().getGpxFile(false); if (activity != null) {
List<GpxDisplayGroup> result = activity.getGpxFile(false);
for (GpxDisplayGroup group : result) { for (GpxDisplayGroup group : result) {
boolean add = hasFilterType(group.getType()); boolean add = hasFilterType(group.getType());
if (isArgumentTrue(ARG_TO_FILTER_SHORT_TRACKS)) { if (isArgumentTrue(ARG_TO_FILTER_SHORT_TRACKS)) {
@ -398,17 +410,19 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
} }
private void shareItems() { private void shareItems() {
final Uri fileUri = Uri.fromFile(new File(getGpx().path)); GPXFile gpxFile = getGpx();
if (gpxFile != null) {
final Uri fileUri = Uri.fromFile(new File(gpxFile.path));
final Intent sendIntent = new Intent(Intent.ACTION_SEND); final Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
sendIntent.setType("application/gpx+xml"); sendIntent.setType("application/gpx+xml");
startActivity(sendIntent); startActivity(sendIntent);
} }
}
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear(); menu.clear();
getTrackActivity().getClearToolbar(false);
MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_dark, MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_dark,
R.drawable.ic_action_search_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); R.drawable.ic_action_search_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
searchView = new SearchView(getActivity()); searchView = new SearchView(getActivity());
@ -450,10 +464,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
if (!MenuItemCompat.isActionViewExpanded(mi)) { if (!MenuItemCompat.isActionViewExpanded(mi)) {
createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark,
R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER); R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER);
if (getGpx().path != null) { GPXFile gpxFile = getGpx();
if (gpxFile != null && gpxFile.path != null) {
final MapMarkersHelper markersHelper = app.getMapMarkersHelper(); final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
final boolean synced = markersHelper.getMarkersGroup(getGpx()) != null; final boolean synced = markersHelper.getMarkersGroup(getGpx()) != null;
createMenuItem(menu, SELECT_MAP_MARKERS_ID, synced ? R.string.remove_from_map_markers createMenuItem(menu, SELECT_MAP_MARKERS_ID, synced ? R.string.remove_from_map_markers
@ -546,92 +560,44 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
} }
private void deleteItems() { private void deleteItems() {
new AsyncTask<Void, Object, String>() { new DeletePointsTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@Override
protected void onPreExecute() {
showProgressBar();
}
@Override
protected void onPostExecute(String result) {
hideProgressBar();
adapter.synchronizeGroups(filterGroups());
}
@Override
protected String doInBackground(Void... params) {
GPXFile gpx = getGpx();
SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper();
if (gpx != null) {
for (GpxDisplayItem item : getSelectedItems()) {
if (gpx.showCurrentTrack) {
savingTrackHelper.deletePointData(item.locationStart);
} else {
if (item.group.getType() == GpxDisplayItemType.TRACK_POINTS) {
gpx.deleteWptPt(item.locationStart);
} else if (item.group.getType() == GpxDisplayItemType.TRACK_ROUTE_POINTS) {
gpx.deleteRtePt(item.locationStart);
}
}
}
if (!gpx.showCurrentTrack) {
GPXUtilities.writeGpxFile(new File(gpx.path), gpx, app);
boolean selected = app.getSelectedGpxHelper().getSelectedFileByPath(gpx.path) != null;
if (selected) {
app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
}
}
syncGpx(gpx);
}
selectedItems.clear();
selectedGroups.clear();
return getString(R.string.points_delete_multiple_succesful);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private void syncGpx(GPXFile gpxFile) {
MapMarkersHelper helper = app.getMapMarkersHelper();
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
if (group != null) {
helper.runSynchronization(group);
}
} }
private void addOrRemoveMapMarkersSyncGroup() { private void addOrRemoveMapMarkersSyncGroup() {
final MapMarkersHelper markersHelper = app.getMapMarkersHelper(); final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
MapMarkersGroup markersSearch = markersHelper.getMarkersGroup(getGpx()); TrackActivity activity = getTrackActivity();
if (activity == null) {
return;
}
GPXFile gpxFile = getGpx();
MapMarkersGroup markersSearch = markersHelper.getMarkersGroup(gpxFile);
final MapMarkersGroup markersGr; final MapMarkersGroup markersGr;
if (markersSearch != null) { if (markersSearch != null) {
markersGr = markersSearch; markersGr = markersSearch;
markersHelper.removeMarkersGroup(markersGr); markersHelper.removeMarkersGroup(markersGr);
} else if (gpxFile != null) {
markersGr = markersHelper.addOrEnableGroup(gpxFile);
} else { } else {
markersGr = markersHelper.addOrEnableGroup(getGpx()); markersGr = null;
} }
final boolean synced = markersGr != null; if (markersGr != null) {
getActionBarActivity().invalidateOptionsMenu(); activity.invalidateOptionsMenu();
GPXFile gpxFile = getTrackActivity().getGpx();
if (gpxFile != null) { if (gpxFile != null) {
app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false); app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false);
} }
hideTransparentOverlay(); hideTransparentOverlay();
closeMenu(); closeMenu();
updateMenuFabVisibility(false); updateMenuFabVisibility(false);
Snackbar snackbar = Snackbar.make(mainView, synced ? R.string.waypoints_removed_from_map_markers : R.string.waypoints_added_to_map_markers, Snackbar snackbar = Snackbar.make(mainView, R.string.waypoints_removed_from_map_markers,
Snackbar.LENGTH_LONG) Snackbar.LENGTH_LONG)
.setAction(synced ? R.string.shared_string_undo : R.string.view, new View.OnClickListener() { .setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (synced) { TrackActivity trackActivity = getTrackActivity();
if (trackActivity != null) {
markersHelper.removeMarkersGroup(markersGr); markersHelper.removeMarkersGroup(markersGr);
getActionBarActivity().invalidateOptionsMenu(); trackActivity.invalidateOptionsMenu();
} else {
Bundle args = new Bundle();
args.putString(MapMarkersGroup.MARKERS_SYNC_GROUP_ID, markersGr.getId());
MapActivity.launchMapActivityMoveToTop(getTrackActivity(), MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS, args);
} }
} }
}); });
@ -645,6 +611,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark); AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
snackbar.show(); snackbar.show();
} }
}
private void updateMenuFabVisibility(boolean visible) { private void updateMenuFabVisibility(boolean visible) {
menuFab.setVisibility(visible ? View.VISIBLE : View.GONE); menuFab.setVisibility(visible ? View.VISIBLE : View.GONE);
@ -689,16 +656,17 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
} }
private void selectFavoritesImpl() { private void selectFavoritesImpl() {
if (getSelectedItemsCount() > 0) { TrackActivity activity = getTrackActivity();
AlertDialog.Builder b = new AlertDialog.Builder(getTrackActivity()); if (activity != null && getSelectedItemsCount() > 0) {
final EditText editText = new EditText(getTrackActivity()); AlertDialog.Builder b = new AlertDialog.Builder(activity);
final EditText editText = new EditText(activity);
String name = getSelectedItems().iterator().next().group.getName(); String name = getSelectedItems().iterator().next().group.getName();
if (name.indexOf('\n') > 0) { if (name.indexOf('\n') > 0) {
name = name.substring(0, name.indexOf('\n')); name = name.substring(0, name.indexOf('\n'));
} }
editText.setText(name); editText.setText(name);
int leftMargin = AndroidUtils.dpToPx(getContext(), 16f); int leftMargin = AndroidUtils.dpToPx(activity, 16f);
int topMargin = AndroidUtils.dpToPx(getContext(), 8f); int topMargin = AndroidUtils.dpToPx(activity, 8f);
editText.setPadding(leftMargin, topMargin, leftMargin, topMargin); editText.setPadding(leftMargin, topMargin, leftMargin, topMargin);
b.setTitle(R.string.save_as_favorites_points); b.setTitle(R.string.save_as_favorites_points);
b.setView(editText); b.setView(editText);
@ -885,8 +853,8 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
description.setText(getString(R.string.route_points_category_name)); description.setText(getString(R.string.route_points_category_name));
} }
if (selectionMode) {
final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item); final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item);
if (selectionMode) {
ch.setVisibility(View.VISIBLE); ch.setVisibility(View.VISIBLE);
ch.setChecked(selectedGroups.contains(groupPosition)); ch.setChecked(selectedGroups.contains(groupPosition));
@ -914,7 +882,6 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
} }
}); });
} else { } else {
final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item);
ch.setVisibility(View.GONE); ch.setVisibility(View.GONE);
} }
row.findViewById(R.id.category_icon).setVisibility(View.GONE); row.findViewById(R.id.category_icon).setVisibility(View.GONE);
@ -1085,4 +1052,74 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
expandAllGroups(); expandAllGroups();
} }
} }
private static class DeletePointsTask extends AsyncTask<Void, Void, Void> {
private OsmandApplication app;
private WeakReference<TrackPointFragment> fragmentRef;
private GPXFile gpx;
private Set<GpxDisplayItem> selectedItems;
DeletePointsTask(TrackPointFragment fragment) {
this.app = fragment.getMyApplication();
this.fragmentRef = new WeakReference<>(fragment);
this.gpx = fragment.getGpx();
this.selectedItems = fragment.getSelectedItems();
}
@Override
protected void onPreExecute() {
TrackPointFragment fragment = fragmentRef.get();
if (fragment != null) {
fragment.showProgressBar();
}
}
@Override
protected Void doInBackground(Void... params) {
SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper();
if (gpx != null) {
for (GpxDisplayItem item : selectedItems) {
if (gpx.showCurrentTrack) {
savingTrackHelper.deletePointData(item.locationStart);
} else {
if (item.group.getType() == GpxDisplayItemType.TRACK_POINTS) {
gpx.deleteWptPt(item.locationStart);
} else if (item.group.getType() == GpxDisplayItemType.TRACK_ROUTE_POINTS) {
gpx.deleteRtePt(item.locationStart);
}
}
}
if (!gpx.showCurrentTrack) {
GPXUtilities.writeGpxFile(new File(gpx.path), gpx, app);
boolean selected = app.getSelectedGpxHelper().getSelectedFileByPath(gpx.path) != null;
if (selected) {
app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
}
}
syncGpx(gpx);
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
TrackPointFragment fragment = fragmentRef.get();
if (fragment != null) {
fragment.selectedItems.clear();
fragment.selectedGroups.clear();
fragment.hideProgressBar();
fragment.adapter.synchronizeGroups(fragment.filterGroups());
}
}
private void syncGpx(GPXFile gpxFile) {
MapMarkersHelper helper = app.getMapMarkersHelper();
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
if (group != null) {
helper.runSynchronization(group);
}
}
}
} }

View file

@ -339,7 +339,6 @@ public class TrackSegmentFragment extends OsmAndListFragment {
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear(); menu.clear();
getTrackActivity().getClearToolbar(false);
if (getGpx() != null && getGpx().path != null && !getGpx().showCurrentTrack) { if (getGpx() != null && getGpx().path != null && !getGpx().showCurrentTrack) {
MenuItem item = menu.add(R.string.shared_string_share).setIcon(R.drawable.ic_action_gshare_dark) MenuItem item = menu.add(R.string.shared_string_share).setIcon(R.drawable.ic_action_gshare_dark)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

View file

@ -111,7 +111,7 @@ public class WikivoyageExploreDialogFragment extends WikiBaseDialogFragment impl
viewPager.setSwipeLocked(true); viewPager.setSwipeLocked(true);
viewPager.setAdapter(new ViewPagerAdapter(childFm)); viewPager.setAdapter(new ViewPagerAdapter(childFm));
final ColorStateList navColorStateList = createBottomNavColorStateList(); final ColorStateList navColorStateList = AndroidUtils.createBottomNavColorStateList(getContext(), nightMode);
final BottomNavigationView bottomNav = (BottomNavigationView) mainView.findViewById(R.id.bottom_navigation); final BottomNavigationView bottomNav = (BottomNavigationView) mainView.findViewById(R.id.bottom_navigation);
bottomNav.setItemIconTintList(navColorStateList); bottomNav.setItemIconTintList(navColorStateList);
bottomNav.setItemTextColor(navColorStateList); bottomNav.setItemTextColor(navColorStateList);
@ -228,12 +228,6 @@ public class WikivoyageExploreDialogFragment extends WikiBaseDialogFragment impl
} }
} }
private ColorStateList createBottomNavColorStateList() {
return AndroidUtils.createCheckedColorStateList(getContext(), nightMode,
R.color.icon_color, R.color.wikivoyage_active_light,
R.color.icon_color, R.color.wikivoyage_active_dark);
}
public static boolean showInstance(FragmentManager fm) { public static boolean showInstance(FragmentManager fm) {
try { try {
WikivoyageExploreDialogFragment fragment = new WikivoyageExploreDialogFragment(); WikivoyageExploreDialogFragment fragment = new WikivoyageExploreDialogFragment();