Fix dashboard bug

This commit is contained in:
Alexey Kulish 2016-02-25 23:27:23 +03:00
parent 3a492d1116
commit ead5ab5d5d
2 changed files with 57 additions and 22 deletions

View file

@ -85,7 +85,20 @@ public class ObservableListView extends ListView implements Scrollable {
init(); init();
} }
@Override public boolean isDragging() {
return mDragging;
}
public void clearParams() {
mPrevFirstVisiblePosition = 0;
mPrevFirstVisibleChildHeight = -1;
mPrevScrolledChildrenHeight = 0;
mPrevScrollY = 0;
mScrollY = 0;
mChildrenHeights = new SparseIntArray();
}
@Override
public void onRestoreInstanceState(Parcelable state) { public void onRestoreInstanceState(Parcelable state) {
SavedState ss = (SavedState) state; SavedState ss = (SavedState) state;
mPrevFirstVisiblePosition = ss.prevFirstVisiblePosition; mPrevFirstVisiblePosition = ss.prevFirstVisiblePosition;
@ -293,6 +306,7 @@ public class ObservableListView extends ListView implements Scrollable {
mScrollY = mPrevScrolledChildrenHeight - firstVisibleChild.getTop(); mScrollY = mPrevScrolledChildrenHeight - firstVisibleChild.getTop();
mPrevFirstVisiblePosition = firstVisiblePosition; mPrevFirstVisiblePosition = firstVisiblePosition;
/*
mCallbacks.onScrollChanged(mScrollY, mFirstScroll, mDragging); mCallbacks.onScrollChanged(mScrollY, mFirstScroll, mDragging);
if (mFirstScroll) { if (mFirstScroll) {
mFirstScroll = false; mFirstScroll = false;
@ -306,11 +320,38 @@ public class ObservableListView extends ListView implements Scrollable {
mScrollState = ScrollState.STOP; mScrollState = ScrollState.STOP;
} }
mPrevScrollY = mScrollY; mPrevScrollY = mScrollY;
*/
} }
} }
} }
} }
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mCallbacks != null) {
//mScrollY = t;
mCallbacks.onScrollChanged(mScrollY + t, mFirstScroll, mDragging);
if (mFirstScroll) {
mFirstScroll = false;
}
if (mPrevScrollY < t) {
mScrollState = ScrollState.UP;
} else if (t < mPrevScrollY) {
mScrollState = ScrollState.DOWN;
//} else {
// Keep previous state while dragging.
// Never makes it STOP even if scrollY not changed.
// Before Android 4.4, onTouchEvent calls onScrollChanged directly for ACTION_MOVE,
// which makes mScrollState always STOP when onUpOrCancelMotionEvent is called.
// STOP state is now meaningless for ScrollView.
}
mPrevScrollY = t;
}
}
static class SavedState extends BaseSavedState { static class SavedState extends BaseSavedState {
int prevFirstVisiblePosition; int prevFirstVisiblePosition;
int prevFirstVisibleChildHeight = -1; int prevFirstVisibleChildHeight = -1;

View file

@ -139,13 +139,14 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
private boolean mapLinkedToLocation; private boolean mapLinkedToLocation;
private float mapRotation; private float mapRotation;
private boolean inLocationUpdate = false; private boolean inLocationUpdate = false;
private ListView listView; private DynamicListView listView;
private View listBackgroundView; private View listBackgroundView;
private Toolbar toolbar; private Toolbar toolbar;
private View paddingView; private View paddingView;
private int mFlexibleSpaceImageHeight; private int mFlexibleSpaceImageHeight;
private int mFlexibleBlurSpaceHeight; private int mFlexibleBlurSpaceHeight;
private boolean portrait; private boolean portrait;
private long lastUpOrCancelMotionEventTime;
int baseColor; int baseColor;
@ -209,10 +210,10 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
}; };
toolbar = ((Toolbar) dashboardView.findViewById(R.id.toolbar)); toolbar = ((Toolbar) dashboardView.findViewById(R.id.toolbar));
ObservableScrollView scrollView = ((ObservableScrollView) dashboardView.findViewById(R.id.main_scroll)); ObservableScrollView scrollView = ((ObservableScrollView) dashboardView.findViewById(R.id.main_scroll));
listView = (ListView) dashboardView.findViewById(R.id.dash_list_view); listView = (DynamicListView) dashboardView.findViewById(R.id.dash_list_view);
//listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); //listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setDrawSelectorOnTop(true); listView.setDrawSelectorOnTop(true);
((DynamicListView) listView).setDynamicListViewCallbacks(this); listView.setDynamicListViewCallbacks(this);
// Create a ListView-specific touch listener. ListViews are given special treatment because // Create a ListView-specific touch listener. ListViews are given special treatment because
// by default they handle touches for their list items... i.e. they're in charge of drawing // by default they handle touches for their list items... i.e. they're in charge of drawing
@ -350,7 +351,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
if (AndroidUiHelper.isOrientationPortrait(mapActivity)) { if (AndroidUiHelper.isOrientationPortrait(mapActivity)) {
this.portrait = true; this.portrait = true;
scrollView.setScrollViewCallbacks(this); scrollView.setScrollViewCallbacks(this);
((ObservableListView) listView).setScrollViewCallbacks(this); listView.setScrollViewCallbacks(this);
mFlexibleSpaceImageHeight = mapActivity.getResources().getDimensionPixelSize( mFlexibleSpaceImageHeight = mapActivity.getResources().getDimensionPixelSize(
R.dimen.dashboard_map_top_padding); R.dimen.dashboard_map_top_padding);
mFlexibleBlurSpaceHeight = mapActivity.getResources().getDimensionPixelSize( mFlexibleBlurSpaceHeight = mapActivity.getResources().getDimensionPixelSize(
@ -736,6 +737,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
} else { } else {
scrollView.setVisibility(View.GONE); scrollView.setVisibility(View.GONE);
listViewLayout.setVisibility(View.VISIBLE); listViewLayout.setVisibility(View.VISIBLE);
listView.scrollTo(0, 0);
listView.clearParams();
if (listView instanceof ObservableListView) { if (listView instanceof ObservableListView) {
onScrollChanged(listView.getScrollY(), false, false); onScrollChanged(listView.getScrollY(), false, false);
} }
@ -844,7 +847,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
OnItemClickListener listener = waypointDialogHelper.getDrawerItemClickListener(mapActivity, running, OnItemClickListener listener = waypointDialogHelper.getDrawerItemClickListener(mapActivity, running,
listAdapter); listAdapter);
setDynamicListItems((DynamicListView) listView, listAdapter); setDynamicListItems(listView, listAdapter);
updateListAdapter(listAdapter, listener); updateListAdapter(listAdapter, listener);
} else if (DashboardType.MAP_MARKERS == visibleType || visibleType == DashboardType.MAP_MARKERS_SELECTION) { } else if (DashboardType.MAP_MARKERS == visibleType || visibleType == DashboardType.MAP_MARKERS_SELECTION) {
@ -854,7 +857,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
StableArrayAdapter listAdapter = mapMarkerDialogHelper.getMapMarkersListAdapter(); StableArrayAdapter listAdapter = mapMarkerDialogHelper.getMapMarkersListAdapter();
OnItemClickListener listener = mapMarkerDialogHelper.getItemClickListener(listAdapter); OnItemClickListener listener = mapMarkerDialogHelper.getItemClickListener(listAdapter);
setDynamicListItems((DynamicListView) listView, listAdapter); setDynamicListItems(listView, listAdapter);
updateListAdapter(listAdapter, listener); updateListAdapter(listAdapter, listener);
} else { } else {
@ -901,7 +904,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
View v = listView.getChildAt(0); View v = listView.getChildAt(0);
int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop()); int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop());
updateListAdapter(); updateListAdapter();
listView.setSelectionFromTop(index, top); ((ListView)listView).setSelectionFromTop(index, top);
} else { } else {
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
@ -1101,7 +1104,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
((DashLocationFragment) df.get()).updateLocation(centerChanged, locationChanged, compassChanged); ((DashLocationFragment) df.get()).updateLocation(centerChanged, locationChanged, compassChanged);
} }
} }
if (visibleType == DashboardType.MAP_MARKERS || visibleType == DashboardType.MAP_MARKERS_SELECTION) { if ((visibleType == DashboardType.MAP_MARKERS || visibleType == DashboardType.MAP_MARKERS_SELECTION)
&& !listView.isDragging()
&& System.currentTimeMillis() - lastUpOrCancelMotionEventTime > 1000) {
mapMarkerDialogHelper.updateLocation(listView, compassChanged); mapMarkerDialogHelper.updateLocation(listView, compassChanged);
} }
} }
@ -1276,16 +1281,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
@Override @Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) { public void onUpOrCancelMotionEvent(ScrollState scrollState) {
// ActionBar ab = getSupportActionBar(); lastUpOrCancelMotionEventTime = System.currentTimeMillis();
// if (scrollState == ScrollState.UP) {
// if (ab.isShowing()) {
// ab.hide();
// }
// } else if (scrollState == ScrollState.DOWN) {
// if (!ab.isShowing()) {
// ab.show();
// }
// }
} }
@ -1431,9 +1427,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
} else if (DashboardType.MAP_MARKERS == visibleType || visibleType == DashboardType.MAP_MARKERS_SELECTION) { } else if (DashboardType.MAP_MARKERS == visibleType || visibleType == DashboardType.MAP_MARKERS_SELECTION) {
mapMarkerDialogHelper.reloadListAdapter(stableAdapter); mapMarkerDialogHelper.reloadListAdapter(stableAdapter);
} }
if (listView instanceof DynamicListView) { setDynamicListItems(listView, stableAdapter);
setDynamicListItems((DynamicListView) listView, stableAdapter);
}
} }
} }