Add functionality to "Move all to history" button
This commit is contained in:
parent
535188de5f
commit
2df51d08f1
4 changed files with 25 additions and 12 deletions
|
@ -281,7 +281,8 @@ public class MapMarkersHelper {
|
|||
cancelAddressRequests();
|
||||
markersDbHelper.moveAllActiveMarkersToHistory();
|
||||
mapMarkers.clear();
|
||||
mapMarkersHistory = markersDbHelper.getMarkersHistory();
|
||||
mapMarkersHistory.clear();
|
||||
mapMarkersHistory.addAll(markersDbHelper.getMarkersHistory());
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
|
|
@ -129,12 +129,14 @@ 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() {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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,18 +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();
|
||||
((MapMarkersActiveFragment) adapter.getItem(0)).hideSnackbar();
|
||||
historyFragment.updateAdapter();
|
||||
activeFragment.hideSnackbar();
|
||||
}
|
||||
viewPager.setCurrentItem(1);
|
||||
optionsButton.setVisibility(View.GONE);
|
||||
|
@ -132,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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -165,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
|
||||
|
|
Loading…
Reference in a new issue