Updated currently showing on map
This commit is contained in:
parent
494b0c2652
commit
1568c96e9e
3 changed files with 121 additions and 56 deletions
|
@ -51,10 +51,18 @@
|
|||
android:id="@+id/turn_off_all"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="?attr/dashboardGeneralButtonStyle"
|
||||
android:textColor="@color/color_distance"
|
||||
android:text="@string/turn_off_all"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
|
||||
<ListView
|
||||
android:id="@+id/gpx_on_map"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -100,12 +100,7 @@
|
|||
android:src="@drawable/ic_action_gsave_dark"/>
|
||||
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/check"
|
||||
android:layout_width="@dimen/list_item_height"
|
||||
android:layout_height="@dimen/list_item_height"
|
||||
android:focusable="false"
|
||||
android:visibility="gone"/>
|
||||
<include layout="@layout/check_item_rel" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ import android.widget.Filter;
|
|||
import android.widget.Filterable;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
@ -82,8 +83,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
private List<GpxInfo> selectedItems = new ArrayList<>();
|
||||
private ActionMode actionMode;
|
||||
private LoadGpxTask asyncLoader;
|
||||
private GpxIndexesAdapter listAdapter;
|
||||
private ShowedOnMapAdapter showOnMapAdapter;
|
||||
private GpxIndexesAdapter allGpxAdapter;
|
||||
private ShowedOnMapAdapter showOnMapGpxAdapter;
|
||||
MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
|
||||
private LoadLocalIndexDescriptionTask descriptionLoader;
|
||||
private ContextMenuAdapter optionsMenuAdapter;
|
||||
|
@ -102,8 +103,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
asyncLoader = new LoadGpxTask();
|
||||
selectedGpxHelper = ((OsmandApplication) activity.getApplication()).getSelectedGpxHelper();
|
||||
savingTrackHelper = ((OsmandApplication) activity.getApplication()).getSavingTrackHelper();
|
||||
listAdapter = new GpxIndexesAdapter(getActivity());
|
||||
setAdapter(listAdapter);
|
||||
allGpxAdapter = new GpxIndexesAdapter(getActivity());
|
||||
setAdapter(allGpxAdapter);
|
||||
}
|
||||
|
||||
public List<GpxInfo> getSelectedItems() {
|
||||
|
@ -123,8 +124,14 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
|
||||
private void createShowedOnMapsView(View v) {
|
||||
ListView onMap = (ListView) v.findViewById(R.id.gpx_on_map);
|
||||
showOnMapAdapter = new ShowedOnMapAdapter(getActivity(), R.layout.dash_gpx_track_item);
|
||||
onMap.setAdapter(showOnMapAdapter);
|
||||
showOnMapGpxAdapter = new ShowedOnMapAdapter(getActivity(), R.layout.dash_gpx_track_item);
|
||||
onMap.setAdapter(showOnMapGpxAdapter);
|
||||
v.findViewById(R.id.turn_off_all).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showOnMapGpxAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -140,11 +147,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
if (visibility) {
|
||||
//temporary hiding this view
|
||||
v.findViewById(R.id.show_on_map).setVisibility(View.GONE);
|
||||
/* if (visibility) {
|
||||
v.findViewById(R.id.on_map_layout).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
v.findViewById(R.id.on_map_layout).setVisibility(View.GONE);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private void updateCurrentTrack(View v) {
|
||||
|
@ -257,13 +266,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
listAdapter.getFilter().filter(query);
|
||||
allGpxAdapter.getFilter().filter(query);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
listAdapter.getFilter().filter(newText);
|
||||
allGpxAdapter.getFilter().filter(newText);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -394,7 +403,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
private void openShowOnMapMode() {
|
||||
enableSelectionMode(true);
|
||||
selectedItems.clear();
|
||||
final Set<GpxInfo> originalSelectedItems = listAdapter.getSelectedGpx();
|
||||
final Set<GpxInfo> originalSelectedItems = allGpxAdapter.getSelectedGpx();
|
||||
selectedItems.addAll(originalSelectedItems);
|
||||
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
|
||||
|
||||
|
@ -435,11 +444,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
enableSelectionMode(false);
|
||||
getView().findViewById(R.id.memory_size).setVisibility(View.GONE);
|
||||
runSelection(false);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
});
|
||||
listAdapter.notifyDataSetChanged();
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
|
@ -451,7 +460,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
value = value.substring(0, value.length() - 3);
|
||||
}
|
||||
final String actionButton = value;
|
||||
if (listAdapter.getGroupCount() == 0) {
|
||||
if (allGpxAdapter.getGroupCount() == 0) {
|
||||
AccessibleToast.makeText(getActivity(), app.getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
@ -496,7 +505,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
public void onDestroyActionMode(ActionMode mode) {
|
||||
enableSelectionMode(false);
|
||||
getView().findViewById(R.id.memory_size).setVisibility(View.GONE);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -505,7 +514,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
((TextView) getView().findViewById(R.id.memory_size)).setText(R.string.local_index_upload_gpx_description);
|
||||
((TextView) getView().findViewById(R.id.memory_size)).setVisibility(View.VISIBLE);
|
||||
}
|
||||
listAdapter.notifyDataSetChanged();
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void renameFile(GpxInfo info) {
|
||||
|
@ -555,7 +564,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
loadGpxAsync(info, resId == R.string.local_index_select_gpx_file);
|
||||
} else {
|
||||
getMyApplication().getSelectedGpxHelper().selectGpxFile(info.gpx, resId == R.string.local_index_select_gpx_file, true);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
showOnMapGpxAdapter.addGpxInfo(info);
|
||||
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
selectedGpxHelper.runUiListeners();
|
||||
}
|
||||
} else if (resId == R.string.local_index_mi_delete) {
|
||||
|
@ -615,6 +626,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
e = false;
|
||||
getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(info.gpx);
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
if (showOnMapGpxAdapter.getCount() == 0) {
|
||||
setShowedOnMapVisibility(true);
|
||||
}
|
||||
showOnMapGpxAdapter.addGpxInfo(info);
|
||||
}
|
||||
}
|
||||
if (e) {
|
||||
|
@ -644,37 +659,37 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
@Override
|
||||
protected void onPreExecute() {
|
||||
((ActionBarActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(true);
|
||||
listAdapter.clear();
|
||||
if (showOnMapAdapter != null) {
|
||||
showOnMapAdapter.clear();
|
||||
allGpxAdapter.clear();
|
||||
if (showOnMapGpxAdapter != null) {
|
||||
showOnMapGpxAdapter.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(GpxInfo... values) {
|
||||
for (GpxInfo v : values) {
|
||||
listAdapter.addLocalIndexInfo(v);
|
||||
allGpxAdapter.addLocalIndexInfo(v);
|
||||
if (selectedGpxHelper.getSelectedFileByName(v.getFileName()) != null) {
|
||||
showOnMapAdapter.add(v);
|
||||
showOnMapGpxAdapter.addGpxInfo(v);
|
||||
}
|
||||
}
|
||||
showOnMapAdapter.notifyDataSetChanged();
|
||||
listAdapter.notifyDataSetChanged();
|
||||
showOnMapGpxAdapter.notifyDataSetChanged();
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setResult(List<GpxInfo> result) {
|
||||
this.result = result;
|
||||
listAdapter.clear();
|
||||
showOnMapAdapter.clear();
|
||||
allGpxAdapter.clear();
|
||||
showOnMapGpxAdapter.clear();
|
||||
if (result != null) {
|
||||
for (GpxInfo v : result) {
|
||||
listAdapter.addLocalIndexInfo(v);
|
||||
allGpxAdapter.addLocalIndexInfo(v);
|
||||
if (selectedGpxHelper.getSelectedFileByName(v.getFileName()) != null) {
|
||||
showOnMapAdapter.add(v);
|
||||
showOnMapGpxAdapter.addGpxInfo(v);
|
||||
}
|
||||
}
|
||||
listAdapter.notifyDataSetChanged();
|
||||
showOnMapAdapter.notifyDataSetChanged();
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
showOnMapGpxAdapter.notifyDataSetChanged();
|
||||
onPostExecute(result);
|
||||
}
|
||||
}
|
||||
|
@ -685,11 +700,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
if (getActivity() != null) {
|
||||
((ActionBarActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(false);
|
||||
}
|
||||
if (listAdapter.getGroupCount() > 0) {
|
||||
if (allGpxAdapter.getGroupCount() > 0) {
|
||||
getExpandableListView().expandGroup(0);
|
||||
}
|
||||
|
||||
if (showOnMapAdapter.getCount() > 0) {
|
||||
if (showOnMapGpxAdapter.getCount() > 0) {
|
||||
setShowedOnMapVisibility(true);
|
||||
} else {
|
||||
setShowedOnMapVisibility(false);
|
||||
|
@ -1082,13 +1097,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
|
||||
@Override
|
||||
protected void onProgressUpdate(GpxInfo... values) {
|
||||
listAdapter.notifyDataSetChanged();
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(GpxInfo[] result) {
|
||||
hideProgressBar();
|
||||
listAdapter.notifyDataSetChanged();
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
|
||||
|
@ -1118,9 +1133,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
@Override
|
||||
protected void onProgressUpdate(GpxInfo... values) {
|
||||
for (GpxInfo g : values) {
|
||||
listAdapter.delete(g);
|
||||
allGpxAdapter.delete(g);
|
||||
}
|
||||
listAdapter.notifyDataSetChanged();
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1166,7 +1181,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
toShow = g.gpx.findPointToShow();
|
||||
}
|
||||
}
|
||||
listAdapter.notifyDataSetInvalidated();
|
||||
allGpxAdapter.notifyDataSetInvalidated();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1218,7 +1233,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
if (info.gpx != null) {
|
||||
getMyApplication().getSelectedGpxHelper().selectGpxFile(info.gpx, selected, true);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
selectedGpxHelper.runUiListeners();
|
||||
}
|
||||
}
|
||||
|
@ -1254,18 +1269,18 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
if (results.values != null) {
|
||||
synchronized (listAdapter) {
|
||||
listAdapter.clear();
|
||||
showOnMapAdapter.clear();
|
||||
synchronized (allGpxAdapter) {
|
||||
allGpxAdapter.clear();
|
||||
showOnMapGpxAdapter.clear();
|
||||
for (GpxInfo i : ((List<GpxInfo>) results.values)) {
|
||||
listAdapter.addLocalIndexInfo(i);
|
||||
allGpxAdapter.addLocalIndexInfo(i);
|
||||
if (selectedGpxHelper.getSelectedFileByName(i.getFileName()) != null) {
|
||||
showOnMapAdapter.add(i);
|
||||
showOnMapGpxAdapter.addGpxInfo(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
showOnMapAdapter.notifyDataSetChanged();
|
||||
listAdapter.notifyDataSetChanged();
|
||||
showOnMapGpxAdapter.notifyDataSetChanged();
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
if (constraint != null && constraint.length() > 3) {
|
||||
collapseTrees(10);
|
||||
}
|
||||
|
@ -1287,7 +1302,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
||||
GpxInfo item = listAdapter.getChild(groupPosition, childPosition);
|
||||
GpxInfo item = allGpxAdapter.getChild(groupPosition, childPosition);
|
||||
if (!selectionMode) {
|
||||
item.setExpanded(!item.isExpanded());
|
||||
if (item.isExpanded()) {
|
||||
|
@ -1302,7 +1317,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
updateSelectionMode(actionMode);
|
||||
}
|
||||
listAdapter.notifyDataSetInvalidated();
|
||||
allGpxAdapter.notifyDataSetInvalidated();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1411,8 +1426,40 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private void adjustShowOnMapListViewSize() {
|
||||
View v = getView();
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
float size = getResources().getDimension(R.dimen.dashListItemHeight) * 3.5f;
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) size);
|
||||
getView().findViewById(R.id.gpx_on_map).setLayoutParams(params);
|
||||
}
|
||||
|
||||
class ShowedOnMapAdapter extends ArrayAdapter<GpxInfo> {
|
||||
|
||||
public void addGpxInfo(GpxInfo info) {
|
||||
boolean contains = false;
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
if (getItem(i).equals(info)) {
|
||||
contains = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (contains) {
|
||||
return;
|
||||
}
|
||||
|
||||
add(info);
|
||||
notifyDataSetChanged();
|
||||
|
||||
//if there's too many items, we need to set size of listview
|
||||
if (getCount() == 4) {
|
||||
adjustShowOnMapListViewSize();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ShowedOnMapAdapter(Context context, int resource) {
|
||||
super(context, resource);
|
||||
}
|
||||
|
@ -1425,7 +1472,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
v = inflater.inflate(R.layout.dash_gpx_track_item, parent, false);
|
||||
}
|
||||
|
||||
GpxInfo gpxInfo = getItem(position);
|
||||
final GpxInfo gpxInfo = getItem(position);
|
||||
|
||||
TextView viewName = ((TextView) v.findViewById(R.id.name));
|
||||
viewName.setText(gpxInfo.getName());
|
||||
|
@ -1443,9 +1490,24 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
|
||||
}
|
||||
|
||||
CompoundButton check = (CompoundButton) v.findViewById(R.id.check);
|
||||
final CompoundButton check = (CompoundButton) v.findViewById(R.id.check_item);
|
||||
check.setVisibility(View.VISIBLE);
|
||||
|
||||
if (selectedGpxHelper.getSelectedFileByName(gpxInfo.getFileName()) != null) {
|
||||
check.setChecked(true);
|
||||
} else {
|
||||
check.setChecked(false);
|
||||
}
|
||||
check.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (gpxInfo.gpx == null) {
|
||||
loadGpxAsync(gpxInfo, check.isChecked());
|
||||
} else {
|
||||
selectedGpxHelper.selectGpxFile(gpxInfo.gpx, check.isChecked(), true);
|
||||
}
|
||||
allGpxAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue