Fix database

(cherry picked from commit 50ebbee)
This commit is contained in:
PavelRatushnyi 2017-07-22 18:07:45 +03:00
parent cd4eca222e
commit df4d926b38
3 changed files with 42 additions and 10 deletions

View file

@ -13,7 +13,7 @@ import java.util.List;
public class GPXDatabase { public class GPXDatabase {
private static final String DB_NAME = "gpx_database"; private static final String DB_NAME = "gpx_database";
private static final int DB_VERSION = 4; private static final int DB_VERSION = 5;
private static final String GPX_TABLE_NAME = "gpxTable"; private static final String GPX_TABLE_NAME = "gpxTable";
private static final String GPX_COL_NAME = "fileName"; private static final String GPX_COL_NAME = "fileName";
private static final String GPX_COL_DIR = "fileDir"; private static final String GPX_COL_DIR = "fileDir";
@ -183,11 +183,43 @@ public class GPXDatabase {
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_TYPE + " int"); db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_TYPE + " int");
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_INTERVAL + " double"); db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_INTERVAL + " double");
} }
if (oldVersion < 3) { if (oldVersion < 5) {
List<GpxDataItem> items = getItems(); boolean colorColumnExists = false;
for (GpxDataItem item : items) { boolean fileLastModifiedTimeColumnExists = false;
updateLastModifiedTime(item); boolean splitTypeColumnExists = false;
boolean splitIntervalColumnExists = false;
SQLiteCursor cursor = db.rawQuery("PRAGMA table_info(" + GPX_TABLE_NAME + ")", null);
if (cursor.moveToFirst()) {
do {
String columnName = cursor.getString(1);
if (!colorColumnExists && columnName.equals(GPX_COL_COLOR)) {
colorColumnExists = true;
} else if (!fileLastModifiedTimeColumnExists && columnName.equals(GPX_COL_FILE_LAST_MODIFIED_TIME)) {
fileLastModifiedTimeColumnExists = true;
} else if (!splitTypeColumnExists && columnName.equals(GPX_COL_SPLIT_TYPE)) {
splitTypeColumnExists = true;
} else if (!splitIntervalColumnExists && columnName.equals(GPX_COL_SPLIT_INTERVAL)) {
splitIntervalColumnExists = true;
}
} while (cursor.moveToNext());
}
cursor.close();
if (!colorColumnExists) {
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_COLOR + " TEXT");
}
if (!fileLastModifiedTimeColumnExists) {
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_FILE_LAST_MODIFIED_TIME + " long");
List<GpxDataItem> items = getItems();
for (GpxDataItem item : items) {
updateLastModifiedTime(item);
}
}
if (!splitTypeColumnExists) {
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_TYPE + " int");
}
if (!splitIntervalColumnExists) {
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_INTERVAL + " double");
} }
} }
} }

View file

@ -165,7 +165,7 @@ public class DashTrackFragment extends DashBaseFragment {
info.subfolder = ""; info.subfolder = "";
info.file = f; info.file = f;
View v = inflater.inflate(R.layout.dash_gpx_track_item, null, false); View v = inflater.inflate(R.layout.dash_gpx_track_item, null, false);
AvailableGPXFragment.udpateGpxInfoView(v, info, app, true); AvailableGPXFragment.updateGpxInfoView(v, info, app, true);
v.setOnClickListener(new View.OnClickListener() { v.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -257,7 +257,7 @@ public class DashTrackFragment extends DashBaseFragment {
AvailableGPXFragment.GpxInfo info = new AvailableGPXFragment.GpxInfo(); AvailableGPXFragment.GpxInfo info = new AvailableGPXFragment.GpxInfo();
info.subfolder = ""; info.subfolder = "";
info.file = f; info.file = f;
AvailableGPXFragment.udpateGpxInfoView(pView, info, app, true); AvailableGPXFragment.updateGpxInfoView(pView, info, app, true);
updateShowOnMap(app, f, v, showOnMap); updateShowOnMap(app, f, v, showOnMap);
} }
}); });

View file

@ -1048,7 +1048,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
LayoutInflater inflater = getActivity().getLayoutInflater(); LayoutInflater inflater = getActivity().getLayoutInflater();
v = inflater.inflate(R.layout.dash_gpx_track_item, parent, false); v = inflater.inflate(R.layout.dash_gpx_track_item, parent, false);
} }
udpateGpxInfoView(v, child, app, false); updateGpxInfoView(v, child, app, false);
ImageView icon = (ImageView) v.findViewById(R.id.icon); ImageView icon = (ImageView) v.findViewById(R.id.icon);
ImageButton options = (ImageButton) v.findViewById(R.id.options); ImageButton options = (ImageButton) v.findViewById(R.id.options);
@ -1752,7 +1752,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
} }
} }
public static void udpateGpxInfoView(View v, GpxInfo child, OsmandApplication app, boolean isDashItem) { public static void updateGpxInfoView(View v, GpxInfo child, OsmandApplication app, boolean isDashItem) {
TextView viewName = ((TextView) v.findViewById(R.id.name)); TextView viewName = ((TextView) v.findViewById(R.id.name));
if (!isDashItem) { if (!isDashItem) {
v.findViewById(R.id.divider_list).setVisibility(View.VISIBLE); v.findViewById(R.id.divider_list).setVisibility(View.VISIBLE);