Fixed gpx selection dialog

This commit is contained in:
Alexey Kulish 2017-03-10 23:20:54 +03:00
parent 8152b9d9d8
commit 9590370725
3 changed files with 235 additions and 61 deletions

View file

@ -187,7 +187,9 @@
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical"/>
<android.support.v7.widget.AppCompatCheckBox
@ -196,6 +198,9 @@
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:visibility="gone"/>
</LinearLayout>

View file

@ -0,0 +1,204 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:orientation="vertical">
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"
android:visibility="gone"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:minHeight="@dimen/list_item_height"
android:paddingLeft="@dimen/dialog_content_margin"
android:gravity="center_vertical">
<CheckBox
android:id="@+id/check_local_index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:layout_marginRight="@dimen/list_content_padding"
android:visibility="gone"/>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_polygom_dark"
android:layout_marginRight="@dimen/list_content_padding"
android:visibility="visible"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingTop="@dimen/gpx_text_top_margin"
android:paddingBottom="@dimen/gpx_text_top_margin"
android:paddingRight="@dimen/showAllButtonMarginRight"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="@string/current_track"/>
<LinearLayout
android:id="@+id/read_section"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="visible"
android:gravity="center_vertical">
<ImageView
android:id="@+id/distance_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/gpx_small_icon_margin"
android:src="@drawable/ic_small_distance"/>
<TextView
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/gpx_small_text_margin"
android:includeFontPadding="false"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"/>
<ImageView
android:id="@+id/points_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/gpx_small_icon_margin"
android:src="@drawable/ic_small_point"/>
<TextView
android:id="@+id/points_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/gpx_small_text_margin"
android:includeFontPadding="false"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"/>
<ImageView
android:id="@+id/time_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/gpx_small_icon_margin"
android:src="@drawable/ic_small_time"/>
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/gpx_small_text_margin"
android:textColor="?android:textColorSecondary"
android:includeFontPadding="false"
android:textSize="@dimen/default_sub_text_size"/>
</LinearLayout>
<LinearLayout
android:id="@+id/unknown_section"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="@+id/date_and_size_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"/>
</LinearLayout>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_sub_text_size"
android:visibility="gone"/>
</LinearLayout>
<ImageButton
android:id="@+id/show_on_map"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_marginLeft="@dimen/favorites_icon_right_margin"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_action_gsave_dark"
android:visibility="gone"/>
<ImageButton
android:id="@+id/stop"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_action_rec_stop"
android:visibility="gone"/>
<ImageButton
android:id="@+id/options"
android:contentDescription="@string/shared_string_more_actions"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:background="?attr/dashboard_button"
android:focusable="false"
android:src="@drawable/ic_overflow_menu_white"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/check_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:visibility="gone">
<android.support.v7.widget.SwitchCompat
android:id="@+id/toggle_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:paddingRight="@dimen/list_content_padding"
android:gravity="center_vertical"/>
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/toggle_checkbox_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingRight="@dimen/dialog_content_margin"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -60,6 +60,7 @@ import net.osmand.IndexConstants;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXDatabase;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.Elevation;
import net.osmand.plus.GPXUtilities.GPXFile;
@ -424,12 +425,14 @@ public class GpxUiHelper {
final DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(activity);
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final int layout = R.layout.dash_gpx_track_item;
final int layout = R.layout.gpx_track_item;
final Map<String, String> gpxAppearanceParams = new HashMap<>();
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(activity, layout, R.id.title,
adapter.getItemNames()) {
List<GpxDataItem> dataItems = null;
@Override
public int getItemViewType(int position) {
return showCurrentGpx && position == 0 ? 1 : 0;
@ -440,6 +443,17 @@ public class GpxUiHelper {
return 2;
}
private GpxDataItem getDataItem(GPXInfo info) {
if (dataItems != null) {
for (GpxDataItem item : dataItems) {
if (item.getFile().getAbsolutePath().endsWith(info.fileName)) {
return item;
}
}
}
return null;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
@ -449,56 +463,13 @@ public class GpxUiHelper {
v = activity.getLayoutInflater().inflate(layout, null);
}
if (dataItems == null) {
dataItems = app.getGpxDatabase().getItems();
}
final ContextMenuItem item = adapter.getItem(position);
GPXInfo info = list.get(position);
udpateGpxInfoView(v, item, info, showCurrentGpx && position == 0, app);
/*
TextView tv = (TextView) v.findViewById(R.id.title);
TextView dv = (TextView) v.findViewById(R.id.description);
if (showCurrentGpx && position == 0) {
tv.setText(item.getTitle());
dv.setText(OsmAndFormatter.getFormattedDistance(app.getSavingTrackHelper().getDistance(), app));
final SwitchCompat ch = ((SwitchCompat) v.findViewById(R.id.toggle_item));
ch.setOnCheckedChangeListener(null);
ch.setChecked(item.getSelected());
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
item.setSelected(isChecked);
}
});
return v;
}
tv.setText(item.getTitle().replace("/", ""));
GPXInfo info = list.get(position);
GPXDatabase.GpxDataItem dataItem = app.getGpxDatabase().getItem(new File(info.fileName));
StringBuilder sb = new StringBuilder();
if (dataItem != null && dataItem.getAnalysis() != null) {
} else {
if (info.getLastModified() > 0) {
sb.append(dateFormat.format(info.getLastModified()));
}
if (info.getFileSize() >= 0) {
if (sb.length() > 0) {
sb.append("");
}
long fileSizeKB = info.getFileSize() / 1000;
if (info.getFileSize() < 5000) {
sb.append(info.getFileSize()).append(" B");
} else if (fileSizeKB > 100) {
sb.append(formatMb.format(new Object[]{(float) fileSizeKB / (1 << 10)}));
} else {
sb.append(fileSizeKB).append(" kB");
}
}
}
dv.setText(sb.toString());
*/
udpateGpxInfoView(v, item, info, getDataItem(info), showCurrentGpx && position == 0, app);
if (item.getSelected() == null) {
v.findViewById(R.id.check_item).setVisibility(View.GONE);
@ -716,12 +687,9 @@ public class GpxUiHelper {
return dlg;
}
public static void udpateGpxInfoView(View v, ContextMenuItem item, GPXInfo info, boolean currentlyRecordingTrack, OsmandApplication app) {
public static void udpateGpxInfoView(View v, ContextMenuItem item, GPXInfo info, GpxDataItem dataItem, boolean currentlyRecordingTrack, OsmandApplication app) {
TextView viewName = ((TextView) v.findViewById(R.id.name));
v.findViewById(R.id.divider_list).setVisibility(View.GONE);
v.findViewById(R.id.divider_dash).setVisibility(View.GONE);
viewName.setText(item.getTitle().replace("/", ""));
viewName.setText(item.getTitle().replace("/", "").trim());
ImageView icon = (ImageView) v.findViewById(R.id.icon);
icon.setVisibility(View.GONE);
//icon.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_polygom_dark));
@ -730,12 +698,9 @@ public class GpxUiHelper {
GPXTrackAnalysis analysis = null;
if (currentlyRecordingTrack) {
analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis();
} else {
GPXDatabase.GpxDataItem dataItem = app.getGpxDatabase().getItem(new File(info.fileName));
if (dataItem != null) {
} else if (dataItem != null) {
analysis = dataItem.getAnalysis();
}
}
boolean sectionRead = analysis == null;
if (sectionRead) {
@ -874,7 +839,7 @@ public class GpxUiHelper {
if (res != 0) {
return res;
}
return -i1.getFileName().compareTo(i2.getFileName());
return -i1.getFileName().toLowerCase().compareTo(i2.getFileName().toLowerCase());
}
});
return list;