diff --git a/OsmAnd/src/net/osmand/FileUtils.java b/OsmAnd/src/net/osmand/FileUtils.java index c24c1ebfa8..4620a38403 100644 --- a/OsmAnd/src/net/osmand/FileUtils.java +++ b/OsmAnd/src/net/osmand/FileUtils.java @@ -46,8 +46,9 @@ public class FileUtils { public void afterTextChanged(Editable s) { Editable text = editText.getText(); if (text.length() >= 1) { - if (ILLEGAL_FILE_NAME_CHARACTERS.matcher(text).find()) { - editText.setError(weakActivity.get().getString(R.string.file_name_containes_illegal_char)); + Activity activity = weakActivity.get(); + if (ILLEGAL_FILE_NAME_CHARACTERS.matcher(text).find() && activity != null) { + editText.setError(activity.getString(R.string.file_name_containes_illegal_char)); } } } @@ -67,16 +68,19 @@ public class FileUtils { new View.OnClickListener() { @Override public void onClick(View v) { - OsmandApplication app = (OsmandApplication) weakActivity.get().getApplication(); - if (ext.equals(SQLiteTileSource.EXT)) { - if (renameSQLiteFile(app, f, editText.getText().toString() + ext, - callback) != null) { - alertDialog.dismiss(); - } - } else { - if (renameGpxFile(app, f, editText.getText().toString() + ext, - false, callback) != null) { - alertDialog.dismiss(); + Activity activity = weakActivity.get(); + if (activity != null) { + OsmandApplication app = (OsmandApplication) activity.getApplication(); + if (ext.equals(SQLiteTileSource.EXT)) { + if (renameSQLiteFile(app, f, editText.getText().toString() + ext, + callback) != null) { + alertDialog.dismiss(); + } + } else { + if (renameGpxFile(app, f, editText.getText().toString() + ext, + false, callback) != null) { + alertDialog.dismiss(); + } } } } diff --git a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java index 1c7d7d17c7..4ef77d76c7 100644 --- a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java +++ b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java @@ -337,6 +337,7 @@ public class SQLiteTileSource implements ITileSource { } public void updateFromTileSourceTemplate(TileSourceTemplate r) { + boolean openedBefore = isDbOpened(); SQLiteConnection db = getDatabase(); if (!onlyReadonlyAvailable && db != null) { int maxZoom = r.getMaximumZoomSupported(); @@ -362,11 +363,15 @@ public class SQLiteTileSource implements ITileSource { db.execSQL("update info set " + EXPIRE_MINUTES + " = '" + r.getExpirationTimeMinutes() + "'"); } } - if (db != null) { + if (db != null && !openedBefore) { db.close(); } } + public boolean isDbOpened() { + return db != null && !db.isClosed(); + } + private void addInfoColumn(SQLiteConnection db, String columnName, String value) { if(!onlyReadonlyAvailable) { try {