Merge branch 'sasha_pasha_branch' of ssh://github.com/osmandapp/Osmand into sasha_pasha_branch

This commit is contained in:
PavelRatushny 2017-09-07 18:17:43 +03:00
commit 540d3c00ae
5 changed files with 47 additions and 25 deletions

View file

@ -241,9 +241,7 @@ public class MapMarkersHelper {
if (marker != null) {
cancelPointAddressRequests(marker.point);
markersDbHelper.moveMarkerToHistory(marker);
mapMarkers.remove(marker);
marker.history = true;
mapMarkersHistory.add(marker);
loadMarkers();
refresh();
}
}
@ -321,7 +319,8 @@ public class MapMarkersHelper {
cancelAddressRequests();
markersDbHelper.moveAllActiveMarkersToHistory();
mapMarkers.clear();
mapMarkersHistory = markersDbHelper.getMarkersHistory();
mapMarkersHistory.clear();
mapMarkersHistory.addAll(markersDbHelper.getMarkersHistory());
refresh();
}

View file

@ -67,6 +67,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
public void onDragEnded(RecyclerView.ViewHolder holder) {
toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
hideSnackbar();
mapActivity.getMyApplication().getMapMarkersHelper().changeActiveMarkerPositionInDb(toPosition);
}
}
@ -127,9 +128,15 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
}
}
void hideSnackbar() {
if (adapter != null) {
adapter.hideSnackbar();
}
}
private void updateLocationUi() {
final MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {
if (mapActivity != null && adapter != null) {
mapActivity.getMyApplication().runInUIThread(new Runnable() {
@Override
public void run() {

View file

@ -314,8 +314,11 @@ public class MapMarkersDbHelper {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_ACTIVE + " = ? " +
"WHERE " + MARKERS_COL_ACTIVE + " = ?", new Object[]{0, 1});
long visitedDate = System.currentTimeMillis();
db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " +
MARKERS_COL_ACTIVE + " = ?, " +
MARKERS_COL_VISITED + " = ? " +
"WHERE " + MARKERS_COL_ACTIVE + " = ?", new Object[]{0, visitedDate, 1});
} finally {
db.close();
}
@ -323,9 +326,6 @@ public class MapMarkersDbHelper {
}
public void restoreMapMarkerFromHistory(MapMarker marker) {
if (!marker.history) {
return;
}
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
@ -333,8 +333,9 @@ public class MapMarkersDbHelper {
db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " +
MARKERS_COL_ACTIVE + " = ?, " +
MARKERS_COL_NEXT_KEY + " = ? " +
"WHERE " + MARKERS_COL_ID + " = ?",
new Object[]{1, active.size() > 0 ? active.get(0).id : TAIL_NEXT_VALUE, marker.id});
"WHERE " + MARKERS_COL_ID + " = ? " +
"AND " + MARKERS_COL_ACTIVE + " = ?",
new Object[]{1, active.size() > 0 ? active.get(0).id : TAIL_NEXT_VALUE, marker.id, 0});
} finally {
db.close();
}
@ -362,14 +363,13 @@ public class MapMarkersDbHelper {
}
public void removeMarkerFromHistory(MapMarker marker) {
if (!marker.history) {
return;
}
SQLiteConnection db = openConnection(true);
if (db != null) {
try {
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_ID + " = ?",
new Object[]{marker.id});
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME +
" WHERE " + MARKERS_COL_ID + " = ?" +
" AND " + MARKERS_COL_ACTIVE + " = ?",
new Object[]{marker.id, 0});
} finally {
db.close();
}

View file

@ -28,6 +28,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
public static final String TAG = "MapMarkersDialogFragment";
private MapMarkersActiveFragment activeFragment;
private MapMarkersHistoryFragment historyFragment;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -40,6 +43,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
activeFragment = new MapMarkersActiveFragment();
historyFragment = new MapMarkersHistoryFragment();
FragmentManager fragmentManager = getChildFragmentManager();
Fragment markerOptionsFragment = fragmentManager.findFragmentByTag(MarkerOptionsBottomSheetDialogFragment.TAG);
if (markerOptionsFragment != null) {
@ -77,17 +83,18 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_active:
((MapMarkersActiveFragment) adapter.getItem(0)).startLocationUpdate();
activeFragment.startLocationUpdate();
if (viewPager.getCurrentItem() != 0) {
((MapMarkersActiveFragment) adapter.getItem(0)).updateAdapter();
activeFragment.updateAdapter();
}
viewPager.setCurrentItem(0);
optionsButton.setVisibility(View.VISIBLE);
return true;
case R.id.action_history:
((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate();
activeFragment.stopLocationUpdate();
if (viewPager.getCurrentItem() != 1) {
((MapMarkersHistoryFragment) adapter.getItem(1)).updateAdapter();
historyFragment.updateAdapter();
activeFragment.hideSnackbar();
}
viewPager.setCurrentItem(1);
optionsButton.setVisibility(View.GONE);
@ -131,7 +138,8 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
@Override
public void moveAllToHistoryOnClick() {
Toast.makeText(getContext(), "Move all to history", Toast.LENGTH_SHORT).show();
mapActivity.getMyApplication().getMapMarkersHelper().removeActiveMarkers();
activeFragment.updateAdapter();
}
};
}
@ -164,7 +172,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
MapMarkersViewPagerAdapter(FragmentManager fm) {
super(fm);
fragments = Arrays.asList(new MapMarkersActiveFragment(), new MapMarkersHistoryFragment());
fragments = Arrays.asList(activeFragment, historyFragment);
}
@Override

View file

@ -24,6 +24,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
private MapActivity mapActivity;
private List<MapMarker> markers;
private MapMarkersActiveAdapterListener listener;
private Snackbar snackbar;
private LatLon location;
private Float heading;
@ -103,14 +104,15 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
notifyItemRemoved(position);
Snackbar.make(holder.itemView, R.string.item_removed, Snackbar.LENGTH_LONG)
snackbar = Snackbar.make(holder.itemView, R.string.item_removed, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, position);
notifyItemInserted(position);
}
}).show();
});
snackbar.show();
}
});
@ -133,6 +135,12 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
return markers;
}
public void hideSnackbar() {
if (snackbar != null && snackbar.isShown()) {
snackbar.dismiss();
}
}
@Override
public boolean onItemMove(int from, int to) {
Collections.swap(markers, from, to);